Skip to content

Commit

Permalink
fix: Silencing Errno 111 during reconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Aug 11, 2024
1 parent 34735f8 commit ecca3df
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ def __init__(self, address, serial, port, mb_slave_id, passthrough):
super().__init__(address, serial, port = port, mb_slave_id = mb_slave_id, logger = _LOGGER, auto_reconnect = AUTO_RECONNECT, socket_timeout = TIMINGS_SOCKET_TIMEOUT)
self._passthrough = passthrough

async def reconnect(self) -> None:
"""
Overridden to silence [ConnectionRefusedError: [Errno 111] Connect call failed] during reconnects
"""
try:
if self.reader_task:
self.reader_task.cancel()
self.reader, self.writer = await asyncio.open_connection(self.address, self.port)
loop = asyncio.get_running_loop()
self.reader_task = loop.create_task(self._conn_keeper(), name = "ConnKeeper")
self.log.debug("[%s] Successful reconnect", self.serial)
if self.data_wanted_ev.is_set():
self.log.debug("[%s] Data expected. Will retry the last request", self.serial)
self.writer.write(self._last_frame)
await self.writer.drain()
except Exception as e:
self.log.debug(f"Cannot open connection to {self.address}. [{type(e).__name__}{f': {e}' if f'{e}' else ''}]")

def _received_frame_is_valid(self, frame):
return super()._received_frame_is_valid(frame) if not self._passthrough else True

Expand Down

0 comments on commit ecca3df

Please sign in to comment.