From f8903e11e0f95f9e123c02ce98891a869986e7b9 Mon Sep 17 00:00:00 2001 From: RDFurman Date: Wed, 29 Sep 2021 15:10:22 -0600 Subject: [PATCH] Fix honeywell connection error (#56757) * Catch ConnectionError and retry * Add unload and reload functionality * Update listener on retry * Call reload directly and await Co-authored-by: J. Nick Koston Co-authored-by: J. Nick Koston --- .../components/honeywell/__init__.py | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/honeywell/__init__.py b/homeassistant/components/honeywell/__init__.py index 03dc9ea9c8c..c61e4fc18eb 100644 --- a/homeassistant/components/honeywell/__init__.py +++ b/homeassistant/components/honeywell/__init__.py @@ -43,15 +43,30 @@ async def async_setup_entry(hass, config): _LOGGER.debug("No devices found") return False - data = HoneywellData(hass, client, username, password, devices) + data = HoneywellData(hass, config, client, username, password, devices) await data.async_update() hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][config.entry_id] = data hass.config_entries.async_setup_platforms(config, PLATFORMS) + config.async_on_unload(config.add_update_listener(update_listener)) + return True +async def update_listener(hass, config) -> None: + """Update listener.""" + await hass.config_entries.async_reload(config.entry_id) + + +async def async_unload_entry(hass, config): + """Unload the config config and platforms.""" + unload_ok = await hass.config_entries.async_unload_platforms(config, PLATFORMS) + if unload_ok: + hass.data.pop(DOMAIN) + return unload_ok + + def get_somecomfort_client(username, password): """Initialize the somecomfort client.""" try: @@ -70,9 +85,10 @@ def get_somecomfort_client(username, password): class HoneywellData: """Get the latest data and update.""" - def __init__(self, hass, client, username, password, devices): + def __init__(self, hass, config, client, username, password, devices): """Initialize the data object.""" self._hass = hass + self._config = config self._client = client self._username = username self._password = password @@ -102,6 +118,7 @@ class HoneywellData: return False self.devices = devices + await self._hass.config_entries.async_reload(self._config.entry_id) return True async def _refresh_devices(self): @@ -120,8 +137,9 @@ class HoneywellData: break except ( somecomfort.client.APIRateLimited, - OSError, + somecomfort.client.ConnectionError, somecomfort.client.ConnectionTimeout, + OSError, ) as exp: retries -= 1 if retries == 0: