Power panel shows 0W discharging when power_now read returns ENODEV
Summary
The battery widget / power panel shows 0W discharging on a laptop whose ACPI embedded controller exposes a power_now sysfs attribute that exists but cannot actually be read. omarchy-battery-status trusts the attribute because [[ -r ]] passes, gets an empty string from the read, and awk coerces it to 0W — discarding the correct value that UPower already computed.
Expected behavior
The widget should show the real power draw (e.g. 16.8W, 29.9W), matching UPower's energy-rate.
Actual behavior
omarchy-battery-status --shell reports rate 0W while discharging.
Steps to reproduce
On affected hardware (here: HP Pavilion Gaming Laptop 15-dk0xxx, battery BAT1):
# The sysfs attribute exists and is world-readable, so [[ -r ]] passes...
ls -l /sys/class/power_supply/BAT1/power_now # -r--r--r-- 1 root root ...
# ...but reading it fails:
head -c 20 /sys/class/power_supply/BAT1/power_now
# head: error reading '.../power_now': No such device
# Meanwhile UPower has the correct value:
upower -i /org/freedesktop/UPower/devices/battery_BAT1 | awk '/energy-rate/ { print $2 }'
# 29.9735
# And the widget script zeroes it out:
omarchy-battery-status --shell
# percentage 40%
# state discharging
# rate 0W <-- should be ~16-30W
Root cause
bin/omarchy-battery-status lines ~50-57:
if [[ -r $battery_path/power_now ]]; then
power_rate_raw=$(awk -v microwatts="$(<"$battery_path/power_now")" 'BEGIN { print microwatts / 1000000 }')
[[ -r ]] only checks that the file exists with read permission, not that the read succeeds. On this HP/ACPI firmware the read() syscall returns ENODEV ("No such device"), so $(<...) captures an empty string, awk computes "" / 1000000 = 0, and the correct UPower energy-rate value is overwritten. The same latent issue affects the current_now/voltage_now fallback.
The fix is to only trust the sysfs value when the read returns a non-empty numeric string, falling back to UPower's energy-rate otherwise.
Notes
- PR #6845 ("Fix battery status on multi-battery machines") rewrites this exact block and, as part of its metering logic, already discards invalid/empty
power_nowreads ([[ $microwatts =~ ^-?[0-9]+$ ]] || continue) — which fixes this bug as a side effect. It would be good to add a regression test there for the ENODEV-on-read case (attribute present but read fails). - A local user-side workaround is to clone the power plugin and guard the sysfs read; happy to share.
System details
- Omarchy: 4.0.0-1 (package
omarchy) - Kernel: 7.1.8-arch1-3 (x86_64)
- Machine: HP Pavilion Gaming Laptop 15-dk0xxx (Mobo 85FA, BIOS Insyde F.67)
- Battery: Hewlett-Packard PABAS0241231, BAT1, Li-ion
- Desktop: Hyprland 0.56.2 (Wayland), SDDM
- CPU: Intel Core i5-9300H; GPU: Intel UHD 630 + NVIDIA GTX 1050 Max-Q
- Full diagnostics in
/tmp/omarchy-debug.log; screenshots of the 0W panel are available and can be attached on request.
Checked against current quattro (902fd8aeb): the bug is still there. In bin/omarchy-battery-status lines 50–51, [[ -r ]] passes for a power_now whose read fails, the failed read substitutes an empty string, and awk turns that into 0, overwriting the energy-rate UPower already supplied. The current_now/voltage_now branch at lines 52–56 has the same hole. This can't be reproduced without the firmware, but the mechanism is in the source and an empty fixture file triggers it.
#12649 fixes it: it uses a sysfs reading only when it is numeric and otherwise keeps UPower's rate, in both branches, with regression tests. It already closes this issue. #12735 reports the same failure on another machine. The pull request is reviewed as its own item, so this issue now waits on the maintainer's decision on #12649.
Reviewed by Claude Opus 5.5 and, as a second opinion, Codex Medium. Codex reached the same diagnosis independently and found the same fix in #12649. One caveat it raised: when power_now fails, the fix goes straight to UPower's rate instead of trying current_now/voltage_now. That still gives the right number, just a few seconds behind the live reading.
#17265 (merged Nov 1) now uses the sysfs rate only when it reads as a number, and otherwise keeps UPower's rate, which covers a power_now that fails with ENODEV. It shipped in v4.5.0. @ujo4eva, could you confirm on 4.5.0 that the panel no longer shows 0W while discharging?
Confirmed from source that #17265 fixes this path on quattro and shipped in v4.5.0 as commit 209a60d7aa2521498ee8bb7544a55c4cafec77e7. A failed or empty power_now read now tries current_now × voltage_now; if neither provides numeric readings, UPower's rate stands. The battery command in v4.5.0 matches current quattro. The earlier proposed fix, #12649, closed without merging.
GPT-6 High in Codex checked the source, merged change, release tag and panel parsing. Second opinions from Opus 5.5 High and muse-wonder via pi, thinking high, agreed on the source diagnosis; independence is not guaranteed. Neither independently verified the release backport, which I checked through Git. No code or tests ran this session, and the existing empty-file regression test does not reproduce the HP firmware's ENODEV failure.
The issue remains open, awaiting the confirmation already requested from @ujo4eva on v4.5.0 or newer. The result on the affected HP hardware is still unverified.
Confirmed on 4.5.0-3: while discharging, omarchy-battery-status --shell now reports rate 15.6W, matching UPower's energy-rate (15.594). power_now on BAT1 still fails with ENODEV, so the fallback is working. Fine to close.