44import pytest
55
66from zigpy .exceptions import DeliveryError
7- from zigpy . types import EUI64 , uint16_t
8- from zigpy .zdo .types import LogicalType
7+ from zigpy import types as t
8+ from zigpy .zdo .types import LogicalType , ZDOCmd
99
1010from zigpy_xbee .api import ModemStatus , XBee
1111from zigpy_xbee .zigbee import application
@@ -143,7 +143,7 @@ def test_rx_failed_deserialize(app, caplog):
143143 app ._handle_reply = mock .MagicMock ()
144144 app .handle_message = mock .MagicMock ()
145145 nwk = 0x1234
146- ieee , _ = EUI64 .deserialize (b'\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 ' )
146+ ieee , _ = t . EUI64 .deserialize (b'\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 ' )
147147 device = app .add_device (ieee , nwk )
148148 device .status = DeviceStatus .ENDPOINTS_INIT
149149 app .get_device = mock .MagicMock (return_value = device )
@@ -168,10 +168,10 @@ def test_rx_failed_deserialize(app, caplog):
168168
169169@pytest .fixture
170170def device (app ):
171- def _device (new = False , zdo_init = False , nwk = uint16_t (0x1234 )):
171+ def _device (new = False , zdo_init = False , nwk = t . uint16_t (0x1234 )):
172172 from zigpy .device import Device , Status as DeviceStatus
173173
174- ieee , _ = EUI64 .deserialize (b'\x08 \x07 \x06 \x05 \x04 \x03 \x02 \x01 ' )
174+ ieee , _ = t . EUI64 .deserialize (b'\x08 \x07 \x06 \x05 \x04 \x03 \x02 \x01 ' )
175175 dev = Device (app , ieee , nwk )
176176 if new :
177177 dev .status = DeviceStatus .NEW
@@ -368,43 +368,43 @@ async def test_startup_ai(app):
368368 auto_form = True
369369 await _test_startup (app , 0x00 , auto_form )
370370 assert app ._nwk == 0x0000
371- assert app ._ieee == EUI64 (range (1 , 9 ))
371+ assert app ._ieee == t . EUI64 (range (1 , 9 ))
372372 assert app .form_network .call_count == 0
373373
374374 auto_form = False
375375 await _test_startup (app , 0x00 , auto_form )
376376 assert app ._nwk == 0x0000
377- assert app ._ieee == EUI64 (range (1 , 9 ))
377+ assert app ._ieee == t . EUI64 (range (1 , 9 ))
378378 assert app .form_network .call_count == 0
379379
380380 auto_form = True
381381 await _test_startup (app , 0x06 , auto_form )
382382 assert app ._nwk == 0xfffe
383- assert app ._ieee == EUI64 (range (1 , 9 ))
383+ assert app ._ieee == t . EUI64 (range (1 , 9 ))
384384 assert app .form_network .call_count == 1
385385
386386 auto_form = False
387387 await _test_startup (app , 0x06 , auto_form )
388388 assert app ._nwk == 0xfffe
389- assert app ._ieee == EUI64 (range (1 , 9 ))
389+ assert app ._ieee == t . EUI64 (range (1 , 9 ))
390390 assert app .form_network .call_count == 0
391391
392392 auto_form = True
393393 await _test_startup (app , 0x00 , auto_form , zs = 1 )
394394 assert app ._nwk == 0x0000
395- assert app ._ieee == EUI64 (range (1 , 9 ))
395+ assert app ._ieee == t . EUI64 (range (1 , 9 ))
396396 assert app .form_network .call_count == 1
397397
398398 auto_form = False
399399 await _test_startup (app , 0x06 , auto_form , legacy_module = True )
400400 assert app ._nwk == 0xfffe
401- assert app ._ieee == EUI64 (range (1 , 9 ))
401+ assert app ._ieee == t . EUI64 (range (1 , 9 ))
402402 assert app .form_network .call_count == 0
403403
404404 auto_form = True
405405 await _test_startup (app , 0x00 , auto_form , zs = 1 , legacy_module = True )
406406 assert app ._nwk == 0x0000
407- assert app ._ieee == EUI64 (range (1 , 9 ))
407+ assert app ._ieee == t . EUI64 (range (1 , 9 ))
408408 assert app .form_network .call_count == 1
409409
410410
@@ -413,7 +413,7 @@ async def test_startup_no_api_mode(app):
413413 auto_form = True
414414 await _test_startup (app , 0x00 , auto_form , api_mode = False )
415415 assert app ._nwk == 0x0000
416- assert app ._ieee == EUI64 (range (1 , 9 ))
416+ assert app ._ieee == t . EUI64 (range (1 , 9 ))
417417 assert app .form_network .call_count == 0
418418 assert app ._api .init_api_mode .call_count == 1
419419 assert app ._api ._at_command .call_count >= 16
@@ -446,7 +446,7 @@ async def _test_request(app, do_reply=True, expect_reply=True,
446446 logical_type = None , ** kwargs ):
447447 seq = 123
448448 nwk = 0x2345
449- ieee = EUI64 (b'\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 ' )
449+ ieee = t . EUI64 (b'\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 ' )
450450 dev = app .add_device (ieee , nwk )
451451 dev .node_desc = mock .MagicMock ()
452452 dev .node_desc .logical_type = logical_type
@@ -591,3 +591,54 @@ def test_remote_at_cmd(app, device):
591591 assert app ._api ._remote_at_command .call_args [0 ][2 ] == 0x22
592592 assert app ._api ._remote_at_command .call_args [0 ][3 ] == s .cmd
593593 assert app ._api ._remote_at_command .call_args [0 ][4 ] == s .data
594+
595+
596+ @pytest .fixture
597+ def ieee ():
598+ return t .EUI64 .deserialize (b'\x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 ' )[0 ]
599+
600+
601+ @pytest .fixture
602+ def nwk ():
603+ return t .uint16_t (0x0100 )
604+
605+
606+ def test_rx_device_annce (app , ieee , nwk ):
607+ dst_ep = 0
608+ cluster_id = ZDOCmd .Device_annce
609+ device = mock .MagicMock ()
610+ device .status = device .Status .NEW
611+ app .get_device = mock .MagicMock (return_value = device )
612+ app .deserialize = mock .MagicMock (return_value = (mock .sentinel .tsn ,
613+ mock .sentinel .cmd_id ,
614+ False ,
615+ mock .sentinel .args , ))
616+ app .handle_join = mock .MagicMock ()
617+ app ._handle_reply = mock .MagicMock ()
618+ app .handle_message = mock .MagicMock ()
619+
620+ data = t .uint8_t (0xaa ).serialize ()
621+ data += nwk .serialize ()
622+ data += ieee .serialize ()
623+ data += t .uint8_t (0x8e ).serialize ()
624+
625+ app .handle_rx (
626+ ieee ,
627+ nwk ,
628+ mock .sentinel .src_ep ,
629+ dst_ep ,
630+ cluster_id ,
631+ mock .sentinel .profile_id ,
632+ mock .sentinel .rx_opt ,
633+ data ,
634+ )
635+
636+ assert app .deserialize .call_count == 1
637+ assert app .deserialize .call_args [0 ][2 ] == cluster_id
638+ assert app .deserialize .call_args [0 ][3 ] == data
639+ assert app ._handle_reply .call_count == 0
640+ assert app .handle_message .call_count == 1
641+ assert app .handle_join .call_count == 1
642+ assert app .handle_join .call_args [0 ][0 ] == nwk
643+ assert app .handle_join .call_args [0 ][1 ] == ieee
644+ assert app .handle_join .call_args [0 ][2 ] == 0
0 commit comments