Renault: handle missing batteryLevel (#13251)

This commit is contained in:
andig 2024-04-01 16:57:46 +02:00 • committed by GitHub
parent 902be1873d
commit b72156159c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View file

@ -54,7 +54,7 @@ type attributes struct {
InstantaneousPower int `json:"instantaneousPower"`
RangeHvacOff int `json:"rangeHvacOff"`
BatteryAutonomy int `json:"batteryAutonomy"`
BatteryLevel int `json:"batteryLevel"`
BatteryLevel *int `json:"batteryLevel"`
BatteryTemperature int `json:"batteryTemperature"`
PlugStatus int `json:"plugStatus"`
LastUpdateTime string `json:"lastUpdateTime"`

View file

@ -55,12 +55,15 @@ var _ api.Battery = (*Provider)(nil)
// Soc implements the api.Vehicle interface
func (v *Provider) Soc() (float64, error) {
res, err := v.batteryG()
if err == nil {
return float64(res.Data.Attributes.BatteryLevel), nil
if err != nil {
return 0, err
}
return 0, err
if res.Data.Attributes.BatteryLevel == nil {
return 0, api.ErrNotAvailable
}
return float64(*res.Data.Attributes.BatteryLevel), nil
}
var _ api.ChargeState = (*Provider)(nil)