From f0cdb790777a2768154bc8253b3e8b07827c4236 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 22 Aug 2025 04:10:48 -0700 Subject: [PATCH] forget and connect --- system/ui/lib/wifi_manager_v2.py | 49 +++++++++++++++++++++++++++++--- system/ui/widgets/network.py | 2 +- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/system/ui/lib/wifi_manager_v2.py b/system/ui/lib/wifi_manager_v2.py index fa15a77b52..a3ff8e9315 100644 --- a/system/ui/lib/wifi_manager_v2.py +++ b/system/ui/lib/wifi_manager_v2.py @@ -64,7 +64,7 @@ class Network: strength=strongest_ap.strength, is_connected=is_connected, security_type=security_type, - is_saved=False, # TODO + is_saved=True, # TODO ) @@ -159,14 +159,55 @@ class WifiManager: return wifi_device def connect_to_network(self, ssid: str, password: str | None): - self._forget_connection(ssid) - ... + t = time.monotonic() + + # Clear all connections that may already exist to the network we are connecting + self.forget_connection(ssid) + + is_hidden = False + + connection = { + 'connection': { + 'type': '802-11-wireless', + 'uuid': str(uuid.uuid4()), + 'id': f'openpilot connection {ssid}', + 'autoconnect-retries': 0, + }, + '802-11-wireless': { + 'ssid': dbus.ByteArray(ssid.encode("utf-8")), + 'hidden': is_hidden, + 'mode': 'infrastructure', + }, + 'ipv4': { + 'method': 'auto', + 'dns-priority': 600, + }, + 'ipv6': {'method': 'ignore'}, + } + + if password is not None: + connection['802-11-wireless-security'] = { + 'key-mgmt': 'wpa-psk', + 'auth-alg': 'open', + 'psk': password, + } + + settings = dbus.Interface( + self._bus.get_object(NM, NM_SETTINGS_PATH), + NM_SETTINGS_IFACE + ) + + conn_path = settings.AddConnection(connection) + + print('Added connection', conn_path) + + print(f'Connecting to network took {time.monotonic() - t}s') def _get_connections(self) -> list[dbus.ObjectPath]: settings_iface = dbus.Interface(self._bus.get_object(NM, NM_SETTINGS_PATH), NM_SETTINGS_IFACE) return settings_iface.ListConnections() - def _forget_connection(self, ssid: str): + def forget_connection(self, ssid: str): for conn_path in self._get_connections(): conn_props = dbus.Interface(self._bus.get_object(NM, conn_path), NM_CONNECTION_IFACE) settings = conn_props.GetSettings() diff --git a/system/ui/widgets/network.py b/system/ui/widgets/network.py index cdd09782db..d67d56821b 100644 --- a/system/ui/widgets/network.py +++ b/system/ui/widgets/network.py @@ -224,7 +224,7 @@ class WifiManagerUI(Widget): def forget_network(self, network: NetworkInfo): self.state = StateForgetting(network) - network.is_saved = False + # network.is_saved = False self.wifi_manager.forget_connection(network.ssid) def _on_network_updated(self, networks: list[Network]):