diff options
author | Sven Wegener <sven.wegener@stealer.net> | 2021-07-04 13:19:43 +0200 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2021-08-13 13:38:07 -0500 |
commit | 63955056ecb98faa1a02d90d5a4742515f0299c8 (patch) | |
tree | a43e1bbf1aac208afbe473eab2e44a3e43a8f633 /scripts | |
parent | 1e975be89670f53db47aeef3dbb3361166517c26 (diff) |
on_ac_power: support multiple power_supply devices in sysfs
Newer devices have multiple power_supply devices in sysfs:
$ grep ^ /sys/class/power_supply/*/type
/sys/class/power_supply/AC/type:Mains
/sys/class/power_supply/BAT0/type:Battery
/sys/class/power_supply/ucsi-source-psy-USBC000:001/type:USB
/sys/class/power_supply/ucsi-source-psy-USBC000:002/type:USB
There are two "USB" Type-C ports than can supply power and both are
aggregated into the "Mains" power supply by the firmware. The "Battery"
also counts as a power supply, but is missing the online attribute.
The -f check with a wildcard pattern results in an error, when multiple
devices are present:
/lib/rc/bin/on_ac_power: line 21: [: too many arguments
When the power_supply class is registered, check for a "Mains" device.
Fixes #427.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/on_ac_power | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/scripts/on_ac_power b/scripts/on_ac_power index 33fb63ae..d448b119 100755 --- a/scripts/on_ac_power +++ b/scripts/on_ac_power @@ -18,9 +18,10 @@ if [ -f /proc/acpi/ac_adapter/*/state ]; then "state:"*"off-line") exit 128;; esac done -elif [ -f /sys/class/power_supply/*/online ]; then - cat /sys/class/power_supply/*/online | while read line; do - [ "${line}" = 0 ] && exit 128 +elif [ -d /sys/class/power_supply ]; then + for dir in /sys/class/power_supply/*/; do + [ "$(cat "${dir}/type")" != "Mains" ] && continue + [ "$(cat "${dir}/online")" = 0 ] && exit 128 done elif [ -f /proc/pmu/info ]; then cat /proc/pmu/info | while read line; do |