From 58685b077e15c32407ddfdceba7805b106f1f20c Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Fri, 19 Dec 2025 14:00:34 +0100 Subject: [PATCH] WiFi app: improve 'forget' handling --- .../apps/com.micropythonos.wifi/assets/wifi.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/internal_filesystem/builtin/apps/com.micropythonos.wifi/assets/wifi.py b/internal_filesystem/builtin/apps/com.micropythonos.wifi/assets/wifi.py index 5ba32fb6..706abd86 100644 --- a/internal_filesystem/builtin/apps/com.micropythonos.wifi/assets/wifi.py +++ b/internal_filesystem/builtin/apps/com.micropythonos.wifi/assets/wifi.py @@ -69,8 +69,8 @@ class WiFi(Activity): if not self.prefs: self.prefs = mpos.config.SharedPreferences("com.micropythonos.system.wifiservice") - global access_points - access_points = self.prefs.get_dict("access_points") + self.access_points = self.prefs.get_dict("access_points") + print(f"loaded access points from preferences: {self.access_points}") if len(self.ssids) == 0: if WifiService.wifi_busy == False: WifiService.wifi_busy = True @@ -128,7 +128,8 @@ class WiFi(Activity): print("refresh_list: Clearing current list") self.aplist.clean() # this causes an issue with lost taps if an ssid is clicked that has been removed print("refresh_list: Populating list with scanned networks") - for ssid in self.ssids: + self.ssids = list(set(self.ssids + list(ssid for ssid in self.access_points))) + for ssid in set(self.ssids): if len(ssid) < 1 or len(ssid) > 32: print(f"Skipping too short or long SSID: {ssid}") continue @@ -143,7 +144,7 @@ class WiFi(Activity): if status != "connected": if self.last_tried_ssid == ssid: # implies not connected because not wlan.isconnected() status = self.last_tried_result - elif ssid in access_points: + elif ssid in self.access_points: status="saved" label=lv.label(button) label.set_text(status) @@ -176,18 +177,20 @@ class WiFi(Activity): forget = data.get("forget") if forget: try: - del access_points[ssid] + del self.access_points[ssid] + self.ssids.remove(ssid) editor.put_dict("access_points", self.access_points) editor.commit() self.refresh_list() except Exception as e: - print(f"Error when trying to forget access point, it might not have been remembered in the first place: {e}") + print(f"WARNING: could not forget access point, maybe it wasn't remembered in the first place: {e}") else: # save or update password = data.get("password") hidden = data.get("hidden") self.setPassword(ssid, password, hidden) editor.put_dict("access_points", self.access_points) editor.commit() + print(f"access points: {self.access_points}") self.start_attempt_connecting(ssid, password) def start_attempt_connecting(self, ssid, password):