1
mirror of https://github.com/home-assistant/core synced 2024-09-09 12:51:22 +02:00

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 <nick@koston.org>

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
RDFurman 2021-09-29 15:10:22 -06:00 committed by GitHub
parent 18340b2fd9
commit f8903e11e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,15 +43,30 @@ async def async_setup_entry(hass, config):
_LOGGER.debug("No devices found") _LOGGER.debug("No devices found")
return False return False
data = HoneywellData(hass, client, username, password, devices) data = HoneywellData(hass, config, client, username, password, devices)
await data.async_update() await data.async_update()
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][config.entry_id] = data hass.data[DOMAIN][config.entry_id] = data
hass.config_entries.async_setup_platforms(config, PLATFORMS) hass.config_entries.async_setup_platforms(config, PLATFORMS)
config.async_on_unload(config.add_update_listener(update_listener))
return True 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): def get_somecomfort_client(username, password):
"""Initialize the somecomfort client.""" """Initialize the somecomfort client."""
try: try:
@ -70,9 +85,10 @@ def get_somecomfort_client(username, password):
class HoneywellData: class HoneywellData:
"""Get the latest data and update.""" """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.""" """Initialize the data object."""
self._hass = hass self._hass = hass
self._config = config
self._client = client self._client = client
self._username = username self._username = username
self._password = password self._password = password
@ -102,6 +118,7 @@ class HoneywellData:
return False return False
self.devices = devices self.devices = devices
await self._hass.config_entries.async_reload(self._config.entry_id)
return True return True
async def _refresh_devices(self): async def _refresh_devices(self):
@ -120,8 +137,9 @@ class HoneywellData:
break break
except ( except (
somecomfort.client.APIRateLimited, somecomfort.client.APIRateLimited,
OSError, somecomfort.client.ConnectionError,
somecomfort.client.ConnectionTimeout, somecomfort.client.ConnectionTimeout,
OSError,
) as exp: ) as exp:
retries -= 1 retries -= 1
if retries == 0: if retries == 0: