Skip to content

Commit

Permalink
Fix reconnect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
CJNE committed Aug 27, 2021
1 parent 2eb666c commit 739766e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion custom_components/sunspec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions custom_components/sunspec/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 739766e

Please sign in to comment.