44import pytest
55
66from zigpy .exceptions import DeliveryError
7+ import zigpy .device
78from zigpy .types import EUI64
9+ import zigpy .zdo .types as zdo_t
810from zigpy_deconz .api import Deconz
911from zigpy_deconz .zigbee .application import ControllerApplication
1012from zigpy_deconz .zigbee import application
@@ -17,18 +19,28 @@ def app(database_file=None):
1719
1820
1921@pytest .fixture
20- def addr_ieee ():
22+ def ieee ():
23+ return EUI64 .deserialize (b'\x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 ' )[0 ]
24+
25+
26+ @pytest .fixture
27+ def nwk ():
28+ return t .uint16_t (0x0100 )
29+
30+
31+ @pytest .fixture
32+ def addr_ieee (ieee ):
2133 addr = t .DeconzAddress ()
2234 addr .address_mode = t .ADDRESS_MODE .IEEE
23- addr .address = b' \x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 '
35+ addr .address = ieee
2436 return addr
2537
2638
2739@pytest .fixture
28- def addr_nwk ():
40+ def addr_nwk (nwk ):
2941 addr = t .DeconzAddress ()
3042 addr .address_mode = t .ADDRESS_MODE .NWK
31- addr .address = b' \x00 \x01 '
43+ addr .address = nwk
3244 return addr
3345
3446
@@ -245,3 +257,44 @@ async def test_shutdown(app):
245257 app ._api .close = mock .MagicMock ()
246258 await app .shutdown ()
247259 assert app ._api .close .call_count == 1
260+
261+
262+ def test_rx_device_annce (app , addr_ieee , addr_nwk ):
263+ dst_ep = 0
264+ cluster_id = zdo_t .ZDOCmd .Device_annce
265+ device = mock .MagicMock ()
266+ device .status = zigpy .device .Status .NEW
267+ app .get_device = mock .MagicMock (return_value = device )
268+ app .deserialize = mock .MagicMock (return_value = (mock .sentinel .tsn ,
269+ mock .sentinel .cmd_id ,
270+ False ,
271+ mock .sentinel .args , ))
272+ app .handle_join = mock .MagicMock ()
273+ app ._handle_reply = mock .MagicMock ()
274+ app .handle_message = mock .MagicMock ()
275+
276+ data = t .uint8_t (0xaa ).serialize ()
277+ data += addr_nwk .address .serialize ()
278+ data += addr_ieee .address .serialize ()
279+ data += t .uint8_t (0x8e ).serialize ()
280+
281+ app .handle_rx (
282+ addr_nwk ,
283+ mock .sentinel .src_ep ,
284+ dst_ep ,
285+ mock .sentinel .profile_id ,
286+ cluster_id ,
287+ data ,
288+ mock .sentinel .lqi ,
289+ mock .sentinel .rssi ,
290+ )
291+
292+ assert app .deserialize .call_count == 1
293+ assert app .deserialize .call_args [0 ][2 ] == cluster_id
294+ assert app .deserialize .call_args [0 ][3 ] == data
295+ assert app ._handle_reply .call_count == 0
296+ assert app .handle_message .call_count == 1
297+ assert app .handle_join .call_count == 1
298+ assert app .handle_join .call_args [0 ][0 ] == addr_nwk .address
299+ assert app .handle_join .call_args [0 ][1 ] == addr_ieee .address
300+ assert app .handle_join .call_args [0 ][2 ] == 0
0 commit comments