Skip to content

Fix omarchy-battery-status to report combined capacity on multi-battery laptops - #7138

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

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

Conversation

@fjse

@fjse fjse commented Aug 16, 2026

Copy link
Copy Markdown

omarchy-battery-status picks the first battery device alphabetically (upower -e | grep BAT | head -n 1), which on dual-battery ThinkPads (e.g. T480 with an internal + hot-swap bay battery) only reports one battery's percentage/capacity/cycles while silently ignoring the other.

This visibly disagrees with the power panel's progress bar and icon, which already correctly bind to UPower's composite DisplayDevice (Quickshell.Services.UPower's UPower.displayDevice) — so the panel shows a percentage number and a bar telling two different stories.

This points the script at the same DisplayDevice object the panel already uses, and checks its present state (mirroring the QML's isPresent check) instead of relying on the removed enumerate step to signal "no battery".

Verified on a ThinkPad T480 with BAT0 (13.49Wh full) + BAT1 (23.72Wh full): before, showed 36% / 13Wh; after, correctly shows ~73% / 37Wh, matching upower -i DisplayDevice directly.

…ry laptops

battery-status picked the first battery device alphabetically
(upower -e | grep BAT | head -n 1), which on dual-battery ThinkPads
(e.g. T480 with an internal + hot-swap bay battery) only reports one
battery's percentage/capacity/cycles while ignoring the other entirely.

This visibly disagreed with the power panel's progress bar and icon,
which already correctly bind to UPower's composite DisplayDevice
(Quickshell.Services.UPower's UPower.displayDevice) -- so the panel
showed a percentage number and a bar that told two different stories.

Point the script at the same DisplayDevice object instead, and check
its "present" state (mirroring the QML's isPresent check) rather than
relying on the now-removed enumerate step to signal "no battery".

Verified on a ThinkPad T480 with BAT0 (13.49Wh full) + BAT1 (23.72Wh
full): before, showed 36% / 13Wh; after, correctly shows ~73% / 37Wh,
matching `upower -i DisplayDevice` directly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXDQXGqQL9eNtwFwPBbQ5f
Copilot AI balanced review requested due to automatic review settings August 16, 2026 13:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 227fc45. The aggregation goal is right and the composite device is a reasonable way to get it, but as written this change has a regression that lands on every laptop, including the single-battery machines this PR is not trying to change.

The composite device has no native-path, and this script needs one. Line 45 reads native-path out of upower -i, line 46 builds battery_path from it, and lines 50-57 use that path for the live sysfs power reading — the one the comment just above it says exists because "UPower's energy-rate can lag the kernel telemetry by tens of seconds". upower -i /org/freedesktop/UPower/devices/DisplayDevice does not print native-path at all; I confirmed that directly on an Omarchy machine (UPower 1.91.3), and UPower's formatter suppresses it for the composite by design. So battery_path collapses to /sys/class/power_supply/, neither power_now nor current_now+voltage_now is readable there, and the rate silently falls back to UPower's lagging energy-rate.

Measured against a realistic pair of upower -i outputs for a one-battery laptop, --shell reports rate 7.3W at this head where the base branch reports rate 10.8W from the live sysfs read. The panel polls every 5 seconds (Panel.qml:230), so the wattage readout it draws goes stale on every laptop. Charge thresholds survive, but only because lines 68-69 already had a sysfs fallback; the rate has no such fallback.

The existing test fails at this head. test/shell.d/battery-status-test.sh goes from 1 passed, 0 failed on quattro to 0 passed, 1 failed here, both run on a disposable VM. The stub's upower -i output has no present: line, so the new guard at line 24 exits 0 with no output and the first assertion fails. Worth saying explicitly: adding present: yes to that fixture would make it green again while leaving an unrealistic native-path: BAT0 in a DisplayDevice response, which would hide the rate regression rather than fix it.

Two smaller things. The description says the old code ignored the second battery's "percentage/capacity/cycles", but line 110 is unchanged and still does cat BAT*/cycle_count | head -1, so cycles are still single-battery. And UPower's DisplayDevice covers a UPS as well as a battery, so a batteryless desktop with a supported UPS now passes the present: yes guard and prints UPS telemetry labelled "Battery"; the old grep BAT enumeration skipped UPS devices.

One claim I want to withdraw rather than leave standing: I initially suspected the composite percentage would differ from a single battery's own percentage on a one-battery machine. Checking UPower's aggregation, it passes a lone battery's percentage through rather than recomputing it, so that does not appear to be a real difference. Flagging it only so nobody inherits it as a finding.

Nothing was pushed to your branch. The repair here is to keep the composite for the aggregate values and get the live rate by summing power_now across the present BAT* supplies instead of via native-path — but that is close to what #9106 already does, and #7186 is a third implementation of the same fix that keeps a per-pack live rate and adds dual-battery test fixtures. Which of the three to take is the maintainer's call, so this is waiting on a maintainer rather than on you, and I have not touched the other two.

Reviewed by Claude Opus 5 in Claude Code and by Codex at xhigh reasoning. Codex agreed on the native-path regression and the failing test, having gone to UPower's source independently; its independence is not currently guaranteed, so weigh that agreement accordingly. The UPS behaviour above is its finding, not mine, and the percentage claim I withdrew is one it talked me out of. Test results are from an Omarchy VM, not from real dual-battery hardware.

@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.

4 participants