68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package charger
|
|
|
|
// Code generated by github.com/evcc-io/evcc/cmd/tools/decorate.go. DO NOT EDIT.
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/evcc-io/evcc/api"
|
|
)
|
|
|
|
func decorateSEMP(base *SEMP, phaseSwitcher func(int) error, phaseGetter func() (int, error), chargeRater func() (float64, error)) api.Charger {
|
|
caps := make(map[reflect.Type]any)
|
|
|
|
if phaseSwitcher != nil {
|
|
caps[reflect.TypeFor[api.PhaseSwitcher]()] = &decorateSEMPPhaseSwitcherImpl{phaseSwitcher: phaseSwitcher}
|
|
}
|
|
|
|
if phaseGetter != nil {
|
|
caps[reflect.TypeFor[api.PhaseGetter]()] = &decorateSEMPPhaseGetterImpl{phaseGetter: phaseGetter}
|
|
}
|
|
|
|
if chargeRater != nil {
|
|
caps[reflect.TypeFor[api.ChargeRater]()] = &decorateSEMPChargeRaterImpl{chargeRater: chargeRater}
|
|
}
|
|
|
|
if len(caps) == 0 {
|
|
return base
|
|
}
|
|
|
|
return &decorateSEMPCapable{SEMP: base, caps: caps}
|
|
}
|
|
|
|
type decorateSEMPCapable struct {
|
|
*SEMP
|
|
caps map[reflect.Type]any
|
|
}
|
|
|
|
func (d *decorateSEMPCapable) Capability(typ reflect.Type) (any, bool) {
|
|
c, ok := d.caps[typ]
|
|
if !ok && reflect.TypeOf(d).Implements(typ) {
|
|
return d, true
|
|
}
|
|
return c, ok
|
|
}
|
|
|
|
type decorateSEMPChargeRaterImpl struct {
|
|
chargeRater func() (float64, error)
|
|
}
|
|
|
|
func (impl *decorateSEMPChargeRaterImpl) ChargedEnergy() (float64, error) {
|
|
return impl.chargeRater()
|
|
}
|
|
|
|
type decorateSEMPPhaseGetterImpl struct {
|
|
phaseGetter func() (int, error)
|
|
}
|
|
|
|
func (impl *decorateSEMPPhaseGetterImpl) GetPhases() (int, error) {
|
|
return impl.phaseGetter()
|
|
}
|
|
|
|
type decorateSEMPPhaseSwitcherImpl struct {
|
|
phaseSwitcher func(int) error
|
|
}
|
|
|
|
func (impl *decorateSEMPPhaseSwitcherImpl) Phases1p3p(p0 int) error {
|
|
return impl.phaseSwitcher(p0)
|
|
}
|