Repository navigation
Support multi-battery laptops via UPower DisplayDevice in omarchy-battery-status - #11750
chartzngrafs wants to merge 1 commit into
Conversation
chadmandoo
left a comment
There was a problem hiding this comment.
Tested head e9009b4 on quattro b679363 with upower stubbed and a scratch sysfs through OMARCHY_POWER_SUPPLY_PATH, the way battery-status-test.sh drives the script. I had no laptop, so every run below is that stub, with the composite's field shape taken from what upower -i .../DisplayDevice prints here.
Two things to change in the new sysfs loop:
sysfs_found == "true" && sysfs_microwatts -gt 0discards a 0 W reading. A pack holding at its charge threshold reads 0 W in sysfs, the composite has no native-path so the old per-pack branch cannot catch it either, and the script falls back to UPower's lagging energy-rate. One pack at 80% with an 80% end threshold on AC, sysfs power_now 0, UPower still saying 12 W: quattro printsstate holdingandrate 0W, this branch printsstate chargingandrate 12W. Every laptop gets the composite, so this reaches everyone with a threshold set until UPower catches up.sysfs_foundalone is enough; a zero reading is a reading.- A power_now the kernel refuses to read (ACPI answers ENODEV when the firmware reports the rate as unknown) passes
[[ -r ]], then$(( sysfs_microwatts + $(<"$bat/power_now") ))printsarithmetic syntax error: operand expectedon every refresh and bash abandons the rest of the loop, so later packs are never summed. With BAT0 unreadable and BAT1 at 16 W, quattro printsrate 0Wsilently and this branch prints the error plus UPower's 5 W. Reading into a variable with stderr dropped, and skipping anything non-numeric, closes it.
What holds: two packs with BAT0 idle at 0 W and BAT1 at 16 W, DisplayDevice at 41%, quattro prints BAT0 (4%, not-charging, 0W, 50Wh) and this branch prints the composite (41%, discharging, 16W, 49Wh, 1h 18m, cycles 53 / 55). One pack, with or without the composite, charging on AC with an 80% threshold, prints the same lines on both trees. ./test/all: your new assertion appears, nothing else changes, the new test fails on quattro and passes on this branch, and locate-test.sh fails the same way on both.
One smaller thing: the new threshold_start -gt 0 guard sits in the --shell branch only, so a zero start threshold now prints threshold 80% there but still Holding at 0-80% in the default output.
Testing performed by Claude Fable 5.1 via Claude Code; reviewed by me before posting.
|
Automated duplication check: this pull request looks similar to #10392, which covers the same battery-status multi-battery aggregation. I keep that one open and close this one to consolidate review. If you feel this is the wrong decision, please open the PR again with a note on the difference. |
Summary
On laptops equipped with dual batteries (such as ThinkPads with internal + removable PowerBridge batteries, e.g. T480/T470),
omarchy-battery-statuspreviously picked only the first battery device found:battery=$(upower -e 2>/dev/null | grep BAT | head -n 1)Because dual-battery systems charge and discharge one battery at a time, the inactive battery sits in a
not charging/pending-chargestate at a fixed percentage (e.g. 4%). As a result:BAT0's reading indefinitely whileBAT1was actively discharging or charging.BAT0(e.g. 23Wh) rather than the total capacity (~49Wh).Changes
/org/freedesktop/UPower/devices/DisplayDevicewhen present, which UPower provides specifically to aggregate multiple batteries into a single composite device with unified percentage, total energy, and time remaining. Falls back to individualBAT*devices if absent.power_now/current_now * voltage_nowacross allBAT*paths so instantaneous power telemetry reflects total system draw across all batteries.threshold_end < 99and includesUSBpower supplies when evaluating AC hold states.test/shell.d/battery-status-test.shverifying multi-batteryDisplayDeviceaggregation and sysfs power rate summing.