Skip to content

Aggregate battery status across multiple batteries - #7295

Closed
lytedev wants to merge 2 commits into
omacom:quattrofrom
lytedev:multi-battery-support
Closed

lytedev wants to merge 2 commits into
omacom:quattrofrom
lytedev:multi-battery-support

Conversation

@lytedev

@lytedev lytedev commented Aug 17, 2026

Copy link
Copy Markdown

Stacked on #7293 — take that one first; this branch contains it.

Laptops with two packs (ThinkPad T480 and friends, internal + hot-swappable) expose one BAT* device each. omarchy-battery-status takes upower -e | grep BAT | head -n 1, so the panel describes one pack and ignores the rest. On a T480 the bar reads:

Battery 80%  ·   left  ·   0W / 16Wh

That is the idle 16Wh internal pack, with no time estimate, while the 71Wh pack does all the work.

Every reading now combines all packs:

  • percentage — each pack's own percentage weighted by its share of total capacity, so a small auxiliary pack cannot skew the number
  • size / rate — summed, still preferring the live sysfs rate per pack
  • time — derived from combined remaining energy divided by combined draw
  • state — discharging wins, then charging, else what the packs agree on
  • cycles — listed per pack (348 / 82); thresholds take the lowest across packs

The panel gains a Battery 1 / Battery 2 row showing each pack's size and charge, emitted only when a second pack exists — single-battery machines see the panel exactly as before, and there are tests on both sides asserting that.

One expectation moves: battery status reports remaining time goes 2h 30m → 2h 37m. Time no longer comes from UPower's time to empty (per-pack, and wrong once there are two) and is derived instead, which is consistent with the sysfs rate the script already prefers.

Verified on a T480 across both directions:

Battery 76%  ·  7h 53m left  ·   8.4W / 87Wh
Battery 78%  ·  38m to full  ·   29.8W / 87Wh   (one pack parked at its threshold, the other charging)

./test/shell passes apart from four failures that reproduce unchanged on a pristine quattro checkout of this machine (bar-icon-geometry, config, snapper, unowned-system-paths).

Copilot AI balanced review requested due to automatic review settings August 17, 2026 17:08

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds multi-battery support end-to-end (status collection → shell output → panel rendering) and hardens state/rate reporting by preferring sysfs over potentially stale UPower values.

Changes:

  • Aggregate battery metrics across all packs in omarchy-battery-status, emitting optional per-pack breakdown keys.
  • Render per-pack battery rows in the power panel when more than one pack is present.
  • Extend shell tests to cover stale UPower state vs sysfs, holding logic, and multi-battery aggregation/breakdown.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/shell.d/power-test.sh Adds unit tests for batteryPacks() parsing behavior.
test/shell.d/battery-status-test.sh Adds integration tests for stale UPower state, holding behavior, and multi-pack aggregation/breakdown.
shell/plugins/panels/power/Panel.qml Displays per-pack breakdown rows for multi-battery machines.
shell/plugins/panels/power/Model.js Introduces batteryPacks(info) to extract per-pack rows from shell output.
bin/omarchy-battery-status Aggregates readings across multiple batteries; prefers sysfs for rate/state; emits per-pack keys.

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

Comment on lines +462 to +465
Repeater {
model: root.batteryPacks.filter(function (pack, index) { return index % 2 === 0 })
InfoPair { label: modelData.label; value: modelData.value }
}
Comment on lines +472 to +475
Repeater {
model: root.batteryPacks.filter(function (pack, index) { return index % 2 === 1 })
InfoPair { label: modelData.label; value: modelData.value }
}
@lytedev

lytedev commented Aug 19, 2026

Copy link
Copy Markdown
Author

Closing this in favour of the earlier work already in flight — there are four PRs solving the same problem, and that is three more than this needs.

Overlapping, in filing order:

Thanks @YuseiRun for cross-linking these.

If it is useful to whoever's work lands, two pieces of this one are worth lifting rather than rewriting:

  • batteryPacks() in Model.js is split out as a pure function, so the per-pack rows are unit-testable without standing up the panel. It returns [] unless the script reports more than one pack, which keeps single-battery machines on exactly the previous layout.
  • test/shell.d/battery-status-test.sh and power-test.sh gained fixtures for the dual-pack case, including the stale-pending-charge-vs-live-sysfs situation.

Happy to rebase either onto whichever PR the maintainers prefer — just say which.

To be clear about scope: #7293 is a separate fix and stays open. It addresses charge state being read from a stale UPower label rather than sysfs, which is independent of aggregating multiple packs and reproduces on single-battery hardware too.

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.

2 participants