Skip to content

Bluelink: convert evModeRange and odometer from miles to km when unit=3#29731

Merged
andig merged 3 commits intomasterfrom
fix/bluelink-eu-range-unit-29728
May 7, 2026
Merged

Bluelink: convert evModeRange and odometer from miles to km when unit=3#29731
andig merged 3 commits intomasterfrom
fix/bluelink-eu-range-unit-29728

Conversation

@andig
Copy link
Copy Markdown
Member

@andig andig commented May 7, 2026

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 receive unit: 1 for odometer in #29728, but a user whose car reports odometer in miles would have hit the same problem.

Change

  • EvModeRange and Odometer now carry the Unit field through JSON.
  • VehicleStatus.Range() and StatusLatestResponse.Odometer() convert miles → km when Unit == 3, matching the existing pattern in vehicle/bluelink_us (same kmPerMile = 1.60934 constant, same rounding for the int range).
  • Added vehicle/bluelink/types_test.go with 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 green
  • go vet ./vehicle/bluelink/..., gofmt -l vehicle/bluelink/, golangci-lint run ./vehicle/bluelink/... — all clean

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread vehicle/bluelink/types.go Outdated
@andig andig added the vehicles Specific vehicle support label May 7, 2026
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@andig andig enabled auto-merge (squash) May 7, 2026 19:00
@andig andig merged commit 20be86f into master May 7, 2026
7 checks passed
@andig andig deleted the fix/bluelink-eu-range-unit-29728 branch May 7, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vehicles Specific vehicle support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When Bluelink API returns range as miles, evcc treats them as km

1 participant