66import pytest
77import zigpy .config
88import zigpy .device
9- import zigpy .neighbor
109from zigpy .types import EUI64
1110import zigpy .zdo .types as zdo_t
1211
@@ -357,52 +356,37 @@ async def test_restore_neighbours(app):
357356 """Test neighbour restoration."""
358357
359358 # FFD, Rx on when idle
360- desc_1 = zdo_t .NodeDescriptor (1 , 64 , 142 , 0xBEEF , 82 , 82 , 0 , 82 , 0 )
361- device_1 = MagicMock ()
362- device_1 .node_desc = desc_1
363- device_1 .ieee = sentinel .ieee_1
364- device_1 .nwk = 0x1111
365- nei_1 = zigpy .neighbor .Neighbor (sentinel .nei_1 , device_1 )
359+ device_1 = app .add_device (nwk = 0x0001 , ieee = EUI64 .convert ("00:00:00:00:00:00:00:01" ))
360+ device_1 .node_desc = zdo_t .NodeDescriptor (1 , 64 , 142 , 0xBEEF , 82 , 82 , 0 , 82 , 0 )
366361
367362 # RFD, Rx on when idle
368- desc_2 = zdo_t .NodeDescriptor (1 , 64 , 142 , 0xBEEF , 82 , 82 , 0 , 82 , 0 )
369- device_2 = MagicMock ()
370- device_2 .node_desc = desc_2
371- device_2 .ieee = sentinel .ieee_2
372- device_2 .nwk = 0x2222
373- nei_2 = zigpy .neighbor .Neighbor (sentinel .nei_2 , device_2 )
374-
375- # Missing node descriptor
376- device_3 = MagicMock ()
377- device_3 .node_desc = None
378- device_3 .ieee = sentinel .ieee_3
379- device_3 .nwk = 0x3333
380- nei_3 = zigpy .neighbor .Neighbor (sentinel .nei_3 , device_3 )
363+ device_2 = app .add_device (nwk = 0x0002 , ieee = EUI64 .convert ("00:00:00:00:00:00:00:02" ))
364+ device_2 .node_desc = zdo_t .NodeDescriptor (1 , 64 , 142 , 0xBEEF , 82 , 82 , 0 , 82 , 0 )
381365
382- # no device
383- nei_4 = zigpy . neighbor . Neighbor ( sentinel . nei_4 , None )
366+ device_3 = app . add_device ( nwk = 0x0003 , ieee = EUI64 . convert ( "00:00:00:00:00:00:00:03" ))
367+ device_3 . node_desc = None
384368
385369 # RFD, Rx off when idle
386- desc_5 = zdo_t .NodeDescriptor (2 , 64 , 128 , 0xBEEF , 82 , 82 , 0 , 82 , 0 )
387- device_5 = MagicMock ()
388- device_5 .node_desc = desc_5
389- device_5 .ieee = sentinel .ieee_5
390- device_5 .nwk = 0x5555
391- nei_5 = zigpy .neighbor .Neighbor (sentinel .nei_5 , device_5 )
370+ device_5 = app .add_device (nwk = 0x0005 , ieee = EUI64 .convert ("00:00:00:00:00:00:00:05" ))
371+ device_5 .node_desc = zdo_t .NodeDescriptor (2 , 64 , 128 , 0xBEEF , 82 , 82 , 0 , 82 , 0 )
392372
393373 coord = MagicMock ()
394- coord .ieee = sentinel .coord_ieee
395- coord .nwk = 0x0000
396- neighbours = zigpy .neighbor .Neighbors (coord )
397- neighbours .neighbors .append (nei_1 )
398- neighbours .neighbors .append (nei_2 )
399- neighbours .neighbors .append (nei_3 )
400- neighbours .neighbors .append (nei_4 )
401- neighbours .neighbors .append (nei_5 )
402- coord .neighbors = neighbours
403-
404- p2 = patch .object (app , "_api" , spec_set = zigpy_deconz .api .Deconz (None , None ))
405- with patch .object (app , "get_device" , return_value = coord ), p2 as api_mock :
374+ coord .ieee = EUI64 .convert ("aa:aa:aa:aa:aa:aa:aa:aa" )
375+
376+ app .devices [coord .ieee ] = coord
377+ app .state .node_info .ieee = coord .ieee
378+
379+ app .topology .neighbors [coord .ieee ] = [
380+ zdo_t .Neighbor (ieee = device_1 .ieee ),
381+ zdo_t .Neighbor (ieee = device_2 .ieee ),
382+ zdo_t .Neighbor (ieee = device_3 .ieee ),
383+ zdo_t .Neighbor (ieee = EUI64 .convert ("00:00:00:00:00:00:00:04" )),
384+ zdo_t .Neighbor (ieee = device_5 .ieee ),
385+ ]
386+
387+ p = patch .object (app , "_api" , spec_set = zigpy_deconz .api .Deconz (None , None ))
388+
389+ with p as api_mock :
406390 api_mock .add_neighbour = AsyncMock ()
407391 await app .restore_neighbours ()
408392
@@ -415,7 +399,6 @@ async def test_delayed_scan():
415399 """Delayed scan."""
416400
417401 coord = MagicMock ()
418- coord .neighbors .scan = AsyncMock ()
419402 config = application .ControllerApplication .SCHEMA (
420403 {
421404 zigpy .config .CONF_DEVICE : {zigpy .config .CONF_DEVICE_PATH : "usb0" },
@@ -425,8 +408,9 @@ async def test_delayed_scan():
425408
426409 app = application .ControllerApplication (config )
427410 with patch .object (app , "get_device" , return_value = coord ):
428- await app ._delayed_neighbour_scan ()
429- assert coord .neighbors .scan .await_count == 1
411+ with patch .object (app , "topology" , AsyncMock ()):
412+ await app ._delayed_neighbour_scan ()
413+ app .topology .scan .assert_called_once_with (devices = [coord ])
430414
431415
432416@patch ("zigpy_deconz.zigbee.application.CHANGE_NETWORK_WAIT" , 0.001 )
0 commit comments