Skip to content

Support multi-battery laptops via UPower DisplayDevice in omarchy-battery-status - #11750

Closed
chartzngrafs wants to merge 1 commit into
omacom:quattrofrom
chartzngrafs:fix-dual-battery-status
Closed

chartzngrafs wants to merge 1 commit into
omacom:quattrofrom
chartzngrafs:fix-dual-battery-status

Conversation

@chartzngrafs

Copy link
Copy Markdown

Summary

On laptops equipped with dual batteries (such as ThinkPads with internal + removable PowerBridge batteries, e.g. T480/T470), omarchy-battery-status previously 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-charge state at a fixed percentage (e.g. 4%). As a result:

  • The battery widget and status notifications were stuck on BAT0's reading indefinitely while BAT1 was actively discharging or charging.
  • Battery capacity only reflected BAT0 (e.g. 23Wh) rather than the total capacity (~49Wh).
  • Power rate, time to empty/full, and charging states were inaccurate or missing.

Changes

  1. Prefer composite DisplayDevice: Checks /org/freedesktop/UPower/devices/DisplayDevice when 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 individual BAT* devices if absent.
  2. Sum live sysfs power rate: Sums power_now / current_now * voltage_now across all BAT* paths so instantaneous power telemetry reflects total system draw across all batteries.
  3. Aggregate cycle counts: Combines cycle counts across present batteries.
  4. AC hold state refinement: Checks threshold_end < 99 and includes USB power supplies when evaluating AC hold states.
  5. Unit test: Added automated test in test/shell.d/battery-status-test.sh verifying multi-battery DisplayDevice aggregation and sysfs power rate summing.

@chadmandoo chadmandoo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. sysfs_found == "true" && sysfs_microwatts -gt 0 discards 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 prints state holding and rate 0W, this branch prints state charging and rate 12W. Every laptop gets the composite, so this reaches everyone with a threshold set until UPower catches up. sysfs_found alone is enough; a zero reading is a reading.
  2. 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") )) prints arithmetic syntax error: operand expected on 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 prints rate 0W silently 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.

@bjarneo

bjarneo commented Sep 20, 2026

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants