mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Fix shelly shutdown AttributeError (#44172)
* Additional check for clean shutdown * Changed approach * Remover leftover * Added callback key * Moved to listen once
This commit is contained in:
parent
baacf2cd7d
commit
338938a38e
@ -143,6 +143,8 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||||||
)
|
)
|
||||||
self._last_input_events_count = dict()
|
self._last_input_events_count = dict()
|
||||||
|
|
||||||
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_input_events_handler(self):
|
def _async_input_events_handler(self):
|
||||||
"""Handle device input events."""
|
"""Handle device input events."""
|
||||||
@ -184,6 +186,7 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||||||
|
|
||||||
async def _async_update_data(self):
|
async def _async_update_data(self):
|
||||||
"""Fetch data."""
|
"""Fetch data."""
|
||||||
|
|
||||||
_LOGGER.debug("Polling Shelly Device - %s", self.name)
|
_LOGGER.debug("Polling Shelly Device - %s", self.name)
|
||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(
|
async with async_timeout.timeout(
|
||||||
@ -206,6 +209,7 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||||||
|
|
||||||
async def async_setup(self):
|
async def async_setup(self):
|
||||||
"""Set up the wrapper."""
|
"""Set up the wrapper."""
|
||||||
|
|
||||||
dev_reg = await device_registry.async_get_registry(self.hass)
|
dev_reg = await device_registry.async_get_registry(self.hass)
|
||||||
model_type = self.device.settings["device"]["type"]
|
model_type = self.device.settings["device"]["type"]
|
||||||
entry = dev_reg.async_get_or_create(
|
entry = dev_reg.async_get_or_create(
|
||||||
@ -225,6 +229,12 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||||||
self.device.shutdown()
|
self.device.shutdown()
|
||||||
self._async_remove_input_events_handler()
|
self._async_remove_input_events_handler()
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _handle_ha_stop(self, _):
|
||||||
|
"""Handle Home Assistant stopping."""
|
||||||
|
_LOGGER.debug("Stopping ShellyDeviceWrapper for %s", self.name)
|
||||||
|
self.shutdown()
|
||||||
|
|
||||||
|
|
||||||
class ShellyDeviceRestWrapper(update_coordinator.DataUpdateCoordinator):
|
class ShellyDeviceRestWrapper(update_coordinator.DataUpdateCoordinator):
|
||||||
"""Rest Wrapper for a Shelly device with Home Assistant specific functions."""
|
"""Rest Wrapper for a Shelly device with Home Assistant specific functions."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user