Skip to content

Commit 9b4904f

Browse files
committed
Example netdevinfo-async: fix edge case when Wi-Fi is not connected
Instead of crashing just print "No active access point". NetworkManager indicates that wireless device not connected by returning "/" path.
1 parent 27f49cc commit 9b4904f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

examples/async/netdevinfo-async.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ async def list_networkdevice_details_async() -> None:
9797
if dev_type == DeviceType.WIFI.name:
9898
wifi = NetworkDeviceWireless(device_path)
9999
print("Wifi: ", WiFiOperationMode(await wifi.mode).name.title())
100-
ap = AccessPoint(await wifi.active_access_point)
101-
ssid: bytes = await ap.ssid
102-
if ssid:
103-
print("SSID: ", ssid.decode("utf-8", "ignore"))
104-
if await ap.strength:
105-
print("Signal: ", await ap.strength)
100+
ap_path = await wifi.active_access_point
101+
if ap_path == "/":
102+
print("No active access point")
103+
else:
104+
ap = AccessPoint(ap_path)
105+
ssid: bytes = await ap.ssid
106+
if ssid:
107+
print("SSID: ", ssid.decode("utf-8", "ignore"))
108+
if await ap.strength:
109+
print("Signal: ", await ap.strength)
106110
connection_id = await get_most_recent_connection_id(dev_name, dev_type)
107111
if connection_id:
108112
print("Profile:", connection_id)

0 commit comments

Comments
 (0)