Fiat: handle evInfo empty for some vehicles (#1960)

This commit is contained in:
andig 2021-11-30 21:07:45 +01:00 • committed by GitHub
parent f89d320b3c
commit 3477ad31fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -85,6 +85,10 @@ func (v *Provider) status(statusG func() (StatusResponse, error)) (StatusRespons
func (v *Provider) SoC() (float64, error) {
res, err := v.statusG()
if res, ok := res.(StatusResponse); err == nil && ok {
if res.EvInfo == nil {
return 0, api.ErrNotAvailable
}
return res.EvInfo.Battery.StateOfCharge, nil
}
@ -97,6 +101,10 @@ var _ api.VehicleRange = (*Provider)(nil)
func (v *Provider) Range() (int64, error) {
res, err := v.statusG()
if res, ok := res.(StatusResponse); err == nil && ok {
if res.EvInfo == nil {
return 0, api.ErrNotAvailable
}
return int64(res.EvInfo.Battery.DistanceToEmpty.Value), nil
}
@ -123,6 +131,10 @@ func (v *Provider) Status() (api.ChargeStatus, error) {
res, err := v.statusG()
if res, ok := res.(StatusResponse); err == nil && ok {
if res.EvInfo == nil {
return api.StatusNone, api.ErrNotAvailable
}
if res.EvInfo.Battery.PlugInStatus {
status = api.StatusB // connected, not charging
}

View file

@ -23,7 +23,7 @@ type StatusResponse struct {
}
Timestamp TimeMillis
}
EvInfo struct {
EvInfo *struct {
Battery struct {
ChargingLevel string // LEVEL_2
ChargingStatus string // CHARGING
@ -38,7 +38,7 @@ type StatusResponse struct {
TotalRange int // 17
}
Timestamp TimeMillis
}
} `json:",omitempty"`
Timestamp TimeMillis
}