oh jubilee is sick you can block on signals!!

pull/36039/head
Shane Smiskol 1 week ago
parent 8d8148d279
commit 5d3437e78e
  1. 48
      system/ui/lib/wifi_manager.py

@ -7,6 +7,11 @@ from collections.abc import Callable
from dataclasses import dataclass
from enum import IntEnum
from collections import deque
from jeepney import DBusAddress, new_method_call
from jeepney.bus_messages import message_bus, MatchRule
from jeepney.io.blocking import open_dbus_connection
from openpilot.common.swaglog import cloudlog
from openpilot.system.ui.lib.networkmanager import (NM, NM_PROPERTIES_IFACE, NM_WIRELESS_IFACE, NM_802_11_AP_SEC_PAIR_WEP40,
NM_802_11_AP_SEC_PAIR_WEP104, NM_802_11_AP_SEC_GROUP_WEP40,
@ -109,6 +114,49 @@ class AccessPoint:
)
NM = "org.freedesktop.NetworkManager"
NM_PATH = "/org/freedesktop/NetworkManager"
NM_IFACE = "org.freedesktop.NetworkManager"
PROPS_IFACE = "org.freedesktop.DBus.Properties"
DEV_IFACE = "org.freedesktop.NetworkManager.Device"
def wait_props_changed(device_path: str):
conn = open_dbus_connection(bus="SYSTEM")
try:
# Subscribe to PropertiesChanged on that device
rule = MatchRule(
type="signal",
interface=PROPS_IFACE,
member="StateChanged",
path=device_path,
)
rule_props = MatchRule(type="signal", sender=NM, interface=PROPS_IFACE, member="PropertiesChanged", path=device_path)
rule_state = MatchRule(type="signal", sender=NM, interface=DEV_IFACE, member="StateChanged", path=device_path)
rule.add_arg_condition(0, DEV_IFACE) # only changes for Device iface
# Tell the bus we want these signals
conn.send_and_get_reply(message_bus.AddMatch(rule_props))
conn.send_and_get_reply(message_bus.AddMatch(rule_state))
# Block until a matching signal arrives
while True:
msg = conn.receive(timeout=None)
print(msg)
with conn.filter(rule, queue=deque(maxlen=1)) as q:
msg = conn.recv_until_filtered(q, timeout=None)
iface, changed, invalidated = msg.body # iface:str, changed:a{sv}, invalidated:as
# changed is a dict of {prop_name: Variant(...)} – pull what you need:
print('changed', changed)
state = changed.get("State")
if state is not None:
# state.value if you’re wrapping Variants; else plain int depending on your helpers
print("New device state:", state)
finally:
conn.close()
class WifiManager:
def __init__(self):
self._networks = [] # a network can be comprised of multiple APs

Loading…
Cancel
Save