From 9077aa83e78fb21029e8613058cd061cc2cfe96c Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sat, 30 Nov 2024 12:35:35 +0100 Subject: [PATCH] Keep the keepalive_loop running when exception occurs --- reolink_aio/baichuan/baichuan.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/reolink_aio/baichuan/baichuan.py b/reolink_aio/baichuan/baichuan.py index d14ea22..fc6a438 100644 --- a/reolink_aio/baichuan/baichuan.py +++ b/reolink_aio/baichuan/baichuan.py @@ -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) @@ -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"""