Avoid fritz API calls during shutdown (#69225)

This commit is contained in:
Simone Chemelli 2022-04-04 11:04:54 +02:00 committed by GitHub
parent e4b148458b
commit bf23abdfae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -91,6 +91,11 @@ def _cleanup_entity_filter(device: er.RegistryEntry) -> bool:
)
def _ha_is_stopping(activity: str) -> None:
"""Inform that HA is stopping."""
_LOGGER.info("Cannot execute %s: HomeAssistant is shutting down", activity)
class ClassSetupMissing(Exception):
"""Raised when a Class func is called before setup."""
@ -351,6 +356,10 @@ class FritzBoxTools(update_coordinator.DataUpdateCoordinator):
def scan_devices(self, now: datetime | None = None) -> None:
"""Scan for new devices and return a list of found device ids."""
if self.hass.is_stopping:
_ha_is_stopping("scan devices")
return
_LOGGER.debug("Checking host info for FRITZ!Box device %s", self.host)
self._update_available, self._latest_firmware = self._update_device_info()
@ -603,6 +612,10 @@ class AvmWrapper(FritzBoxTools):
) -> dict:
"""Return service details."""
if self.hass.is_stopping:
_ha_is_stopping(f"{service_name}/{action_name}")
return {}
if f"{service_name}{service_suffix}" not in self.connection.services:
return {}