Repository navigation
Conversation
Some ACPI firmware advertises power_now and then fails the read itself with ENODEV. `[[ -r ]]` only proves the file exists with read permission, so the empty string that comes back divides down to 0 and overwrites the energy-rate UPower had already computed correctly, leaving the power panel reading 0W while the battery drains. Read the attribute through a helper that requires the read to succeed and the contents to parse as a number, and fall through to UPower otherwise. The current_now/voltage_now fallback had the same hole and gets the same guard. Where the kernel does answer, its instantaneous reading still wins, which is why the sysfs override exists in the first place. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Confirming the same
At the same moment: $ omarchy-battery-status --shell
percentage 90%
state discharging
rate 0W
size 55Wh
time 4h 5m
cycles 0UPower has the correct rate: $ upower -i "$battery" | grep -E 'state|energy-rate|time to|native-path'
native-path: BAT1
state: discharging
energy-rate: 11.9872 W
time to empty: 4.1 hoursBut the sysfs attribute exists and fails when read: $ cat /sys/class/power_supply/BAT1/power_now
cat: /sys/class/power_supply/BAT1/power_now: No such device
|
|
Heads up: #6845 now covers this failure too — commit 3c40745 there discards a power_now/current_now read that passes |
|
@geirolafs this is my first pr, so I'm not sure what you want me to do? Should I take it down? |
|
@geirolafs Thanks for the heads up — you're right, and no action needed from you. I pulled your branch and ran it on the machine from this PR (HP Spectre x360 14-ea0, So closing this in favour of #6845 rather than leaving two overlapping changes to the same block for the maintainers. I've posted the hardware verification over there. @sorena100 thanks for the third confirmation — that detail is on #6845 now too, and #6845 is the one to watch for the fix. |
On an HP Spectre x360 14-ea0 the power panel sits at
0Wwhile the battery visibly drains.omarchy-battery-statusreportsrate 0Wat the same moment UPower has the right answer:The cause is the sysfs override that keeps the open panel live:
[[ -r ]]proves the attribute exists with read permission — not that reading it works. This firmware advertisespower_nowand then fails theread()itself:So the guard passes,
$(<...)hands back an empty string, awk computes"" / 1000000 = 0, and the correctenergy-rateread out of UPower ten lines earlier is overwritten with zero. Thecurrent_now/voltage_nowfallback has the same hole — a failed read there multiplies out to 0W just as quietly.The fix:
read_power_attributerequires the read to succeed and the contents to parse as an integer. When it doesn't,power_rate_rawkeeps the UPower value it already held, which is the correct figure on this hardware.current_now/voltage_nowpath is covered too.Notes for review:
BAT1); I hit the identical failure on an HP Spectre x360 14-ea0 (BAT0), so it is an ACPI firmware class rather than one machine.power_nowin its fixture. AnENODEVread and an empty file hand bash the same empty string, so the fixture reproduces precisely what the script sees without needing the broken firmware — and it covers the non-numeric case as well.battery-status-test.sh, to stay out of the way of the two open PRs on this script. Fix battery status on multi-battery machines #6845 rewrites this same block for multi-battery machines and discards invalid reads as a side effect of its metering loop; if that lands first, only the regression test here is still needed, and Power panel shows 0W discharging when power_now read returns ENODEV #6895 explicitly asks for that coverage. Fix omarchy-battery-status to report combined capacity on multi-battery laptops #7138 touches the surrounding lines but not this failure. This change is deliberately four lines of logic so it rebases cleanly behind either.Verified:
rateomarchy-battery-status0W11.1Wupower -ienergy-rate11.1458 WThe new test fails on
quattro(expected: 7.3W / actual: 0W) and passes with the fix../test/shellruns 178 of 181 files green; the three failures are pre-existing on a clean checkout and unrelated (config,snapper,unowned-system-pathsall want anomarchy-pkgscheckout that isn't present here)../test/clipasses.🤖 Generated with Claude Code