Toyota: support range units (#27371)

This commit is contained in:
Nicky Bulthuis 2026-02-12 15:40:38 +01:00 • committed by GitHub
parent 79da63671b
commit 88ecd6f152
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -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()
}

View file

@ -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"`