Skip to content

Commit e19a286

Browse files
Tweak HotspotSettings:
- show hotspot name + security in status - hide password for none security - hotspot enabled/disabled should NOT be persisted, only starts/stops the hotspot
1 parent 3e6ee11 commit e19a286

2 files changed

Lines changed: 26 additions & 17 deletions

File tree

internal_filesystem/builtin/apps/com.micropythonos.hotspot/assets/hotspot_settings.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class HotspotSettings(Activity):
1212
"""
1313

1414
DEFAULTS = {
15-
"enabled": False,
1615
"ssid": "MicroPythonOS",
1716
"password": "",
1817
"channel": 1,
@@ -77,18 +76,21 @@ def onResume(self, screen):
7776
def refresh_status(self):
7877
is_running = WifiService.is_hotspot_enabled()
7978
state_text = "Running" if is_running else "Stopped"
80-
self.status_label.set_text(f"Status: {state_text}")
79+
ssid = self.prefs.get_string("ssid", self.DEFAULTS["ssid"])
80+
authmode = self.prefs.get_string("authmode", None)
81+
security_text = self._format_security_label(authmode)
82+
self.status_label.set_text(
83+
f"Status: {state_text}\nHotspot name: {ssid}\nSecurity: {security_text}"
84+
)
8185
button_text = "Stop" if is_running else "Start"
8286
self.action_label.set_text(button_text)
8387
self.action_label.center()
8488

8589
def toggle_hotspot_button(self, event):
8690
if WifiService.is_hotspot_enabled():
8791
WifiService.disable_hotspot()
88-
self._set_enabled_pref(False)
8992
else:
9093
WifiService.enable_hotspot()
91-
self._set_enabled_pref(True)
9294
self.refresh_status()
9395

9496
def open_settings(self, event):
@@ -108,35 +110,43 @@ def _settings_entries(self):
108110
"title": "Password",
109111
"key": "password",
110112
"placeholder": "Leave empty for open network",
113+
"should_show": self.should_show_password,
111114
},
112115
{
113116
"title": "Auth Mode",
114117
"key": "authmode",
115118
"ui": "dropdown",
116119
"ui_options": [
117120
("Auto", None),
118-
("Open", "open"),
119-
("WPA", "wpa"),
121+
("None", "none"),
122+
#("Open", "open"),
123+
#("WPA", "wpa"),
120124
("WPA2", "wpa2"),
121-
("WPA/WPA2", "wpa_wpa2"),
125+
#("WPA/WPA2", "wpa_wpa2"),
122126
],
123127
"changed_callback": self.toggle_hotspot,
124128
},
125129
]
126130

127131
def toggle_hotspot(self, new_value):
128-
enabled_value = self.prefs.get_string("enabled", "False")
129-
should_enable = str(enabled_value).lower() in ("true", "1", "yes", "on")
130-
if should_enable:
132+
if WifiService.is_hotspot_enabled():
131133
WifiService.enable_hotspot()
132-
else:
133-
WifiService.disable_hotspot()
134134
self.refresh_status()
135135

136-
def _set_enabled_pref(self, enabled):
137-
editor = self.prefs.edit()
138-
editor.put_string("enabled", "True" if enabled else "False")
139-
editor.apply()
136+
def should_show_password(self, setting):
137+
authmode = self.prefs.get_string("authmode", None)
138+
return authmode != "none"
139+
140+
def _format_security_label(self, authmode):
141+
labels = {
142+
None: "Auto",
143+
"none": "None",
144+
"open": "Open",
145+
#"wpa": "WPA",
146+
"wpa2": "WPA2",
147+
#"wpa_wpa2": "WPA/WPA2",
148+
}
149+
return labels.get(authmode, "Auto")
140150

141151

142152
'''

internal_filesystem/lib/mpos/net/wifi_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def _resolve_hotspot_authmode(net, password, authmode_value):
8282
"open": net.AUTH_OPEN,
8383
"wpa": net.AUTH_WPA_PSK,
8484
"wpa2": net.AUTH_WPA2_PSK,
85-
"wpa_wpa2": net.AUTH_WPA_WPA2_PSK,
8685
"wpa-wpa2": net.AUTH_WPA_WPA2_PSK,
8786
}
8887
return mapping.get(authmode_key, net.AUTH_WPA_WPA2_PSK)

0 commit comments

Comments
 (0)