@@ -354,7 +354,7 @@ async def test_force_remove(app):
354354 await app .force_remove (sentinel .device )
355355
356356
357- async def test_restore_neighbours (app ):
357+ async def test_restore_neighbours (app , caplog ):
358358 """Test neighbour restoration."""
359359
360360 # FFD, Rx on when idle
@@ -372,6 +372,10 @@ async def test_restore_neighbours(app):
372372 device_5 = app .add_device (nwk = 0x0005 , ieee = EUI64 .convert ("00:00:00:00:00:00:00:05" ))
373373 device_5 .node_desc = zdo_t .NodeDescriptor (2 , 64 , 128 , 0xBEEF , 82 , 82 , 0 , 82 , 0 )
374374
375+ # RFD, Rx off when idle (duplicate)
376+ device_6 = app .add_device (nwk = 0x0005 , ieee = EUI64 .convert ("00:00:00:00:00:00:00:06" ))
377+ device_6 .node_desc = zdo_t .NodeDescriptor (2 , 64 , 128 , 0xBEEF , 82 , 82 , 0 , 82 , 0 )
378+
375379 coord = MagicMock ()
376380 coord .ieee = EUI64 .convert ("aa:aa:aa:aa:aa:aa:aa:aa" )
377381
@@ -384,16 +388,33 @@ async def test_restore_neighbours(app):
384388 zdo_t .Neighbor (ieee = device_3 .ieee ),
385389 zdo_t .Neighbor (ieee = EUI64 .convert ("00:00:00:00:00:00:00:04" )),
386390 zdo_t .Neighbor (ieee = device_5 .ieee ),
391+ zdo_t .Neighbor (ieee = device_6 .ieee ),
387392 ]
388393
394+ max_neighbors = 1
395+
396+ def mock_add_neighbour (nwk , ieee , mac_capability_flags ):
397+ nonlocal max_neighbors
398+ max_neighbors -= 1
399+
400+ if max_neighbors < 0 :
401+ raise zigpy_deconz .exception .CommandError (
402+ deconz_api .Status .FAILURE , "Failure"
403+ )
404+
389405 p = patch .object (app , "_api" , spec_set = zigpy_deconz .api .Deconz (None , None ))
390406
391407 with p as api_mock :
392- api_mock .add_neighbour = AsyncMock ()
393- await app .restore_neighbours ()
408+ err = zigpy_deconz .exception .CommandError (deconz_api .Status .FAILURE , "Failure" )
409+ api_mock .add_neighbour = AsyncMock (side_effect = [None , err , err , err ])
410+
411+ with caplog .at_level (logging .DEBUG ):
412+ await app .restore_neighbours ()
413+
414+ assert caplog .text .count ("Failed to add device to neighbor table" ) == 1
394415
395- assert api_mock .add_neighbour .call_count == 1
396- assert api_mock .add_neighbour .await_count == 1
416+ assert api_mock .add_neighbour .call_count == 2
417+ assert api_mock .add_neighbour .await_count == 2
397418
398419
399420@patch ("zigpy_deconz.zigbee.application.DELAY_NEIGHBOUR_SCAN_S" , 0 )
0 commit comments