mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Properly unload listener for SimpliSafe config entry updates (#42579)
This commit is contained in:
parent
9bb1c6f188
commit
b0a6ac7e91
@ -177,6 +177,8 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
async def async_setup_entry(hass, config_entry):
|
async def async_setup_entry(hass, config_entry):
|
||||||
"""Set up SimpliSafe as config entry."""
|
"""Set up SimpliSafe as config entry."""
|
||||||
|
hass.data[DOMAIN][DATA_LISTENER][config_entry.entry_id] = []
|
||||||
|
|
||||||
entry_updates = {}
|
entry_updates = {}
|
||||||
if not config_entry.unique_id:
|
if not config_entry.unique_id:
|
||||||
# If the config entry doesn't already have a unique ID, set one:
|
# 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)
|
async_register_admin_service(hass, DOMAIN, service, method, schema=schema)
|
||||||
|
|
||||||
config_entry.add_update_listener(async_reload_entry)
|
hass.data[DOMAIN][DATA_LISTENER][config_entry.entry_id].append(
|
||||||
|
config_entry.add_update_listener(async_reload_entry)
|
||||||
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -329,8 +333,8 @@ async def async_unload_entry(hass, entry):
|
|||||||
)
|
)
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN][DATA_CLIENT].pop(entry.entry_id)
|
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()
|
remove_listener()
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
@ -460,10 +464,10 @@ class SimpliSafe:
|
|||||||
"""Define an event handler to disconnect from the websocket."""
|
"""Define an event handler to disconnect from the websocket."""
|
||||||
await self.websocket.async_disconnect()
|
await self.websocket.async_disconnect()
|
||||||
|
|
||||||
self._hass.data[DOMAIN][DATA_LISTENER][
|
self._hass.data[DOMAIN][DATA_LISTENER][self.config_entry.entry_id].append(
|
||||||
self.config_entry.entry_id
|
self._hass.bus.async_listen_once(
|
||||||
] = self._hass.bus.async_listen_once(
|
EVENT_HOMEASSISTANT_STOP, async_websocket_disconnect
|
||||||
EVENT_HOMEASSISTANT_STOP, async_websocket_disconnect
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.systems = await self._api.get_systems()
|
self.systems = await self._api.get_systems()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user