Bluelink: convert evModeRange and odometer from miles to km when unit=3#29731
Merged
Bluelink: convert evModeRange and odometer from miles to km when unit=3#29731
Conversation
The Hyundai/Kia EU Bluelink API returns range and odometer values with a unit code (1 = km, 3 = miles), but the EU package ignored the field entirely and treated all values as kilometers. UK Bluelink users (where the car defaults to miles) saw their reported range presented at ~62% of its real value; odometer is affected the same way for users whose cars report it in miles. Read the Unit field for both evModeRange and the odometer struct, convert miles → km using the same constant the bluelink_us package already applies, and add regression tests using the exact payload reported in #29728. Fixes #29728 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
kmPerMileconstant and miles→km conversion logic now duplicated fromvehicle/bluelink_uscould be refactored into a shared helper or common package to avoid divergence between regions in future changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `kmPerMile` constant and miles→km conversion logic now duplicated from `vehicle/bluelink_us` could be refactored into a shared helper or common package to avoid divergence between regions in future changes.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
andig
commented
May 7, 2026
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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 #29728
Summary
The Hyundai/Kia EU Bluelink API returns range and odometer values with a unit code (
1= km,3= miles), but the EU package ignored the field entirely and treated all values as kilometers. UK Bluelink users (where the car defaults to miles) saw their reported EV range presented at ~62% of its real value. The odometer parser had the same latent bug — the reporter happened to receiveunit: 1for odometer in #29728, but a user whose car reports odometer in miles would have hit the same problem.Change
EvModeRangeandOdometernow carry theUnitfield through JSON.VehicleStatus.Range()andStatusLatestResponse.Odometer()convert miles → km whenUnit == 3, matching the existing pattern invehicle/bluelink_us(samekmPerMile = 1.60934constant, same rounding for the int range).vehicle/bluelink/types_test.gowith regression tests that use the exact payload reported in When Bluelink API returns range as miles, evcc treats them as km #29728 plus a miles-odometer case.Test plan
go test ./vehicle/bluelink/...— all subtests pass (range km, range miles, odometer km, odometer miles, missing fields)go test ./vehicle/...— full vehicle test suite greengo vet ./vehicle/bluelink/...,gofmt -l vehicle/bluelink/,golangci-lint run ./vehicle/bluelink/...— all clean🤖 Generated with Claude Code