Ocpp: fix range values not gathered from the API (#3667)
This commit is contained in:
parent
0f5a72bb02
commit
2bb9e5a631
2 changed files with 31 additions and 1 deletions
|
|
@ -48,6 +48,9 @@ func (v *API) SoC(vin string) (EVResponse, error) {
|
|||
|
||||
uri := fmt.Sprintf("%s/vehicles/%s/resources/soc", v.BaseURI(), vin)
|
||||
err := v.GetJSON(uri, &res)
|
||||
if err != nil {
|
||||
res, err = v.allinOne(vin)
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
|
@ -58,6 +61,33 @@ func (v *API) Range(vin string) (EVResponse, error) {
|
|||
|
||||
uri := fmt.Sprintf("%s/vehicles/%s/resources/rangeelectric", v.BaseURI(), vin)
|
||||
err := v.GetJSON(uri, &res)
|
||||
if err != nil {
|
||||
res, err = v.allinOne(vin)
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
// allinOne is a 'fallback' to gather both metrics range and soc.
|
||||
// It is used in case for any reason the single endpoints return an error - which happend in the past.
|
||||
func (v *API) allinOne(vin string) (EVResponse, error) {
|
||||
var res []EVResponse
|
||||
|
||||
uri := fmt.Sprintf("%s/vehicles/%s/containers/electricvehicle", v.BaseURI(), vin)
|
||||
err := v.GetJSON(uri, &res)
|
||||
|
||||
evres := EVResponse{}
|
||||
|
||||
for _, r := range res {
|
||||
if r.SoC.Timestamp != 0 {
|
||||
evres.SoC = r.SoC
|
||||
continue
|
||||
}
|
||||
|
||||
if r.RangeElectric.Timestamp != 0 {
|
||||
evres.RangeElectric = r.RangeElectric
|
||||
}
|
||||
}
|
||||
|
||||
return evres, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func (v *Provider) SoC() (float64, error) {
|
|||
|
||||
// Range implements the api.VehicleRange interface
|
||||
func (v *Provider) Range() (rng int64, err error) {
|
||||
res, err := v.chargerG()
|
||||
res, err := v.rangeG()
|
||||
if err == nil {
|
||||
return int64(res.RangeElectric.Value), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue