forget and connect

pull/36039/head
Shane Smiskol 6 days ago
parent 0a0d42d449
commit f0cdb79077
  1. 49
      system/ui/lib/wifi_manager_v2.py
  2. 2
      system/ui/widgets/network.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()

@ -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]):

Loading…
Cancel
Save