From db7c16162d2e2f002f9a63f5dc6a946ad49eb7ac Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Thu, 15 Oct 2020 10:36:04 -0600 Subject: [PATCH] Remove duplicated options handling in SimpliSafe (#41806) * Remove duplicated options handling in SimpliSafe * Incorrect property name --- .../components/simplisafe/__init__.py | 23 +++++++++---------- .../simplisafe/alarm_control_panel.py | 12 +++++----- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index 2699c2b1a56..3a1dfc3b23f 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -349,7 +349,7 @@ async def async_setup_entry(hass, config_entry): ]: async_register_admin_service(hass, DOMAIN, service, method, schema=schema) - config_entry.add_update_listener(async_update_options) + config_entry.add_update_listener(async_reload_entry) return True @@ -372,7 +372,7 @@ async def async_unload_entry(hass, entry): return unload_ok -async def async_update_options(hass, config_entry): +async def async_reload_entry(hass, config_entry): """Handle an options update.""" await hass.config_entries.async_reload(config_entry.entry_id) @@ -439,11 +439,10 @@ class SimpliSafe: def __init__(self, hass, api, config_entry): """Initialize.""" self._api = api - self._config_entry = config_entry self._emergency_refresh_token_used = False self._hass = hass self._system_notifications = {} - self.options = config_entry.options or {} + self.config_entry = config_entry self.initial_event_to_use = {} self.systems = {} self.websocket = SimpliSafeWebsocket(hass, api.websocket) @@ -495,7 +494,7 @@ class SimpliSafe: self._hass.async_create_task( async_register_base_station( - self._hass, system, self._config_entry.entry_id + self._hass, system, self.config_entry.entry_id ) ) @@ -515,7 +514,7 @@ class SimpliSafe: await self.async_update() self._hass.data[DOMAIN][DATA_LISTENER][ - self._config_entry.entry_id + self.config_entry.entry_id ] = async_track_time_interval(self._hass, refresh, DEFAULT_SCAN_INTERVAL) await self.async_update() @@ -543,7 +542,7 @@ class SimpliSafe: for flow in self._hass.config_entries.flow.async_progress() if flow["context"].get("source") == SOURCE_REAUTH and flow["context"].get("unique_id") - == self._config_entry.unique_id + == self.config_entry.unique_id ] if not matching_flows: @@ -552,9 +551,9 @@ class SimpliSafe: DOMAIN, context={ "source": SOURCE_REAUTH, - "unique_id": self._config_entry.unique_id, + "unique_id": self.config_entry.unique_id, }, - data=self._config_entry.data, + data=self.config_entry.data, ) ) @@ -565,7 +564,7 @@ class SimpliSafe: try: await self._api.refresh_access_token( - self._config_entry.data[CONF_TOKEN] + self.config_entry.data[CONF_TOKEN] ) return except SimplipyError as err: @@ -587,9 +586,9 @@ class SimpliSafe: LOGGER.error("Unknown error while updating: %s", result) return - if self._api.refresh_token != self._config_entry.data[CONF_TOKEN]: + if self._api.refresh_token != self.config_entry.data[CONF_TOKEN]: _async_save_refresh_token( - self._hass, self._config_entry, self._api.refresh_token + self._hass, self.config_entry, self._api.refresh_token ) # If we've reached this point using an emergency refresh token, we're in the diff --git a/homeassistant/components/simplisafe/alarm_control_panel.py b/homeassistant/components/simplisafe/alarm_control_panel.py index acc7e3bb0a8..11f794eef5d 100644 --- a/homeassistant/components/simplisafe/alarm_control_panel.py +++ b/homeassistant/components/simplisafe/alarm_control_panel.py @@ -119,11 +119,11 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity): @property def code_format(self): """Return one or more digits/characters.""" - if not self._simplisafe.options.get(CONF_CODE): + if not self._simplisafe.config_entry.options.get(CONF_CODE): return None - if isinstance(self._simplisafe.options[CONF_CODE], str) and re.search( - "^\\d+$", self._simplisafe.options[CONF_CODE] - ): + if isinstance( + self._simplisafe.config_entry.options[CONF_CODE], str + ) and re.search("^\\d+$", self._simplisafe.config_entry.options[CONF_CODE]): return FORMAT_NUMBER return FORMAT_TEXT @@ -140,10 +140,10 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity): @callback def _is_code_valid(self, code, state): """Validate that a code matches the required one.""" - if not self._simplisafe.options.get(CONF_CODE): + if not self._simplisafe.config_entry.options.get(CONF_CODE): return True - if not code or code != self._simplisafe.options[CONF_CODE]: + if not code or code != self._simplisafe.config_entry.options[CONF_CODE]: LOGGER.warning( "Incorrect alarm code entered (target state: %s): %s", state, code )