modules/battery: Deprioritize capacity
/sys value for battery calculation if other methods are available
#3381
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #3293
The current code for battery calculation seems to assume that the
capacity
value returns the non-design battery capacity. This is not the case, and it instead returns the design capacity of the battery.Currently, the
capacity
value is used above all other methods if it is present in the /sys directory of the battery. This means that the design capacity of the battery will always be displayed regardless of thedesign-capacity
configuration option.To remedy this issue, I have restructured the code so that the
capacity
value is only used if the other possible options for calculation have been exhausted beforehand.This screenshot shows two instances Waybar while the battery is plugged in at full capacity. The top instance is the current release version, and the bottom instance is the code present in this pull request:
This pull request maintains the functionality of the
design-capacity
configuration option. Here is the previous screenshot taken again withdesign-capacity
set totrue
:Please correct me if I have done anything incorrectly in this pull request, as I am not very familiar with the codebase.