Skip to content

Gate low-battery warn and sleep on live remaining energy - #7965

Draft
hilather wants to merge 6 commits into
omacom:quattrofrom
hilather:fix/battery-live-energy-policy
Draft

hilather wants to merge 6 commits into
omacom:quattrofrom
hilather:fix/battery-live-energy-policy

Conversation

@hilather

Copy link
Copy Markdown

Depends on #7917. Draft until that lands — rebase onto quattro after merge. Unique work is the commit after Match CLI pack ids to UPower nativePath suffixes.

Fixes the other half of the dual-battery ThinkPad failure: the bar can show a live pack at ~40% while UPower Auto still suspend-then-hibernates because DisplayDevice / the EC fuel gauge cliffed to ~3%.

On a T460 with a present-but-dead internal pack, BAT1 dropped 40% → 6% in 60 seconds at ~8 W (physically ~1%). upowerd then requested suspend-then-hibernate. The machine never resumed (e1000e Failed to disable ULP); a tap on the power button does nothing in that S3.

#7917 already skips dead packs for the widget and omarchy-battery-status. This PR points the warning and the 2% action at the same live watt-hour remainder, and stops UPower from racing it.

Behavior

  • Warn at 10% and act at 2% only while discharging on battery, using live remaining energy (dead packs skipped; EC cliffs that beat measured watts rejected).
  • A 40% → 6% cliff at ~8 W must not notify or sleep.
  • A present-but-dead pack cannot pull either decision to empty while a live pack is above those marks.
  • omarchy.battery no longer reads UPower.displayDevice.
  • Hidden omarchy-battery-critical runs systemctl suspend-then-hibernate (falls back to suspend). Hibernate is still optional; the contract is “do not act before live 2%”.
  • Migration sets CriticalPowerAction=Ignore (and AllowRiskyCriticalPowerAction=true) so UPower Auto cannot suspend on the EC percentage. The shell owns the 2% path after login.

Tests

  • test/shell.d/battery-test.sh — live 10% warn, live 2% act, dead-pack skip, 8.4→1.3 Wh / 60 s / 8 W cliff, Service.qml wiring.
  • test/shell.d/power-test.sh — same cliff reject on applyEnergySample.

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

Verified on a ThinkPad T460 (dead BAT0, live BAT1): the local clone of this path is what now owns warn/act; UPower reports critical-action: Ignore.

hilather and others added 6 commits August 23, 2026 10:47
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.
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.
DisplayDevice and the EC fuel gauge can cliff (40% → 6% in a minute)
while live watt-hours are still ~40%. Warn at 10% and suspend-then-hibernate
at 2% only from that live remainder; ignore UPower Auto so it cannot race.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants