Skip to content

Commit

Permalink
Merge branch 'evcc-io:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
thierolm authored Mar 20, 2024
2 parents 6602b61 + bdee2e5 commit c0da481
Show file tree
Hide file tree
Showing 2 changed files with 733 additions and 42 deletions.
29 changes: 20 additions & 9 deletions vehicle/vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/evcc-io/evcc/util"
)

//go:generate go run ../cmd/tools/decorate.go -f decorateVehicle -b api.Vehicle -t "api.ChargeState,Status,func() (api.ChargeStatus, error)" -t "api.VehicleRange,Range,func() (int64, error)" -t "api.VehicleOdometer,Odometer,func() (float64, error)" -t "api.VehicleClimater,Climater,func() (bool, error)" -t "api.Resurrector,WakeUp,func() error"
//go:generate go run ../cmd/tools/decorate.go -f decorateVehicle -b api.Vehicle -t "api.ChargeState,Status,func() (api.ChargeStatus, error)" -t "api.VehicleRange,Range,func() (int64, error)" -t "api.VehicleOdometer,Odometer,func() (float64, error)" -t "api.VehicleClimater,Climater,func() (bool, error)" -t "api.CurrentController,MaxCurrent,func(int64) error" -t "api.Resurrector,WakeUp,func() error"

// Vehicle is an api.Vehicle implementation with configurable getters and setters.
type Vehicle struct {
Expand All @@ -23,13 +23,14 @@ func init() {
// NewConfigurableFromConfig creates a new Vehicle
func NewConfigurableFromConfig(other map[string]interface{}) (api.Vehicle, error) {
var cc struct {
embed `mapstructure:",squash"`
Soc provider.Config
Status *provider.Config
Range *provider.Config
Odometer *provider.Config
Climater *provider.Config
Wakeup *provider.Config
embed `mapstructure:",squash"`
Soc provider.Config
Status *provider.Config
Range *provider.Config
Odometer *provider.Config
Climater *provider.Config
MaxCurrent *provider.Config
Wakeup *provider.Config
}

if err := util.DecodeOther(other, &cc); err != nil {
Expand Down Expand Up @@ -92,6 +93,16 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Vehicle, error
climater = climateG
}

// decorate maxCurrent
var maxCurrent func(int64) error
if cc.MaxCurrent != nil {
maxCurrentS, err := provider.NewIntSetterFromConfig("maxCurrent", *cc.MaxCurrent)
if err != nil {
return nil, fmt.Errorf("maxCurrent: %w", err)
}
maxCurrent = maxCurrentS
}

// decorate wakeup
var wakeup func() error
if cc.Wakeup != nil {
Expand All @@ -104,7 +115,7 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Vehicle, error
}
}

return decorateVehicle(v, status, rng, odo, climater, wakeup), nil
return decorateVehicle(v, status, rng, odo, climater, maxCurrent, wakeup), nil
}

// Soc implements the api.Vehicle interface
Expand Down
Loading

0 comments on commit c0da481

Please sign in to comment.