From 739766e18c124faf33119bee2240e35ea0a292bd Mon Sep 17 00:00:00 2001 From: Johan Isacsson Date: Fri, 27 Aug 2021 15:52:35 +0200 Subject: [PATCH] Fix reconnect issue --- custom_components/sunspec/__init__.py | 3 ++- custom_components/sunspec/api.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/custom_components/sunspec/__init__.py b/custom_components/sunspec/__init__.py index 80c30ce..37a45e8 100644 --- a/custom_components/sunspec/__init__.py +++ b/custom_components/sunspec/__init__.py @@ -129,5 +129,6 @@ async def _async_update_data(self): self.api.close() return data except Exception as exception: - _LOGGER.warning("Update Sunspec data failed") + _LOGGER.warning(exception) + self.api.reconnect() raise UpdateFailed() from exception diff --git a/custom_components/sunspec/api.py b/custom_components/sunspec/api.py index ed8bbe8..dbbabaa 100644 --- a/custom_components/sunspec/api.py +++ b/custom_components/sunspec/api.py @@ -100,6 +100,11 @@ def close(self): client = self.get_client() client.close() + def reconnect(self): + _LOGGER.debug("Client reconnecting") + client = self.get_client() + client.connect() + def modbus_connect(self): _LOGGER.debug( f"Client connect to IP {self._host} port {self._port} slave id {self._slave_id} using timeout {TIMEOUT}"