Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwitchSocket: decorate energy #17602

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion charger/switchsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ type SwitchSocket struct {
*switchSocket
}

//go:generate go run ../cmd/tools/decorate.go -f decorateSwitchSocket -b *SwitchSocket -r api.Charger -t "api.MeterEnergy,TotalEnergy,func() (float64, error)"

func NewSwitchSocketFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
var cc struct {
embed `mapstructure:",squash"`
Enabled provider.Config
Enable provider.Config
Power provider.Config
Energy *provider.Config
StandbyPower float64
}

Expand All @@ -47,13 +50,21 @@ func NewSwitchSocketFromConfig(ctx context.Context, other map[string]interface{}
return nil, err
}

var energy func() (float64, error)
if cc.Energy != nil {
energy, err = provider.NewFloatGetterFromConfig(ctx, *cc.Energy)
if err != nil {
return nil, err
}
}

c := &SwitchSocket{
enabled: enabled,
enable: enable,
switchSocket: NewSwitchSocket(&cc.embed, enabled, power, cc.StandbyPower),
}

return c, nil
return decorateSwitchSocket(c, energy), nil
}

func (c *SwitchSocket) Enabled() (bool, error) {
Expand Down
35 changes: 35 additions & 0 deletions charger/switchsocket_decorators.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading