From 03d72ff2ecd30eea21c48257a33e9c68f0dcd58d Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Thu, 23 Apr 2020 10:52:11 -0600 Subject: [PATCH] Handle flaky SimpliSafe notification registration (#34475) --- homeassistant/components/simplisafe/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index ae0e119c083..963195e6f64 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -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