battery/OpenBSD: improved charge%, adds status

This commit adds support for hw.sensors.acpibat0.amphour[03] for battery
charge statistics in addition to watthour[03]. It also adds charging status.
This commit is contained in:
Charlène 2018-07-16 22:58:47 +02:00
parent 22df76c3b6
commit 1332874265
1 changed files with 11 additions and 4 deletions

View File

@ -3176,12 +3176,19 @@ get_battery() {
;; ;;
"OpenBSD"* | "Bitrig"*) "OpenBSD"* | "Bitrig"*)
battery0full="$(sysctl -n hw.sensors.acpibat0.watthour0)" battery0full="$(sysctl -n hw.sensors.acpibat0.watthour0\
battery0full="${battery0full/ Wh*}" hw.sensors.acpibat0.amphour0)"
battery0full="${battery0full%% *}"
battery0now="$(sysctl -n hw.sensors.acpibat0.watthour3)" battery0now="$(sysctl -n hw.sensors.acpibat0.watthour3\
battery0now="${battery0now/ Wh*}" hw.sensors.acpibat0.amphour3)"
battery0now="${battery0now%% *}"
state="$(sysctl -n hw.sensors.acpibat0.raw0)"
state="${state##? (battery }"
state="${state%)*}"
[[ "${state}" == "charging" ]] && battery_state="charging"
[[ "$battery0full" ]] && \ [[ "$battery0full" ]] && \
battery="$((100 * ${battery0now/\.} / ${battery0full/\.}))%" battery="$((100 * ${battery0now/\.} / ${battery0full/\.}))%"
;; ;;