Smart: add charge status (#3179)
This commit is contained in:
parent
fe7b4ff021
commit
904eca0dc7
2 changed files with 52 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package smart
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
|
|
@ -33,8 +34,11 @@ func NewProvider(log *util.Logger, api *API, vin string, expiry, cache time.Dura
|
|||
func (v *Provider) status(statusG func() (StatusResponse, error), refreshG func() (StatusResponse, error)) (StatusResponse, error) {
|
||||
res, err := statusG()
|
||||
|
||||
// if err == nil && res.Status.StatusData.Soc.Ts.Time.Add(v.expiry).Before(time.Now()) {
|
||||
// if ts := res.Status.Data.Soc.Ts.Time; err == nil && ts.Add(v.expiry).Before(time.Now()) {
|
||||
// fmt.Println("--------------------------", ts)
|
||||
// res, err = refreshG()
|
||||
// ts := res.Status.Data.Soc.Ts.Time
|
||||
// fmt.Println("--------------------------", ts)
|
||||
// }
|
||||
|
||||
return res, err
|
||||
|
|
@ -43,7 +47,28 @@ func (v *Provider) status(statusG func() (StatusResponse, error), refreshG func(
|
|||
// SoC implements the api.Vehicle interface
|
||||
func (v *Provider) SoC() (float64, error) {
|
||||
res, err := v.statusG()
|
||||
return res.Status.StatusData.Soc.Value, err
|
||||
return res.Status.Data.Soc.Value, err
|
||||
}
|
||||
|
||||
var _ api.ChargeState = (*Provider)(nil)
|
||||
|
||||
// Range implements the api.VehicleRange interface
|
||||
func (v *Provider) Status() (api.ChargeStatus, error) {
|
||||
res, err := v.statusG()
|
||||
|
||||
switch v := res.PreCond.Data.ChargingStatus.Value; v {
|
||||
case 0:
|
||||
return api.StatusC, err
|
||||
case 1, 2:
|
||||
return api.StatusB, err
|
||||
case 3:
|
||||
return api.StatusA, err
|
||||
default:
|
||||
if err == nil {
|
||||
err = fmt.Errorf("unknown status: %d", v)
|
||||
}
|
||||
return api.StatusNone, err
|
||||
}
|
||||
}
|
||||
|
||||
var _ api.VehicleRange = (*Provider)(nil)
|
||||
|
|
@ -51,7 +76,7 @@ var _ api.VehicleRange = (*Provider)(nil)
|
|||
// Range implements the api.VehicleRange interface
|
||||
func (v *Provider) Range() (int64, error) {
|
||||
res, err := v.statusG()
|
||||
return int64(res.Status.StatusData.RangeElectric.Value), err
|
||||
return int64(res.Status.Data.RangeElectric.Value), err
|
||||
}
|
||||
|
||||
var _ api.VehicleOdometer = (*Provider)(nil)
|
||||
|
|
@ -59,5 +84,5 @@ var _ api.VehicleOdometer = (*Provider)(nil)
|
|||
// Odometer implements the Provider.VehicleOdometer interface
|
||||
func (v *Provider) Odometer() (float64, error) {
|
||||
res, err := v.statusG()
|
||||
return res.Status.StatusData.Odo.Value, err
|
||||
return res.Status.Data.Odo.Value, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,18 @@ import (
|
|||
)
|
||||
|
||||
type StatusResponse struct {
|
||||
PreCond struct{}
|
||||
PreCond struct {
|
||||
Data struct {
|
||||
ChargingActive BoolValue
|
||||
ChargingStatus IntValue
|
||||
} `json:"data"`
|
||||
}
|
||||
ChargeOpt struct{}
|
||||
Status struct {
|
||||
StatusData struct {
|
||||
Odo Value
|
||||
RangeElectric Value
|
||||
Soc Value
|
||||
Data struct {
|
||||
Odo FloatValue
|
||||
RangeElectric FloatValue
|
||||
Soc FloatValue
|
||||
} `json:"data"`
|
||||
}
|
||||
Images []string
|
||||
|
|
@ -20,7 +25,19 @@ type StatusResponse struct {
|
|||
ErrorDescription string `json:"error_description"`
|
||||
}
|
||||
|
||||
type Value struct {
|
||||
type BoolValue struct {
|
||||
Status int
|
||||
Value bool
|
||||
Ts TimeSecs
|
||||
}
|
||||
|
||||
type IntValue struct {
|
||||
Status int
|
||||
Value int
|
||||
Ts TimeSecs
|
||||
}
|
||||
|
||||
type FloatValue struct {
|
||||
Status int
|
||||
Value float64
|
||||
Ts TimeSecs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue