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:
Simone Chemelli 2020-12-30 10:29:54 +01:00 committed by GitHub
parent baacf2cd7d
commit 338938a38e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -143,6 +143,8 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
)
self._last_input_events_count = dict()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop)
@callback
def _async_input_events_handler(self):
"""Handle device input events."""
@ -184,6 +186,7 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
async def _async_update_data(self):
"""Fetch data."""
_LOGGER.debug("Polling Shelly Device - %s", self.name)
try:
async with async_timeout.timeout(
@ -206,6 +209,7 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
async def async_setup(self):
"""Set up the wrapper."""
dev_reg = await device_registry.async_get_registry(self.hass)
model_type = self.device.settings["device"]["type"]
entry = dev_reg.async_get_or_create(
@ -225,6 +229,12 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
self.device.shutdown()
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):
"""Rest Wrapper for a Shelly device with Home Assistant specific functions."""