Skip to content

feat: add SOC kWh fallback for vehicles without realtimePower#448

Merged
nanomad merged 2 commits into
SAIC-iSmart-API:developfrom
nanomad:feat/mgs5-soc-kwh-fallback
May 11, 2026
Merged

feat: add SOC kWh fallback for vehicles without realtimePower#448
nanomad merged 2 commits into
SAIC-iSmart-API:developfrom
nanomad:feat/mgs5-soc-kwh-fallback

Conversation

@nanomad
Copy link
Copy Markdown
Contributor

@nanomad nanomad commented May 11, 2026

Summary

  • For vehicles (e.g. MGS5) where RvsChargeStatus.realtimePower is always None or 0, DRIVETRAIN_SOC_KWH was silently never published
  • Adds extract_soc_kwh(charge_status, soc) to the extractors module, following the same pattern as extract_soc / extract_electric_range
  • Prefers the realtimePower-derived value when valid (> 0); falls back to soc% × real_total_battery_capacity otherwise
  • Publishing moves from RvsChargeStatusPublisher to update_data_conflicting_in_vehicle_and_bms, where both the charge result and the resolved SoC% are already in scope

Design notes

  • soc_kwh is now carried through RvsChargeStatusProcessingResultChrgMgmtDataRespProcessingResult as a computed field (no mutable state, no wiring through call sites)
  • __validate_and_convert_soc_kwh enforces the > 0 rule for both the primary reading and real_total_battery_capacity, consistent with the existing validator pattern
  • The fallback activates from the second poll onward on first startup (SoC% from extract_soc is set during update_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 for RvsChargeStatusPublisher: soc_kwh present when realtimePower is set, None when zero or missing
  • tests/test_extractors.py — unit tests for extract_soc_kwh: primary path, fallback path, all None/zero edge cases
  • tests/test_vehicle_handler.py — integration test for full polling cycle publishing DRIVETRAIN_SOC_KWH, and fallback test with realtimePower=None
  • Full suite: poetry run pytest tests/ — 166 passed

🤖 Generated with Claude Code

@nanomad nanomad force-pushed the feat/mgs5-soc-kwh-fallback branch from 5b2b42d to 8ef508f Compare May 11, 2026 19:31
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.
@nanomad nanomad force-pushed the feat/mgs5-soc-kwh-fallback branch from 8ef508f to 8b812d3 Compare May 11, 2026 19:32
@nanomad nanomad merged commit 98c677a into SAIC-iSmart-API:develop May 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant