From a396d94ca869edd4276cdba88c76a3bdc8978250 Mon Sep 17 00:00:00 2001 From: Emanuele Palazzetti Date: Fri, 6 Oct 2023 18:40:42 +0000 Subject: [PATCH] fix(collector): force the next update when the central unit is not available --- custom_components/econnect_metronet/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/custom_components/econnect_metronet/__init__.py b/custom_components/econnect_metronet/__init__.py index 093e89d..fa68db7 100644 --- a/custom_components/econnect_metronet/__init__.py +++ b/custom_components/econnect_metronet/__init__.py @@ -4,6 +4,7 @@ from datetime import timedelta import async_timeout +from elmo import query as q from elmo.api.client import ElmoClient from elmo.api.exceptions import InvalidToken from elmo.systems import ELMO_E_CONNECT as E_CONNECT_DEFAULT @@ -82,6 +83,14 @@ async def async_update_data(): # action blocks the thread for at most 15 seconds, or when # something changes in the backend. POLLING_TIMEOUT ensures # an upper bound regardless of the underlying implementation. + coordinator = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR] + if not coordinator.last_update_success: + # Force a reset if the last update has failed, this forces an update + # until the device is available again. + device._lastIds = { + q.SECTORS: 0, + q.INPUTS: 0, + } ids = await hass.async_add_executor_job(device._get_last_IDS) _LOGGER.debug(f"Polling IDs registered in the device: {device._lastIds}") _LOGGER.debug(f"Polling IDs expected in the update: {ids}")