From 9ac3b416fa81bbd0c78372ec78e5d659cac49793 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 22 Mar 2026 11:26:37 -0700 Subject: [PATCH 1/4] Don't log packet multiple times in debug --- custom_components/tekmar_482/hub.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/tekmar_482/hub.py b/custom_components/tekmar_482/hub.py index b2bac91..5e27055 100644 --- a/custom_components/tekmar_482/hub.py +++ b/custom_components/tekmar_482/hub.py @@ -266,7 +266,7 @@ async def async_init_tha(self) -> None: self._tha_inventory[b["address"]]["events"] = b["events"] else: - _LOGGER.warning(f"Ignored method {p} during setup.") + _LOGGER.warning(f"Ignored method {tha_method} during setup.") except KeyError as e: _LOGGER.debug(f"Ignored unknown key: {e}") @@ -371,7 +371,7 @@ async def run(self) -> None: _LOGGER.debug(f"Run {p}") if b["address"] in self.tha_ignore_addr: - _LOGGER.debug(f"Ignored {p} from address {b['address']}") + _LOGGER.debug(f"Ignored {tha_method} from address {b['address']}") continue if tha_method in ["ReportingState"]: @@ -545,7 +545,7 @@ async def run(self) -> None: pass else: - _LOGGER.warning(f"Unhandeled method: {p}") + _LOGGER.warning(f"Unhandeled method: {tha_method}") except KeyError as e: _LOGGER.debug(f"Ignored unknown key: {e}") From dc7948b9e410dfc527f22dd2d74acd3cfb5ecfb6 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 22 Mar 2026 11:27:23 -0700 Subject: [PATCH 2/4] Format with ruff --- custom_components/tekmar_482/hub.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/tekmar_482/hub.py b/custom_components/tekmar_482/hub.py index 5e27055..6a135cb 100644 --- a/custom_components/tekmar_482/hub.py +++ b/custom_components/tekmar_482/hub.py @@ -371,7 +371,9 @@ async def run(self) -> None: _LOGGER.debug(f"Run {p}") if b["address"] in self.tha_ignore_addr: - _LOGGER.debug(f"Ignored {tha_method} from address {b['address']}") + _LOGGER.debug( + f"Ignored {tha_method} from address {b['address']}" + ) continue if tha_method in ["ReportingState"]: From 38acabba22bc00b9747d3dbdb25ebdd0cf6a0a62 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jun 2026 14:36:27 -0700 Subject: [PATCH 3/4] Use readline instead of read --- custom_components/tekmar_482/trpc_sock.py | 29 +++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/custom_components/tekmar_482/trpc_sock.py b/custom_components/tekmar_482/trpc_sock.py index e2424dd..30a6e60 100644 --- a/custom_components/tekmar_482/trpc_sock.py +++ b/custom_components/tekmar_482/trpc_sock.py @@ -11,7 +11,6 @@ def __init__(self, addr=None, port=None): self._sock_writer = None self._is_open = False self._error = None - self._rx_queue = [] self.addr = addr self.port = port @@ -61,23 +60,17 @@ async def read(self): Otherwise a tHA object is returned. """ if self._sock_reader is not None: - if len(self._rx_queue) != 0: - return self._rx_queue.pop(0) - - else: - try: - rx_data = await asyncio.wait_for( - self._sock_reader.read(1024), timeout=0.5 - ) - rx_data = rx_data.rsplit("\n".encode()) - for st in [r for r in rx_data if r]: - self._rx_queue.append(TrpcPacket.from_rx_packet(st)) - - except asyncio.TimeoutError: - return None - - else: - return None + try: + rx_data = await asyncio.wait_for( + self._sock_reader.readline(), timeout=0.5 + ) + if rx_data: + return TrpcPacket.from_rx_packet(rx_data.rstrip(b"\n")) + + except asyncio.TimeoutError: + pass + + return None # ************************************************************************** async def write(self, trpc_packet) -> None: From 863b889d48dbc2b25049fe1ebd7e8e73f6bc52b3 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 7 Jun 2026 14:37:53 -0700 Subject: [PATCH 4/4] Revert "Use readline instead of read" This reverts commit 38acabba22bc00b9747d3dbdb25ebdd0cf6a0a62. --- custom_components/tekmar_482/trpc_sock.py | 29 ++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/custom_components/tekmar_482/trpc_sock.py b/custom_components/tekmar_482/trpc_sock.py index 30a6e60..e2424dd 100644 --- a/custom_components/tekmar_482/trpc_sock.py +++ b/custom_components/tekmar_482/trpc_sock.py @@ -11,6 +11,7 @@ def __init__(self, addr=None, port=None): self._sock_writer = None self._is_open = False self._error = None + self._rx_queue = [] self.addr = addr self.port = port @@ -60,17 +61,23 @@ async def read(self): Otherwise a tHA object is returned. """ if self._sock_reader is not None: - try: - rx_data = await asyncio.wait_for( - self._sock_reader.readline(), timeout=0.5 - ) - if rx_data: - return TrpcPacket.from_rx_packet(rx_data.rstrip(b"\n")) - - except asyncio.TimeoutError: - pass - - return None + if len(self._rx_queue) != 0: + return self._rx_queue.pop(0) + + else: + try: + rx_data = await asyncio.wait_for( + self._sock_reader.read(1024), timeout=0.5 + ) + rx_data = rx_data.rsplit("\n".encode()) + for st in [r for r in rx_data if r]: + self._rx_queue.append(TrpcPacket.from_rx_packet(st)) + + except asyncio.TimeoutError: + return None + + else: + return None # ************************************************************************** async def write(self, trpc_packet) -> None: