Skip to content

Commit

Permalink
Remove deprecated use of type instead of source for specifying plugin (
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Mar 17, 2022
1 parent 38defb6 commit 7649eff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 55 deletions.
7 changes: 0 additions & 7 deletions charger/charger.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Charger, error
return nil, err
}

// TODO deprecate
log := util.NewLogger("charger")
cc.Status.Deprecate(log)
cc.Enable.Deprecate(log)
cc.Enabled.Deprecate(log)
cc.MaxCurrent.Deprecate(log)

status, err := provider.NewStringGetterFromConfig(cc.Status)
if err != nil {
return nil, fmt.Errorf("status: %w", err)
Expand Down
9 changes: 0 additions & 9 deletions meter/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Meter, error)
return nil, fmt.Errorf("power: %w", err)
}

// TODO deprecate
log := util.NewLogger("meter")
cc.Power.Deprecate(log)
cc.Energy.Deprecate(log)
cc.SoC.Deprecate(log)
for _, p := range cc.Currents {
p.Deprecate(log)
}

m, _ := NewConfigurable(power)

// decorate Meter with MeterEnergy
Expand Down
44 changes: 12 additions & 32 deletions provider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package provider

import (
"fmt"
"strings"

"github.com/evcc-io/evcc/util"
)

// provider types
Expand Down Expand Up @@ -54,29 +51,12 @@ var registry providerRegistry = make(map[string]func(map[string]interface{}) (In
// Config is the general provider config
type Config struct {
Source string
Type string // TODO remove deprecated
Other map[string]interface{} `mapstructure:",remain"`
}

// TODO prepare for removing deprecated type attribute
func (c *Config) Deprecate(log *util.Logger) {
if c != nil && c.Type != "" {
log.WARN.Printf("type:%s is deprecated, use source:%s instead", c.Type, c.Type)
}
}

// PluginType returns the plugin type in a legacy-aware way
func (c Config) PluginType() string {
typ := c.Source
if typ == "" {
typ = c.Type
}
return strings.ToLower(typ)
}

// NewIntGetterFromConfig creates a IntGetter from config
func NewIntGetterFromConfig(config Config) (res func() (int64, error), err error) {
factory, err := registry.Get(config.PluginType())
factory, err := registry.Get(config.Source)
if err == nil {
var provider IntProvider
provider, err = factory(config.Other)
Expand All @@ -87,15 +67,15 @@ func NewIntGetterFromConfig(config Config) (res func() (int64, error), err error
}

if err == nil && res == nil {
err = fmt.Errorf("invalid plugin type: %s", config.PluginType())
err = fmt.Errorf("invalid plugin type: %s", config.Source)
}

return
}

// NewFloatGetterFromConfig creates a FloatGetter from config
func NewFloatGetterFromConfig(config Config) (res func() (float64, error), err error) {
factory, err := registry.Get(config.PluginType())
factory, err := registry.Get(config.Source)
if err == nil {
var provider IntProvider
provider, err = factory(config.Other)
Expand All @@ -106,15 +86,15 @@ func NewFloatGetterFromConfig(config Config) (res func() (float64, error), err e
}

if err == nil && res == nil {
err = fmt.Errorf("invalid plugin type: %s", config.PluginType())
err = fmt.Errorf("invalid plugin type: %s", config.Source)
}

return
}

// NewStringGetterFromConfig creates a StringGetter from config
func NewStringGetterFromConfig(config Config) (res func() (string, error), err error) {
switch typ := config.PluginType(); typ {
switch typ := config.Source; typ {
case "combined", "openwb":
res, err = NewOpenWBStatusProviderFromConfig(config.Other)

Expand All @@ -131,7 +111,7 @@ func NewStringGetterFromConfig(config Config) (res func() (string, error), err e
}

if err == nil && res == nil {
err = fmt.Errorf("invalid plugin type: %s", config.PluginType())
err = fmt.Errorf("invalid plugin type: %s", config.Source)
}
}

Expand All @@ -140,7 +120,7 @@ func NewStringGetterFromConfig(config Config) (res func() (string, error), err e

// NewBoolGetterFromConfig creates a BoolGetter from config
func NewBoolGetterFromConfig(config Config) (res func() (bool, error), err error) {
factory, err := registry.Get(config.PluginType())
factory, err := registry.Get(config.Source)
if err == nil {
var provider IntProvider
provider, err = factory(config.Other)
Expand All @@ -151,15 +131,15 @@ func NewBoolGetterFromConfig(config Config) (res func() (bool, error), err error
}

if err == nil && res == nil {
err = fmt.Errorf("invalid plugin type: %s", config.PluginType())
err = fmt.Errorf("invalid plugin type: %s", config.Source)
}

return
}

// NewIntSetterFromConfig creates a IntSetter from config
func NewIntSetterFromConfig(param string, config Config) (res func(int64) error, err error) {
factory, err := registry.Get(config.PluginType())
factory, err := registry.Get(config.Source)
if err == nil {
var provider IntProvider
provider, err = factory(config.Other)
Expand All @@ -170,15 +150,15 @@ func NewIntSetterFromConfig(param string, config Config) (res func(int64) error,
}

if err == nil && res == nil {
err = fmt.Errorf("invalid plugin type: %s", config.PluginType())
err = fmt.Errorf("invalid plugin type: %s", config.Source)
}

return
}

// NewBoolSetterFromConfig creates a BoolSetter from config
func NewBoolSetterFromConfig(param string, config Config) (res func(bool) error, err error) {
factory, err := registry.Get(config.PluginType())
factory, err := registry.Get(config.Source)
if err == nil {
var provider IntProvider
provider, err = factory(config.Other)
Expand All @@ -189,7 +169,7 @@ func NewBoolSetterFromConfig(param string, config Config) (res func(bool) error,
}

if err == nil && res == nil {
err = fmt.Errorf("invalid plugin type: %s", config.PluginType())
err = fmt.Errorf("invalid plugin type: %s", config.Source)
}

return
Expand Down
7 changes: 0 additions & 7 deletions vehicle/vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Vehicle, error
return nil, err
}

// TODO deprecate
log := util.NewLogger("vehicle")
cc.Soc.Deprecate(log)
cc.Status.Deprecate(log)
cc.Range.Deprecate(log)
cc.Odometer.Deprecate(log)

socG, err := provider.NewFloatGetterFromConfig(cc.Soc)
if err != nil {
return nil, fmt.Errorf("soc: %w", err)
Expand Down

0 comments on commit 7649eff

Please sign in to comment.