Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: services: wifi: Remove all wifis with same ssid in database #1899

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions core/services/wifi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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