Skip to content

Commit

Permalink
Prepare for removing deprecated type identifier (#2685)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Feb 23, 2022
1 parent fe0478f commit 5ce7be4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions charger/charger.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ 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: 9 additions & 0 deletions meter/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ 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
9 changes: 9 additions & 0 deletions provider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package provider
import (
"fmt"
"strings"

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

// provider types
Expand Down Expand Up @@ -56,6 +58,13 @@ type Config struct {
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
Expand Down
7 changes: 7 additions & 0 deletions vehicle/vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ 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)

if cc.Cache != nil {
util.NewLogger("vehicle").WARN.Println("cache is deprecated and will be removed in a future release")
}
Expand Down

0 comments on commit 5ce7be4

Please sign in to comment.