Skip to content

Leave out a charge limit UPower reports as disabled - #17138

Closed
jasasonc wants to merge 2 commits into
omacom:quattrofrom
jasasonc:fix-battery-disabled-threshold
Closed

jasasonc wants to merge 2 commits into
omacom:quattrofrom
jasasonc:fix-battery-disabled-threshold

Conversation

@jasasonc

@jasasonc jasasonc commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

UPower fills in its hwdb default thresholds (75/80) for batteries that expose the charge control attributes, even when the limit is off and the firmware refuses it, so omarchy-battery-status reported a 75-80% limit on this Dell that is not active. UPower prints charge-threshold-enabled only while the limit is on, so the status now ignores UPower's thresholds when it reports a supported limit without that line, and still shows an enabled limit or one the kernel itself reports. The battery status test covers all three.

Closes #17137

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Updates omarchy-battery-status to ignore UPower’s default thresholds when charge limits are supported but not enabled.

  • Battery status ignores disabled UPower defaults but keeps kernel limits.

Reviews (2) · Last reviewed commit: "Treat a supported charge limit UPower do..." · Reviewed by Greptile

@areezen

areezen commented Oct 31, 2026

Copy link
Copy Markdown

Thanks for picking this up so fast. I tested this change against the hardware from #17137, and the guard can never match, so the phantom value remains.

Why: UPower only prints charge-threshold-enabled when the value is true. From libupower-glib/up-device.c (UPower 1.91.5):

if (up_exported_device_get_charge_threshold_enabled (priv->proxy_device))
    g_string_append_printf (string, "    charge-threshold-enabled:      %s\n",
                            up_device_bool_to_string (...));

up_device_bool_to_string() returns yes/no, and the line is emitted only on the true branch:

  • limit enabled → charge-threshold-enabled: yes
  • limit disabled → the line is omitted entirely

So charge-threshold-enabled: no never appears in real upower -i output.

Reproduced on the Dell XPS 13 DX13260 (limit disabled, thresholds 75/80 from hwdb, sysfs reads fail with ENXIO): applied this PR's diff to the current bin/omarchy-battery-status and ran both against the same system:

$ omarchy-battery-status --shell | tail -1
threshold	75-80%
$ bash patched-battery-status --shell | tail -1
threshold	75-80%

No change. The added test passes because the stub supplies a charge-threshold-enabled: no line that real upower does not emit, so it does not cover this path.

What would work here:

  1. Treat charge-threshold-supported: yes with no charge-threshold-enabled: line as disabled (matches 1.91.x output), or
  2. Query the property directly via D-Bus (busctl get-property … ChargeThresholdEnabled returns b false here), or
  3. If the goal is full accuracy, only trust the kernel's own charge_control_* reading and use UPower as the fallback — though note this machine's sysfs reads fail too, so that variant still needs the enabled-flag check.

Happy to test a revised patch on this machine and report the output.

@jasasonc

Copy link
Copy Markdown
Contributor Author

@areen-dev Thank you for testing it on the hardware, and for the pointer into up-device.c. You're right: the stub printed a line real UPower never prints.

1a8e768 follows your first option. When UPower reports charge-threshold-supported: yes without charge-threshold-enabled: yes, its thresholds are ignored; the kernel's own charge_control_* reading still applies, and an enabled limit still shows. The test stub now matches 1.91.x output (no enabled line for a disabled limit) and also covers the enabled case.

If you can run the updated script on the XPS once more, that would confirm it.

@areezen

areezen commented Nov 2, 2026

Copy link
Copy Markdown

Confirmed on the XPS 13 DX13260 (BIOS 1.6.0, UPower 1.91.5) with 1a8e768.

Real upower -i output here is exactly the case this revision targets — supported, no enabled line, hwdb defaults still present:

charge-start-threshold:        75%
charge-end-threshold:          80%
charge-threshold-supported:    yes

and busctl get-property … ChargeThresholdEnabled returns b false.

Results:

$ omarchy-battery-status --shell        # installed 4.0.6
…
threshold	75-80%

$ bin/omarchy-battery-status --shell    # 1a8e76807
…
cycles	18

The phantom line is gone, and nothing is lost in its place: the kernel's charge_control_* reads still fail with ENXIO on this firmware, so there is no real value to show. That is the correct outcome for this machine.

I also checked the two cases the guard must not break, with stubbed output:

  • charge-threshold-supported: yes + charge-threshold-enabled: yes → threshold 75-80% still shown
  • limit not reported as enabled, but BAT0/charge_control_end_threshold readable (85) → threshold 85% still shown

And test/shell.d/battery-status-test.sh at 1a8e768 passes here, including the new case (9/9 ok).

This fixes the reporting bug from #17137 on this hardware. The underlying limitation is unchanged — the firmware still refuses every write, so no OS-side charge limit — but the panel no longer claims one exists.

@jasasonc

jasasonc commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @areen-dev, that covers all three cases.

@jasasonc

jasasonc commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #16685, which covers this too. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dell XPS 13 DX13260: charge threshold reported as 75-80% although the EC refuses every operation (ENXIO)

2 participants