waybar/scripts/batt_watts.py
Steins7 5af3ab092b Improve battery management scripts
Fixes various issues, including power counter not working properly
during charge and multiple batteries support
2024-09-04 17:00:03 +02:00

25 lines
670 B
Python
Executable File

#!/usr/bin/python
dir0='/sys/class/power_supply/BAT0/'
dir1='/sys/class/power_supply/BAT1/'
with open(dir0 + 'power_now', 'r') as f:
power0 = int(f.read()) / 1000000.0
with open(dir1 + 'power_now', 'r') as f:
power1 = int(f.read()) / 1000000.0
with open(dir0 + 'status', 'r') as f:
status0 = f.read().rstrip()
with open(dir1 + 'status', 'r') as f:
status1 = f.read().rstrip()
if status0 == "Discharging" or status1 == "Discharging"
wattage = - power0 - power1
elif status0 == "Charging" or status0 == "Full"
or status1 == "Charging" or status1 == "Full":
wattage = power0 + power1
else:
wattage = 0
#return wattage