Repository navigation
Decide the charge limit from the threshold, not the charge level - #10502
brightwalker25 wants to merge 1 commit into
Conversation
chargeThresholdActive() inferred whether a charge limit was in force from the battery's state and level, because UPower publishes no charge-threshold property for the panel to read. Inference cannot separate a configured limit from the other reasons a battery sits on AC without charging, and it got three distinct cases wrong: - A cap lowered below a nearly full battery read as no cap at all. Lowering a cap stops the charge but does not discharge the pack, so the state is FullyCharged at 99% and `fraction >= 0.99` returned false while the firmware was holding at 60. This is the normal state for days on mains (#10344). - A dead battery read as a cap. PendingCharge only means AC is present and the EC is not charging, for any reason; returning true on it unconditionally reported "Holding at 75-80%" for a pack at 0% (#7803). - Hardware with no charge control read as a cap. Apple's SMC leaves a battery alone until it falls to roughly 93%, which arrives as FullyCharged below 0.99 and rendered a charge-limit row on a machine with no charge_control_end_threshold at all (#10193). omarchy-battery-status already reads the threshold from the hardware and emits it, and already gates its own charge_holding block on that value existing. The panel dropped that half of the guard and re-derived the answer instead, which is why the two disagree on the same machine. Take the value the CLI already provides and decide from it: a limit is in force when the hardware exposes one, it is set below full, and the charge has reached it. The bar icon reads the same predicate, so the battery status is now also read once on startup rather than only while the panel is open, otherwise the icon would sit on an unset limit until the panel was first opened. This does not touch where the threshold value comes from. On hardware whose UPower hwdb default masks the real sysfs value the number shown is still UPower's; #9612 fixes that half, and the two changes compose. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VADsy8CLE8n9hpfWUKt3vM
|
Hardware verification of Environment: Omarchy 4.0.2-1, Quickshell 0.3.1-1, UPower 1.91.3-1. AC connected, UPower reports Test method: temporarily loaded the exact, unmodified
Two follow-up observations from isolated model checks, distinct from the hardware verification above:
No live unplug/replug, configured-limit, or failed-battery hardware testing was performed. This report was prepared with AI assistance; no screenshots or diagnostic logs are attached. |
|
Automated duplication check: this pull request looks similar to #10196, which covers the same charge threshold gate. 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. |
Fixes #10344 (the panel half), #7803 (the panel half), #10193.
The problem
Model.chargeThresholdActive()decides whether a charge limit is holding the battery back, and it drives theCharge limit/Holdingpair inPanel.qml, theThresholdmode label, and the battery icon. It never reads a threshold. It infers one from the state of charge:It infers because there is nothing to read:
Quickshell.Services.UPowerpublishes no charge-threshold property at all. But inference cannot separate a configured limit from the other reasons a battery sits on AC without charging, and it gets three distinct cases wrong. None of them are edge cases.A cap below a nearly full battery reads as no cap (#10344). Lowering a cap stops the charge but does not discharge the pack, so the state is
FullyChargedat 99% while the firmware holds at 60. Line 61 returns false and the panel shows FULLY CHARGED with no charge limit row. This is the ordinary state for days on a machine that stays on mains.A dead battery reads as a cap (#7803).
PendingChargeonly means AC is present and the EC is not charging, for any reason: a threshold hold, a battery fault, an insufficient supply,charge_behaviour=inhibit-charge. Returning true on it unconditionally reports a hold for a pack at 0% that the EC has given up on.Hardware with no charge control reads as a cap (#10193). Apple's SMC leaves a battery alone until it falls to roughly 93%, which arrives as
FullyChargedbelow 0.99 and renders a charge-limit row on a machine with nocharge_control_end_thresholdto show.The fix
bin/omarchy-battery-statusalready reads the threshold from the hardware, already emits it asthreshold, and already gates its owncharge_holdingblock on that value existing.Panel.qmlalready displays that value on line 445. The panel simply dropped the guard half and re-derived the answer instead, which is why the CLI and the panel disagree on the same machine, as #10193 sets out.So take the value the CLI already provides and decide from it:
A limit is in force when the hardware exposes one, it is set below full, and the charge has reached it.
parseThresholdEnd()takes the end value out of thethresholdfield, which is80%for a single value and75-80%for a start-end pair, and returnsNaNwhen the battery exposes no charge-control interface, since that is a meaningful answer rather than a missing one. A limit of 100 is the sysfs way of saying charge to full, so it is not a limit either.Every state-based branch goes away.
statesis no longer a parameter of the predicate;batteryIcon()andmodeLabel()still take it and now also forward the limit.Scope
This does not change where the threshold value comes from. On hardware whose UPower hwdb
CHARGE_LIMITdefault masks the real sysfs value, the number displayed is still UPower's. #9612 fixes that half by preferring sysfs inomarchy-battery-status, and the two changes compose without touching the same code: this PR makes the panel ask the right question, #9612 makes the CLI give the right answer. On the ASUS machine in #10344 the panel goes from showing no limit at all to showing75-80%, and lands on the true60%once #9612 is in.It also leaves
omarchy-battery-status's ownpending-chargebranch alone, which is the CLI half of #7803 and is covered by #7915/#7895.One behavioural note: the bar icon reads the same predicate, and the full refresh only runs while the panel is open, so the battery status is now also read once on startup. Without it the icon would sit on an unset limit until the panel was first opened.
Tests
test/shell.d/power-test.shcovers the three reported cases directly, plus the threshold parsing, a limit the battery is still charging toward, a limit of 100, and the icon while a limit is holding. The two assertions that encoded the old heuristic are replaced by ones that supply a real limit.223 of the 230 tests in
test/shell.d/pass. The 5 failures (base,bin-style,config,snapper,unowned-system-paths) fail identically on an untouchedquattro.I do not have the ThinkPad from #7803 or the MacBook from #10193, so those two are covered by the unit tests and by the reported readings rather than on the hardware. #10344 is my own machine.
🤖 Generated with Claude Code
https://claude.ai/code/session_01VADsy8CLE8n9hpfWUKt3vM