Fiat: handle evInfo empty for some vehicles (#1960)
This commit is contained in:
parent
f89d320b3c
commit
3477ad31fd
2 changed files with 14 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue