Properly unload listener for SimpliSafe config entry updates (#42579)

This commit is contained in:
Aaron Bach 2020-11-04 12:28:43 -07:00 committed by GitHub
parent 9bb1c6f188
commit b0a6ac7e91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -177,6 +177,8 @@ async def async_setup(hass, config):
async def async_setup_entry(hass, config_entry):
"""Set up SimpliSafe as config entry."""
hass.data[DOMAIN][DATA_LISTENER][config_entry.entry_id] = []
entry_updates = {}
if not config_entry.unique_id:
# If the config entry doesn't already have a unique ID, set one:
@ -312,7 +314,9 @@ async def async_setup_entry(hass, config_entry):
]:
async_register_admin_service(hass, DOMAIN, service, method, schema=schema)
hass.data[DOMAIN][DATA_LISTENER][config_entry.entry_id].append(
config_entry.add_update_listener(async_reload_entry)
)
return True
@ -329,7 +333,7 @@ async def async_unload_entry(hass, entry):
)
if unload_ok:
hass.data[DOMAIN][DATA_CLIENT].pop(entry.entry_id)
remove_listener = hass.data[DOMAIN][DATA_LISTENER].pop(entry.entry_id)
for remove_listener in hass.data[DOMAIN][DATA_LISTENER].pop(entry.entry_id):
remove_listener()
return unload_ok
@ -460,11 +464,11 @@ class SimpliSafe:
"""Define an event handler to disconnect from the websocket."""
await self.websocket.async_disconnect()
self._hass.data[DOMAIN][DATA_LISTENER][
self.config_entry.entry_id
] = self._hass.bus.async_listen_once(
self._hass.data[DOMAIN][DATA_LISTENER][self.config_entry.entry_id].append(
self._hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STOP, async_websocket_disconnect
)
)
self.systems = await self._api.get_systems()
for system in self.systems.values():