Skip to content

Commit

Permalink
core: services: wifi: Remove all wifis with same ssid in database
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Jul 26, 2023
1 parent 7318cb2 commit 58094a5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/services/wifi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ async def remove(ssid: str) -> Any:
logger.info(f"Trying to remove network '{ssid}'.")
try:
saved_networks = await wifi_manager.get_saved_wifi_network()
match_network = next(filter(lambda network: network.ssid == ssid, saved_networks))
await wifi_manager.remove_network(match_network.networkid)
# Here we get all networks that match the ssid
# and get a list where the biggest networkid comes first.
# If we remove the lowest numbers first, it'll change the highest values to -1
# TODO: We should move the entire wifi framestack to work with bssid
match_networks = [network for network in saved_networks if network.ssid == ssid]
match_networks = sorted(match_networks, key=lambda network: network.networkid, reverse=True)
for match_network in match_networks:
await wifi_manager.remove_network(match_network.networkid)
except StopIteration as error:
logger.info(f"Network '{ssid}' is unknown.")
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=f"Network '{ssid}' not saved.") from error
Expand Down

0 comments on commit 58094a5

Please sign in to comment.