Display battery percentage as weighted average of battery levels #2134
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.
A few days ago, I opened issue #2126 requesting this feature. I had some free time recently and decided to try making a pull request. I determined that weighted average of percentages with capacities as weights was a little complex, and that a better way to calculate the percentage that I wanted would be to just compute total_energy * 100 / total_energy_full. No change is required for the condition where the user sets design-capacity to true, as that is already total_energy * 100 / total_energy_full_design.
Right now, the option to enable this is called weighted-average. Is that an appropriate name, or should I call it something else?
Additionally, I discovered that it total_capacity is not greater than zero, Waybar already falls back to doing this calculation. (And still would, even if weighted-average is set to false.) However, it does not fall back if total_capacity could not be calculated at all. Is this the intended behavior? I have a feeling that the following code a few lines before my changes:
should have been this:
but I wasn't quite confident enough to make the change myself. Is that correct?