Skip to content

Commit

Permalink
Improve Baichuan parsing exception logging
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Nov 5, 2024
1 parent 2af4154 commit 09ab53a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion reolink_aio/baichuan/tcp_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __init__(self, loop, host: str, push_callback: Callable[[int, bytes, int], N
self._push_callback = push_callback
self.time_recv: float = 0

self._log_once: list[str] = []

def connection_made(self, transport: asyncio.BaseTransport) -> None:
"""Connection callback"""
_LOGGER.debug("Baichuan host %s: opened connection", self._host)
Expand Down Expand Up @@ -64,7 +66,15 @@ def data_received(self, data: bytes) -> None:
try:
self.parse_data()
except Exception as exc:
_LOGGER.exception("Baichuan host %s: error during parsing of received data: %s", self._host, str(exc))
try:
cmd_id = int.from_bytes(self._data[4:8], byteorder="little")
header = self._data[0:24].hex()
except Exception:
cmd_id = 0
header = "<24"
if f"parse_data_cmd_id_{cmd_id}" not in self._log_once:
self._log_once.append(f"parse_data_cmd_id_{cmd_id}")
_LOGGER.exception("Baichuan host %s: error during parsing of received data, cmd_id %s, header %s: %s", self._host, cmd_id, header, str(exc))
self._data = b""

def parse_data(self) -> None:
Expand Down

0 comments on commit 09ab53a

Please sign in to comment.