mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-27 17:42:04 +08:00
Reduce wifi dbus calls pt. 4 (#37174)
* combine active AP and all APs into getall * combine these two functions reducing more calls * little clean up * down here
This commit is contained in:
@@ -527,30 +527,6 @@ class WifiManager:
|
||||
|
||||
threading.Thread(target=worker, daemon=True).start()
|
||||
|
||||
def _update_current_network_metered(self, active_conns) -> None:
|
||||
self._current_network_metered = MeteredType.UNKNOWN
|
||||
for active_conn in active_conns:
|
||||
conn_addr = DBusAddress(active_conn, bus_name=NM, interface=NM_ACTIVE_CONNECTION_IFACE)
|
||||
props = self._router_main.send_and_get_reply(Properties(conn_addr).get_all()).body[0]
|
||||
|
||||
if props.get('Type', ('s', ''))[1] == '802-11-wireless':
|
||||
conn_path = props.get('Connection', ('o', '/'))[1]
|
||||
if conn_path == "/":
|
||||
continue
|
||||
|
||||
settings = self._get_connection_settings(conn_path)
|
||||
|
||||
if len(settings) == 0:
|
||||
cloudlog.warning(f'Failed to get connection settings for {conn_path}')
|
||||
continue
|
||||
|
||||
metered_prop = settings['connection'].get('metered', ('i', 0))[1]
|
||||
if metered_prop == MeteredType.YES:
|
||||
self._current_network_metered = MeteredType.YES
|
||||
elif metered_prop == MeteredType.NO:
|
||||
self._current_network_metered = MeteredType.NO
|
||||
return
|
||||
|
||||
def set_current_network_metered(self, metered: MeteredType):
|
||||
def worker():
|
||||
for active_conn in self._get_active_connections():
|
||||
@@ -595,10 +571,11 @@ class WifiManager:
|
||||
cloudlog.warning("No WiFi device found")
|
||||
return
|
||||
|
||||
# returns '/' if no active AP
|
||||
# NOTE: AccessPoints property may exclude hidden APs (use GetAllAccessPoints method if needed)
|
||||
wifi_addr = DBusAddress(self._wifi_device, NM, interface=NM_WIRELESS_IFACE)
|
||||
active_ap_path = self._router_main.send_and_get_reply(Properties(wifi_addr).get('ActiveAccessPoint')).body[0][1]
|
||||
ap_paths = self._router_main.send_and_get_reply(new_method_call(wifi_addr, 'GetAllAccessPoints')).body[0]
|
||||
wifi_props = self._router_main.send_and_get_reply(Properties(wifi_addr).get_all()).body[0]
|
||||
active_ap_path = wifi_props.get('ActiveAccessPoint', ('o', '/'))[1]
|
||||
ap_paths = wifi_props.get('AccessPoints', ('ao', []))[1]
|
||||
|
||||
aps: dict[str, list[AccessPoint]] = {}
|
||||
|
||||
@@ -630,20 +607,20 @@ class WifiManager:
|
||||
networks.sort(key=lambda n: (-n.is_connected, -n.is_saved, -round(n.strength / 100 * 2), n.ssid.lower()))
|
||||
self._networks = networks
|
||||
|
||||
# Get active connections once
|
||||
active_conns = self._get_active_connections()
|
||||
self._update_ipv4_address(active_conns)
|
||||
self._update_current_network_metered(active_conns)
|
||||
self._update_active_connection_info()
|
||||
|
||||
self._enqueue_callbacks(self._networks_updated, self._networks)
|
||||
|
||||
def _update_ipv4_address(self, active_conns):
|
||||
def _update_active_connection_info(self):
|
||||
self._ipv4_address = ""
|
||||
self._current_network_metered = MeteredType.UNKNOWN
|
||||
|
||||
for conn_path in active_conns:
|
||||
conn_addr = DBusAddress(conn_path, bus_name=NM, interface=NM_ACTIVE_CONNECTION_IFACE)
|
||||
for active_conn in self._get_active_connections():
|
||||
conn_addr = DBusAddress(active_conn, bus_name=NM, interface=NM_ACTIVE_CONNECTION_IFACE)
|
||||
props = self._router_main.send_and_get_reply(Properties(conn_addr).get_all()).body[0]
|
||||
|
||||
if props.get('Type', ('s', ''))[1] == '802-11-wireless':
|
||||
# IPv4 address
|
||||
ip4config_path = props.get('Ip4Config', ('o', '/'))[1]
|
||||
|
||||
if ip4config_path != "/":
|
||||
@@ -653,7 +630,21 @@ class WifiManager:
|
||||
for entry in address_data:
|
||||
if 'address' in entry:
|
||||
self._ipv4_address = entry['address'][1]
|
||||
return
|
||||
break
|
||||
|
||||
# Metered status
|
||||
conn_path = props.get('Connection', ('o', '/'))[1]
|
||||
if conn_path != "/":
|
||||
settings = self._get_connection_settings(conn_path)
|
||||
|
||||
if len(settings) > 0:
|
||||
metered_prop = settings['connection'].get('metered', ('i', 0))[1]
|
||||
|
||||
if metered_prop == MeteredType.YES:
|
||||
self._current_network_metered = MeteredType.YES
|
||||
elif metered_prop == MeteredType.NO:
|
||||
self._current_network_metered = MeteredType.NO
|
||||
return
|
||||
|
||||
def __del__(self):
|
||||
self.stop()
|
||||
|
||||
Reference in New Issue
Block a user