Skip to content

Commit

Permalink
2022.12.4
Browse files Browse the repository at this point in the history
- Move Distance Unit config override to OAuth setup config
  • Loading branch information
craibo committed Dec 15, 2022
1 parent 5feab86 commit 6844d5e
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions custom_components/ha_strava/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def __init__(self):
self._config_entry_title = None
self._import_strava_images = None
self._img_update_interval_seconds = None
self._config_distance_unit_override = None

async def show_form_init(self):
"""
Expand Down Expand Up @@ -103,13 +102,6 @@ async def show_form_init(self):
ha_strava_config_entries[0].data.get(CONF_PHOTOS),
),
): bool,
vol.Required(
CONF_DISTANCE_UNIT_OVERRIDE,
default=ha_strava_config_entries[0].options.get(
CONF_DISTANCE_UNIT_OVERRIDE,
CONF_DISTANCE_UNIT_OVERRIDE_DEFAULT,
),
): vol.In(DISTANCE_UNIT_OVERRIDE_OPTIONS),
}
),
)
Expand Down Expand Up @@ -161,7 +153,6 @@ async def async_step_init(self, user_input=None):
self._nb_activities = user_input.get(CONF_NB_ACTIVITIES)
self._import_strava_images = user_input.get(CONF_PHOTOS)
self._img_update_interval_seconds = int(user_input.get(CONF_IMG_UPDATE_INTERVAL_SECONDS))
self._config_distance_unit_override = user_input.get(CONF_DISTANCE_UNIT_OVERRIDE)
self._config_entry_title = ha_strava_config_entries[0].title

ha_strava_options = { # pylint: disable=unnecessary-comprehension
Expand All @@ -173,9 +164,6 @@ async def async_step_init(self, user_input=None):
CONF_IMG_UPDATE_INTERVAL_SECONDS
] = self._img_update_interval_seconds
ha_strava_options[CONF_PHOTOS] = self._import_strava_images
ha_strava_options[
CONF_DISTANCE_UNIT_OVERRIDE
] = self._config_distance_unit_override

_LOGGER.debug(f"Strava Config Options: {ha_strava_options}")
return self.async_create_entry(
Expand All @@ -193,6 +181,7 @@ class OAuth2FlowHandler(
DOMAIN = DOMAIN
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_PUSH
_import_photos_from_strava = True
_distance_unit_override_metric = CONF_DISTANCE_UNIT_OVERRIDE_DEFAULT

@property
def logger(self) -> logging.Logger:
Expand Down Expand Up @@ -220,6 +209,10 @@ async def async_step_get_oauth_info(self, user_input=None):
vol.Required(CONF_CLIENT_ID): str,
vol.Required(CONF_CLIENT_SECRET): str,
vol.Required(CONF_PHOTOS, default=self._import_photos_from_strava): bool,
vol.Required(
CONF_DISTANCE_UNIT_OVERRIDE,
default=self._distance_unit_override_metric
): vol.In(DISTANCE_UNIT_OVERRIDE_OPTIONS),
}

assert self.hass is not None
Expand All @@ -234,6 +227,7 @@ async def async_step_get_oauth_info(self, user_input=None):

if user_input is not None:
self._import_photos_from_strava = user_input[CONF_PHOTOS]
self._distance_unit_override_metric = user_input[CONF_DISTANCE_UNIT_OVERRIDE]
config_entry_oauth2_flow.async_register_implementation(
self.hass,
DOMAIN,
Expand All @@ -259,6 +253,7 @@ async def async_oauth_create_entry(self, data: dict) -> dict:
data[CONF_CLIENT_ID] = self.flow_impl.client_id
data[CONF_CLIENT_SECRET] = self.flow_impl.client_secret
data[CONF_PHOTOS] = self._import_photos_from_strava
data[CONF_DISTANCE_UNIT_OVERRIDE] = self._distance_unit_override_metric

return self.async_create_entry(title=CONFIG_ENTRY_TITLE, data=data)

Expand Down

0 comments on commit 6844d5e

Please sign in to comment.