Skip to content

Commit 4311c2a

Browse files
committed
Improve test coverage
1 parent a1edd16 commit 4311c2a

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

tests/application/test_requests.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
2+
import logging
23

34
import pytest
4-
import zigpy.zdo
55
import zigpy.endpoint
66
import zigpy.profiles
77
import zigpy.zdo.types as zdo_t
@@ -967,3 +967,36 @@ async def test_route_discovery_concurrency(device, make_application):
967967
assert route_discovery2.call_count == 2
968968

969969
await app.shutdown()
970+
971+
972+
@pytest.mark.parametrize("device", [FormedLaunchpadCC26X2R1])
973+
async def test_zdo_from_unknown(device, make_application, caplog, mocker):
974+
mocker.patch("zigpy_znp.zigbee.application.IEEE_ADDR_DISCOVERY_TIMEOUT", new=0.1)
975+
976+
app, znp_server = make_application(server_cls=device)
977+
978+
znp_server.reply_once_to(
979+
request=c.ZDO.IEEEAddrReq.Req(partial=True),
980+
responses=[c.ZDO.IEEEAddrReq.Rsp(Status=t.Status.SUCCESS)],
981+
)
982+
983+
await app.startup(auto_form=False)
984+
985+
caplog.set_level(logging.WARNING)
986+
987+
znp_server.send(
988+
c.ZDO.MsgCbIncoming.Callback(
989+
Src=0x1234,
990+
IsBroadcast=t.Bool.false,
991+
ClusterId=zdo_t.ZDOCmd.Mgmt_Leave_rsp,
992+
SecurityUse=0,
993+
TSN=123,
994+
MacDst=0x0000,
995+
Data=t.Bytes([123, 0x00]),
996+
)
997+
)
998+
999+
await asyncio.sleep(0.5)
1000+
assert "unknown device" in caplog.text
1001+
1002+
await app.shutdown()

zigpy_znp/zigbee/application.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,13 @@ async def on_zdo_message(self, msg: c.ZDO.MsgCbIncoming.Callback) -> None:
693693
self.on_zdo_device_announce(*args)
694694
device = self.get_device(ieee=kwargs["IEEEAddr"])
695695
else:
696-
device = await self._get_or_discover_device(nwk=msg.Src)
697-
698-
if device is None:
699-
LOGGER.warning("Received a ZDO message from an unknown device: %s", msg.Src)
700-
return
696+
try:
697+
device = await self._get_or_discover_device(nwk=msg.Src)
698+
except KeyError:
699+
LOGGER.warning(
700+
"Received a ZDO message from an unknown device: %s", msg.Src
701+
)
702+
return
701703

702704
self.handle_message(
703705
sender=device,

0 commit comments

Comments
 (0)