Rename charge plugin to soc and remove caching (#2242)
This commit is contained in:
parent
b38265a1ce
commit
8633eb9c15
1 changed files with 13 additions and 16 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue