Skip to content

Trust sysfs over stale upower state for battery charge status - #7293

Closed
lytedev wants to merge 1 commit into
omacom:quattrofrom
lytedev:fix-stale-battery-charge-state
Closed

lytedev wants to merge 1 commit into
omacom:quattrofrom
lytedev:fix-stale-battery-charge-state

Conversation

@lytedev

@lytedev lytedev commented Aug 17, 2026

Copy link
Copy Markdown

omarchy-battery-status reports "Holding" while the battery is actively charging on a ThinkPad with a charge threshold set.

UPower's state lags the kernel by tens of seconds, the same way its energy-rate does. The script already works around that lag for the rate, reading power_now from sysfs, but still takes state from UPower. On a T480 charging at 29W:

$ upower -i /org/freedesktop/UPower/devices/battery_BAT1
    state:               pending-charge
    energy-rate:         0 W
$ cat /sys/class/power_supply/BAT1/status /sys/class/power_supply/BAT1/power_now
Charging
29207000

The pending-charge branch has no rate guard, so the panel shows Battery 75% · Holding at 75-80% · 28.7W / 87Wh mid-charge — holding and 28.7W at the same time.

Two changes:

  • Prefer $battery_path/status over UPower's state when it is readable.
  • Require an idle rate for every charge_holding branch. Holding means no power is moving, so a stale label must not claim it while watts are flowing. The charging branch's now-redundant charge_idle check folds into that precondition.

Covered by two cases in battery-status-test.sh: sysfs reporting charging against a stale pending-charge label, and the same fixture at 0W confirming genuine holding still reports.

Copilot AI balanced review requested due to automatic review settings August 17, 2026 17:06

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

Note

Copilot was unable to run its full agentic suite in this review.

Updates the battery status script to avoid reporting “holding” when UPower’s state is stale by trusting sysfs for charge state and tightening the “holding” detection logic.

Changes:

  • Prefer sysfs status over UPower state when available.
  • Require an idle (near-zero) charge rate before reporting “holding”.
  • Add regression tests covering stale UPower pending-charge vs live sysfs charging.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/shell.d/battery-status-test.sh Adds test cases to ensure stale UPower state doesn’t override live sysfs state and rate.
bin/omarchy-battery-status Uses sysfs status to override UPower state and refines holding detection to require idle rate.

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

Comment on lines +50 to +51
stale_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir" "$stale_dir"' EXIT
@YuseiRun

Copy link
Copy Markdown

Was thIs closed because it will be fixed by another PR?

@lytedev

lytedev commented Sep 23, 2026 •

Copy link
Copy Markdown
Author

Not sure, sorry. I just needed to close this because I could no longer follow through on this work.

@lytedev
lytedev deleted the fix-stale-battery-charge-state branch September 23, 2026 16:42
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.

3 participants