summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2024-01-22 10:52:22 +0100
committertv <tv@krebsco.de>2024-01-22 10:52:22 +0100
commit650c9297d854b46e5009473767e2914653c99fec (patch)
treeee0da087bd2dbd94911feb46a90d29d03477d4c4
parent364e727359a86a047e0987c1be99909228cd5177 (diff)
q-power_supply: handle Mains type
-rw-r--r--pkgs/simple/q-power_supply.nix32
1 files changed, 29 insertions, 3 deletions
diff --git a/pkgs/simple/q-power_supply.nix b/pkgs/simple/q-power_supply.nix
index 5e7cd0d..b7e5aaa 100644
--- a/pkgs/simple/q-power_supply.nix
+++ b/pkgs/simple/q-power_supply.nix
@@ -7,11 +7,25 @@ writeDashBin "q-power_supply" ''
eval "$(${gnused}/bin/sed -n '
s/^\([A-Z_]\+=[0-9A-Za-z_-]*\)$/export \1/p
' $uevent)"
- case $POWER_SUPPLY_NAME in
- AC|Mains)
- exit # not battery
+ case $POWER_SUPPLY_TYPE in
+ Battery)
+ power_supply_battery "$uevent"
+ ;;
+ Mains)
+ power_supply_mains "$uevent"
+ ;;
+ UPS|USB|Wireless)
+ echo "$uevent: warning: unsuppoerted type: $POWER_SUPPLY_TYPE" >&2
+ exit 1
+ ;;
+ *)
+ echo "$uevent: warning: unknown type: $POWER_SUPPLY_TYPE" >&2
+ exit 2
;;
esac
+ )}
+
+ power_supply_battery() {(
exec </dev/null
exec ${gawk}/bin/awk '
function die(s) {
@@ -146,6 +160,18 @@ writeDashBin "q-power_supply" ''
'
)}
+ power_supply_mains() {(
+ set -efu
+ uevent=$1
+ case $POWER_SUPPLY_ONLINE in
+ 0) printf '%s: offline\n' "$POWER_SUPPLY_NAME";;
+ 1) printf '%s: online\n' "$POWER_SUPPLY_NAME";;
+ 2) printf '%s: online\n' "$POWER_SUPPLY_NAME";;
+ *) printf '%s: unknown VBUS state: %s\n' "$POWER_SUPPLY_NAME" "$POWER_SUPPLY_ONLINE";;
+ esac
+ )}
+
+
for uevent in /sys/class/power_supply/*/uevent; do
power_supply "$uevent" || :
done