Skip to content

Skip dead battery packs in power status - #7917

Closed
hilather wants to merge 5 commits into
omacom:quattrofrom
hilather:fix/battery-dead-pack
Closed

hilather wants to merge 5 commits into
omacom:quattrofrom
hilather:fix/battery-dead-pack

Conversation

@hilather

Copy link
Copy Markdown

Fixes #7916.

On dual-battery ThinkPads omarchy-battery-status takes upower -e | grep BAT | head -n 1 — always BAT0. When the internal pack is present but electrically dead (0 V / 0 Wh / pending-charge), the power panel shows 0% / 0W / Holding while the slice is charging.

UPower's composite DisplayDevice is not a drop-in fix: it still counts the dead cell's energy-full, so the bar icon reports ~49% with a ~10 hour ETA while the live pack is at 99% / 2.2W / 3 minutes to full. Related PRs that sum every present BAT* or switch to DisplayDevice (#7138, #6845, #7186) keep that composite-denominator bug.

This keeps one bar icon and makes the numbers match the pack that actually holds a charge.

  • omarchy-battery-status walks every BAT* and skips packs with no voltage, energy, or current. A healthy empty cell still shows voltage, so a real 0% pack is not dropped. If every pack looks dead, the previous present set is used rather than printing nothing.
  • The panel icon and fill use the same live set instead of UPower.displayDevice. A long charge (timeToFull >= 8h) no longer counts as a hold.
  • Notifications that call omarchy-battery-status get the same live-pack line.

Verified on a ThinkPad T460s (dead BAT0, live BAT1 charging): 99% / 20Wh / 2.2W / 3m to full.

Tests

  • test/shell.d/battery-status-test.sh — existing single-pack fixture still passes; added a T460s-shaped dead-first fixture (98% / charging / 2.2W / 20Wh / 14m, not 0% holding and not 49%).
  • test/shell.d/power-test.sh — live-pack filtering, combined fraction, and an 20-hour charge not counting as holding.

bash test/shell.d/battery-status-test.sh and bash test/shell.d/power-test.sh are green.

Screenshots

After, on this T460s (open power panel): 99%, pumping power, 2.2W, 3m to full, 20Wh.

Filed by Grok 4.6 via Grok Build.

omarchy-battery-status always took the first BAT* device, so a dual-battery
ThinkPad with a present-but-dead internal pack reported 0% / 0W / Holding.
UPower's DisplayDevice is not a substitute: it still counts the dead cell's
energy-full, so the bar showed ~49% with a 10-hour ETA while the live pack
was at 99%.

Aggregate only packs that still show voltage, energy, or current. A healthy
empty cell keeps voltage, so a real 0% pack is not dropped. The power panel
uses the same live set for the icon and fill instead of DisplayDevice.

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

Filters electrically dead battery packs so CLI and power panel readings reflect live batteries.

Changes:

  • Aggregates live battery status while excluding dead packs.
  • Aligns panel percentage, icon, and charge-threshold logic.
  • 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 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
bin/omarchy-battery-status Selects and aggregates live battery packs.
shell/plugins/panels/power/Model.js Adds live-pack and combined-state helpers.
shell/plugins/panels/power/Panel.qml Uses live-pack data in the panel and bar.
test/shell.d/battery-status-test.sh Tests dead-first dual-battery status.
test/shell.d/power-test.sh Tests panel filtering and hold detection.
Suppressed comments (1)

shell/plugins/panels/power/Panel.qml:86

  • Once the panel has been opened, batteryInfo.percentage remains populated, while its refresh timer stops when the panel closes. This branch therefore freezes the bar percentage/fill at the last panel reading indefinitely; meanwhile viewDevice() continues following UPower, so the icon can diverge again. Use the CLI value only while it is being refreshed, or run the refresh while closed.
    var fromStatus = Model.combinedFractionFromStatus(root.batteryInfo)
    if (fromStatus >= 0) return fromStatus

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

Comment thread shell/plugins/panels/power/Panel.qml Resolved
Comment thread shell/plugins/panels/power/Model.js Resolved
hilather and others added 4 commits August 23, 2026 10:58
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
isLivePack only looked at energy, rate, and percentage, so a 0% cell with
voltage was dropped while omarchy-battery-status kept it. Use the same
voltage floor as the CLI, and emit pack.N.path so the panel can follow the
CLI-selected set when Quickshell's UPowerDevice has no voltage.
UPower's percentage and time-to-full still count a dead pack's energy-full,
so a T460 with a 0 V internal cell showed ~50% and a 10 hour ETA while the
working slice was nearly full. Always derive % and remaining time from the
live energy and instantaneous watts, prefer kernel charge limits, and stop
falling the bar fill back to DisplayDevice.

Signed sysfs power_now is taken as magnitude so charging time is not blank.
A 0-100 kernel window is treated as no charge limit.
omarchy-battery-status emits BAT1; Quickshell may expose the sysfs path.
Basename match keeps CLI-selected packs when voltage is missing.
@geirolafs

Copy link
Copy Markdown

You're right about the composite denominator, and it's confirmed against #6845: with a dead pack advertising 20.65Wh next to a 20.94Wh live pack near full, DisplayDevice reports 49% with a ~9.6h time-to-full. The mechanism is in UPower's up_daemon_update_display_battery: it sums energy-full across every present power-supply battery and computes percentage = 100 * energy / energy_full, so a dead pack's advertised capacity stays in the denominator.

I've pushed a fix to #6845 that takes the same approach as yours on the script side: packs split by electrical liveness (voltage, stored energy, or current flow — deliberately not energy_full, since that's the one value a dead pack keeps lying about), and when a dead pack is excluded the percentage/capacity/time are rebuilt from the live packs' own energy readings. Your T460s shape is a regression test there now: 97% / charging / 2.2W / 20Wh / 14m instead of 49% and ten hours.

What #6845 deliberately doesn't touch is the QML side: the panel icon fill and battery service still read UPower.displayDevice, so on your hardware the glyph would still sag even with the script fixed. That part of this PR (plus the long-charge holding heuristic) is complementary rather than competing. If the maintainers take #6845 for the script, rebasing this down to the Panel.qml/Model.js changes would slot right on top.

@hilather

Copy link
Copy Markdown
Author

I'll close mine in favor of yours then. The icon isn't a big deal and I'm just going to replace the internal battery.

I ran into a later problem where the hibernate/sleep function kicked in when the battery was still half full due to the misleading indicators. Not sure if yours handles that (or doesn't need to). Just thought I'd mention it.

@hilather hilather closed this Aug 26, 2026
@geirolafs

geirolafs commented Aug 26, 2026 •

Copy link
Copy Markdown

Thanks for closing in favor. The T460s numbers, they're the regression test now.

The early hibernate isn't omarchy, it's upowerd: the daemon triggers hibernate on its own, from the same broken composite reading, so #6845 can't fix it. Until you swap the pack, set UsePercentageForPolicy=false in /etc/UPower/UPower.conf. Then upowerd decides based on time-to-empty instead of percentage, and the dead pack doesn't affect that number. The real fix belongs upstream in UPower.

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.

Power panel reports dead BAT0 (0% / 0W / Holding) on dual-battery ThinkPads

3 participants