Skip to content

Commit aa58eaa

Browse files
committed
Properly deduplicate scanned networks
1 parent f775fb5 commit aa58eaa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

zigpy_cli/radio.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,25 @@ def iter_channels():
304304

305305
await asyncio.sleep(1)
306306
for channel in channels:
307-
print(f"Scanning for networks on channel {channel}")
308307
networks = set()
309308

310309
for attempt in range(num_network_scans):
310+
print(
311+
"Scanning for networks on channel"
312+
f" {channel} ({attempt + 1} / {num_network_scans})"
313+
)
311314
networks_scan = await app._ezsp.startScan(
312315
scanType=bellows.types.EzspNetworkScanType.ACTIVE_SCAN,
313316
channelMask=zigpy.types.Channels.from_channel_list([channel]),
314317
duration=6,
315318
)
316-
networks_scan = tuple(
317-
[(network.freeze(), lqi, rssi) for network, lqi, rssi in networks_scan]
318-
)
319-
new_networks = set(networks_scan) - networks
320319

321-
for network, lqi, rssi in new_networks:
320+
for network, lqi, rssi in networks_scan:
321+
if network.replace(allowingJoin=None).freeze() in networks:
322+
continue
323+
324+
networks.add(network.replace(allowingJoin=None).freeze())
325+
322326
print(f"Found network {network}: LQI={lqi}, RSSI={rssi}")
323327
scan_data["network_scan"].append(
324328
{
@@ -332,8 +336,6 @@ def iter_channels():
332336
}
333337
)
334338

335-
networks.update(new_networks)
336-
337339
json.dump(scan_data, output, separators=(",", ":"))
338340

339341

0 commit comments

Comments
 (0)