Toyota: support range units (#27371)
This commit is contained in:
parent
79da63671b
commit
88ecd6f152
2 changed files with 19 additions and 1 deletions
|
|
@ -27,5 +27,8 @@ func (v *Provider) Soc() (float64, error) {
|
|||
// Range implements the api.VehicleRange interface
|
||||
func (v *Provider) Range() (int64, error) {
|
||||
res, err := v.status()
|
||||
return int64(res.Payload.EvRangeWithAc.Value), err
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.Payload.EvRangeWithAc.ValueInKilometers()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,26 @@ type Status struct {
|
|||
} `json:"payload"`
|
||||
}
|
||||
|
||||
const kmPerMile = 1.609344
|
||||
|
||||
type EvRange struct {
|
||||
Unit string `json:"unit"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
func (e EvRange) ValueInKilometers() (int64, error) {
|
||||
u := strings.ToLower(strings.TrimSpace(e.Unit))
|
||||
|
||||
switch u {
|
||||
case "km":
|
||||
return int64(e.Value), nil
|
||||
case "mi":
|
||||
return int64(e.Value * kmPerMile), nil
|
||||
default:
|
||||
return 0, fmt.Errorf("unsupported unit type: %s", e.Unit)
|
||||
}
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
AuthID string `json:"authId"`
|
||||
Callbacks []AuthCallback `json:"callbacks"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue