Skip to content

Read battery size from sysfs when UPower reports 0 Wh - #14957

Open
omarchybot wants to merge 1 commit into
quattrofrom
fix/issue-10026
Open

omarchybot wants to merge 1 commit into
quattrofrom
fix/issue-10026

Conversation

@omarchybot

@omarchybot omarchybot commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

The power panel's "Battery size" comes from omarchy-battery-status, which takes it from UPower's energy-full. On the reporter's ThinkPad P1 Gen 2 (UPower 1.91.3), UPower reports energy-full: 0 Wh for both battery_BAT0 and DisplayDevice while the kernel's /sys/class/power_supply/BAT0/energy_full holds the real 79.84 Wh, so the panel shows "Battery size: 0Wh".

When UPower's figure comes out as 0, the script now reads the battery's own sysfs entry instead: energy_full (µWh) first, then charge_full × voltage_min_design (µAh × µV) for batteries that report charge rather than energy. Each source is tried only while capacity is still 0, so an energy_full that reads empty or 0 does not stop the charge source from answering, and a non-zero UPower figure is left alone. This is the same fallback the script already makes for the power rate, which prefers sysfs power_now over UPower's energy-rate, and it reads the battery UPower resolved, so the Apple Silicon and non-BAT* names keep working. Why UPower zeroes the value on this machine is upstream and not established here.

The new test in test/shell.d/battery-status-test.sh fails on quattro and passes with this change, on an Omarchy worker. Reviewed by Claude Opus 5.5 and, as a second opinion, Codex at medium effort, whose last round found nothing open.

Fixes #10026

On a ThinkPad P1 Gen 2, UPower 1.91.3 reports energy-full as 0 Wh while the kernel's energy_full is correct, so the power panel showed "Battery size: 0Wh". Fall back to energy_full, then charge_full x voltage_min_design, trying each while capacity is still 0, as the rate already falls back to power_now.

Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Adds fallback logic to battery capacity reporting.

The PR appears safe to merge, with a non-blocking gap in tests for source order.

Findings

  1. P2 Source order lacks tests ▶

Summary

When UPower reports zero battery capacity, omarchy-battery-status now reads the battery's sysfs files.

  • Battery size falls back to kernel data when UPower reports zero.

Reviews (1) · Last reviewed commit: "Read battery size from sysfs when UPower..." · Reviewed by Greptile

Comment on lines +125 to +134
sed -i 's/energy-full: 69.6 Wh/energy-full: 0 Wh/' "$hold_dir/bin/upower"
printf '79840000\n' >"$hold_dir/power/BAT0/energy_full"
zero_output=$(OMARCHY_POWER_SUPPLY_PATH="$hold_dir/power" PATH="$hold_dir/bin:$PATH" "$ROOT/bin/omarchy-battery-status" --shell)
grep -Fx $'size\t79Wh' <<<"$zero_output" >/dev/null || fail "battery status falls back to sysfs energy_full when UPower reports 0 Wh"

printf '0\n' >"$hold_dir/power/BAT0/energy_full"
printf '5200000\n' >"$hold_dir/power/BAT0/charge_full"
printf '15400000\n' >"$hold_dir/power/BAT0/voltage_min_design"
charge_output=$(OMARCHY_POWER_SUPPLY_PATH="$hold_dir/power" PATH="$hold_dir/bin:$PATH" "$ROOT/bin/omarchy-battery-status" --shell)
grep -Fx $'size\t80Wh' <<<"$charge_output" >/dev/null || fail "battery status derives capacity from sysfs charge_full when energy_full reads 0 too"

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.

P2 Source order lacks tests

The new tests only run with UPower reporting zero, and they never give both sysfs sources different nonzero values. A later change could replace a valid reading with a lower-priority source without failing these tests. Add cases where a nonzero UPower value wins over sysfs, and where nonzero energy_full wins over charge_full.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@omarchybot

Copy link
Copy Markdown
Collaborator Author

This pull request no longer merges into quattro. Since it was opened, #15285 (time left worked out from the draw) and #15326 (battery status in the Omarchy language) both rewrote bin/omarchy-battery-status around the lines this change sits beside, so it needs quattro merged in and the fallback re-tested on top of that code before it can go further.

That port and its re-verification are on hold this pass. Every item is classified and checked by two models, and the second one, Codex at medium effort, could not run: today's review budget is spent. So this pull request has no class label yet, and nothing was run on a worker this pass. It comes round again once a second opinion is available.

The confirmation asked for on #10026 is still the thing that decides it. Testing commit 7211154ca69877f7600ec0c45f2abff52481d603 on the P1 Gen 2, as described there, still answers it: the merge does not change the fallback itself. Until then this waits on the reporter and on that second review.

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.

Battery Size Detection on Lenovo P1 Gen 2 Not Working

1 participant