dotfiles/duskwm/.config/dusk/status_scripts/scripts/get_wifi.py

49 lines
1.5 KiB
Python
Raw Normal View History

2025-06-24 16:57:29 -04:00
import subprocess
from theme import current_theme, default
dbmRange = {(-10, "󰤨"), (-70, "󰤥"), (-80, "󰤢"), (-90, "󰤟")}
# full data
try:
data = subprocess.run(
["iwctl", "station", "wlan0", "show"], stdout=subprocess.PIPE, encoding="utf-8"
2025-06-24 16:57:29 -04:00
).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"] = ' '.join(l.split()[2:])
2025-06-24 16:57:29 -04:00
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