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