Skip to content

Give each battery its own section in the power panel - #8774

Closed
alhasapi wants to merge 1 commit into
omacom:quattrofrom
alhasapi:per-battery-cards
Closed

alhasapi wants to merge 1 commit into
omacom:quattrofrom
alhasapi:per-battery-cards

Conversation

@alhasapi

Copy link
Copy Markdown

Charge cycles, design capacity and health are facts about a physical cell. They have no aggregate — a machine with a 965-cycle pack and a 156-cycle pack has no cycle count of its own.

The panel reports the first cell's numbers under a machine-wide label. On my T480 it shows 965 cycles and 57% health for a laptop whose other pack is at 156 and 42%. Swap which pack the kernel enumerates first and the same machine reports the other set. Neither is wrong about a battery; both are wrong about the laptop.

What this does

Renders one section per battery below the machine-wide summary, each with its own charge level, cycles, capacity, health and flow. The hero and the stats row keep describing the machine; the sections describe the cells.

On a single-battery machine nothing changes. The sections only appear when there is more than one cell to tell apart, and omarchy-battery-details exits 0 with no output when there is nothing to say.

bin/omarchy-battery-details

UPower's QML API exposes neither charge cycles nor charge thresholds, so the panel cannot reach them through UPowerDevice. This supplies those, plus a vendor and model so a cell is identifiable, and falls back to /sys/class/power_supply where the firmware reports nothing to UPower — common on older machines. Live values still come from UPower; this only covers the gaps.

Cells are selected on UPower's power-supply flag rather than the battery_ D-Bus prefix. Peripherals enumerate under that same prefix, so the prefix alone is not a filter — without this, a paired Bluetooth mouse takes an ordinal and turns "Battery" into "Battery 1". Model.isPhysicalBattery applies the same test on the QML side, so the two agree on what counts.

Two-battery ThinkPads are named Internal and External from DMI, since Power Bridge always enumerates the built-in cell first. That is the only layout nameable with confidence; every other machine gets ordinals.

Testing

test/shell.d/battery-details-test.sh is new and covers four machines with a stubbed upower: a Power Bridge ThinkPad with a Bluetooth mouse attached, a three-battery non-ThinkPad, a single-battery laptop with a paired keyboard, and a desktop with only a mouse. Removing the power-supply filter fails it with not ok - power bridge names the built-in cell, because the mouse inflates the count to three and the naming no longer applies.

Verified on a ThinkPad T480 running the exact files in this PR — script resolved through PATH, no QML errors in the journal:

Panel showing INTERNAL and EXTERNAL sections with separate cycles, capacity and health

Same sections, captured from this code running as a local plugin so the machine-wide figures above them are already correct; in this PR alone the hero still comes from omarchy-battery-status until #8770 lands.

Relationship to #8770

Independent — no overlapping files — but they are two halves of the same problem, and this one reads better on top of #8770. That PR fixes the machine-wide figures (the hero percentage and runtime, which today come from the first cell too); this one gives the per-cell facts somewhere honest to live. #8770 deliberately left cycles alone because there was nowhere to put it; this is that somewhere.

Copilot AI balanced review requested due to automatic review settings August 28, 2026 16:00

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

Adds per-cell battery sections while retaining machine-wide power summaries.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Changes:

  • Adds battery detail discovery with UPower/sysfs fallbacks.
  • Renders multi-battery cards with cell-specific metrics.
  • Adds shell scenarios for several battery configurations.

Reviewed changes

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

File Description
bin/omarchy-battery-details Emits per-battery metadata.
shell/plugins/panels/power/Model.js Adds filtering, parsing, and labels.
shell/plugins/panels/power/Panel.qml Renders per-battery sections.
test/shell.d/battery-details-test.sh Tests battery discovery scenarios.

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

Comment on lines +141 to +144
if (d.state === s.FullyCharged) return "Full"
if (d.state === s.PendingCharge) return "Holding"
if (d.state === s.PendingDischarge) return "Pending"
return "Idle"
Comment on lines +96 to +101
function isPhysicalBattery(device, displayDevice, types) {
var d = device || {}
var t = types || {}
if (!d || d === displayDevice) return false
if (d.type !== t.Battery) return false
if (d.powerSupply === false) return false
Charge cycles, design capacity and health are facts about a physical cell.
They have no aggregate: a machine with a 965-cycle pack and a 156-cycle pack
has no cycle count of its own. The panel reported the first cell's numbers
under a machine-wide label, so a T480 showed 965 cycles and 57% health for a
laptop whose other pack was at 156 and 42%.

Render one section per battery below the machine-wide summary, each with its
own charge level, cycles, capacity, health and flow. The hero and the stats
row above keep describing the machine; the sections describe the cells. On a
single-battery machine nothing changes — the sections only appear when there
is more than one cell to tell apart.

omarchy-battery-details supplies what UPower's QML API does not expose:
charge cycles and charge thresholds, plus a vendor and model so a cell is
identifiable. It falls back to /sys/class/power_supply where the firmware
reports nothing to UPower, which is common on older machines.

Cells are selected on UPower's power-supply flag rather than the battery_
D-Bus prefix. Peripherals enumerate under that same prefix, so the prefix
alone is not a filter, and a paired mouse would otherwise take an ordinal and
turn "Battery" into "Battery 1".

Two-battery ThinkPads are named Internal and External from DMI, since
Lenovo's Power Bridge always enumerates the built-in cell first. That is the
only layout nameable with confidence; every other machine gets ordinals
rather than a guess.
@bjarneo

bjarneo commented Sep 21, 2026

Copy link
Copy Markdown
Member

Automated duplication check: this pull request looks similar to #8904, which covers the same per-battery power sections. 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.

@bjarneo bjarneo closed this Sep 21, 2026
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