49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
|
import subprocess
|
||
|
|
||
|
from theme import current_theme, default
|
||
|
|
||
|
dbmRange = {(-10, ""), (-70, ""), (-80, ""), (-90, "")}
|
||
|
|
||
|
# full data
|
||
|
try:
|
||
|
data = subprocess.run(
|
||
|
["iwd", "station", "wlan0", "show"], stdout=subprocess.PIPE, encoding="utf-8"
|
||
|
).stdout.split("\n")
|
||
|
|
||
|
status = {}
|
||
|
for line in data:
|
||
|
line = line.strip()
|
||
|
if not line:
|
||
|
continue
|
||
|
|
||
|
match line:
|
||
|
case l if l.startswith("State"):
|
||
|
status["state"] = l.split()[1]
|
||
|
case l if l.startswith("Connected network"):
|
||
|
status["SSID"] = l.split()[2:]
|
||
|
case l if l.startswith("Frequency"):
|
||
|
f = int(l.split()[1])
|
||
|
if f >= 5925:
|
||
|
status["frequency"] = "6G"
|
||
|
elif f >= 5000:
|
||
|
status["frequency"] = "5G"
|
||
|
elif f >= 2400:
|
||
|
status["frequency"] = "2.4G"
|
||
|
else:
|
||
|
f = f / 1000
|
||
|
status["frequency"] = f"{f}GHz"
|
||
|
case l if l.startswith("RSSI"):
|
||
|
dbm = int(l.split()[1])
|
||
|
for value, icon in dbmRange:
|
||
|
if dbm < value:
|
||
|
status["icon"] = icon
|
||
|
|
||
|
status["strength"] = dbm
|
||
|
|
||
|
if status["state"] == "connected":
|
||
|
content = f"{status['icon']} {status['SSID']}({status['frequency']})"
|
||
|
else:
|
||
|
content = ""
|
||
|
except Exception:
|
||
|
content = None
|