Skip to content

Commit

Permalink
Fix Multimode 2 zigbee debug
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Dec 24, 2023
1 parent 1d64266 commit 68c471c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
12 changes: 9 additions & 3 deletions custom_components/xiaomi_gateway3/core/gateway/silabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
23 changes: 23 additions & 0 deletions tests/test_conv_silabs.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 68c471c

Please sign in to comment.