From 4341a0e5ff931606f4c7c282393c7d4b88763de8 Mon Sep 17 00:00:00 2001 From: Jon Connell Date: Mon, 18 Sep 2023 10:07:51 +0100 Subject: [PATCH] Fixed intrerval checks --- .../kingspan_watchman_sensit/__init__.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/custom_components/kingspan_watchman_sensit/__init__.py b/custom_components/kingspan_watchman_sensit/__init__.py index 51814b9..ca5b1d1 100644 --- a/custom_components/kingspan_watchman_sensit/__init__.py +++ b/custom_components/kingspan_watchman_sensit/__init__.py @@ -89,20 +89,28 @@ def __init__( self, hass: HomeAssistant, client: SENSiTApiClient, - update_interval=DEFAULT_UPDATE_INTERVAL, + update_interval: timedelta = DEFAULT_UPDATE_INTERVAL, ) -> None: """Initialize.""" self.api = client self.platforms = [] - super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval) + _LOGGER.debug("Update interval set to %s", update_interval) + super().__init__( + hass, + _LOGGER, + name=DOMAIN, + update_method=self.update, + update_interval=update_interval, + ) - async def _async_update_data(self): - """Update data via library.""" + async def update(self): + """Update data via API.""" try: return await self.api.async_get_data() - except Exception as exception: - raise UpdateFailed() from exception + except Exception as e: + _LOGGER.debug("API update failed: %s", e) + raise UpdateFailed() from e async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: