Skip to content

Commit

Permalink
Properly deduplicate scanned networks
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Aug 12, 2024
1 parent f775fb5 commit aa58eaa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions zigpy_cli/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,21 +304,25 @@ def iter_channels():

await asyncio.sleep(1)
for channel in channels:
print(f"Scanning for networks on channel {channel}")
networks = set()

for attempt in range(num_network_scans):
print(
"Scanning for networks on channel"
f" {channel} ({attempt + 1} / {num_network_scans})"
)
networks_scan = await app._ezsp.startScan(
scanType=bellows.types.EzspNetworkScanType.ACTIVE_SCAN,
channelMask=zigpy.types.Channels.from_channel_list([channel]),
duration=6,
)
networks_scan = tuple(
[(network.freeze(), lqi, rssi) for network, lqi, rssi in networks_scan]
)
new_networks = set(networks_scan) - networks

for network, lqi, rssi in new_networks:
for network, lqi, rssi in networks_scan:
if network.replace(allowingJoin=None).freeze() in networks:
continue

networks.add(network.replace(allowingJoin=None).freeze())

print(f"Found network {network}: LQI={lqi}, RSSI={rssi}")
scan_data["network_scan"].append(
{
Expand All @@ -332,8 +336,6 @@ def iter_channels():
}
)

networks.update(new_networks)

json.dump(scan_data, output, separators=(",", ":"))


Expand Down

0 comments on commit aa58eaa

Please sign in to comment.