dotfiles/.config/i3pystatus/rfkill-wifi.py

32 lines
702 B
Python
Executable file

#!/usr/bin/python
from subprocess import check_output
devices = {}
for line in check_output(['rfkill', '-rn']).decode('UTF-8').splitlines():
nr, identifier, device, soft, hard = line.split(' ')
devices[device] = {
'soft': True if soft == 'blocked' else False,
'hard': True if hard == 'blocked' else False,
}
wifi_dev = None
for device in devices:
if device.startswith('phy'):
wifi_dev = device
break
if not wifi_dev:
print('No WLAN?')
else:
if devices[wifi_dev]['hard']:
wlan = '#FF0000'
elif devices[wifi_dev]['soft']:
wlan = '#FF9900'
else:
wlan = '#00FF00'
print(f'<span color="{wlan}">WLAN</span>')