Prevent discharging more power from battery with nearly 0% power #1600
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.
Summary
SUMMARY: Bugfixes "Prevent discharging too much power from nearly empty batteries"
Purpose of change
Consider the situation when charging from large storage battery (80 MJ) with 10 kJ remaining. It would have 0% power level (10*100 / 80_000) so our "prev_charge_level" would
-800
and we would loweramount
by 810.Essentially free energy when it shouldn't be so I ensure that we cannot charge more power than remaining.
Describe the solution
Just ensure that we never try to lower our power amount more than we have.
Describe alternatives you've considered
Testing
Only run autotests because change is trivial.
Additional context