diff --git a/charger/alfen.go b/charger/alfen.go index bab7635b2..9ad954aa1 100644 --- a/charger/alfen.go +++ b/charger/alfen.go @@ -55,7 +55,7 @@ func init() { registry.Add("alfen", NewAlfenFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decorateAlfen -b "*Alfen" -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" +//go:generate go run ../cmd/tools/decorate.go -f decorateAlfen -b *Alfen -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewAlfenFromConfig creates a Alfen charger from generic config func NewAlfenFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/alfen_decorators.go b/charger/alfen_decorators.go index d3d660ec2..e7067abf5 100644 --- a/charger/alfen_decorators.go +++ b/charger/alfen_decorators.go @@ -30,6 +30,6 @@ type decorateAlfenPhaseSwitcherImpl struct { phaseSwitcher func(int) error } -func (impl *decorateAlfenPhaseSwitcherImpl) Phases1p3p(phases int) error { - return impl.phaseSwitcher(phases) +func (impl *decorateAlfenPhaseSwitcherImpl) Phases1p3p(p0 int) error { + return impl.phaseSwitcher(p0) } diff --git a/charger/cfos.go b/charger/cfos.go index 0337d2d47..60961f2bd 100644 --- a/charger/cfos.go +++ b/charger/cfos.go @@ -30,7 +30,7 @@ func init() { registry.Add("cfos", NewCfosPowerBrainFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decorateCfos -b "*CfosPowerBrain" -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" +//go:generate go run ../cmd/tools/decorate.go -f decorateCfos -b *CfosPowerBrain -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewCfosPowerBrainFromConfig creates a cFos charger from generic config func NewCfosPowerBrainFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/cfos_decorators.go b/charger/cfos_decorators.go index 84b9cadcf..d527089ec 100644 --- a/charger/cfos_decorators.go +++ b/charger/cfos_decorators.go @@ -30,6 +30,6 @@ type decorateCfosPhaseSwitcherImpl struct { phaseSwitcher func(int) error } -func (impl *decorateCfosPhaseSwitcherImpl) Phases1p3p(phases int) error { - return impl.phaseSwitcher(phases) +func (impl *decorateCfosPhaseSwitcherImpl) Phases1p3p(p0 int) error { + return impl.phaseSwitcher(p0) } diff --git a/charger/charger.go b/charger/charger.go index 22fd2e7a2..3196ea8d9 100644 --- a/charger/charger.go +++ b/charger/charger.go @@ -22,7 +22,7 @@ func init() { registry.Add(api.Custom, NewConfigurableFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decorateCustom -b *Charger -r api.Charger -t "api.ChargerEx,MaxCurrentMillis,func(float64) error" -t "api.Identifier,Identify,func() (string, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.Resurrector,WakeUp,func() error" -t "api.Battery,Soc,func() (float64, error)" +//go:generate go run ../cmd/tools/decorate.go -f decorateCustom -b *Charger -r api.Charger -t "api.ChargerEx,MaxCurrentMillis,func(float64) error" -t "api.Identifier,Identify,func() (string, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.Resurrector,WakeUp,func() error" -t "api.Battery,Soc,func() (float64, error)" // NewConfigurableFromConfig creates a new configurable charger func NewConfigurableFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/charger_decorators.go b/charger/charger_decorators.go index b8e22caad..faf30c44c 100644 --- a/charger/charger_decorators.go +++ b/charger/charger_decorators.go @@ -564,8 +564,8 @@ type decorateCustomChargerExImpl struct { chargerEx func(float64) error } -func (impl *decorateCustomChargerExImpl) MaxCurrentMillis(current float64) error { - return impl.chargerEx(current) +func (impl *decorateCustomChargerExImpl) MaxCurrentMillis(p0 float64) error { + return impl.chargerEx(p0) } type decorateCustomIdentifierImpl struct { @@ -580,8 +580,8 @@ type decorateCustomPhaseSwitcherImpl struct { phaseSwitcher func(int) error } -func (impl *decorateCustomPhaseSwitcherImpl) Phases1p3p(phases int) error { - return impl.phaseSwitcher(phases) +func (impl *decorateCustomPhaseSwitcherImpl) Phases1p3p(p0 int) error { + return impl.phaseSwitcher(p0) } type decorateCustomResurrectorImpl struct { diff --git a/charger/evsewifi.go b/charger/evsewifi.go index 2ed4a4182..015d162c9 100644 --- a/charger/evsewifi.go +++ b/charger/evsewifi.go @@ -28,7 +28,7 @@ func init() { registry.Add("evsewifi", NewEVSEWifiFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decorateEVSE -b *EVSEWifi -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.ChargerEx,MaxCurrentMillis,func(current float64) error" -t "api.Identifier,Identify,func() (string, error)" +//go:generate go run ../cmd/tools/decorate.go -f decorateEVSE -b *EVSEWifi -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.ChargerEx,MaxCurrentMillis,func(float64) error" -t "api.Identifier,Identify,func() (string, error)" // NewEVSEWifiFromConfig creates a EVSEWifi charger from generic config func NewEVSEWifiFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/evsewifi_decorators.go b/charger/evsewifi_decorators.go index d032e0306..ae4da2a9d 100644 --- a/charger/evsewifi_decorators.go +++ b/charger/evsewifi_decorators.go @@ -6,7 +6,7 @@ import ( "github.com/evcc-io/evcc/api" ) -func decorateEVSE(base *EVSEWifi, meter func() (float64, error), meterEnergy func() (float64, error), phaseCurrents func() (float64, float64, float64, error), phaseVoltages func() (float64, float64, float64, error), chargerEx func(current float64) error, identifier func() (string, error)) api.Charger { +func decorateEVSE(base *EVSEWifi, meter func() (float64, error), meterEnergy func() (float64, error), phaseCurrents func() (float64, float64, float64, error), phaseVoltages func() (float64, float64, float64, error), chargerEx func(float64) error, identifier func() (string, error)) api.Charger { switch { case chargerEx == nil && identifier == nil && meter == nil && meterEnergy == nil && phaseCurrents == nil && phaseVoltages == nil: return base @@ -1225,11 +1225,11 @@ func decorateEVSE(base *EVSEWifi, meter func() (float64, error), meterEnergy fun } type decorateEVSEChargerExImpl struct { - chargerEx func(current float64) error + chargerEx func(float64) error } -func (impl *decorateEVSEChargerExImpl) MaxCurrentMillis(current float64) error { - return impl.chargerEx(current) +func (impl *decorateEVSEChargerExImpl) MaxCurrentMillis(p0 float64) error { + return impl.chargerEx(p0) } type decorateEVSEIdentifierImpl struct { diff --git a/charger/go-e.go b/charger/go-e.go index cb951da75..3b9979b38 100644 --- a/charger/go-e.go +++ b/charger/go-e.go @@ -41,7 +41,7 @@ func init() { registry.Add("go-e", NewGoEFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decorateGoE -b *GoE -r api.Charger -t "api.MeterEnergy,func() (float64, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" +//go:generate go run ../cmd/tools/decorate.go -f decorateGoE -b *GoE -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewGoEFromConfig creates a go-e charger from generic config func NewGoEFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/go-e_decorators.go b/charger/go-e_decorators.go index aa6b1a3fa..43aac409a 100644 --- a/charger/go-e_decorators.go +++ b/charger/go-e_decorators.go @@ -1,24 +1,16 @@ package charger -// Code generated by github.com/andig/cmd/tools/decorate.go. DO NOT EDIT. +// Code generated by github.com/evcc-io/evcc/cmd/tools/decorate.go. DO NOT EDIT. import ( "github.com/evcc-io/evcc/api" ) -func decorateGoE(base *GoE, phaseSwitcher func(phases int) error) api.Charger { +func decorateGoE(base *GoE, phaseSwitcher func(int) error) api.Charger { switch { case phaseSwitcher == nil: return base - case phaseSwitcher == nil: - return &struct { - *GoE - api.MeterEnergy - }{ - GoE: base, - } - case phaseSwitcher != nil: return &struct { *GoE @@ -29,18 +21,6 @@ func decorateGoE(base *GoE, phaseSwitcher func(phases int) error) api.Charger { phaseSwitcher: phaseSwitcher, }, } - - case phaseSwitcher != nil: - return &struct { - *GoE - api.PhaseSwitcher - api.MeterEnergy - }{ - GoE: base, - PhaseSwitcher: &decorateGoEPhaseSwitcherImpl{ - phaseSwitcher: phaseSwitcher, - }, - } } return nil @@ -50,6 +30,6 @@ type decorateGoEPhaseSwitcherImpl struct { phaseSwitcher func(int) error } -func (impl *decorateGoEPhaseSwitcherImpl) Phases1p3p(phases int) error { - return impl.phaseSwitcher(phases) +func (impl *decorateGoEPhaseSwitcherImpl) Phases1p3p(p0 int) error { + return impl.phaseSwitcher(p0) } diff --git a/charger/keba-modbus.go b/charger/keba-modbus.go index 9bedb5226..2d3388d3b 100644 --- a/charger/keba-modbus.go +++ b/charger/keba-modbus.go @@ -64,7 +64,7 @@ func init() { registry.Add("keba-modbus", NewKebaFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decorateKeba -b *Keba -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.Identifier,Identify,func() (string, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" +//go:generate go run ../cmd/tools/decorate.go -f decorateKeba -b *Keba -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.Identifier,Identify,func() (string, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewKebaFromConfig creates a new Keba ModbusTCP charger func NewKebaFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/keba-modbus_decorators.go b/charger/keba-modbus_decorators.go index 6344393bf..fe332850d 100644 --- a/charger/keba-modbus_decorators.go +++ b/charger/keba-modbus_decorators.go @@ -588,6 +588,6 @@ type decorateKebaPhaseSwitcherImpl struct { phaseSwitcher func(int) error } -func (impl *decorateKebaPhaseSwitcherImpl) Phases1p3p(phases int) error { - return impl.phaseSwitcher(phases) +func (impl *decorateKebaPhaseSwitcherImpl) Phases1p3p(p0 int) error { + return impl.phaseSwitcher(p0) } diff --git a/charger/ocpp.go b/charger/ocpp.go index 9b599edc8..9d9854fe3 100644 --- a/charger/ocpp.go +++ b/charger/ocpp.go @@ -99,7 +99,7 @@ func NewOCPPFromConfig(other map[string]interface{}) (api.Charger, error) { return decorateOCPP(c, powerG, totalEnergyG, currentsG, phasesS), nil } -// go:generate go run ../cmd/tools/decorate.go -f decorateOCPP -b *OCPP -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" +//go:generate go run ../cmd/tools/decorate.go -f decorateOCPP -b *OCPP -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewOCPP creates OCPP charger func NewOCPP(id string, connector int, idtag string, diff --git a/charger/ocpp_decorators.go b/charger/ocpp_decorators.go index 848370465..9dfcba05f 100644 --- a/charger/ocpp_decorators.go +++ b/charger/ocpp_decorators.go @@ -6,7 +6,7 @@ import ( "github.com/evcc-io/evcc/api" ) -func decorateOCPP(base *OCPP, meter func() (float64, error), meterEnergy func() (float64, error), phaseCurrents func() (float64, float64, float64, error), phaseSwitcher func(phases int) error) api.Charger { +func decorateOCPP(base *OCPP, meter func() (float64, error), meterEnergy func() (float64, error), phaseCurrents func() (float64, float64, float64, error), phaseSwitcher func(int) error) api.Charger { switch { case meter == nil && meterEnergy == nil && phaseCurrents == nil && phaseSwitcher == nil: return base @@ -276,6 +276,6 @@ type decorateOCPPPhaseSwitcherImpl struct { phaseSwitcher func(int) error } -func (impl *decorateOCPPPhaseSwitcherImpl) Phases1p3p(phases int) error { - return impl.phaseSwitcher(phases) +func (impl *decorateOCPPPhaseSwitcherImpl) Phases1p3p(p0 int) error { + return impl.phaseSwitcher(p0) } diff --git a/charger/openevse.go b/charger/openevse.go index 26c5d32e8..9aacdc0c0 100644 --- a/charger/openevse.go +++ b/charger/openevse.go @@ -29,7 +29,7 @@ func init() { registry.Add("openevse", NewOpenEVSEFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decorateOpenEVSE -b ""*OpenEVSE" -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" +//go:generate go run ../cmd/tools/decorate.go -f decorateOpenEVSE -b *OpenEVSE -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewOpenEVSEFromConfig creates an OpenEVSE charger from generic config func NewOpenEVSEFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/openevse_decorators.go b/charger/openevse_decorators.go index 47adc57ed..8cddd0c32 100644 --- a/charger/openevse_decorators.go +++ b/charger/openevse_decorators.go @@ -6,7 +6,7 @@ import ( "github.com/evcc-io/evcc/api" ) -func decorateOpenEVSE(base *OpenEVSE, phaseSwitcher func(phases int) error) api.Charger { +func decorateOpenEVSE(base *OpenEVSE, phaseSwitcher func(int) error) api.Charger { switch { case phaseSwitcher == nil: return base @@ -30,6 +30,6 @@ type decorateOpenEVSEPhaseSwitcherImpl struct { phaseSwitcher func(int) error } -func (impl *decorateOpenEVSEPhaseSwitcherImpl) Phases1p3p(phases int) error { - return impl.phaseSwitcher(phases) +func (impl *decorateOpenEVSEPhaseSwitcherImpl) Phases1p3p(p0 int) error { + return impl.phaseSwitcher(p0) } diff --git a/charger/openwb.go b/charger/openwb.go index eecc569e6..2da6cd7c6 100644 --- a/charger/openwb.go +++ b/charger/openwb.go @@ -29,7 +29,7 @@ type OpenWB struct { authS func(string) error } -// go:generate go run ../cmd/tools/decorate.go -f decorateOpenWB -b *OpenWB -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.Battery,Soc,func() (float64, error)" +//go:generate go run ../cmd/tools/decorate.go -f decorateOpenWB -b *OpenWB -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.Battery,Soc,func() (float64, error)" // NewOpenWBFromConfig creates a new configurable charger func NewOpenWBFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/openwb_decorators.go b/charger/openwb_decorators.go index d57e9336c..f2def867f 100644 --- a/charger/openwb_decorators.go +++ b/charger/openwb_decorators.go @@ -64,6 +64,6 @@ type decorateOpenWBPhaseSwitcherImpl struct { phaseSwitcher func(int) error } -func (impl *decorateOpenWBPhaseSwitcherImpl) Phases1p3p(phases int) error { - return impl.phaseSwitcher(phases) +func (impl *decorateOpenWBPhaseSwitcherImpl) Phases1p3p(p0 int) error { + return impl.phaseSwitcher(p0) } diff --git a/charger/phoenix-ev-eth.go b/charger/phoenix-ev-eth.go index 160a60537..9609c0b2f 100644 --- a/charger/phoenix-ev-eth.go +++ b/charger/phoenix-ev-eth.go @@ -61,7 +61,7 @@ func init() { registry.Add("phoenix-ev-eth", NewPhoenixEVEthFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decoratePhoenixEVEth -b *PhoenixEVEth -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.ChargerEx,MaxCurrentMillis,func(current float64) error" -t "api.Identifier,Identify,func() (string, error)" +//go:generate go run ../cmd/tools/decorate.go -f decoratePhoenixEVEth -b *PhoenixEVEth -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.ChargerEx,MaxCurrentMillis,func(float64) error" -t "api.Identifier,Identify,func() (string, error)" // NewPhoenixEVEthFromConfig creates a PhoenixEVEth charger from generic config func NewPhoenixEVEthFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/phoenix-ev-eth_decorators.go b/charger/phoenix-ev-eth_decorators.go index fb2636d17..75b52d0af 100644 --- a/charger/phoenix-ev-eth_decorators.go +++ b/charger/phoenix-ev-eth_decorators.go @@ -1225,11 +1225,11 @@ func decoratePhoenixEVEth(base *PhoenixEVEth, meter func() (float64, error), met } type decoratePhoenixEVEthChargerExImpl struct { - chargerEx func(current float64) error + chargerEx func(float64) error } -func (impl *decoratePhoenixEVEthChargerExImpl) MaxCurrentMillis(current float64) error { - return impl.chargerEx(current) +func (impl *decoratePhoenixEVEthChargerExImpl) MaxCurrentMillis(p0 float64) error { + return impl.chargerEx(p0) } type decoratePhoenixEVEthIdentifierImpl struct { diff --git a/charger/wallbe.go b/charger/wallbe.go index 9f43c1596..74577420d 100644 --- a/charger/wallbe.go +++ b/charger/wallbe.go @@ -40,7 +40,7 @@ func init() { registry.Add("wallbe", NewWallbeFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decorateWallbe -b *Wallbe -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.ChargerEx,MaxCurrentMillis,func(current float64) error" +//go:generate go run ../cmd/tools/decorate.go -f decorateWallbe -b *Wallbe -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.ChargerEx,MaxCurrentMillis,func(float64) error" // NewWallbeFromConfig creates a Wallbe charger from generic config func NewWallbeFromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/wallbe_decorators.go b/charger/wallbe_decorators.go index 7cd2a1a5a..b932c5dc4 100644 --- a/charger/wallbe_decorators.go +++ b/charger/wallbe_decorators.go @@ -6,7 +6,7 @@ import ( "github.com/evcc-io/evcc/api" ) -func decorateWallbe(base *Wallbe, meter func() (float64, error), meterEnergy func() (float64, error), phaseCurrents func() (float64, float64, float64, error), chargerEx func(current float64) error) api.Charger { +func decorateWallbe(base *Wallbe, meter func() (float64, error), meterEnergy func() (float64, error), phaseCurrents func() (float64, float64, float64, error), chargerEx func(float64) error) api.Charger { switch { case chargerEx == nil && meter == nil && meterEnergy == nil && phaseCurrents == nil: return base @@ -249,11 +249,11 @@ func decorateWallbe(base *Wallbe, meter func() (float64, error), meterEnergy fun } type decorateWallbeChargerExImpl struct { - chargerEx func(current float64) error + chargerEx func(float64) error } -func (impl *decorateWallbeChargerExImpl) MaxCurrentMillis(current float64) error { - return impl.chargerEx(current) +func (impl *decorateWallbeChargerExImpl) MaxCurrentMillis(p0 float64) error { + return impl.chargerEx(p0) } type decorateWallbeMeterImpl struct { diff --git a/charger/warp2.go b/charger/warp2.go index d2e2ba033..29a0f6215 100644 --- a/charger/warp2.go +++ b/charger/warp2.go @@ -37,7 +37,7 @@ func init() { registry.Add("warp-fw2", NewWarp2FromConfig) // deprecated } -// go:generate go run ../cmd/tools/decorate.go -f decorateWarp2 -b *Warp2 -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.Identifier,Identify,func() (string, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" +//go:generate go run ../cmd/tools/decorate.go -f decorateWarp2 -b *Warp2 -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.Identifier,Identify,func() (string, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewWarpFromConfig creates a new configurable charger func NewWarp2FromConfig(other map[string]interface{}) (api.Charger, error) { diff --git a/charger/warp2_decorators.go b/charger/warp2_decorators.go index 980015f67..c2451ccb4 100644 --- a/charger/warp2_decorators.go +++ b/charger/warp2_decorators.go @@ -1260,8 +1260,8 @@ type decorateWarp2PhaseSwitcherImpl struct { phaseSwitcher func(int) error } -func (impl *decorateWarp2PhaseSwitcherImpl) Phases1p3p(phases int) error { - return impl.phaseSwitcher(phases) +func (impl *decorateWarp2PhaseSwitcherImpl) Phases1p3p(p0 int) error { + return impl.phaseSwitcher(p0) } type decorateWarp2PhaseVoltagesImpl struct { diff --git a/cmd/tools/decorate.go b/cmd/tools/decorate.go index 5403b3e54..9b208d644 100644 --- a/cmd/tools/decorate.go +++ b/cmd/tools/decorate.go @@ -8,6 +8,7 @@ import ( "go/format" "io" "os" + "slices" "strings" "text/template" @@ -23,7 +24,8 @@ type dynamicType struct { } type typeStruct struct { - Type, ShortType, Signature, Function, VarName string + Type, ShortType, Signature, Function, VarName, ReturnTypes string + Params []string } func generate(out io.Writer, packageName, functionName, baseType string, dynamicTypes ...dynamicType) error { @@ -48,14 +50,9 @@ func generate(out io.Writer, packageName, functionName, baseType string, dynamic }, // contains checks if slice contains string "contains": func(combo []string, typ string) bool { - for _, v := range combo { - if v == typ { - return true - } - } - return false + return slices.Contains(combo, typ) }, - // ordered checks if slice ordered string + // ordered returns a slice of typeStructs ordered by dynamicType "ordered": func() []typeStruct { ordered := make([]typeStruct, 0) for _, k := range dynamicTypes { @@ -65,7 +62,6 @@ func generate(out io.Writer, packageName, functionName, baseType string, dynamic return ordered }, }).Parse(srcTmpl) - if err != nil { return err } @@ -73,12 +69,27 @@ func generate(out io.Writer, packageName, functionName, baseType string, dynamic for _, dt := range dynamicTypes { parts := strings.SplitN(dt.typ, ".", 2) + openingBrace := strings.Index(dt.signature, "(") + closingBrace := strings.Index(dt.signature, ")") + paramsStr := dt.signature[openingBrace+1 : closingBrace] + + paramsStr = strings.TrimSpace(paramsStr) + + var params []string + if len(paramsStr) > 0 { + params = strings.Split(paramsStr, ",") + } + + returnValuesStr := dt.signature[closingBrace+1:] + types[dt.typ] = typeStruct{ - Type: dt.typ, - ShortType: parts[1], - VarName: strings.ToLower(parts[1][:1]) + parts[1][1:], - Signature: dt.signature, - Function: dt.function, + Type: dt.typ, + ShortType: parts[1], + VarName: strings.ToLower(parts[1][:1]) + parts[1][1:], + Signature: dt.signature, + Function: dt.function, + Params: params, + ReturnTypes: returnValuesStr, } combos = append(combos, dt.typ) diff --git a/cmd/tools/decorate.tpl b/cmd/tools/decorate.tpl index f164bde64..96dbbf1e4 100644 --- a/cmd/tools/decorate.tpl +++ b/cmd/tools/decorate.tpl @@ -33,7 +33,7 @@ import ( } {{- end -}} -func {{.Function}}(base {{.BaseType}}{{range ordered}}, {{.VarName}} func() {{slice .Signature 7}}{{end}}) {{.ReturnType}} { +func {{.Function}}(base {{.BaseType}}{{range ordered}}, {{.VarName}} {{.Signature}}{{end}}) {{.ReturnType}} { {{- $basetype := .BaseType}} {{- $shortbase := .ShortBase}} {{- $prefix := .Function}} @@ -56,8 +56,14 @@ type {{$prefix}}{{.ShortType}}Impl struct { {{.VarName}} {{.Signature}} } -func (impl *{{$prefix}}{{.ShortType}}Impl) {{.Function}}{{slice .Signature 4}} { - return impl.{{.VarName}}() -} +func (impl *{{$prefix}}{{.ShortType}}Impl) {{.Function}}( + {{- range $idx, $param := .Params -}} + {{- if gt $idx 0}}, {{end -}} + p{{$idx}} {{ $param -}} + {{end}}){{ .ReturnTypes }} { + return impl.{{.VarName}}( + {{- range $idx, $param := .Params -}} + {{- if gt $idx 0}}, {{end}}p{{- $idx -}}{{end}}) + } {{end}} diff --git a/meter/meter.go b/meter/meter.go index 3ff9393e2..5bb00eb70 100644 --- a/meter/meter.go +++ b/meter/meter.go @@ -13,7 +13,7 @@ func init() { registry.Add(api.Custom, NewConfigurableFromConfig) } -// go:generate go run ../cmd/tools/decorate.go -f decorateMeter -b api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.PhasePowers,Powers,func() (float64, float64, float64, error)" -t "api.Battery,Soc,func() (float64, error)" -t "api.BatteryCapacity,Capacity,func() float64" -t "api.BatteryController,SetBatteryMode,func(api.BatteryMode) error" +//go:generate go run ../cmd/tools/decorate.go -f decorateMeter -b api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.PhasePowers,Powers,func() (float64, float64, float64, error)" -t "api.Battery,Soc,func() (float64, error)" -t "api.BatteryCapacity,Capacity,func() float64" -t "api.BatteryController,SetBatteryMode,func(api.BatteryMode) error" // NewConfigurableFromConfig creates api.Meter from config func NewConfigurableFromConfig(other map[string]interface{}) (api.Meter, error) { diff --git a/meter/meter_decorators.go b/meter/meter_decorators.go index 3a84a751f..c53e1516b 100644 --- a/meter/meter_decorators.go +++ b/meter/meter_decorators.go @@ -2716,8 +2716,8 @@ type decorateMeterBatteryControllerImpl struct { batteryController func(api.BatteryMode) error } -func (impl *decorateMeterBatteryControllerImpl) SetBatteryMode(mode api.BatteryMode) error { - return impl.batteryController(mode) +func (impl *decorateMeterBatteryControllerImpl) SetBatteryMode(p0 api.BatteryMode) error { + return impl.batteryController(p0) } type decorateMeterMeterEnergyImpl struct {