mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Properly disconnect from SimpliSafe websocket on HASS shutdown (#41894)
* Properly disconnect from SimpliSafe websocket on HASS shutdown * Update homeassistant/components/simplisafe/__init__.py Co-authored-by: J. Nick Koston <nick@koston.org> * Update homeassistant/components/simplisafe/__init__.py Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
ba789105ee
commit
2079e41b7a
@ -23,6 +23,7 @@ from homeassistant.const import (
|
|||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_TOKEN,
|
CONF_TOKEN,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
from homeassistant.core import CoreState, callback
|
from homeassistant.core import CoreState, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
@ -424,7 +425,7 @@ class SimpliSafeWebsocket:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_websocket_connect(self):
|
async def async_connect(self):
|
||||||
"""Register handlers and connect to the websocket."""
|
"""Register handlers and connect to the websocket."""
|
||||||
self._websocket.on_connect(self._on_connect)
|
self._websocket.on_connect(self._on_connect)
|
||||||
self._websocket.on_disconnect(self._on_disconnect)
|
self._websocket.on_disconnect(self._on_disconnect)
|
||||||
@ -432,6 +433,10 @@ class SimpliSafeWebsocket:
|
|||||||
|
|
||||||
await self._websocket.async_connect()
|
await self._websocket.async_connect()
|
||||||
|
|
||||||
|
async def async_disconnect(self):
|
||||||
|
"""Disconnect from the websocket."""
|
||||||
|
await self._websocket.async_disconnect()
|
||||||
|
|
||||||
|
|
||||||
class SimpliSafe:
|
class SimpliSafe:
|
||||||
"""Define a SimpliSafe data object."""
|
"""Define a SimpliSafe data object."""
|
||||||
@ -486,7 +491,10 @@ class SimpliSafe:
|
|||||||
|
|
||||||
async def async_init(self):
|
async def async_init(self):
|
||||||
"""Initialize the data class."""
|
"""Initialize the data class."""
|
||||||
asyncio.create_task(self.websocket.async_websocket_connect())
|
asyncio.create_task(self.websocket.async_connect())
|
||||||
|
self._hass.bus.async_listen_once(
|
||||||
|
EVENT_HOMEASSISTANT_STOP, self.websocket.async_disconnect
|
||||||
|
)
|
||||||
|
|
||||||
self.systems = await self._api.get_systems()
|
self.systems = await self._api.get_systems()
|
||||||
for system in self.systems.values():
|
for system in self.systems.values():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user