Skip to content

KiaEurope: traverse JSON array indices so legacy (non-CCS2) EV range/SOC parse correctly#41

Open
MrL0 wants to merge 1 commit into
schmidtwmark:mainfrom
MrL0:fix/kia-eu-json-array-traversal
Open

KiaEurope: traverse JSON array indices so legacy (non-CCS2) EV range/SOC parse correctly#41
MrL0 wants to merge 1 commit into
schmidtwmark:mainfrom
MrL0:fix/kia-eu-json-array-traversal

Conversation

@MrL0

@MrL0 MrL0 commented Jun 28, 2026

Copy link
Copy Markdown

What this does

Kia EU's legacy (non-CCS2) parse paths index into JSON arrays, e.g.:

vehicleStatus.evStatus.drvDistance.0.rangeByFuel.evModeRange.value

But getAnyFromJson only descended [String: Any] — when traversal reached drvDistance (an array) it returned the whole array and never applied the .0.rangeByFuel… segments. Net result for legacy (non-CCS2) Kia EU EVs: estimatedRange/driveUnit resolve to 0. Separately, the legacy targetSocList (an array leaf) was read via getChildFromJson, which only returns dictionaries, so the as? [[String: Any]] cast always failed and AC/DC charge targets were always empty.

The Hyundai EU sibling already handles both correctly. This aligns Kia EU with it:

  • getAnyFromJson gains the array-index branch (array[index] for numeric path segments), matching HyundaiEuropeAPIClient.getAnyFromJson.
  • targetSocList is read via getAnyFromJson (array leaf), matching the Hyundai EU read.

The file already notes this helper duplication is intentional-but-drift-prone — happy to follow up by lifting these into a shared utility if you'd prefer.

Testing

swift test290 tests pass; the existing CCS2 status test is unaffected (CCS2 uses direct dict keys, not array indices). The traversal change is a verbatim port of the proven Hyundai EU implementation. Note: the suite has no legacy/non-CCS2 Kia EU status fixture to assert the fixed path end-to-end — if you have a sample payload I'm glad to add one.


Drafted with AI assistance; verified locally with swift test.

Kia EU's JSON traversal only descended dictionaries, so legacy (non-CCS2) paths indexing into arrays (evStatus.drvDistance.0.rangeByFuel.evModeRange.value) stopped at the array and read back 0, and the array-leaf targetSocList read via dict-only getChildFromJson always cast to empty. Align with the Hyundai EU sibling's array-index branch and read targetSocList via getAnyFromJson, so legacy EV range/unit and AC/DC charge targets populate.
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