Add percentage range support to maintain command#398
Add percentage range support to maintain command#398actuallymentor merged 2 commits intoactuallymentor:mainfrom
Conversation
The .* pattern already covers .claude/ directory, but explicitly adding CLAUDE.md to ensure Claude Code configuration files are not committed. Also re-allowing .github and .vscode directories that should be tracked. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add valid_percentage_range() validation function - Validates NUMBER-NUMBER format - Ensures lower < upper - Enforces lower >= 10 and upper <= 100 - No maximum range spread limit - Update maintain_synchronous to handle ranges - Parse range into lower_bound and upper_bound - Enable charging when battery < lower_bound - Disable charging when battery >= upper_bound - Fully backward compatible with single values - Update help message and README - Add examples: 'battery maintain 70-80' - Document range syntax alongside single values - Maintain daemon persists ranges across reboots - Stores range format (e.g., '70-80') in maintain.percentage - Recovery logic auto-detects and restores ranges Tested: - Single value (80) works as before - Valid ranges (70-80) work correctly - Invalid ranges rejected (80-70, 5-15, 95-105, 70-70) - Status display shows ranges properly (70% - 80%) CLI-only feature. GUI support deferred to future work. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Thanks for this addition and well formatted PR @seefood! I welcome good AI x human collaborative pull requests. |
|
It was really the second time I submitted it, only this time I implemented nothing and let Claude do all the work, and it was embarrassingly a bit better than my first organic attempt... |
|
Is it true that |
|
true, I discovered that only after using this feature for a while. unlike a phone, when the upper limit is reached, the laptop does not continue working on the battery, it works directly with the mains. |
Modern phones work the same actually. I thought the range support was a feature people wanted because they unplug their laptop a bunch during the day or something. |
…ange Add percentage range support to maintain command
Summary
Adds support for maintaining battery within a percentage range (e.g.,
battery maintain 70-80) while preserving full backward compatibility with single-value syntax (e.g.,battery maintain 80).Motivation
When using
battery maintain 80, the battery constantly cycles between ~79% and ~81%, which still causes some wear. This PR allows users to set a wider range likebattery maintain 70-80, letting the battery rest anywhere in that range, reducing charge/discharge cycles.Changes
Core Functionality
New validation function
valid_percentage_range():NUMBER-NUMBERformatUpdated
maintain_synchronouslogic:lower_boundandupper_boundEnhanced status display:
Documentation
Persistence
70-80) in~/.battery/maintain.percentageTesting
Tested on macOS with the following scenarios:
battery maintain 80works as beforebattery maintain 70-8080-70(upper < lower)5-15(lower < 10)95-105(upper > 100)70-70(equal values)CLI-Only Feature
This implementation is CLI-only. GUI support for ranges is deferred to future work.
Example Usage