mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Fix error where SimpliSafe websocket would disconnect and not reconnect (#32199)
* Fix error where SimpliSafe websocket would disconnect and not reconnect * Await
This commit is contained in:
parent
5a67d73a37
commit
e435f6eb67
@ -474,16 +474,9 @@ class SimpliSafe:
|
|||||||
|
|
||||||
tasks = [update_system(system) for system in self.systems.values()]
|
tasks = [update_system(system) for system in self.systems.values()]
|
||||||
|
|
||||||
def cancel_tasks():
|
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||||
"""Cancel tasks and ensure their cancellation is processed."""
|
for result in results:
|
||||||
for task in tasks:
|
if isinstance(result, InvalidCredentialsError):
|
||||||
task.cancel()
|
|
||||||
|
|
||||||
try:
|
|
||||||
await asyncio.gather(*tasks)
|
|
||||||
except InvalidCredentialsError:
|
|
||||||
cancel_tasks()
|
|
||||||
|
|
||||||
if self._emergency_refresh_token_used:
|
if self._emergency_refresh_token_used:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"SimpliSafe authentication disconnected. Please restart HASS."
|
"SimpliSafe authentication disconnected. Please restart HASS."
|
||||||
@ -499,16 +492,21 @@ class SimpliSafe:
|
|||||||
return await self._api.refresh_access_token(
|
return await self._api.refresh_access_token(
|
||||||
self._config_entry.data[CONF_TOKEN]
|
self._config_entry.data[CONF_TOKEN]
|
||||||
)
|
)
|
||||||
except SimplipyError as err:
|
|
||||||
cancel_tasks()
|
if isinstance(result, SimplipyError):
|
||||||
_LOGGER.error("SimpliSafe error while updating: %s", err)
|
_LOGGER.error("SimpliSafe error while updating: %s", result)
|
||||||
return
|
return
|
||||||
except Exception as err: # pylint: disable=broad-except
|
|
||||||
cancel_tasks()
|
if isinstance(result, SimplipyError):
|
||||||
_LOGGER.error("Unknown error while updating: %s", err)
|
_LOGGER.error("Unknown error while updating: %s", result)
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._api.refresh_token_dirty:
|
if self._api.refresh_token_dirty:
|
||||||
|
# Reconnect the websocket:
|
||||||
|
await self._api.websocket.async_disconnect()
|
||||||
|
await self._api.websocket.async_connect()
|
||||||
|
|
||||||
|
# Save the new refresh token:
|
||||||
_async_save_refresh_token(
|
_async_save_refresh_token(
|
||||||
self._hass, self._config_entry, self._api.refresh_token
|
self._hass, self._config_entry, self._api.refresh_token
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user