-
-
Notifications
You must be signed in to change notification settings - Fork 335
fix: start/stop thresholds not being set because of initial values #900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: start/stop thresholds not being set because of initial values #900
Conversation
|
Sounds good, please let me know once it's complete. Thanks! |
…stop charge thres settings don't apply
Done 👍 Have a look when you can :) |
|
@PurpleWazard since you originally implemented this feature, please let me know if you have any comments. In meantime, @CasperVM please give me some time to further review and test this. |
|
@AdnanHodzic @CasperVM. this PR adds a batterydevice class which i like makes the code a bit cleaner. however, thinkpad_acpi and ideapad_acpi were removed for unknown reason and they dont seem to be implemented with the changes.
which is backwards the start shouldn't be higher then the stop. the reason for the error is becuase the kernel module wont work with those values. the start value is what % at or under for the battery to start charging. the stop value is that value should charging at. ie. start: 70, stop: 80. the battery will maintain % between 70 and 80. |
Let me elaborate a little bit here, because I was probably a bit too unclear with my changes: First of the class is an abstraction, both the For the battery percent, yes, the start shouldn't be higher than the stop. That was never in my config, but if you change the config it might become an issue:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the battery threshold management scripts to fix a critical issue where start/stop thresholds fail to apply due to conflicting initial values. The solution sets temporary safe values (0/100) before applying the actual configured thresholds, with a 100ms delay to allow driver processing.
- Consolidates common battery management logic into a shared
BatteryDevicebase class - Implements a two-step threshold setting process to avoid "Invalid argument" errors
- Refactors Ideapad and Asus battery scripts to use class-based inheritance
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| auto_cpufreq/battery_scripts/shared.py | New shared base class implementing common battery threshold management logic with two-step threshold setting |
| auto_cpufreq/battery_scripts/ideapad_laptop.py | Refactored to extend BatteryDevice class with Ideapad-specific conservation mode handling |
| auto_cpufreq/battery_scripts/asus.py | Refactored to extend BatteryDevice class with Asus-specific fallback paths |
| auto_cpufreq/battery_scripts/battery.py | Updated to instantiate device classes instead of calling standalone functions |
| auto_cpufreq/battery_scripts/thinkpad.py | Removed - functionality now provided by shared BatteryDevice class |
| auto_cpufreq/battery_scripts/ideapad_acpi.py | Removed - functionality now provided by shared BatteryDevice class |
Comments suppressed due to low confidence (2)
auto_cpufreq/battery_scripts/ideapad_laptop.py:27
- Normal methods should have 'self', rather than 'value', as their first parameter.
def set_conservation_mode(value):
auto_cpufreq/battery_scripts/asus.py:9
- This class does not call BatteryDevice.init during initialization. (AsusBatteryDevice.init may be missing a call to a base class init)
class AsusBatteryDevice(BatteryDevice):
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Code changes (logic) generally make sense to me and from my testing everything worked as it should on ThinkPad X1 Carbon. I ran Copilot review also since there are a lot of changes and refactoring so please take a look at those, as it made some good remarks.
instead I had to restart the auto-cpufreq daemon in order for them to be picked up (or simply
With that said I think, after mentioned things above are addressed I think we're good to merge this, unless you have any other major concerns @PurpleWazard |
|
In meantime, I ran into a major issue, after I disabled I realized that my laptop was still not charging above 90% because permanent changes were made to my After I manually edited it back to 100, it charges past 90%. |
|
@AdnanHodzic Fixed some of the issues that the auto-review caught. Should this also perhaps be tested before merge? Added some clarification in the Readme as well As for the thresholds not resetting, we could add that to the |
|
One small oversight still, but unsure what would be the proper way to go around it here: If we only have e.g. the stop threshold, the start will be at 0. Meaning we wont start charging until the battery is dead. We should probably keep some sane defaults instead? Or just ignore the config if only one of the values is set? Edit: made it so we actually validate now, and both start/stop are needed. I don't think it makes sense to apply anything if either one is not set. |
Thanks, I can also test this if changes are finalized, just please note it might not happen until end of the week.
Option 1: Ideally, changes would be updated immediately as soon as they are written to config file. Some kind of hook could be created to trigger it, but would need to think more about this. As this will be the problem with enabling and disabling the changes. Option 2: Alternatively, we could update config part (and README) and below auto-cpufreq daemon should be restart or simply removed and enabled again (`auto-cpufreq --remove && auto-cpufreq --install). It's not pretty, but it's the simplest thing I can think of now.
If we're going for Option 2, then it can be part of this PR.
Not sure if I understand this part, as during my testing I used following config: and charging worked fine? |
|
I think that option 2 for now would be the best and a proper hook should be implemented later. So we just add more documentation. It's odd that your charging worked fine, as in the previous commit the default for start = 0, and stop = 100. As per the kernel docs: charge_control_start_threshold accepts an integer between 0 and 99 (inclusive); this value represents a battery percentage level, below which charging will begin. and charge_control_end_threshold accepts an integer between 1 and 100 (inclusive); this value represents a battery percentage level, above which charging will stop. I'll make one last commit to properly enforce this + add documentation/comments. Again, I don't think it make sense to have only 1 of the values set up. It might just end up in someone having issues and not understanding why. Additionally, it's difficult to determine 'sane' defaults. |
Agreed.
I think it worked because by not setting
Sounds good, better to relate them to avoid unnecessary new issues and questions. |
…check_thresholds=false for exceptional cases
|
@CasperVM Once you're done making all the changes and testing from your side, please let me know so I know when I can do the final review and test. Thanks P.S: reference from #898 how users setup battery charging thresholds.
|
|
@AdnanHodzic I'm happy with the current changes, you can do the final review and test when you have the time |
Background
I had this issue on my thinkpad where sometimes the start/stop thresholds of the battery charge were not being applied and failed with this;
This can happen when e.g. our start value is higher than the current stop value. In those cases we should lower the stop value to below our start.
What this change does
Impact
If writes somehow fail user might end up with incorrect settings, but this was the case before anyway.
The 100ms sleep is to ensure settings are applied by the driver, but this might not be needed?