Bluelink: convert evModeRange and odometer from miles to km when unit=3 (#29731)
This commit is contained in:
parent
cf5038cc89
commit
20be86fec8
1 changed files with 15 additions and 3 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue