mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Properly unload SimpliSafe websocket listener (#41952)
This commit is contained in:
parent
8c0b39eb9c
commit
eff0c4a494
@ -173,6 +173,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:
|
||||||
@ -324,8 +326,9 @@ 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][entry.entry_id]:
|
||||||
remove_listener()
|
remove_listener()
|
||||||
|
hass.data[DOMAIN][DATA_LISTENER].pop(entry.entry_id)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
@ -454,8 +457,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.bus.async_listen_once(
|
self._hass.data[DOMAIN][DATA_LISTENER][self.config_entry.entry_id].append(
|
||||||
EVENT_HOMEASSISTANT_STOP, async_websocket_disconnect
|
self._hass.bus.async_listen_once(
|
||||||
|
EVENT_HOMEASSISTANT_STOP, async_websocket_disconnect
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.systems = await self._api.get_systems()
|
self.systems = await self._api.get_systems()
|
||||||
@ -483,9 +488,9 @@ class SimpliSafe:
|
|||||||
"""Refresh data from the SimpliSafe account."""
|
"""Refresh data from the SimpliSafe account."""
|
||||||
await self.async_update()
|
await self.async_update()
|
||||||
|
|
||||||
self._hass.data[DOMAIN][DATA_LISTENER][
|
self._hass.data[DOMAIN][DATA_LISTENER][self.config_entry.entry_id].append(
|
||||||
self.config_entry.entry_id
|
async_track_time_interval(self._hass, refresh, DEFAULT_SCAN_INTERVAL)
|
||||||
] = async_track_time_interval(self._hass, refresh, DEFAULT_SCAN_INTERVAL)
|
)
|
||||||
|
|
||||||
await self.async_update()
|
await self.async_update()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user