Skip to content

Keep UPower's battery rate when sysfs power can't be read - #15377

Open
pcakounes wants to merge 3 commits into
omacom:quattrofrom
pcakounes:fix-battery-unreadable-power-now
Open

pcakounes wants to merge 3 commits into
omacom:quattrofrom
pcakounes:fix-battery-unreadable-power-now

Conversation

@pcakounes

@pcakounes pcakounes commented Oct 14, 2026 •

Copy link
Copy Markdown

Fixes #15373

On some ACPI batteries (seen on an HP Spectre x360 13-aw0xxx), power_now and current_now exist and pass [[ -r ]], but every read fails with ENODEV. omarchy-battery-status gated only on -r, so the empty read reached awk as 0 and replaced UPower's correct energy-rate. The widget then showed 0W while charging.

Change

  • Read power_now, current_now and voltage_now up front with errors suppressed. Use the sysfs rate only when the read actually returns a value, and otherwise keep UPower's energy-rate.

Testing

  • Added a case to test/shell.d/battery-status-test.sh. It uses directories in place of power_now/current_now, since a directory passes -r but can't be read, like the ENODEV attribute. It fails before this change and passes after it, along with the existing cases.
  • On the affected laptop, the widget now shows the charge rate (7.3W) instead of 0W.

Some ACPI batteries list power_now and current_now with read permission
but fail every read with ENODEV. The empty read became 0W and replaced
UPower's correct energy-rate. Go by what the read returns instead.

Fixes omacom#15373

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pcakounes
pcakounes marked this pull request as ready for review October 14, 2026 00:46
@omarchybot omarchybot added bug Something isn't working compatibility Make Omarchy work better on everything! labels Oct 17, 2026
The battery-status test conflicted with the Omarchy language case quattro added at the same spot. Both are kept, the language case first: the unreadable-sysfs case turns power_now into a directory and raises UPower's rate in the shared fixture, which would change the time to full the language case expects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 17, 2026
@greptile-apps

greptile-apps Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

omarchy-battery-status keeps UPower’s rate when sysfs reads return no value.

  • Battery status keeps UPower’s rate when sysfs readings are empty.

Reviews (2) · Last reviewed commit: "Merge quattro into fix-battery-unreadabl..." · Reviewed by Greptile

@omarchybot omarchybot added the ready Good to merge label Oct 17, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and verified on a worker built from the Omarchy ISO. The fix holds, and nothing in it needs changing.

Merge with quattro. The branch conflicted with quattro in test/shell.d/battery-status-test.sh, where #15326 added an Omarchy-language case at the same spot as your new one. I pushed ef4ff6c, a merge of quattro that keeps both cases, with the language case first. Your case turns power_now into a directory and raises UPower's rate in the shared fixture, so running it first would change the time to full the language case expects. The diff against quattro is still only your two files.

What was checked:

  • My own reproduction, with a directory standing in for an attribute that passes -r but can't be read. On quattro, and on this head with the script reverted, both "power_now and current_now unreadable" and "power_now unreadable, current and voltage readable" show 0W. On this head the first keeps UPower's 21.5W and the second falls back to current × voltage (12W). A readable power_now and an empty sysfs behave as before.
  • Your new test fails with the script reverted and passes on the head.
  • ./test/cli and test/shell.d/battery-status-test.sh passed on the worker.
  • The bug is real: the kernel's ACPI battery driver returns -ENODEV for power_now/current_now when the battery reports no rate, while the attribute stays listed.

Second opinion: Codex Medium reviewed this head and found no correctness defect. Its reasoning was not guaranteed to be independent of mine. It made two optional points, which I left alone. The script reads current_now and voltage_now even when power_now works. The test merges stderr into stdout, so it would not notice if the read stopped being quiet.

Related: #15389 and #15541 fix the same issue a different way. This PR is the oldest of the three and covers the same cases, including the current × voltage fallback when power_now fails, so it is the one carried forward. #15541's extra tests (current × voltage, an unreadable voltage_now, quiet stderr) would be a reasonable follow-up.

This is waiting on the maintainer.

omacom#16272 added full and sparse status-line cases at the same spot in battery-status-test.sh. The unreadable-attribute case runs first and then removes the directories it put in place of power_now and current_now, since the cases after it write power_now as a file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge and removed verified Omarchy Triage has verified that this issue is ready for final review labels Oct 22, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

The branch conflicted with quattro again, so I merged quattro into it a second time. I pushed 0238bba. Nothing in your fix changed.

The merge. #16272 added a full-battery case and a sparse-reading case to test/shell.d/battery-status-test.sh, at the same spot as your case. Both are kept, with your case first. It now ends by removing the power_now and current_now directories it creates, because the cases after it write power_now as a file. The leftover voltage_now doesn't affect them, since each has a readable power_now. The diff against quattro is still only your two files.

What was checked, on a worker built from the Omarchy ISO, at 0238bba:

  • My own reproduction uses a directory in place of an attribute that passes -r but can't be read. On quattro, and on this head with bin/omarchy-battery-status reverted, two cases show 0W: power_now and current_now both unreadable, and only power_now unreadable with current and voltage readable. On this head the first keeps UPower's 21.5W and the second falls back to current × voltage (12W). A readable power_now and an empty sysfs behave as before.
  • ./test/cli passed. test/shell.d/battery-status-test.sh passed all 10 checks, including Battery notification says Fully charged and leaves out readings it doesn't have #16272's new cases. It fails with your script change reverted.
  • Your rate change works with Battery notification says Fully charged and leaves out readings it doesn't have #16272's new status line. UPower's rate counts as a live draw, so it is shown. A full or idle battery still drops it.

Second opinion: Codex Medium and muse-spark-1.3-contributor (High) reviewed this head, including the merge resolution, and found no defect. They agreed with my reading, but their independence from it isn't guaranteed. Both noted that the test doesn't check stderr stays quiet. Codex also noted that current_now and voltage_now are read even when power_now works. Neither changes behaviour, so I left them.

Related: #15389 and #15541 fix the same issue, #15373, a different way. Both models were asked separately which to carry forward, and both picked this one: it is the oldest, and it covers the same cases. #15541's extra tests (current × voltage, an unreadable voltage_now, quiet stderr) would still be a reasonable follow-up.

This is waiting on the maintainer.

@omarchybot

Copy link
Copy Markdown
Collaborator

The reported failure is now covered on quattro by #17265, merged as 4761d7b. Its numeric read helper keeps UPower’s rate when sysfs reads fail and preserves the current × voltage fallback.

On a fresh ISO worker, I checked this head (0238bba), its old merge base, and current quattro (f989b43). With directories simulating failed attribute reads, the old base gives 0W; both this head and current quattro retain 21.5W from UPower and produce 12W when current and voltage can be read. This is simulated read-failure coverage, not a new hardware confirmation. This head’s 10 battery checks and CLI suite also pass.

The recorded translation CI failure has no retained jobs or logs, so its original cause is unknown. On the worker, the structural translation test fails with the same locale-generation permission error on this head and its old base; current quattro passes. The English-literal scan passes on this head and its old base.

Codex High reviewed this with Opus 5.5 High and muse-wonder via pi, thinking high. Both agreed that no behavior or additional test needs porting; their independence from my review is not guaranteed. Nothing was pushed. This remains open for the maintainer to close as superseded by #17265.

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