Skip to content

Add battery health toggle to the power panel - #17484

Open
dkalinkov wants to merge 5 commits into
omacom:quattrofrom
dkalinkov:battery-conservation-toggle
Open

dkalinkov wants to merge 5 commits into
omacom:quattrofrom
dkalinkov:battery-conservation-toggle

Conversation

@dkalinkov

@dkalinkov dkalinkov commented Nov 3, 2026 •

Copy link
Copy Markdown

Add Charge limit to the power panel when UPower reports support. Turning it on applies the hardware's battery protection policy; turning it off permits a full charge.

The compact row shows the available policy: “Maximum 80%”, “Start below 75% · stop at 80%”, or “Device default” for firmware-controlled protection. The caption stays in place when switching on/off. Up/Down moves between profiles and the charge limit, Left/Right selects off/on, and Enter/Space toggles. The switch keeps its keyboard focus during writes and refreshes.

Behavior

  • omarchy battery charge-limit [status|on|off|toggle] [--shell] discovers present system batteries using typed UPower properties. Peripherals, UPS devices, absent batteries and unsupported batteries are excluded. The control is hidden when unsupported. Mixed settings are shown explicitly; toggling a mixed state enables all supported batteries.
  • Writes use EnableChargeThreshold with an explicit state, skip batteries already in that state, and verify readback before reporting success. Refused or ignored changes fail. Partial changes are not rolled back; the panel reads and displays the resulting state.
  • Numeric policies are shown only for supported settings with valid values. Different policies across batteries are identified without presenting one battery's limit as a shared limit.
  • Read failures preserve and identify the last known policy, disable changes and show a retry message. An initial read failure is distinguished from confirmed unsupported hardware. A successful refresh recovers the control; output and process exit are joined regardless of completion order.
  • UPower events refresh thresholds, capabilities, battery presence and device changes while the panel is open. The listener stops on close; policy queries are not added to the periodic statistics refresh.

UPower owns hardware access, authorization and persistence. There are no vendor-specific paths, direct sysfs writes, sudoers rules or privileged background service.

Verification

  • Power command/model and real QML controller tests pass, covering supported policies, multiple batteries, peripheral exclusion, mixed states, idempotence, refused/ignored writes, partial failure, keyboard navigation, failed reads and recovery.
  • i18n, QML plain-text checks, catalog extraction, motion tokens and git diff --check pass. CLI routing/metadata and Bash syntax checks passed in the preceding backend revision; this revision changes panel interaction, copy and documentation.
  • Ran the branch's desktop shell and inspected numeric range/end-only policies, differing policies, mixed settings, unsupported hardware, refused writes and read-failure recovery using fixtures. Refreshed the numeric-policy and unavailable-state captures for the compact row.
  • Real hardware: ThinkBook 14 G8 IAL, UPower 1.91.5, firmware-controlled protection. One Down press reaches the control; Right/Left selects on/off and Space/Enter toggles. Changes were verified against UPower. External changes refresh the panel, and the listener stops on close. The original charging setting and installed shell were restored.
  • Inspected screenshots and a 60 fps keyboard recording, including frames through the switch transition. Physical testing covers one laptop; other policies and multiple batteries use fixtures. Reboot persistence and a full charge-to-limit cycle have not been tested for this implementation.

Related work

This overlaps #8579, #13205, #15431 and #16516. Policy explanations draw on #8579, percentage/firmware capability handling follows the direction of #15431, and tested keyboard selection follows the approach discussed in #16516. These are design references; their commits have not been incorporated.

This proposal combines those ideas with per-battery policy reconciliation, verified writes, explicit mixed state, read-failure recovery and change-driven refresh. The core feature and UPower approach are shared; maintainers should coordinate the proposals.

Screenshots

Before
01-before

After — charge limit off
02-after-protection-off

After — charge limit on
03-after-protection-on

Keyboard interaction
https://github.com/user-attachments/assets/befc9f7f-9663-4bdf-b533-4d7fec11283f

Start/stop thresholds — test fixture
05-numeric-range-FIXTURE

Settings unavailable — test fixture
06-unavailable-settings-FIXTURE

@sanjyay

sanjyay commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

I have a Lenovo LOQ where Conservation Mode works by writing 1 to /sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode. I’d be happy to help validate the fallback interface on real hardware, including authenticated on/off changes and state reporting. Is there a preferred revision or test procedure you’d like me to use?

@dkalinkov
dkalinkov force-pushed the battery-conservation-toggle branch from e624350 to 99b9034 Compare November 9, 2026 07:47
@dkalinkov dkalinkov changed the title Add Lenovo conservation mode toggle to the power panel Add battery health toggle to the power panel Nov 9, 2026
@dkalinkov
dkalinkov marked this pull request as ready for review November 9, 2026 19:09
@greptile-apps

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Adds a UPower-backed charge-limit command and power-panel switch.

  • The charge-limit command reads and changes supported system batteries.
  • The Power panel lets users switch battery protection on supported machines.
  • The open Power panel refreshes charge-limit state and recovers from failed reads.

Diagram

sequenceDiagram
  participant User
  participant Panel
  participant Command
  participant UPower
  User->>Panel: Select on or off
  Panel->>Command: Apply explicit setting
  Command->>UPower: EnableChargeThreshold
  Command->>UPower: Verify current setting
  Command-->>Panel: Exit
  Panel->>Panel: Defer refresh
  Panel->>Command: Read status
  Command-->>Panel: Current state and policy
Loading

Reviews (3) · Last reviewed commit: "Defer charge limit refresh until write e..." · Reviewed by Greptile

Comment thread shell/plugins/panels/power/Panel.qml Resolved
@omarchybot omarchybot added the enhancement New feature or request label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants