Don't wait for PV timer when battery boost ends without surplus#28511
Open
blampe wants to merge 1 commit intoevcc-io:masterfrom
Open
Don't wait for PV timer when battery boost ends without surplus#28511blampe wants to merge 1 commit intoevcc-io:masterfrom
blampe wants to merge 1 commit intoevcc-io:masterfrom
Conversation
If we start battery boosting with PV surplus, and the boost finishes when no more surplus remains, then we end up waiting for the full `pvTimer` duration before we stop charging. This ends up sipping a little extra from the battery, and it can give the impression that the feature isn't working correctly because the battery continues discharging despite hitting the cutoff. Instead, if boosting ends without a PV surplus we can stop charging immediately by pre-expiring `pvTimer`. This _only_ triggers an immediate stop when boost ends in a no-surplus situation. If boosting ends with PV surplus still available, `targetCurrent >= minCurrent` so the disable sequence is never entered and the pre-expired `pvTimer` has no effect. A failing unit test is included to confirm the behavior. I would understand if this isn't accepted, since it does introduce a (unlikely) edge case where boosting could expire when the surplus is borderline, which could lead to some flapping. NB: I'm very excited for the optimizer work since this battery boosting is very valuable but also very suboptimal due to all the manual thresholds!
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Mutating
lp.pvTimerinside thetargetCurrent < minCurrentbranch ofpvMaxCurrentintroduces a side effect in what is otherwise mostly a calculation/helper; consider tightening the condition (e.g. only whenbatteryBufferedis true, notbatteryStart) or moving the timer manipulation to a place where side effects are expected to avoid surprising future maintainers. - The new behavior relies on the sentinel
elapsedvalue and the mock clock interaction in a fairly implicit way; a brief explanation near thelp.pvTimer = elapsedassignment (or a small helper) clarifying that this is a deliberate pre-expiration mechanism would make the intent and coupling to the timer logic clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Mutating `lp.pvTimer` inside the `targetCurrent < minCurrent` branch of `pvMaxCurrent` introduces a side effect in what is otherwise mostly a calculation/helper; consider tightening the condition (e.g. only when `batteryBuffered` is true, not `batteryStart`) or moving the timer manipulation to a place where side effects are expected to avoid surprising future maintainers.
- The new behavior relies on the sentinel `elapsed` value and the mock clock interaction in a fairly implicit way; a brief explanation near the `lp.pvTimer = elapsed` assignment (or a small helper) clarifying that this is a deliberate pre-expiration mechanism would make the intent and coupling to the timer logic clearer.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
If we start battery boosting with PV surplus, and the boost finishes when no more surplus remains, then we end up waiting for the full
pvTimerduration before we stop charging. This ends up sipping a little extra from the battery, and it can give the impression that the feature isn't working correctly because the battery continues discharging despite hitting the cutoff.Instead, if boosting ends without a PV surplus we can stop charging immediately by pre-expiring
pvTimer. This only triggers an immediate stop when boost ends in a no-surplus situation.If boosting ends with PV surplus still available,
targetCurrent >= minCurrentso the disable sequence is never entered and the pre-expiredpvTimerhas no effect.A failing unit test is included to confirm the behavior.
NB: I can understand if this isn't accepted, since it does introduce an (unlikely) edge case where boosting could expire when the surplus is borderline, which could lead to some flapping. I'm also very excited for the optimizer work since this battery boosting is very valuable but also very suboptimal due to all the manual thresholds!