Skip to content

Commit 1a39f16

Browse files
authored
Fix group request exception (#138)
1 parent 24b4a2a commit 1a39f16

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

tests/test_application.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import pytest
44
import logging
5-
import zigpy.types as zigpy_types
5+
import zigpy.types as zigpy_t
66
import zigpy.exceptions
77

8-
import zigpy_zigate.config as config
8+
import zigpy_zigate.api
99
import zigpy_zigate.types as t
10+
import zigpy_zigate.config as config
1011
import zigpy_zigate.zigbee.application
1112

1213
APP_CONFIG = zigpy_zigate.zigbee.application.ControllerApplication.SCHEMA(
@@ -22,7 +23,7 @@
2223
def app():
2324
a = zigpy_zigate.zigbee.application.ControllerApplication(APP_CONFIG)
2425
a.version = FAKE_FIRMWARE_VERSION
25-
a._api = MagicMock()
26+
a._api = MagicMock(spec_set=zigpy_zigate.api.ZiGate)
2627
return a
2728

2829

@@ -32,7 +33,7 @@ def test_zigpy_ieee(app):
3233
data = b"\x01\x02\x03\x04\x05\x06\x07\x08"
3334

3435
zigate_ieee, _ = t.EUI64.deserialize(data)
35-
app.state.node_info.ieee = zigpy_types.EUI64(zigate_ieee)
36+
app.state.node_info.ieee = zigpy_t.EUI64(zigate_ieee)
3637

3738
dst_addr = app.get_dst_address(cluster)
3839
assert dst_addr.serialize() == b"\x03" + data[::-1] + b"\x01"
@@ -148,4 +149,14 @@ async def test_startup_connect(zigate_new, app, version_rsp, expected_version):
148149

149150
await app.connect()
150151

151-
assert app.version == expected_version
152+
assert app.version == expected_version
153+
154+
155+
@pytest.mark.asyncio
156+
async def test_send_group_request(app):
157+
packet = zigpy_t.ZigbeePacket(src=None, src_ep=1, dst=zigpy_t.AddrModeAddress(addr_mode=zigpy_t.AddrMode.Group, address=0x0002), dst_ep=None, source_route=None, extended_timeout=False, tsn=21, profile_id=260, cluster_id=6, data=zigpy_t.SerializableBytes(b'\x01\x15\x00'), tx_options=zigpy_t.TransmitOptions.NONE, radius=0, non_member_radius=3, lqi=None, rssi=None)
158+
159+
app._api.raw_aps_data_request.return_value = ([t.Status.Success, 0, 1328, b'\x01\xea\x00\x00'], 0)
160+
await app.send_packet(packet)
161+
162+
app._api.raw_aps_data_request.assert_called_once()

zigpy_zigate/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,12 @@ def set_application(self, app):
290290
self._app = app
291291

292292
def data_received(self, cmd, data, lqi):
293-
LOGGER.debug("data received %s %s LQI:%s", hex(cmd),
294-
binascii.hexlify(data), lqi)
295293
if cmd not in RESPONSES:
296-
LOGGER.warning('Received unhandled response 0x%04x', cmd)
294+
LOGGER.warning('Received unhandled response 0x%04x: %r', cmd, binascii.hexlify(data))
297295
return
298296
cmd = ResponseId(cmd)
299297
data, rest = t.deserialize(data, RESPONSES[cmd])
298+
LOGGER.debug("Response received: %s %s %s (LQI:%s)", cmd, data, rest, lqi)
300299
if cmd == ResponseId.STATUS:
301300
if data[2] in self._status_awaiting:
302301
fut = self._status_awaiting.pop(data[2])

zigpy_zigate/zigbee/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ async def send_packet(self, packet):
243243
try:
244244
(status, tsn, packet_type, _), _ = await self._api.raw_aps_data_request(
245245
addr=packet.dst.address,
246-
src_ep=(1 if packet.dst_ep > 0 else 0), # ZiGate only support endpoint 1
247-
dst_ep=packet.dst_ep,
246+
src_ep=(1 if packet.dst_ep is None or packet.dst_ep > 0 else 0), # ZiGate only support endpoint 1
247+
dst_ep=packet.dst_ep or 0,
248248
profile=packet.profile_id,
249249
cluster=packet.cluster_id,
250250
payload=packet.data.serialize(),

0 commit comments

Comments
 (0)