@@ -6,54 +6,38 @@ def wifi(ifname):
66 wifi_data = {}
77
88 try :
9-
10- data = HOST .run (tuple (f"wpa_cli -i { ifname } status" .split ()), default = "" )
119 iw_data = HOST .run (tuple (f"iw dev { ifname } info" .split ()), default = "" )
12-
13- if iw_data != "" :
14- for line in iw_data .splitlines ():
15- line = line .strip () # Fix crazy output from iw.
16- l = line .split (" " )
17- if l [0 ] == "type" :
18- if l [1 ] == "AP" :
10+ if iw_data != "" :
11+ for line in iw_data .splitlines ():
12+ line = line .strip () # Fix crazy output from iw.
13+ if line == "type AP" :
1914 wifi_data ["mode" ] = "accesspoint"
15+ break
2016 else :
2117 wifi_data ["mode" ] = "station"
2218
23- if wifi_data ["mode" ] == "station" :
24- station_data = HOST .run (tuple (f"wpa_cli -i { ifname } status" .split ()), default = "" )
25- if station_data != "" :
26- for line in station_data .splitlines ():
27- k ,v = line .split ("=" )
28- if k == "ssid" :
29- wifi_data ["active-ssid" ] = v
30- except ValueError :
31- # Skip malformed lines
32- continue
33-
34- try :
35- if wifi_data ["mode" ] == "client" :
36- client_data = HOST .run (tuple (f"wpa_cli -i { ifname } status" .split ()), default = "" )
37- if client_data != "" :
38- for line in client_data .splitlines ():
39- k ,v = line .split ("=" )
40- if k == "ssid" :
41- wifi_data ["active-ssid" ] = v
42-
43- data = HOST .run (tuple (f"wpa_cli -i { ifname } signal_poll" .split ()), default = "FAIL" )
44-
45- # signal_poll return FAIL not connected
46- if data .strip () != "FAIL" :
47- for line in data .splitlines ():
48- k ,v = line .strip ().split ("=" )
49- if k == "RSSI" :
50- wifi_data ["active-rssi" ]= int (v )
51- data = HOST .run (tuple (f"wpa_cli -i { ifname } scan_result" .split ()), default = "FAIL" )
52- if data != "FAIL" :
53- wifi_data ["scan-results" ] = parse_wpa_scan_result (data )
54- elif wifi_data ["mode" ] == "accesspoint" :
55- stations = HOST .run_json (tuple (f"/usr/libexec/infix/wifi-ap-stations { ifname } " .split ()), default = [])
56- wifi_data ["connected-stations" ] = stations
19+ if wifi_data ["mode" ] == "station" :
20+ client_data = HOST .run (tuple (f"wpa_cli -i { ifname } status" .split ()), default = "" )
21+ if client_data != "" :
22+ for line in client_data .splitlines ():
23+ k ,v = line .split ("=" )
24+ if k == "ssid" :
25+ wifi_data ["active-ssid" ] = v
26+
27+ data = HOST .run (tuple (f"wpa_cli -i { ifname } signal_poll" .split ()), default = "FAIL" )
28+
29+ # signal_poll return FAIL not connected
30+ if data .strip () != "FAIL" :
31+ for line in data .splitlines ():
32+ k ,v = line .strip ().split ("=" )
33+ if k == "RSSI" :
34+ wifi_data ["active-rssi" ]= int (v )
35+ data = HOST .run (tuple (f"wpa_cli -i { ifname } scan_result" .split ()), default = "FAIL" )
36+ if data != "FAIL" :
37+ wifi_data ["scan-results" ] = parse_wpa_scan_result (data )
38+ elif wifi_data ["mode" ] == "accesspoint" :
39+ stations = HOST .run_json (tuple (f"/usr/libexec/infix/wifi-ap-stations { ifname } " .split ()), default = [])
40+ wifi_data ["connected-stations" ] = stations
5741 except Exception :
5842 # If status query fails entirely, continue with scan results
5943 pass
0 commit comments