diff --git a/vehicle/fiat/provider.go b/vehicle/fiat/provider.go index c67f4887e..f32dcfd2c 100644 --- a/vehicle/fiat/provider.go +++ b/vehicle/fiat/provider.go @@ -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 } diff --git a/vehicle/fiat/types.go b/vehicle/fiat/types.go index a88da991b..a1632975c 100644 --- a/vehicle/fiat/types.go +++ b/vehicle/fiat/types.go @@ -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 }