From 57bcaaca6c30a34645cc2ccfa5311280f7aa241f Mon Sep 17 00:00:00 2001 From: David Rapan Date: Thu, 8 Aug 2024 14:30:43 +0200 Subject: [PATCH] feat: Don't raise TimeoutError immediately --- custom_components/solarman/api.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/custom_components/solarman/api.py b/custom_components/solarman/api.py index fb61584..7d89b10 100644 --- a/custom_components/solarman/api.py +++ b/custom_components/solarman/api.py @@ -139,7 +139,7 @@ def get_result(self, middleware = None): result = middleware.get_result() if middleware else {} if len(result) > 0: - _LOGGER.debug(f"Returning new values to the Coordinator. [Previous Status: {self.get_connection_status()}]") + _LOGGER.debug(f"Returning new values to the Coordinator. [Previous State: {self.get_connection_status()} ({self.status})]") now = datetime.now() self.status_interval = now - self.status_updated self.status_updated = now @@ -147,13 +147,13 @@ def get_result(self, middleware = None): return result - async def async_get_failed(self, message): - _LOGGER.debug(f"Request failed. [Previous Status: {self.get_connection_status()}]") + async def async_get_failed(self, message = None): + _LOGGER.debug(f"Request failed. [Previous State: {self.get_connection_status()} ({self.status})]") self.status = 0 if self.status == 1 else -1 await self.async_disconnect() - if self.status == -1: + if message and self.status == -1: raise UpdateFailed(message) async def async_get(self, runtime = 0): @@ -200,6 +200,13 @@ async def async_get(self, runtime = 0): else: await self.async_get_failed(f"Querying {self.serial} at {self.address}:{self.port} failed.") + except TimeoutError: + last_state = self.status + await self.async_get_failed() + if last_state < 1: + raise + else: + _LOGGER.debug(f"Timeout fetching {self.name} data") except UpdateFailed: raise except Exception as e: