From 68c471c6556a4dd7c45a8f9989823cc8d8a367b5 Mon Sep 17 00:00:00 2001 From: Alex X Date: Sun, 24 Dec 2023 13:38:52 +0300 Subject: [PATCH] Fix Multimode 2 zigbee debug --- .../xiaomi_gateway3/core/gateway/silabs.py | 12 +++++++--- tests/test_conv_silabs.py | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/custom_components/xiaomi_gateway3/core/gateway/silabs.py b/custom_components/xiaomi_gateway3/core/gateway/silabs.py index 549d6ec4..a6e94f55 100644 --- a/custom_components/xiaomi_gateway3/core/gateway/silabs.py +++ b/custom_components/xiaomi_gateway3/core/gateway/silabs.py @@ -86,10 +86,16 @@ async def silabs_process_recv(self, data: dict): async def silabs_process_send(self, data: dict): if "zigbee" not in self.debug_mode: return - did = "lumi." + data["eui64"].lstrip("0x").lower() - if did not in self.devices: + if "eui64" in data: + did = "lumi." + data["eui64"].lstrip("0x").lower() + device = self.devices.get(did) + elif "shortId" in data: + nwk = data["shortId"].lower() + device = next((d for d in self.devices.values() if d.nwk == nwk), None) + else: + return + if not device: return - device = self.devices[did] zb_msg = silabs.decode(data) self.debug_tag(f"{device.mac} {device.nwk} send {zb_msg}", tag="ZIGB") diff --git a/tests/test_conv_silabs.py b/tests/test_conv_silabs.py index 56df31b5..2083aca8 100644 --- a/tests/test_conv_silabs.py +++ b/tests/test_conv_silabs.py @@ -1,9 +1,13 @@ +import asyncio +import json + from homeassistant.components.sensor import DOMAIN from zigpy.types import EUI64 from custom_components.xiaomi_gateway3.core.converters import silabs, ZIGBEE from custom_components.xiaomi_gateway3.core.converters.zigbee import ZConverter from custom_components.xiaomi_gateway3.core.device import XDevice +from custom_components.xiaomi_gateway3.core.gateway.silabs import SilabsGateway assert DOMAIN # fix circular import @@ -244,3 +248,22 @@ def test_hass2023_4(): {"commandcli": "send 0x12ab 1 1"}, ] } + + +def test_message_pre_sent_callback(): + gw = SilabsGateway() + gw.options = {"debug": ["zigbee"]} + + # Xiaomi Multimode 1 and 2 + raw = json.loads( + b'{"eui64":"0xAABBCCDDEEFF1122","destinationEndpoint":"0x01","clusterId":"0x0006","profileId":"0x0104","sourceEndpoint":"0x01","APSCounter":"0x00","APSPlayload":"0x1001000000"}' + ) + coro = gw.silabs_process_send(raw) + asyncio.get_event_loop().run_until_complete(coro) + + # Xiaomi Multimode fw 1.0.7_0019+ + raw = json.loads( + b'{"msgTick":"0x0000000000000721","type":"0x00","shortId":"0xDDCB","destinationEndpoint":"0x01","clusterId":"0x000A","profileId":"0x0104","sourceEndpoint":"0x01","APSCounter":"0x00","APSPlayload":"0x189F01000000E2407DF42C"}' + ) + coro = gw.silabs_process_send(raw) + asyncio.get_event_loop().run_until_complete(coro)