Repository navigation
Conversation
There was a problem hiding this comment.
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.
| 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" |
c4904dd to
df6061d
Compare
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.
df6061d to
7065451
Compare
|
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:
One line in #8864 has no equivalent in mine, so I checked it against hardware before closing: the 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 Verified throughout on a dual-battery ThinkPad T480 with a Power Bridge bay. |
omarchy-battery-statusreads 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.qmlrenders the hero percentage from this script, while the progress bar directly beneath it and the bar widget itself both useUPower.displayDevice::281Math.round(root.batteryFraction * 100)→displayDevice:372root.batteryInfo.percentage→ this script:403root.batteryFraction→displayDeviceSo 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.
DisplayDevicecarries nonative-pathto 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 atcurrent_now=0, so a rate read from one cell reports0Wwhile 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,
DisplayDevicedoes not carry them, and sourcing them from it would silently demote every machine to theBAT*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.shgains a dual-battery case: two stub packs withBAT0atcurrent_now=0, asserting the aggregate percentage, combined capacity, aggregate runtime, and a summed non-zero draw. It fails against the current script withnot ok - battery status reports the machine percentage, not the first celland passes with this change. The existing single-battery assertions, including the10.8Wsysfs rate, are unchanged and still pass.Verified on a ThinkPad T480 with both packs installed and with only the internal pack:
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.