|
6 | 6 | from zigpy_znp.types.nvids import NwkNvIds
|
7 | 7 | from zigpy_znp.tools.network_scan import main as network_scan
|
8 | 8 |
|
9 |
| -from ..conftest import FormedLaunchpadCC26X2R1 |
| 9 | +from ..conftest import FormedZStack1CC2531, FormedLaunchpadCC26X2R1 |
10 | 10 |
|
11 | 11 | pytestmark = [pytest.mark.asyncio]
|
12 | 12 |
|
@@ -322,3 +322,57 @@ async def test_network_scan_duplicates(device, make_znp_server, capsys):
|
322 | 322 |
|
323 | 323 | # No duplicates were filtered
|
324 | 324 | assert captured.out.count(", from: ") == 4
|
| 325 | + |
| 326 | + |
| 327 | +@pytest.mark.parametrize("device", [FormedZStack1CC2531, FormedLaunchpadCC26X2R1]) |
| 328 | +async def test_network_scan_nib_clear(device, make_znp_server, capsys): |
| 329 | + znp_server = make_znp_server(server_cls=device) |
| 330 | + old_nib = znp_server.nib.serialize() |
| 331 | + |
| 332 | + beacon = t.Beacon( |
| 333 | + Src=0x0000, |
| 334 | + PanId=0x7ABE, |
| 335 | + Channel=25, |
| 336 | + PermitJoining=0, |
| 337 | + RouterCapacity=1, |
| 338 | + DeviceCapacity=1, |
| 339 | + ProtocolVersion=2, |
| 340 | + StackProfile=2, |
| 341 | + LQI=39, |
| 342 | + Depth=0, |
| 343 | + UpdateId=0, |
| 344 | + ExtendedPanId=t.EUI64.convert("92:6b:f8:1e:df:1b:e8:1c"), |
| 345 | + ) |
| 346 | + |
| 347 | + znp_server.reply_once_to( |
| 348 | + c.ZDO.NetworkDiscoveryReq.Req(Channels=t.Channels.ALL_CHANNELS, ScanDuration=2), |
| 349 | + responses=[ |
| 350 | + c.ZDO.NetworkDiscoveryReq.Rsp(Status=t.Status.SUCCESS), |
| 351 | + c.ZDO.BeaconNotifyInd.Callback(Beacons=[beacon]), |
| 352 | + c.ZDO.NwkDiscoveryCnf.Callback(Status=t.ZDOStatus.SUCCESS), |
| 353 | + ], |
| 354 | + ) |
| 355 | + |
| 356 | + nib_deleted = znp_server.reply_once_to( |
| 357 | + c.SYS.OSALNVDelete.Req(Id=NwkNvIds.NIB, ItemLen=len(old_nib)), |
| 358 | + responses=[], |
| 359 | + ) |
| 360 | + |
| 361 | + nib_written = znp_server.reply_once_to( |
| 362 | + c.SYS.OSALNVWriteExt.Req(Id=NwkNvIds.NIB, Offset=0, Value=old_nib), |
| 363 | + responses=[], |
| 364 | + ) |
| 365 | + |
| 366 | + await network_scan([znp_server._port_path, "-v", "-v", "-n", "1"]) |
| 367 | + |
| 368 | + captured = capsys.readouterr() |
| 369 | + |
| 370 | + # No duplicates were filtered |
| 371 | + assert captured.out.count(", from: ") == 1 |
| 372 | + |
| 373 | + if device is FormedZStack1CC2531: |
| 374 | + await nib_deleted |
| 375 | + await nib_written |
| 376 | + else: |
| 377 | + assert not nib_deleted.done() |
| 378 | + assert not nib_written.done() |
0 commit comments