Skip to content

Commit

Permalink
Fiat: handle evInfo empty for some vehicles (#1960)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Nov 30, 2021
1 parent f89d320 commit 3477ad3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions vehicle/fiat/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions vehicle/fiat/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type StatusResponse struct {
}
Timestamp TimeMillis
}
EvInfo struct {
EvInfo *struct {
Battery struct {
ChargingLevel string // LEVEL_2
ChargingStatus string // CHARGING
Expand All @@ -38,7 +38,7 @@ type StatusResponse struct {
TotalRange int // 17
}
Timestamp TimeMillis
}
} `json:",omitempty"`
Timestamp TimeMillis
}

Expand Down

0 comments on commit 3477ad3

Please sign in to comment.