feat: add SOC kWh fallback for vehicles without realtimePower#448
Merged
nanomad merged 2 commits intoMay 11, 2026
Merged
Conversation
5b2b42d to
8ef508f
Compare
For car models (e.g. MGS5) where RvsChargeStatus.realtimePower is always None or 0, DRIVETRAIN_SOC_KWH was never published. Add extract_soc_kwh(charge_status, soc) to the extractors module, following the same pattern as extract_soc / extract_electric_range. It prefers the realtimePower-derived value when valid (> 0), and falls back to soc% * real_total_battery_capacity otherwise. Publishing moves from RvsChargeStatusPublisher to update_data_conflicting_in_vehicle_and_bms in VehicleState, where both the charge result and the resolved SoC% are in scope.
8ef508f to
8b812d3
Compare
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.
Summary
RvsChargeStatus.realtimePoweris alwaysNoneor0,DRIVETRAIN_SOC_KWHwas silently never publishedextract_soc_kwh(charge_status, soc)to the extractors module, following the same pattern asextract_soc/extract_electric_rangerealtimePower-derived value when valid (> 0); falls back tosoc% × real_total_battery_capacityotherwiseRvsChargeStatusPublishertoupdate_data_conflicting_in_vehicle_and_bms, where both the charge result and the resolved SoC% are already in scopeDesign notes
soc_kwhis now carried throughRvsChargeStatusProcessingResult→ChrgMgmtDataRespProcessingResultas a computed field (no mutable state, no wiring through call sites)__validate_and_convert_soc_kwhenforces the> 0rule for both the primary reading andreal_total_battery_capacity, consistent with the existing validator patternextract_socis set duringupdate_data_conflicting_in_vehicle_and_bms, which runs after charge status is published)Test plan
tests/status_publisher/test_rvs_charge_status.py— unit tests forRvsChargeStatusPublisher:soc_kwhpresent whenrealtimePoweris set,Nonewhen zero or missingtests/test_extractors.py— unit tests forextract_soc_kwh: primary path, fallback path, all None/zero edge casestests/test_vehicle_handler.py— integration test for full polling cycle publishingDRIVETRAIN_SOC_KWH, and fallback test withrealtimePower=Nonepoetry run pytest tests/— 166 passed🤖 Generated with Claude Code