Handle flaky SimpliSafe notification registration (#34475)

pull/34850/head
Aaron Bach 2020-04-23 10:52:11 -06:00 committed by Paulus Schoutsen
parent 1595ed1228
commit 03d72ff2ec
1 changed files with 8 additions and 7 deletions

View File

@ -428,20 +428,19 @@ class SimpliSafe:
# ready. If that's the case, skip:
return
old_notifications = self._system_notifications.get(system.system_id, [])
latest_notifications = system.notifications
latest_notifications = set(system.notifications)
# Save the latest notifications:
self._system_notifications[system.system_id] = latest_notifications
# Process any notifications that are new:
to_add = set(latest_notifications) - set(old_notifications)
to_add = latest_notifications.difference(
self._system_notifications[system.system_id]
)
if not to_add:
return
_LOGGER.debug("New system notifications: %s", to_add)
self._system_notifications[system.system_id].update(to_add)
for notification in to_add:
text = notification.text
if notification.link:
@ -463,6 +462,8 @@ class SimpliSafe:
self.systems = await self._api.get_systems()
for system in self.systems.values():
self._system_notifications[system.system_id] = set()
self._hass.async_create_task(
async_register_base_station(
self._hass, system, self._config_entry.entry_id