ha-inlite

Home Assistant integration for in-lite
git clone https://git.stephank.nl/ha-inlite
Log | Files | Refs | README | LICENSE | ZIP

commit 29df6869ee9466216dd1cf261b1f562b50464bb4
parent 430316f489b8ec2d43d100fca1f77e87707c8d85
Author: Stéphan Kochen <git@stephank.nl>
Date: Thu, 03 Sep 2026 22:03:25 +0200

Queue hub response flush packets

diff --git a/custom_components/inlite/lib/inlite_ble/hub.py b/custom_components/inlite/lib/inlite_ble/hub.py index 83204156eabe9a0f50acc09db3ee5aeb0b07b477..e84d4949a7c7f7a0b5f514d794af1351ea874605 100644 --- a/custom_components/inlite/lib/inlite_ble/hub.py +++ b/custom_components/inlite/lib/inlite_ble/hub.py @@ -268,10 +268,11 @@ loop = self._loop if loop is None or loop.is_closed(): return - if pkt_type == PKT_BLOCK_ACK: - # ACK/FLUSH control packets for a command are unicast. Filter - # before queuing so traffic from another mesh node cannot satisfy - # this hub's active command. + if pkt_type in (PKT_BLOCK_ACK, PKT_BLOCK_FLUSH): + # Control packets for a command are unicast. The hub uses ACKs + # while receiving our request, then FLUSH packets for its response. + # Filter before queuing so traffic from another mesh node cannot + # satisfy this hub's active command. if ( decrypted["src_id"] == self._device_id and decrypted["dest_id"] == self._crypto.controller_address diff --git a/tests/test_hub.py b/tests/test_hub.py index f44cb7597a3e7ee3ec0af6b4534623c294ca8877..6288831eded0b145957db5cf521cac0cb58ba268 100644 --- a/tests/test_hub.py +++ b/tests/test_hub.py @@ -78,6 +78,22 @@ assert hub._accept_stream_segment(b"\x00\x00abc") assert not hub._accept_stream_segment(b"\x04\x00de") assert hub._stream_invalid is True + def test_response_flush_is_queued_as_control_packet(self) -> None: + async def run() -> bytes: + hub = InliteHub(device_id=0x1234, passphrase="test") + hub._loop = asyncio.get_running_loop() + hub._crypto.decrypt_packet = lambda _packet: { # type: ignore[method-assign] + "pkt_type": PKT_BLOCK_FLUSH, + "src_id": hub.device_id, + "dest_id": hub._crypto.controller_address, + "data": b"\x00\x00", + } + hub.handle_notification(CHAR_WRITE_UUID, bytearray(b"packet")) + await asyncio.sleep(0) + return await hub._wait_ack() + + assert asyncio.run(run()) == b"\x00\x00" + def test_identify_is_fire_and_forget(self) -> None: async def run() -> list[tuple[int, int, bytes]]: hub = InliteHub(device_id=0x1234, passphrase="test")