From 5255e3e2a609e58b4954882da32d7854ddba09e9 Mon Sep 17 00:00:00 2001 From: David Rapan Date: Mon, 16 Dec 2024 20:50:38 +0100 Subject: [PATCH] refactor: api.py error handling --- custom_components/solarman/api.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/custom_components/solarman/api.py b/custom_components/solarman/api.py index e81e964..913f484 100644 --- a/custom_components/solarman/api.py +++ b/custom_components/solarman/api.py @@ -234,16 +234,12 @@ async def get(self, runtime = 0, requests = None): _LOGGER.debug(f"[{self.config.serial}] Returning {rcount} new value{'s' if rcount > 1 else ''}. [Previous State: {self.state.print} ({self.state.value})]") self.state.update() - except (TimeoutError, Exception) as e: - _LOGGER.debug(f"[{self.config.serial}] Fetching failed. [Previous State: {self.state.print} ({self.state.value})]") - + except Exception as e: await self.endpoint.discover() - if self.state.reevaluate(): await self.modbus.disconnect() raise - - _LOGGER.debug(f"[{self.config.serial}] {"Timeout" if isinstance(e, TimeoutError) else "Error"} fetching {self.config.name} data: {format_exception(e)}") + _LOGGER.debug(f"[{self.config.serial}] {"Timeout" if isinstance(e, TimeoutError) else "Error"} fetching {self.config.name} data. [Previous State: {self.state.print} ({self.state.value}), {format_exception(e)}]") return result