diff --git a/vehicle/vehicle.go b/vehicle/vehicle.go index c8d559bbe..ead5b9616 100644 --- a/vehicle/vehicle.go +++ b/vehicle/vehicle.go @@ -2,7 +2,6 @@ package vehicle import ( "fmt" - "time" "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/provider" @@ -14,7 +13,7 @@ import ( // Vehicle is an api.Vehicle implementation with configurable getters and setters. type Vehicle struct { *embed - chargeG func() (float64, error) + socG func() (float64, error) statusG func() (string, error) } @@ -26,31 +25,29 @@ func init() { func NewConfigurableFromConfig(other map[string]interface{}) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` - Charge provider.Config + Soc provider.Config Status *provider.Config Range *provider.Config Odometer *provider.Config - Cache time.Duration - }{ - Cache: interval, - } + Cache interface{} + }{} if err := util.DecodeOther(other, &cc); err != nil { return nil, err } - getter, err := provider.NewFloatGetterFromConfig(cc.Charge) - if err != nil { - return nil, fmt.Errorf("charge: %w", err) + if cc.Cache != nil { + util.NewLogger("vehicle").WARN.Println("cache is deprecated and will be removed in a future release") } - if cc.Cache > 0 { - getter = provider.NewCached(getter, cc.Cache).FloatGetter() + socG, err := provider.NewFloatGetterFromConfig(cc.Soc) + if err != nil { + return nil, fmt.Errorf("soc: %w", err) } v := &Vehicle{ - embed: &cc.embed, - chargeG: getter, + embed: &cc.embed, + socG: socG, } // decorate vehicle with Status @@ -90,10 +87,10 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Vehicle, error // SoC implements the api.Vehicle interface func (v *Vehicle) SoC() (float64, error) { - return v.chargeG() + return v.socG() } -// SoC implements the api.ChargeState interface +// status implements the api.ChargeState interface func (v *Vehicle) status() (api.ChargeStatus, error) { status := api.StatusF