Repository navigation
Read battery size from sysfs when UPower reports 0 Wh - #14957
omarchybot wants to merge 1 commit into
Conversation
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>
|
| 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" |
There was a problem hiding this comment.
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!
|
This pull request no longer merges into 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 |
The power panel's "Battery size" comes from
omarchy-battery-status, which takes it from UPower'senergy-full. On the reporter's ThinkPad P1 Gen 2 (UPower 1.91.3), UPower reportsenergy-full: 0 Whfor bothbattery_BAT0andDisplayDevicewhile the kernel's/sys/class/power_supply/BAT0/energy_fullholds 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, thencharge_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 anenergy_fullthat 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 sysfspower_nowover UPower'senergy-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.shfails onquattroand 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