Skip to content

battery-status: keep UPower's rate when the sysfs read fails (#15373) - #15389

Closed
nekomario28 wants to merge 1 commit into
omacom:quattrofrom
nekomario28:battery-power-now-fallback
Closed

nekomario28 wants to merge 1 commit into
omacom:quattrofrom
nekomario28:battery-power-now-fallback

Conversation

@nekomario28

Copy link
Copy Markdown
Contributor

Closes #15373.

/sys/class/power_supply/BAT0/power_now can exist, be readable, and fail the read: the ACPI battery driver advertises the attribute and a battery that only reports energy answers it with ENODEV. $(<...) is empty then — and awk called that 0, which overwrote the energy-rate UPower had reported correctly (21.5 W on the HP Spectre x360 in the report). The elif never ran either, because [[ -r ]] passed and took the branch.

The value is read into a variable now and only a reading that produced a value replaces UPower's, so the current_now × voltage_now pair is still tried when power_now fails.

Testing

bash test/shell.d/battery-status-test.sh — two cases added, using a directory to stand in for the unreadable power_now ([[ -r ]] is true for it, the read is not):

  • with current_now/voltage_now present the rate must come from them (10.8 W);
  • with no other sysfs reading the rate must stay UPower's (0.1 W).

Against the old code the file stops at not ok - battery status falls back to current x voltage when power_now cannot be read; with that assertion disabled the second also fails (not ok - battery status keeps UPower's rate when no sysfs reading works), so both are guards that can fail rather than restatements. With the change the whole file is green, including the cases it already had (Apple Silicon's signed power_now, the charge-hold thresholds, the shared-owner calculation).

@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for this. It's been read but not yet verified, because the classification step didn't finish: I read it as a hardware-caused bug fix (compatibility), and the second model that confirms that (Codex Medium) didn't run today because its daily review budget is used up. Until a second model agrees on the class, nothing was run on a worker and no labels were added. It goes round again when the reviewer is available.

What I did check, by reading only:

Waiting on: the second model's classification, then the maintainer.

power_now being readable is not the same as reading it: a battery that only
reports energy advertises the attribute and answers the read with ENODEV, and
the empty result then divides to 0 W - hiding the rate UPower reported. A
failed power_now read also took the branch, so the current_now x voltage_now
pair below it never ran.

Read the value into a variable and only let a reading that produced a value
replace UPower's (omacom#15373).
@nekomario28
nekomario28 force-pushed the battery-power-now-fallback branch from c1da757 to b16df03 Compare October 24, 2026 12:08
@greptile-apps

greptile-apps Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

omarchy-battery-status now keeps UPower’s rate when kernel files return no value.

  • Battery status keeps UPower’s rate when sysfs has no usable reading.

Reviews (1) · Last reviewed commit: "battery-status: keep UPower's rate when ..." · Reviewed by Greptile

@omarchybot omarchybot added bug Something isn't working compatibility Make Omarchy work better on everything! labels Nov 2, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks, @nekomario28. I classified this again on the current head (b16df03) and read it against quattro. quattro already fixes the bug it addresses, so I recommend closing it. That decision is the maintainer's.

What was checked, by reading only. Nothing ran on a worker:

Second opinion: Codex Medium and muse-wonder (pi, thinking high) both reviewed it, and both agreed that #12755 wins and that this pull request adds nothing #12755 lacks; their independence is not guaranteed. Codex pointed out that quattro already fixes the cause, which I then confirmed against the code. muse-wonder flagged that the 2>/dev/null after $(<file) does not silence the read error. I tested that in bash and the redirect does silence it, so that finding does not hold. muse-wonder also noted that a non-empty, non-numeric reading would still become 0 W here. That is true, and quattro's numeric check now handles it.

Labelled bug and compatibility (Codex Medium agreed on the class). Waiting on: the maintainer, to close this. #15373 is also still open, even though quattro fixes it.

@nekomario28 nekomario28 closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Power widget shows 0W while charging on HP Spectre x360 (power_now read fails with ENODEV but passes -r check)

2 participants