monitor AC status rather than battery status

If you set a charging threshold on the battery, you may bounce between
charging and discharging while still on AC. The profile only needs to
change when AC is disconnected. If the battery is discharging, but AC is
connected, don't switch to a power-saving profile.

I think.
This commit is contained in:
Pig Monkey 2025-01-14 09:22:38 -08:00
parent 89ee8d7360
commit 3dd640ed31

5
roles/laptop/files/power_monitor.sh Normal file → Executable file
View file

@ -5,6 +5,7 @@
BAT=$(echo /sys/class/power_supply/BAT*)
BAT_STATUS="$BAT/status"
BAT_CAP="$BAT/capacity"
AC_STATUS=/sys/class/power_supply/ACAD/online
LOW_BAT_PERCENT=50
AC_PROFILE="desktop"
@ -19,7 +20,7 @@ prev=0
while true; do
# read the current state
if [[ $(cat "$BAT_STATUS") == "Discharging" ]]; then
if [[ $(cat "$AC_STATUS") == "0" ]]; then
if [[ $(cat "$BAT_CAP") -gt $LOW_BAT_PERCENT ]]; then
profile=$BAT_PROFILE
else
@ -39,5 +40,5 @@ while true; do
prev=$profile
# wait for the next power change event
inotifywait -qq "$BAT_STATUS" "$BAT_CAP"
inotifywait -qq "$AC_STATUS" "$BAT_CAP"
done