Skip to content

Commit

Permalink
Keep the keepalive_loop running when exception occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Nov 30, 2024
1 parent ff973db commit 9077aa8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions reolink_aio/baichuan/baichuan.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,10 @@ def _parse_xml(self, cmd_id: int, xml: str) -> None:

async def _keepalive_loop(self) -> None:
"""Loop which keeps the TCP connection allive when subscribed for events"""
try:
now: float = 0
while True:
now: float = 0
while True:
try:

while self._protocol is not None:
now = time_now()
sleep_t = min(self._keepalive_interval - (now - self._protocol.time_recv), self._keepalive_interval)
Expand Down Expand Up @@ -517,8 +518,8 @@ async def _keepalive_loop(self) -> None:
_LOGGER.debug("Baichuan host %s: increasing keepalive interval from %.2f to %.2f s", self._host, origianal_keepalive, self._keepalive_interval)

await asyncio.sleep(self._keepalive_interval)
except Exception as err:
_LOGGER.exception("Baichuan host %s: error during keepalive loop: %s", self._host, str(err))
except Exception as err:
_LOGGER.exception("Baichuan host %s: error during keepalive loop: %s", self._host, str(err))

async def subscribe_events(self) -> None:
"""Subscribe to baichuan push events, keeping the connection open"""
Expand Down

0 comments on commit 9077aa8

Please sign in to comment.