Soc: extrapolate from charged energy when vehicle api is unavailable - #33122
Merged
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="core/soc/estimator.go" line_range="97-98" />
<code_context>
- s.log.WARN.Println("missing vehicle soc- ignored by estimator")
+ // extrapolate soc from charged energy while no vehicle soc is available,
+ // never below the current estimate to stay monotonic across energy resets
+ if energyDelta := max(chargedEnergy, 0) - s.prevChargedEnergy; s.initialSoc > 0 && energyDelta >= 0 {
+ s.vehicleSoc = min(max(s.vehicleSoc, s.prevSoc+energyDelta/s.energyPerSocStep), 100)
+ s.log.DEBUG.Printf("soc extrapolated: %.2f%%", s.vehicleSoc)
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** A vehicle whose first valid fetched SOC is exactly 0% never enters the nil-SOC extrapolation branch because `initialSoc > 0` is false, so the estimator freezes at 0% throughout a backend outage despite charged energy increasing.
**Triggers:** When charging starts at 0% SOC and the vehicle API becomes unavailable before the next SOC sample.
**Suggested fix:** Track whether a valid SOC sample exists separately from the SOC value, instead of using `initialSoc > 0` as the initialization test.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: core/soc/estimator.go:98
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
2 tasks
This comment has been minimized.
This comment has been minimized.
Contributor
|
✅ Opened backport pull request on |
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.
fixes #33116
When the vehicle backend becomes unavailable during charging, the estimator so far froze the last known soc, so a configured soc limit could be exceeded until the backend returned.
The estimator's
fetchedSoc == nilbranch now extrapolates the soc from charged energy using the already sampled state (prevSoc + energyDelta/energyPerSocStep) — the same formula as the existing interpolation branch, so the estimate stays continuous once the backend returns. The sampled state itself remains untouched and the next fetched soc always takes precedence. The estimate is clamped to 100% and kept monotonic so a mid-outage session energy reset cannot move it backwards. This implements thenil | value | prevsoc + deltacase documented incore/soc/README.md.publishSocAndRangenow passes a missing soc through to the estimator instead of skipping it. A freshly created estimator without any prior sample returns 0 and does not overwrite a known soc (same-vehicle reconnect must keep the published value). As a side effect, the published soc now also advances with charged energy between regular soc polls.🤖 Generated with Claude Code