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

This commit is contained in:
andig 2026-05-07 21:01:02 +02:00 • committed by GitHub
parent cf5038cc89
commit 20be86fec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -82,12 +82,15 @@ const (
timeOffset = " +0100"
plugTypeAC = 1
unitMiles = 3
kmPerMile = 1.60934
)
type DrivingDistance struct {
RangeByFuel struct {
EvModeRange struct {
Value float64
Unit int
}
}
}
@ -144,7 +147,12 @@ func (d VehicleStatus) FinishTime() (time.Time, error) {
func (d VehicleStatus) Range() (int64, error) {
if d.EvStatus != nil {
if dist := d.EvStatus.DrvDistance; len(dist) == 1 {
return int64(dist[0].RangeByFuel.EvModeRange.Value), nil
evRange := dist[0].RangeByFuel.EvModeRange
value := evRange.Value
if evRange.Unit == unitMiles {
value *= kmPerMile
}
return int64(value), nil
}
}
return 0, api.ErrNotAvailable
@ -194,8 +202,12 @@ func (d StatusLatestResponse) GetLimitSoc() (int64, error) {
}
func (d StatusLatestResponse) Odometer() (float64, error) {
if d.ResMsg.VehicleStatusInfo.Odometer != nil {
return d.ResMsg.VehicleStatusInfo.Odometer.Value, nil
if odo := d.ResMsg.VehicleStatusInfo.Odometer; odo != nil {
value := odo.Value
if odo.Unit == unitMiles {
value *= kmPerMile
}
return value, nil
}
return 0, api.ErrNotAvailable
}