Skip to content

Keep the battery icon charging while UPower measures a fresh plug-in - #8663

Open
ztyankov wants to merge 1 commit into
omacom:quattrofrom
ztyankov:fix/battery-charging-icon-on-plug-in
Open

ztyankov wants to merge 1 commit into
omacom:quattrofrom
ztyankov:fix/battery-charging-icon-on-plug-in

Conversation

@ztyankov

Copy link
Copy Markdown

chargeThresholdActive() reads a stalled charge as changeRate at or below 0.2 W, or a time-to-full over eight hours. A battery that was just plugged in reports changeRate 0 and timeToFull 0 until UPower measures the charge, which can take up to a minute, and 0 clears both of those bars. So for that first minute the bar showed the static (non-charging) icon and the panel read "Charge limit", on a machine with no charge limit set, every time the charger went in.

Empty readings are "not known yet", not "stalled": while the state still says Charging, treat changeRate 0 with timeToFull 0 as active charging and let UPower's next update decide. A real charge limit still reports either a PendingCharge/FullyCharged state or a measured low rate, all of which are unchanged.

chargeThresholdActive() reads a stalled charge as changeRate at or below
0.2 W, or a time-to-full over eight hours. A battery that was just plugged
in reports changeRate 0 and timeToFull 0 until UPower measures the charge,
which can take up to a minute, and 0 clears both of those bars. So for
that first minute the bar showed the static (non-charging) icon and the
panel read "Charge limit", on a machine with no charge limit set, every
time the charger went in.

Empty readings are "not known yet", not "stalled": while the state still
says Charging, treat changeRate 0 with timeToFull 0 as active charging and
let UPower's next update decide. A real charge limit still reports either
a PendingCharge/FullyCharged state or a measured low rate, all of which
are unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings August 27, 2026 19:59

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

Prevents fresh UPower readings from incorrectly showing a charge limit immediately after connecting power.

Changes:

  • Treats zero rate/time readings as pending measurements while charging.
  • Adds regression coverage for threshold detection and charging icons.

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 2 out of 2 changed files in this pull request and generated no comments.

File Description
shell/plugins/panels/power/Model.js Handles unknown initial charging measurements correctly.
test/shell.d/power-test.sh Tests fresh plug-in threshold and icon behavior.

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

@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 233a20f by Claude Opus 5.5. The fix works as described, and nothing in the diff needed changing.

What was run, on a disposable Omarchy VM: a probe that feeds chargeThresholdActive, batteryIcon and modeLabel what this PR says UPower publishes right after plug-in (state Charging, changeRate 0, timeToFull 0). On quattro the model flags a charge limit and shows the non-charging icon. On this head it reports Charging with the charging icon. With Model.js reverted to quattro, it flags the limit again. A real stall (0.1 W) and PendingCharge still read as a hold on this head. test/shell.d/power-test.sh fails on quattro with the new assertions and passes here (24/24), and ./test/cli is green.

What was not checked: the VM has no battery, so the claim that UPower publishes 0 W and time-to-full 0 while Charging was not observed on hardware. This run also did not check whether some firmware holds at a charge limit while still reporting Charging at exactly 0 W, rather than PendingCharge or a small positive rate. On a machine like that, the panel would now show "Charging" during the hold instead of "Holding".

Second opinion: none. The configured reviewer (Codex Medium) answers, but omabot's daily review budget was spent, so no second model reviewed this pull request. It is labelled verified but not ready, because ready needs a clean second review.

Related: #9668 reports the same function misreading a charging battery when time-to-full is bogus (27 h). This PR does not change that case. #12115 rewrites chargeThresholdActive to require a configured limit, and that would cover this case too. It is a 25-file bundle that currently conflicts with quattro.

Waiting on a second review, then on the maintainer.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 16, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This pull request has been overtaken by #19046, which a maintainer merged to quattro on November 15. That is also why it no longer merges cleanly.

What #19046 does. It fixes the same symptom in a different way. When external power arrives, the panel marks the charge rate as not yet trustworthy for 90 seconds (chargeRateFresh in shell/plugins/panels/power/Panel.qml), and chargeThresholdActive() skips the stalled-rate rule during that window. Every caller on quattro passes the flag: the bar icon, the panel icon, the mode label and the "Charge limit"/"Holding" rows. So the case this PR describes, Charging at 0 W with time-to-full 0 right after plug-in, already shows as charging on quattro.

What merging this on top would change. Model.js merges without conflict; only test/shell.d/power-test.sh conflicts. With both test blocks kept, the guard here would make quattro's test/shell.d/power-test.sh:28 fail. That assertion says Charging at 0 W with time-to-full 0 is a charge-limit hold once the rate has had time to settle, and this PR treats that reading as "not measured yet" forever. #19046 made the opposite choice on purpose, and it is now on quattro.

What #19046 still leaves open. If the shell starts while already plugged in, chargeRateFresh begins true and never goes through the settling window. A battery whose first measurement takes longer than 90 seconds can also still show the old false "Holding". This PR would cover both, but in Model.js it cannot tell those readings apart from a real hold. A follow-up for those cases belongs in #19046's settling mechanism.

What was checked. Claude Opus 5.5 read both diffs and every caller of the three model functions on quattro, and did a trial merge of quattro into this branch to find the conflict. Nothing ran on a worker this time: with the fix already on quattro, there was nothing left to reproduce. The September reproduction above was against the code before #19046. Two second opinions, Codex Medium and muse-wonder via pi (thinking high), were given both pull requests and asked which should stand. Both said #19046, and both named the same defect here, the 0 W hold being missed. Their independence is not guaranteed. muse-wonder also found the startup case above, which the first review had not considered.

Thank you, @ztyankov. You found this bug and fixed it first; #19046 just landed a different way of handling it. This now waits on the maintainer, and the recommendation is to close it as superseded by #19046.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants