Skip to content

Report the machine's battery figures, not the first cell's - #8770

Closed
alhasapi wants to merge 1 commit into
omacom:quattrofrom
alhasapi:battery-aggregate-figures
Closed

alhasapi wants to merge 1 commit into
omacom:quattrofrom
alhasapi:battery-aggregate-figures

Conversation

@alhasapi

Copy link
Copy Markdown

omarchy-battery-status reads a single device:

battery=$(upower -e | grep BAT | head -n 1)

Everything downstream of that line describes one cell while claiming to describe the laptop. On my T480 with the internal pack at 21% and the external at 95%, it reports 21% and 38m left for a machine that actually holds 53% and 2h 42m.

This reaches the Quattro shell

shell/plugins/panels/power/Panel.qml renders the hero percentage from this script, while the progress bar directly beneath it and the bar widget itself both use UPower.displayDevice:

line value source
:281 bar widget percentage Math.round(root.batteryFraction * 100) → displayDevice
:372 panel hero percentage root.batteryInfo.percentage → this script
:403 progress bar fill root.batteryFraction → displayDevice

So on a dual-battery machine the bar widget reads 53%, and the panel it opens reads 21% — printed directly above a bar drawn at half full.

That is the same inconsistency #5780 reported against Waybar ("inconsistent battery reading between what is shown in the waybar and the notification"), now inside the native shell.

What changed

Percentage, state, capacity and remaining time now come from DisplayDevice, which is the aggregate and mirrors the single cell on a one-battery machine.

The instantaneous sysfs rate is summed across packs. DisplayDevice carries no native-path to read it from, and the reading has to cover every pack in any case: a ThinkPad drains its external battery first, leaving the internal one at current_now=0, so a rate read from one cell reports 0W while the laptop is visibly discharging. That is the second symptom reported in #7214.

Charge thresholds deliberately stay on a battery. They are per-cell configuration, DisplayDevice does not carry them, and sourcing them from it would silently demote every machine to the BAT* sysfs fallback — which does not always agree. This ThinkPad reports an 80% end threshold through UPower and 100% through sysfs.

Charge cycles are deliberately untouched. They have no aggregate, so reporting them honestly needs somewhere per-battery to put them — a separate change, not this one.

Testing

test/shell.d/battery-status-test.sh gains a dual-battery case: two stub packs with BAT0 at current_now=0, asserting the aggregate percentage, combined capacity, aggregate runtime, and a summed non-zero draw. It fails against the current script with not ok - battery status reports the machine percentage, not the first cell and passes with this change. The existing single-battery assertions, including the 10.8W sysfs rate, are unchanged and still pass.

Verified on a ThinkPad T480 with both packs installed and with only the internal pack:

$ bin/omarchy-battery-status --shell
percentage  47%          $ upower -i .../DisplayDevice
state       discharging    state:        discharging
rate        4.2W           energy-rate:  3.979 W
size        23Wh           time to empty: 2.8 hours
time        2h 36m         percentage:   47.615%

Credits

Reported in #5780 by @Michael-Steshenko and again in #7214 by @syntaxboybe, with a second T480 confirmation from @raplo-z. #5958 by @stefanomainardi was an earlier fix for the pre-Quattro surfaces.

Closes #7214.

Copilot AI balanced review requested due to automatic review settings August 28, 2026 15:44

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

Updates battery reporting to use UPower’s aggregate DisplayDevice while summing available per-pack sysfs power rates.

Changes:

  • Reports aggregate percentage, state, capacity, and runtime.
  • Adds dual-battery regression coverage.

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.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
bin/omarchy-battery-status Aggregates machine-level battery statistics and per-pack rates.
test/shell.d/battery-status-test.sh Adds a dual-battery test fixture and assertions.

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

Comment on lines +87 to +103
native-path: BAT0
state: discharging
percentage: 21%
INFO
;;
esac
exit 0
fi

exit 1
STUB
chmod +x "$dual_dir/bin/upower"

dual_output=$(OMARCHY_POWER_SUPPLY_PATH="$dual_dir/power" PATH="$dual_dir/bin:$PATH" "$ROOT/bin/omarchy-battery-status" --shell)

grep -Fx $'percentage\t53%' <<<"$dual_output" >/dev/null || fail "battery status reports the machine percentage, not the first cell"
grep -Fx $'time\t3h' <<<"$dual_output" >/dev/null || fail "battery status reports the machine remaining time"
omarchy-battery-status reads a single device:

    battery=$(upower -e | grep BAT | head -n 1)

Everything downstream of that describes one cell while claiming to describe
the laptop. On a dual-battery ThinkPad with the internal pack at 21% and the
external at 95%, it reports 21% and 38m left for a machine that holds 53%
and 2h 42m.

That reaches the shell. The power panel's hero percentage is
root.batteryInfo.percentage, fed by this script, while the progress bar
directly beneath it and the bar widget itself both use
UPower.displayDevice — so the widget reads 53% and the panel it opens reads
21%, over a half-full bar.

Read percentage, state, capacity and remaining time from DisplayDevice,
which is that aggregate and mirrors the single cell on a one-battery
machine.

DisplayDevice carries no native-path for the instantaneous sysfs rate, and
that reading has to cover every pack in any case: a ThinkPad drains its
external battery first, leaving the internal one at current_now=0, so a rate
read from one cell reports 0W while the laptop is visibly discharging. Sum
it across the batteries instead.

Charge thresholds stay on a battery rather than the aggregate. They are
per-cell configuration, DisplayDevice does not carry them, and sourcing them
from it would silently demote every machine to the sysfs fallback — which
does not always agree: this ThinkPad reports an 80% end threshold through
UPower and 100% through sysfs.

Charge cycles are deliberately untouched. They have no aggregate, and
reporting one cell's count for the machine needs somewhere per-battery to
put them.

Closes omacom#7214.
@alhasapi
alhasapi force-pushed the battery-aggregate-figures branch from df6061d to 7065451 Compare September 2, 2026 07:26
@alhasapi

alhasapi commented Sep 2, 2026

Copy link
Copy Markdown
Author

Closing in favour of #8864, which does the same thing and does several of them better.

I opened this on the 28th and @zmitton opened #8864 the next day. Two near-identical PRs sitting in a queue this size helps nobody, and having read theirs line by line against mine, theirs is the one to take:

  • Same core fix — read DisplayDevice for percentage, state, capacity and time.
  • Same handling of the trap underneath it. DisplayDevice has no native-path, so the live sysfs rate has to be summed across every BAT* rather than read from one device. Fix battery status reading the wrong device on multi-battery hardware #8864 globs BAT* under the power supply path directly, which is simpler than my resolving each native-path back through upower -i.
  • Same reasoning on charge thresholds, which have to keep coming from an individual device. That one bit me while writing this PR and it is the easiest part of the fix to get wrong: moving thresholds to the aggregate silently demotes every machine to the sysfs fallback, and the two do not always agree — this T480 reports an 80% end threshold through UPower and 100% through sysfs.
  • Fix battery status reading the wrong device on multi-battery hardware #8864 also takes the max cycle count rather than the first, which mine left alone.
  • Its dual-battery fixture is stronger than mine. BAT0 is not-charging while the aggregate is discharging, so the state assertion actually pins the behaviour. Copilot flagged precisely that gap in my fixture, where both were discharging and the assertion would have passed even if state still came from the first cell.

One line in #8864 has no equivalent in mine, so I checked it against hardware before closing: the present: yes gate on DisplayDevice. It holds — my T480 reports present: yes on the aggregate with both packs installed, so the early exit does not misfire on multi-battery machines.

The piece neither PR covers is per-battery detail. Cycle count, design capacity and health belong to a physical cell and have no aggregate: taking the max is the right call for one machine-level number, but a pack at 965 cycles sitting next to one at 156 has no meaningful cycle count of its own. That is #8774, which is independent of this and does not touch omarchy-battery-status, so it applies cleanly on top of #8864.

Verified throughout on a dual-battery ThinkPad T480 with a Power Bridge bay.

@alhasapi alhasapi closed this Sep 2, 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.

omarchy-battery-status reads only the first battery on dual-battery laptops

2 participants