From 675525f47c81669c2afe082efca075b723ba6e4f Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Sun, 19 Apr 2020 19:41:16 -0600 Subject: [PATCH] Ensure existing SimpliSafe notifications trigger event on HASS startup (#34232) * Ensure existing SimpliSafe notifications trigger event on HASS startup * Don't redefine a standing function each loop iteration * Wait until HASS state is "running" * Linting * Linting * Code review * Code review * Simplify * Code review * Cleanup --- homeassistant/components/simplisafe/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index 53a844ccb9a..ae0e119c083 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -24,7 +24,7 @@ from homeassistant.const import ( CONF_TOKEN, CONF_USERNAME, ) -from homeassistant.core import callback +from homeassistant.core import CoreState, callback from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import ( aiohttp_client, @@ -422,6 +422,12 @@ class SimpliSafe: @callback def _async_process_new_notifications(self, system): """Act on any new system notifications.""" + if self._hass.state != CoreState.running: + # If HASS isn't fully running yet, it may cause the SIMPLISAFE_NOTIFICATION + # event to fire before dependent components (like automation) are fully + # ready. If that's the case, skip: + return + old_notifications = self._system_notifications.get(system.system_id, []) latest_notifications = system.notifications