Skip to content

Commit

Permalink
attempt auto-reconnect in HA
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-j-h committed Feb 12, 2023
1 parent 52d70f3 commit 6b564a8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pyvantage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,18 @@ def _send_ascii_nl_locked(self, cmd, i):
_LOGGER.info("Vantage #%s send_ascii_nl: %s", i, cmd)
try:
self._telnet[i].write(cmd.encode('ascii') + b'\r\n')
except BrokenPipeError:
_LOGGER.warning("Vantage BrokenPipeError - disconnected but retrying")
except BrokenPipeError as err:
_LOGGER.warning(f'Vantage BrokenPipeError - disconnected but retrying for "{cmd}", connection #{i}', exc_info=err)
self._connected[i] = False

def send_ascii_nl(self, cmd):
"""Sends the specified command to the vantage controller.
Must not hold self._lock"""
with self._lock:
if not self._connected[self._iconn]:
_LOGGER.info(f"attempting reconnecting for connection {self._iconn}")
self._connected[self._iconn] = self._do_login_locked(self._iconn)
self._send_ascii_nl_locked(cmd, self._iconn)
if not cmd.startswith("GET"):
self._iconn = (self._iconn + 1) % self._num_connections
Expand Down

0 comments on commit 6b564a8

Please sign in to comment.