diff --git a/Makefile b/Makefile index 7cfe14229..278bb91ed 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,10 @@ docs:: lint:: golangci-lint run + go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test -category "-omitzero" -c 0 ./... + +modernize: + go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test -category "-omitzero" -fix ./... lint-ui:: npm run lint diff --git a/api/globalconfig/types.go b/api/globalconfig/types.go index 700147998..4b9579414 100644 --- a/api/globalconfig/types.go +++ b/api/globalconfig/types.go @@ -40,7 +40,7 @@ type All struct { Chargers []config.Named Vehicles []config.Named Tariffs Tariffs - Site map[string]interface{} + Site map[string]any Loadpoints []config.Named Circuits []config.Named } diff --git a/charger/abb.go b/charger/abb.go index d93d1c722..294d37a46 100644 --- a/charger/abb.go +++ b/charger/abb.go @@ -57,7 +57,7 @@ func init() { } // NewABBFromConfig creates a ABB charger from generic config -func NewABBFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewABBFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ ID: 1, } diff --git a/charger/abl-em4.go b/charger/abl-em4.go index ca79ec19d..38e93109f 100644 --- a/charger/abl-em4.go +++ b/charger/abl-em4.go @@ -53,7 +53,7 @@ func init() { } // NewAblEm4FromConfig creates an ABL eM4 charger from generic config -func NewAblEm4FromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewAblEm4FromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.TcpSettings `mapstructure:",squash"` Connector uint16 diff --git a/charger/abl.go b/charger/abl.go index 0aeef857f..fc1fdad49 100644 --- a/charger/abl.go +++ b/charger/abl.go @@ -79,7 +79,7 @@ func init() { // https://www.goingelectric.de/forum/viewtopic.php?p=1550459#p1550459 // NewABLeMHFromConfig creates a ABLeMH charger from generic config -func NewABLeMHFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewABLeMHFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.Settings `mapstructure:",squash"` Timeout time.Duration diff --git a/charger/alfen.go b/charger/alfen.go index bf2733fd2..ab34ba179 100644 --- a/charger/alfen.go +++ b/charger/alfen.go @@ -59,7 +59,7 @@ func init() { //go:generate go tool decorate -f decorateAlfen -b *Alfen -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.PhaseGetter,GetPhases,func() (int, error)" // NewAlfenFromConfig creates a Alfen charger from generic config -func NewAlfenFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewAlfenFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 1, } diff --git a/charger/alphatec.go b/charger/alphatec.go index 0689cfa10..0b05fe84e 100644 --- a/charger/alphatec.go +++ b/charger/alphatec.go @@ -47,7 +47,7 @@ func init() { } // NewAlphatecFromConfig creates a Alphatec charger from generic config -func NewAlphatecFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewAlphatecFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ ID: 1, } diff --git a/charger/amperfied.go b/charger/amperfied.go index 6a348c789..9880beacd 100644 --- a/charger/amperfied.go +++ b/charger/amperfied.go @@ -62,7 +62,7 @@ func init() { //go:generate go tool decorate -f decorateAmperfied -b *Amperfied -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.PhaseGetter,GetPhases,func() (int, error)" // NewAmperfiedFromConfig creates a Amperfied charger from generic config -func NewAmperfiedFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewAmperfiedFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.TcpSettings `mapstructure:",squash"` Phases1p3p bool diff --git a/charger/bender.go b/charger/bender.go index cb6ee3946..d013513e3 100644 --- a/charger/bender.go +++ b/charger/bender.go @@ -92,7 +92,7 @@ func init() { } // NewBenderCCFromConfig creates a BenderCC charger from generic config -func NewBenderCCFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewBenderCCFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.TcpSettings `mapstructure:",squash"` Cache time.Duration diff --git a/charger/cfos.go b/charger/cfos.go index 9c8f54c35..ea9ed3b71 100644 --- a/charger/cfos.go +++ b/charger/cfos.go @@ -41,7 +41,7 @@ func init() { //go:generate go tool decorate -f decorateCfos -b *CfosPowerBrain -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" // NewCfosPowerBrainFromConfig creates a cFos charger from generic config -func NewCfosPowerBrainFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewCfosPowerBrainFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 1, } diff --git a/charger/charger.go b/charger/charger.go index d90a6510a..911497baa 100644 --- a/charger/charger.go +++ b/charger/charger.go @@ -28,7 +28,7 @@ func init() { //go:generate go tool decorate -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)" -t "api.SocLimiter,GetLimitSoc,func() (int64, error)" -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)" // NewConfigurableFromConfig creates a new configurable charger -func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewConfigurableFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { var cc struct { embed `mapstructure:",squash"` Status, Enable, Enabled, MaxCurrent plugin.Config diff --git a/charger/compleo.go b/charger/compleo.go index e404da19f..03a267609 100644 --- a/charger/compleo.go +++ b/charger/compleo.go @@ -61,7 +61,7 @@ func init() { } // NewCompleoFromConfig creates a Compleo charger from generic config -func NewCompleoFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewCompleoFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { Connector uint16 modbus.TcpSettings `mapstructure:",squash"` diff --git a/charger/config.go b/charger/config.go index 05b95ae91..946fd8ec3 100644 --- a/charger/config.go +++ b/charger/config.go @@ -15,6 +15,6 @@ func Types() []string { } // NewFromConfig creates charger from configuration -func NewFromConfig(ctx context.Context, typ string, other map[string]interface{}) (api.Charger, error) { +func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.Charger, error) { return config.NewFromConfig(ctx, typ, other) } diff --git a/charger/config/config.go b/charger/config/config.go index 7f575b6f6..80751b11f 100644 --- a/charger/config/config.go +++ b/charger/config/config.go @@ -12,7 +12,7 @@ import ( var Registry = reg.New[api.Charger]("charger") // NewFromConfig creates charger from configuration -func NewFromConfig(ctx context.Context, typ string, other map[string]interface{}) (api.Charger, error) { +func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.Charger, error) { factory, err := Registry.Get(strings.ToLower(typ)) if err != nil { return nil, err diff --git a/charger/connectiq.go b/charger/connectiq.go index c2886fb19..1c629e4a3 100644 --- a/charger/connectiq.go +++ b/charger/connectiq.go @@ -43,7 +43,7 @@ func init() { } // NewConnectIqFromConfig creates a ConnectIq charger from generic config -func NewConnectIqFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewConnectIqFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string Cache time.Duration diff --git a/charger/dadapower.go b/charger/dadapower.go index 3cb8bc90b..20babd9fb 100644 --- a/charger/dadapower.go +++ b/charger/dadapower.go @@ -41,7 +41,7 @@ func init() { } // NewDadapowerFromConfig creates a Dadapower charger from generic config -func NewDadapowerFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewDadapowerFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{} if err := util.DecodeOther(other, &cc); err != nil { diff --git a/charger/daheimladen.go b/charger/daheimladen.go index 3773ecef0..e703d50e0 100644 --- a/charger/daheimladen.go +++ b/charger/daheimladen.go @@ -67,7 +67,7 @@ func init() { //go:generate go tool decorate -f decorateDaheimLaden -b *DaheimLaden -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.PhaseGetter,GetPhases,func() (int, error)" // NewDaheimLadenFromConfig creates a DaheimLaden charger from generic config -func NewDaheimLadenFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewDaheimLadenFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.TcpSettings `mapstructure:",squash"` Phases1p3p bool diff --git a/charger/delta.go b/charger/delta.go index 27e1420de..f2dbd2eb8 100644 --- a/charger/delta.go +++ b/charger/delta.go @@ -64,7 +64,7 @@ func init() { } // NewDeltaFromConfig creates a Delta charger from generic config -func NewDeltaFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewDeltaFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { Connector uint16 modbus.Settings `mapstructure:",squash"` diff --git a/charger/easee.go b/charger/easee.go index cd2cb669c..3933bbc6c 100644 --- a/charger/easee.go +++ b/charger/easee.go @@ -74,7 +74,7 @@ func init() { } // NewEaseeFromConfig creates a Easee charger from generic config -func NewEaseeFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewEaseeFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { User string Password string @@ -202,7 +202,7 @@ func NewEasee(ctx context.Context, user, password, charger string, timeout time. } func (c *Easee) waitForOptionalState() { - for i := 0; i < 30; i++ { + for range 30 { if c.optionalStatePresent() { return } diff --git a/charger/easee/log.go b/charger/easee/log.go index cba22bc6a..80e56a5c7 100644 --- a/charger/easee/log.go +++ b/charger/easee/log.go @@ -10,7 +10,7 @@ import ( // Logger is a simple logger interface type Logger interface { - Println(v ...interface{}) + Println(v ...any) } type logger struct { @@ -23,7 +23,7 @@ func SignalrLogger(log Logger) signalr.StructuredLogger { var skipped = []string{"ts", "class", "hub", "protocol", "value"} -func (l *logger) Log(keyVals ...interface{}) error { +func (l *logger) Log(keyVals ...any) error { b := new(strings.Builder) var skip bool diff --git a/charger/easee/signalr.go b/charger/easee/signalr.go index 14d8194db..545e90df2 100644 --- a/charger/easee/signalr.go +++ b/charger/easee/signalr.go @@ -13,7 +13,7 @@ type Observation struct { Value string } -func (o *Observation) TypedValue() (interface{}, error) { +func (o *Observation) TypedValue() (any, error) { switch o.DataType { case Boolean: return o.Value == "1", nil diff --git a/charger/eebus.go b/charger/eebus.go index 75bb725b8..1820e879d 100644 --- a/charger/eebus.go +++ b/charger/eebus.go @@ -54,7 +54,7 @@ func init() { } // NewEEBusFromConfig creates an EEBus charger from generic config -func NewEEBusFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewEEBusFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { var cc struct { Ski string Ip string diff --git a/charger/em2go-duo.go b/charger/em2go-duo.go index 190870af0..bc0eb503f 100644 --- a/charger/em2go-duo.go +++ b/charger/em2go-duo.go @@ -59,7 +59,7 @@ func init() { } // NewEm2GoDuoFromConfig creates a Em2GoDuo charger from generic config -func NewEm2GoDuoFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewEm2GoDuoFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.TcpSettings `mapstructure:",squash"` Connector int diff --git a/charger/em2go.go b/charger/em2go.go index 4a2f485c7..c26a27bfd 100644 --- a/charger/em2go.go +++ b/charger/em2go.go @@ -72,7 +72,7 @@ func init() { //go:generate go tool decorate -f decorateEm2Go -b *Em2Go -r api.Charger -t "api.ChargerEx,MaxCurrentMillis,func(float64) error" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.PhaseGetter,GetPhases,func() (int, error)" // NewEm2GoFromConfig creates a Em2Go charger from generic config -func NewEm2GoFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewEm2GoFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.TcpSettings `mapstructure:",squash"` Connector int // TODO remove deprecated @@ -371,7 +371,7 @@ func (wb *Em2Go) Diagnose() { fmt.Printf("\tCable Max. Current:\t%.1fA\n", float64(binary.BigEndian.Uint16(b)/10)) } var serial []byte - for reg := 0; reg < 8; reg++ { + for reg := range 8 { b, err := wb.conn.ReadHoldingRegisters(em2GoRegSerial+2*uint16(reg), 2) if err != nil { return diff --git a/charger/etrel.go b/charger/etrel.go index 155542409..8e0a406ad 100644 --- a/charger/etrel.go +++ b/charger/etrel.go @@ -64,7 +64,7 @@ func init() { } // NewEtrelFromConfig creates a Etrel charger from generic config -func NewEtrelFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewEtrelFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { Connector int modbus.TcpSettings `mapstructure:",squash"` diff --git a/charger/evecube.go b/charger/evecube.go index b4d770f31..3f9afe346 100644 --- a/charger/evecube.go +++ b/charger/evecube.go @@ -90,7 +90,7 @@ type EVECUBELastStatusPacket struct { // EVECUBEAutomationStatus is the /api/admin/automation/status response type EVECUBEAutomationStatus struct { - Connectors map[string]interface{} `json:"connectors"` + Connectors map[string]any `json:"connectors"` AuthTag struct { Tag string `json:"tag"` } `json:"authTag"` @@ -98,11 +98,11 @@ type EVECUBEAutomationStatus struct { // EVECUBEUnitConfigRequest is the request body for /api/admin/unitconfig POST type EVECUBEUnitConfigRequest struct { - Values map[string]interface{} `json:"values"` + Values map[string]any `json:"values"` } // NewEVECUBEFromConfig creates a EVECUBE charger from generic config -func NewEVECUBEFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewEVECUBEFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string User string @@ -276,7 +276,7 @@ func (wb *EVECUBE) MaxCurrent(current int64) error { // setValue sets a named value via admin API func (wb *EVECUBE) setValue(key string, value int64) error { reqBody := EVECUBEUnitConfigRequest{ - Values: map[string]interface{}{ + Values: map[string]any{ key: value, }, } @@ -296,7 +296,7 @@ func (wb *EVECUBE) setValue(key string, value int64) error { req.SetBasicAuth(wb.user, wb.pass) } - var resp map[string]interface{} + var resp map[string]any if err := wb.DoJSON(req, &resp); err != nil { return err } diff --git a/charger/evsedin.go b/charger/evsedin.go index 75bfbff1d..ce16413c6 100644 --- a/charger/evsedin.go +++ b/charger/evsedin.go @@ -32,7 +32,7 @@ func init() { // https://www.evracing.cz/user/documents/upload/EVSE-WB-DIN_latest.pdf // NewEvseDINFromConfig creates an EVSE DIN charger from generic config -func NewEvseDINFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewEvseDINFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ Baudrate: 9600, Comset: "8N1", diff --git a/charger/evsewifi.go b/charger/evsewifi.go index a04d40d9c..792e21b6f 100644 --- a/charger/evsewifi.go +++ b/charger/evsewifi.go @@ -30,7 +30,7 @@ func init() { //go:generate go tool decorate -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) { +func NewEVSEWifiFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string Meter struct { diff --git a/charger/evsewifi_test.go b/charger/evsewifi_test.go index ba09b9a86..88b7f998d 100644 --- a/charger/evsewifi_test.go +++ b/charger/evsewifi_test.go @@ -15,9 +15,9 @@ func TestEvseWifi(t *testing.T) { })) defer ts.Close() - wb, err := NewEVSEWifiFromConfig(map[string]interface{}{ + wb, err := NewEVSEWifiFromConfig(map[string]any{ "uri": ts.URL, - "meter": map[string]interface{}{ + "meter": map[string]any{ "power": true, "energy": true, "currents": true, @@ -51,7 +51,7 @@ func TestEvseWifiEx(t *testing.T) { })) defer ts.Close() - wb, err := NewEVSEWifiFromConfig(map[string]interface{}{ + wb, err := NewEVSEWifiFromConfig(map[string]any{ "uri": ts.URL, }) if err != nil { diff --git a/charger/fritzdect.go b/charger/fritzdect.go index 4fec36857..1b68bbc2c 100644 --- a/charger/fritzdect.go +++ b/charger/fritzdect.go @@ -23,7 +23,7 @@ func init() { } // NewFritzDECTFromConfig creates a fritzdect charger from generic config -func NewFritzDECTFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewFritzDECTFromConfig(other map[string]any) (api.Charger, error) { var cc struct { embed `mapstructure:",squash"` fritzdect.Settings `mapstructure:",squash"` diff --git a/charger/fronius-wattpilot.go b/charger/fronius-wattpilot.go index de277e655..181b42315 100644 --- a/charger/fronius-wattpilot.go +++ b/charger/fronius-wattpilot.go @@ -22,7 +22,7 @@ func init() { } // NewWattpilotFromConfig creates a wattpilot charger from generic config -func NewWattpilotFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewWattpilotFromConfig(other map[string]any) (api.Charger, error) { var cc struct { URI string Password string diff --git a/charger/go-e.go b/charger/go-e.go index 1fad21baa..1423b7ed8 100644 --- a/charger/go-e.go +++ b/charger/go-e.go @@ -38,10 +38,10 @@ type GoE struct { } func init() { - registry.Add("go-e", func(other map[string]interface{}) (api.Charger, error) { + registry.Add("go-e", func(other map[string]any) (api.Charger, error) { return newGoEFromConfig(true, other) }) - registry.Add("go-e-v3", func(other map[string]interface{}) (api.Charger, error) { + registry.Add("go-e-v3", func(other map[string]any) (api.Charger, error) { return newGoEFromConfig(false, other) }) } @@ -49,7 +49,7 @@ func init() { //go:generate go tool decorate -f decorateGoE -b *GoE -r api.Charger -t "api.ChargeRater,ChargedEnergy,func() (float64, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // newGoEFromConfig creates a go-e charger from generic config -func newGoEFromConfig(v2 bool, other map[string]interface{}) (api.Charger, error) { +func newGoEFromConfig(v2 bool, other map[string]any) (api.Charger, error) { cc := struct { Token string URI string diff --git a/charger/go-e/api.go b/charger/go-e/api.go index 53a6aa6cf..2c6edbb5c 100644 --- a/charger/go-e/api.go +++ b/charger/go-e/api.go @@ -24,7 +24,7 @@ type Response interface { Identify() string } -type UpdateResponse map[string]interface{} +type UpdateResponse map[string]any type API interface { IsV2() bool @@ -78,7 +78,7 @@ func (c *LocalAPI) IsV2() bool { } // response returns a v1/v2 api response -func (c *LocalAPI) response(partial string, res interface{}) error { +func (c *LocalAPI) response(partial string, res any) error { url := fmt.Sprintf("%s/%s", c.uri, partial) return c.GetJSON(url, &res) } diff --git a/charger/hardybarth-ecb1.go b/charger/hardybarth-ecb1.go index 5e899c653..fb5bdd752 100644 --- a/charger/hardybarth-ecb1.go +++ b/charger/hardybarth-ecb1.go @@ -52,7 +52,7 @@ func init() { } // NewHardyBarthFromConfig creates a HardyBarth cPH1 charger from generic config -func NewHardyBarthFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewHardyBarthFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string ChargeControl int diff --git a/charger/hardybarth-salia.go b/charger/hardybarth-salia.go index ebe2a16dc..bd062d12a 100644 --- a/charger/hardybarth-salia.go +++ b/charger/hardybarth-salia.go @@ -56,7 +56,7 @@ func init() { //go:generate go tool decorate -f decorateSalia -b *Salia -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" -t "api.PhaseGetter,GetPhases,func() (int, error)" // NewSaliaFromConfig creates a Salia cPH2 charger from generic config -func NewSaliaFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSaliaFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { URI string User string diff --git a/charger/heatpump.go b/charger/heatpump.go index bd8e52a6d..1eae1ac61 100644 --- a/charger/heatpump.go +++ b/charger/heatpump.go @@ -43,7 +43,7 @@ func init() { //go:generate go tool decorate -f decorateHeatpump -b *Heatpump -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Battery,Soc,func() (float64, error)" -t "api.SocLimiter,GetLimitSoc,func() (int64, error)" // NewHeatpumpFromConfig creates heatpump configurable charger from generic config -func NewHeatpumpFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewHeatpumpFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { embed `mapstructure:",squash"` SetMaxPower plugin.Config diff --git a/charger/heidelberg-ec.go b/charger/heidelberg-ec.go index f6c44d461..cf0082898 100644 --- a/charger/heidelberg-ec.go +++ b/charger/heidelberg-ec.go @@ -61,7 +61,7 @@ func init() { // https://cdn.shopify.com/s/files/1/0101/2409/9669/files/heidelberg-energy-control-modbus.pdf (older) // NewHeidelbergECFromConfig creates a HeidelbergEC charger from generic config -func NewHeidelbergECFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewHeidelbergECFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ ID: 1, } diff --git a/charger/hesotec.go b/charger/hesotec.go index 693eee45b..0cf78d86d 100644 --- a/charger/hesotec.go +++ b/charger/hesotec.go @@ -60,7 +60,7 @@ func init() { } // NewHesotecFromConfig creates a Hesotec charger from generic config -func NewHesotecFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewHesotecFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 1, } diff --git a/charger/homeassistant-switch.go b/charger/homeassistant-switch.go index 3849560ef..9bf52f6cc 100644 --- a/charger/homeassistant-switch.go +++ b/charger/homeassistant-switch.go @@ -19,7 +19,7 @@ func init() { registry.Add("homeassistant-switch", NewHomeAssistantSwitchFromConfig) } -func NewHomeAssistantSwitchFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewHomeAssistantSwitchFromConfig(other map[string]any) (api.Charger, error) { var cc struct { embed `mapstructure:",squash"` URI string diff --git a/charger/homeassistant.go b/charger/homeassistant.go index 7c200616e..e81e80bf4 100644 --- a/charger/homeassistant.go +++ b/charger/homeassistant.go @@ -26,7 +26,7 @@ func init() { } // NewHomeAssistantFromConfig creates a HomeAssistant charger from generic config -func NewHomeAssistantFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewHomeAssistantFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string Token string diff --git a/charger/homematic.go b/charger/homematic.go index ec2a7382c..80ad932cc 100644 --- a/charger/homematic.go +++ b/charger/homematic.go @@ -19,7 +19,7 @@ func init() { } // NewCCUFromConfig creates a Homematic charger from generic config -func NewCCUFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewCCUFromConfig(other map[string]any) (api.Charger, error) { cc := struct { embed `mapstructure:",squash"` URI string diff --git a/charger/homewizard.go b/charger/homewizard.go index 445503095..48e3c8c3a 100644 --- a/charger/homewizard.go +++ b/charger/homewizard.go @@ -23,7 +23,7 @@ func init() { } // NewHomeWizardFromConfig creates a HomeWizard charger from generic config -func NewHomeWizardFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewHomeWizardFromConfig(other map[string]any) (api.Charger, error) { cc := struct { embed `mapstructure:",squash"` URI string diff --git a/charger/innogy.go b/charger/innogy.go index 7298caf07..a35d16f02 100644 --- a/charger/innogy.go +++ b/charger/innogy.go @@ -56,7 +56,7 @@ func init() { } // NewInnogyFromConfig creates a Innogy charger from generic config -func NewInnogyFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewInnogyFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 1, } diff --git a/charger/keba-modbus.go b/charger/keba-modbus.go index 10b1de9ad..e132fd790 100644 --- a/charger/keba-modbus.go +++ b/charger/keba-modbus.go @@ -75,7 +75,7 @@ func init() { //go:generate go tool decorate -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.StatusReasoner,StatusReason,func() (api.Reason, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.PhaseGetter,GetPhases,func() (int, error)" // NewKebaFromConfig creates a new Keba ModbusTCP charger -func NewKebaFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewKebaFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { embed `mapstructure:",squash"` modbus.TcpSettings `mapstructure:",squash"` diff --git a/charger/keba-udp.go b/charger/keba-udp.go index a562e2774..43bd1383c 100644 --- a/charger/keba-udp.go +++ b/charger/keba-udp.go @@ -35,7 +35,7 @@ func init() { //go:generate go tool decorate -f decorateKebaUdp -b *KebaUdp -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)" // NewKebaUdpFromConfig creates a new Keba UDP charger -func NewKebaUdpFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewKebaUdpFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string Serial string @@ -124,7 +124,7 @@ func (c *KebaUdp) receive(report int, resC chan<- keba.UDPMsg, errC chan<- error } } -func (c *KebaUdp) roundtrip(msg string, report int, res interface{}) error { +func (c *KebaUdp) roundtrip(msg string, report int, res any) error { resC := make(chan keba.UDPMsg) errC := make(chan error) closeC := make(chan struct{}) diff --git a/charger/kse.go b/charger/kse.go index 794f57d4a..e9541812b 100644 --- a/charger/kse.go +++ b/charger/kse.go @@ -57,7 +57,7 @@ func init() { } // NewKSEFromConfig creates a KSE charger from generic config -func NewKSEFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewKSEFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ ID: 100, Baudrate: 9600, diff --git a/charger/mennekes-compact.go b/charger/mennekes-compact.go index f0aa0b9d7..054205438 100644 --- a/charger/mennekes-compact.go +++ b/charger/mennekes-compact.go @@ -68,7 +68,7 @@ func init() { } // NewMennekesCompactFromConfig creates a new Mennekes ModbusTCP charger -func NewMennekesCompactFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewMennekesCompactFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.Settings `mapstructure:",squash"` Timeout time.Duration diff --git a/charger/mennekes-hcc3.go b/charger/mennekes-hcc3.go index 46d51e0f4..8a5fb11f8 100644 --- a/charger/mennekes-hcc3.go +++ b/charger/mennekes-hcc3.go @@ -53,7 +53,7 @@ func init() { } // NewMennekesHcc3FromConfig creates a Mennekes mennekesHcc3 charger from generic config -func NewMennekesHcc3FromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewMennekesHcc3FromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 255, } diff --git a/charger/mypv.go b/charger/mypv.go index 8876f9dc5..cf6fc386b 100644 --- a/charger/mypv.go +++ b/charger/mypv.go @@ -60,22 +60,22 @@ var elwaStandbyPower uint16 = 10 func init() { // https://github.com/evcc-io/evcc/discussions/12761 - registry.AddCtx("ac-elwa-2", func(ctx context.Context, other map[string]interface{}) (api.Charger, error) { + registry.AddCtx("ac-elwa-2", func(ctx context.Context, other map[string]any) (api.Charger, error) { return newMyPvFromConfig(ctx, "ac-elwa-2", other, 2) }) // https: // github.com/evcc-io/evcc/issues/18020 - registry.AddCtx("ac-thor", func(ctx context.Context, other map[string]interface{}) (api.Charger, error) { + registry.AddCtx("ac-thor", func(ctx context.Context, other map[string]any) (api.Charger, error) { return newMyPvFromConfig(ctx, "ac-thor", other, 9) }) - registry.AddCtx("ac-elwa-e", func(ctx context.Context, other map[string]interface{}) (api.Charger, error) { + registry.AddCtx("ac-elwa-e", func(ctx context.Context, other map[string]any) (api.Charger, error) { return newMyPvFromConfig(ctx, "ac-elwa-e", other, 2) }) } // newMyPvFromConfig creates a MyPv charger from generic config -func newMyPvFromConfig(ctx context.Context, name string, other map[string]interface{}, statusC uint16) (api.Charger, error) { +func newMyPvFromConfig(ctx context.Context, name string, other map[string]any, statusC uint16) (api.Charger, error) { cc := struct { modbus.TcpSettings `mapstructure:",squash"` TempSource int diff --git a/charger/mystrom.go b/charger/mystrom.go index 1e38957df..e21d8d04b 100644 --- a/charger/mystrom.go +++ b/charger/mystrom.go @@ -24,7 +24,7 @@ type MyStrom struct { } // NewMyStromFromConfig creates a myStrom charger from generic config -func NewMyStromFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewMyStromFromConfig(other map[string]any) (api.Charger, error) { cc := struct { embed `mapstructure:",squash"` URI string diff --git a/charger/nrgble.go b/charger/nrgble.go index bb93c12fd..32c723e8d 100644 --- a/charger/nrgble.go +++ b/charger/nrgble.go @@ -13,6 +13,6 @@ func init() { } // NewNRGKickBLEFromConfig creates a NRGKickBLE charger from generic config -func NewNRGKickBLEFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewNRGKickBLEFromConfig(other map[string]any) (api.Charger, error) { return nil, errors.New("NRGKick bluetooth is only supported on linux") } diff --git a/charger/nrgconnect.go b/charger/nrgconnect.go index 4403850d8..77bbacbfa 100644 --- a/charger/nrgconnect.go +++ b/charger/nrgconnect.go @@ -31,7 +31,7 @@ func init() { } // NewNRGKickConnectFromConfig creates a NRGKickConnect charger from generic config -func NewNRGKickConnectFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewNRGKickConnectFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI, Mac, Password string Cache time.Duration @@ -84,7 +84,7 @@ func (nrg *NRGKickConnect) apiURL(api string) string { return fmt.Sprintf("%s/api/%s/%s", nrg.uri, api, nrg.mac) } -func (nrg *NRGKickConnect) putJSON(url string, data interface{}) error { +func (nrg *NRGKickConnect) putJSON(url string, data any) error { req, err := request.New(http.MethodPut, url, request.MarshalJSON(data), request.JSONEncoding) if err != nil { return err diff --git a/charger/nrggen2.go b/charger/nrggen2.go index 1254d68ab..a4fb61c16 100644 --- a/charger/nrggen2.go +++ b/charger/nrggen2.go @@ -52,7 +52,7 @@ func init() { //go:generate go tool decorate -f decorateNRGKickGen2 -b *NRGKickGen2 -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewNRGKickGen2FromConfig creates a NRGKickGen2 charger from generic config -func NewNRGKickGen2FromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewNRGKickGen2FromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.TcpSettings `mapstructure:",squash"` Phases1p3p bool diff --git a/charger/obo.go b/charger/obo.go index 826ffa32a..0f71cbb53 100644 --- a/charger/obo.go +++ b/charger/obo.go @@ -29,7 +29,7 @@ func init() { } // NewOboFromConfig creates a OBO Bettermann charger from generic config -func NewOboFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewOboFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ Baudrate: 19200, Comset: "8E1", diff --git a/charger/ocpp.go b/charger/ocpp.go index 8130c0e19..6c8a21b54 100644 --- a/charger/ocpp.go +++ b/charger/ocpp.go @@ -56,7 +56,7 @@ func init() { } // NewOCPPFromConfig creates a OCPP charger from generic config -func NewOCPPFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewOCPPFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { StationId string IdTag string diff --git a/charger/ocpp/cp_setup.go b/charger/ocpp/cp_setup.go index fbc6389c8..c2aea505a 100644 --- a/charger/ocpp/cp_setup.go +++ b/charger/ocpp/cp_setup.go @@ -174,7 +174,7 @@ func (cp *CP) HasMeasurement(val types.Measurand) bool { func (cp *CP) tryMeasurands(measurands string, key string) []string { var accepted []string - for _, m := range strings.Split(measurands, ",") { + for m := range strings.SplitSeq(measurands, ",") { if err := cp.ChangeConfigurationRequest(key, m); err == nil { accepted = append(accepted, m) } diff --git a/charger/ocpp/cs_log.go b/charger/ocpp/cs_log.go index adb2e81f0..517ae6c95 100644 --- a/charger/ocpp/cs_log.go +++ b/charger/ocpp/cs_log.go @@ -31,26 +31,26 @@ func (cs *CS) print(s string) { } } -func (cs *CS) Debug(args ...interface{}) { +func (cs *CS) Debug(args ...any) { cs.print(fmt.Sprintln(args...)) } -func (cs *CS) Debugf(f string, args ...interface{}) { +func (cs *CS) Debugf(f string, args ...any) { cs.print(fmt.Sprintf(f, args...)) } -func (cs *CS) Info(args ...interface{}) { +func (cs *CS) Info(args ...any) { cs.print(fmt.Sprintln(args...)) } -func (cs *CS) Infof(f string, args ...interface{}) { +func (cs *CS) Infof(f string, args ...any) { cs.print(fmt.Sprintf(f, args...)) } -func (cs *CS) Error(args ...interface{}) { +func (cs *CS) Error(args ...any) { cs.print(fmt.Sprintln(args...)) } -func (cs *CS) Errorf(f string, args ...interface{}) { +func (cs *CS) Errorf(f string, args ...any) { cs.print(fmt.Sprintf(f, args...)) } diff --git a/charger/ocpp/instance.go b/charger/ocpp/instance.go index 6cc3a2aff..025a56e56 100644 --- a/charger/ocpp/instance.go +++ b/charger/ocpp/instance.go @@ -32,7 +32,7 @@ func Instance() *CS { dispatcher.SetTimeout(Timeout) endpoint := ocppj.NewServer(server, dispatcher, nil, core.Profile, remotetrigger.Profile, smartcharging.Profile, security.Profile) - endpoint.SetInvalidMessageHook(func(client ws.Channel, err *ocpp.Error, rawMessage string, parsedFields []interface{}) *ocpp.Error { + endpoint.SetInvalidMessageHook(func(client ws.Channel, err *ocpp.Error, rawMessage string, parsedFields []any) *ocpp.Error { log.ERROR.Printf("%v (%s)", err, rawMessage) return nil }) diff --git a/charger/ocpp_test_logger.go b/charger/ocpp_test_logger.go index ab6618a99..b5fdc4c24 100644 --- a/charger/ocpp_test_logger.go +++ b/charger/ocpp_test_logger.go @@ -14,15 +14,15 @@ func print(t *testing.T, s string) { t.Log((time.Now().Format(time.DateTime)), s) } -func (l *ocppLogger) Debug(args ...interface{}) { print(l.t, fmt.Sprint(args...)) } -func (l *ocppLogger) Debugf(format string, args ...interface{}) { +func (l *ocppLogger) Debug(args ...any) { print(l.t, fmt.Sprint(args...)) } +func (l *ocppLogger) Debugf(format string, args ...any) { print(l.t, fmt.Sprintf(format, args...)) } -func (l *ocppLogger) Info(args ...interface{}) { print(l.t, fmt.Sprint(args...)) } -func (l *ocppLogger) Infof(format string, args ...interface{}) { +func (l *ocppLogger) Info(args ...any) { print(l.t, fmt.Sprint(args...)) } +func (l *ocppLogger) Infof(format string, args ...any) { print(l.t, fmt.Sprintf(format, args...)) } -func (l *ocppLogger) Error(args ...interface{}) { print(l.t, fmt.Sprint(args...)) } -func (l *ocppLogger) Errorf(format string, args ...interface{}) { +func (l *ocppLogger) Error(args ...any) { print(l.t, fmt.Sprint(args...)) } +func (l *ocppLogger) Errorf(format string, args ...any) { print(l.t, fmt.Sprintf(format, args...)) } diff --git a/charger/openevse.go b/charger/openevse.go index b08668009..21de2ff89 100644 --- a/charger/openevse.go +++ b/charger/openevse.go @@ -31,7 +31,7 @@ func init() { //go:generate go tool decorate -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) { +func NewOpenEVSEFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string User string diff --git a/charger/openwb-2.0.go b/charger/openwb-2.0.go index 39eb9c80b..5cb7b7045 100644 --- a/charger/openwb-2.0.go +++ b/charger/openwb-2.0.go @@ -44,7 +44,7 @@ func init() { //go:generate go tool decorate -f decorateOpenWB20 -b *OpenWB20 -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.Identifier,Identify,func() (string, error)" // NewOpenWB20FromConfig creates a OpenWB20 charger from generic config -func NewOpenWB20FromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewOpenWB20FromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { Connector uint16 Phases1p3p bool diff --git a/charger/openwb-pro.go b/charger/openwb-pro.go index d697c997b..0fc40f436 100644 --- a/charger/openwb-pro.go +++ b/charger/openwb-pro.go @@ -29,7 +29,7 @@ type OpenWBPro struct { } // NewOpenWBProFromConfig creates a OpenWBPro charger from generic config -func NewOpenWBProFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewOpenWBProFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { URI string Cache time.Duration diff --git a/charger/openwb.go b/charger/openwb.go index 69f5d5462..acd50c734 100644 --- a/charger/openwb.go +++ b/charger/openwb.go @@ -33,7 +33,7 @@ type OpenWB struct { //go:generate go tool decorate -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) { +func NewOpenWBFromConfig(other map[string]any) (api.Charger, error) { cc := struct { mqtt.Config `mapstructure:",squash"` Topic string diff --git a/charger/pantabox.go b/charger/pantabox.go index 4b94c969e..d112ba99e 100644 --- a/charger/pantabox.go +++ b/charger/pantabox.go @@ -21,7 +21,7 @@ func init() { } // NewPantaboxFromConfig creates a Pantabox charger from generic config -func NewPantaboxFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewPantaboxFromConfig(other map[string]any) (api.Charger, error) { var cc struct { URI string } diff --git a/charger/pcelectric.go b/charger/pcelectric.go index e178a65ca..a33e01656 100644 --- a/charger/pcelectric.go +++ b/charger/pcelectric.go @@ -33,7 +33,7 @@ func init() { //go:generate go tool decorate -f decoratePCE -b *PCElectric -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)" // NewPCElectricFromConfig creates a PCElectric charger from generic config -func NewPCElectricFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewPCElectricFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string SlaveIndex int diff --git a/charger/pcelectric/types.go b/charger/pcelectric/types.go index 884a47bb2..73b5a5dac 100644 --- a/charger/pcelectric/types.go +++ b/charger/pcelectric/types.go @@ -41,7 +41,7 @@ type Status struct { NrOfPhases int // 1, TwinSerial int // -1, } - TwinCharger interface{} + TwinCharger any } // /servlet/rest/chargebox/slaves/false diff --git a/charger/peblar.go b/charger/peblar.go index 92de8bb17..1e281b134 100644 --- a/charger/peblar.go +++ b/charger/peblar.go @@ -74,7 +74,7 @@ func init() { //go:generate go tool decorate -f decoratePeblar -b *Peblar -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.PhaseGetter,GetPhases,func() (int, error)" // NewPeblarFromConfig creates a Peblar charger from generic config -func NewPeblarFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewPeblarFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 255, } diff --git a/charger/phoenix-charx.go b/charger/phoenix-charx.go index 46801a3df..6f404b89a 100644 --- a/charger/phoenix-charx.go +++ b/charger/phoenix-charx.go @@ -50,7 +50,7 @@ func init() { //go:generate go tool decorate -f decoratePhoenixCharx -b *PhoenixCharx -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)" // NewPhoenixCharxFromConfig creates a Phoenix charger from generic config -func NewPhoenixCharxFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewPhoenixCharxFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { modbus.TcpSettings `mapstructure:",squash"` Connector uint16 diff --git a/charger/phoenix-em-eth.go b/charger/phoenix-em-eth.go index 5313f7359..e55cc57f1 100644 --- a/charger/phoenix-em-eth.go +++ b/charger/phoenix-em-eth.go @@ -37,7 +37,7 @@ func init() { //go:generate go tool decorate -f decoratePhoenixEMEth -b *PhoenixEMEth -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)" // NewPhoenixEMEthFromConfig creates a Phoenix charger from generic config -func NewPhoenixEMEthFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewPhoenixEMEthFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 180, } diff --git a/charger/phoenix-ev-eth.go b/charger/phoenix-ev-eth.go index 78b739f58..a76aeba3b 100644 --- a/charger/phoenix-ev-eth.go +++ b/charger/phoenix-ev-eth.go @@ -65,7 +65,7 @@ func init() { //go:generate go tool decorate -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(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewPhoenixEVEthFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 255, } diff --git a/charger/phoenix-ev-ser.go b/charger/phoenix-ev-ser.go index 6e6799072..ceadd9901 100644 --- a/charger/phoenix-ev-ser.go +++ b/charger/phoenix-ev-ser.go @@ -26,7 +26,7 @@ func init() { } // NewPhoenixEVSerFromConfig creates a Phoenix charger from generic config -func NewPhoenixEVSerFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewPhoenixEVSerFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ ID: 1, } diff --git a/charger/plugchoice.go b/charger/plugchoice.go index 3371002ab..5d1e2e195 100644 --- a/charger/plugchoice.go +++ b/charger/plugchoice.go @@ -51,7 +51,7 @@ func init() { } // NewPlugchoiceFromConfig creates a Plugchoice charger from generic config -func NewPlugchoiceFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewPlugchoiceFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string UUID string // kept for backward compatibility diff --git a/charger/pracht-alpha.go b/charger/pracht-alpha.go index 708d5d2fe..b47cc0a63 100644 --- a/charger/pracht-alpha.go +++ b/charger/pracht-alpha.go @@ -51,7 +51,7 @@ func init() { } // NewPrachtAlphaFromConfig creates a PrachtAlpha charger from generic config -func NewPrachtAlphaFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewPrachtAlphaFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { Connector uint16 modbus.Settings `mapstructure:",squash"` diff --git a/charger/pulsares.go b/charger/pulsares.go index 9257ede9f..14ceeb6d2 100644 --- a/charger/pulsares.go +++ b/charger/pulsares.go @@ -54,7 +54,7 @@ func init() { //go:generate go tool decorate -f decoratePulsares -b *Pulsares -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewPulsaresFromConfig creates a Pulsares charger from generic config -func NewPulsaresFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewPulsaresFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ ID: 1, } diff --git a/charger/pulsatrix.go b/charger/pulsatrix.go index 665aea049..9b6063f89 100644 --- a/charger/pulsatrix.go +++ b/charger/pulsatrix.go @@ -96,7 +96,7 @@ func init() { } // NewPulsatrixFromConfig creates a pulsatrix charger from generic config -func NewPulsatrixFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewPulsatrixFromConfig(other map[string]any) (api.Charger, error) { var cc struct { Host string } @@ -173,7 +173,7 @@ func (c *Pulsatrix) connect() error { // sync attempts synchronization with retry mechanism func (c *Pulsatrix) sync() error { - for i := 0; i < syncRetries; i++ { + for i := range syncRetries { if err := c.Enable(false); err == nil { return nil } diff --git a/charger/schneider-v3.go b/charger/schneider-v3.go index 41f1de5ad..66cf87e09 100644 --- a/charger/schneider-v3.go +++ b/charger/schneider-v3.go @@ -62,7 +62,7 @@ func init() { // https://download.schneider-electric.com/files?p_enDocType=Other+technical+guide&p_File_Name=GEX1969300-04.pdf&p_Doc_Ref=GEX1969300 // NewSchneiderV3FromConfig creates a Schneider charger from generic config -func NewSchneiderV3FromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSchneiderV3FromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 255, } diff --git a/charger/semp.go b/charger/semp.go index e8f00b515..13c4fc2b7 100644 --- a/charger/semp.go +++ b/charger/semp.go @@ -51,7 +51,7 @@ func init() { } // NewSEMPFromConfig creates a SEMP charger from generic config -func NewSEMPFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSEMPFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { URI string DeviceID string diff --git a/charger/semp_test.go b/charger/semp_test.go index 8ecb7c6d6..cb261ba47 100644 --- a/charger/semp_test.go +++ b/charger/semp_test.go @@ -255,8 +255,7 @@ func TestSEMPCharger(t *testing.T) { server := httptest.NewServer(handler) defer server.Close() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + ctx := t.Context() wb, err := NewSEMP(ctx, server.URL+"/semp", "F-12345678-ABCDEF123456-00", time.Second) require.NoError(t, err) @@ -323,8 +322,7 @@ func TestSEMPChargerOff(t *testing.T) { server := httptest.NewServer(handler) defer server.Close() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + ctx := t.Context() wb, err := NewSEMP(ctx, server.URL+"/semp", "F-12345678-ABCDEF123456-00", time.Second) require.NoError(t, err) @@ -376,8 +374,7 @@ func TestSEMPChargerReady(t *testing.T) { server := httptest.NewServer(handler) defer server.Close() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + ctx := t.Context() wb, err := NewSEMP(ctx, server.URL+"/semp", "F-12345678-ABCDEF123456-00", time.Second) require.NoError(t, err) @@ -405,8 +402,7 @@ func TestSEMPChargerPhases1p3p(t *testing.T) { server := httptest.NewServer(handler) defer server.Close() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + ctx := t.Context() wb, err := NewSEMP(ctx, server.URL+"/semp", "F-12345678-ABCDEF123456-00", time.Second) require.NoError(t, err) @@ -450,8 +446,7 @@ func TestSEMPChargerChargedEnergy(t *testing.T) { server := httptest.NewServer(handler) defer server.Close() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + ctx := t.Context() wb, err := NewSEMP(ctx, server.URL+"/semp", "F-12345678-ABCDEF123456-00", time.Second) require.NoError(t, err) @@ -496,8 +491,7 @@ func TestSEMPChargerAutoDetectDeviceID(t *testing.T) { server := httptest.NewServer(handler) defer server.Close() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + ctx := t.Context() // Create charger without deviceID - should auto-detect wb, err := NewSEMP(ctx, server.URL+"/semp", "", time.Second) diff --git a/charger/sgready-boost.go b/charger/sgready-boost.go index f7844de51..67eccb8cf 100644 --- a/charger/sgready-boost.go +++ b/charger/sgready-boost.go @@ -15,7 +15,7 @@ func init() { } // NewSgReadyBoostFromConfig creates an SG Ready charger with boost relay from generic config -func NewSgReadyBoostFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSgReadyBoostFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { embed `mapstructure:",squash"` Charger config.Typed diff --git a/charger/sgready.go b/charger/sgready.go index 7c7c53f2d..c57c4f550 100644 --- a/charger/sgready.go +++ b/charger/sgready.go @@ -55,7 +55,7 @@ const ( //go:generate go tool decorate -f decorateSgReady -b *SgReady -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Battery,Soc,func() (float64, error)" -t "api.SocLimiter,GetLimitSoc,func() (int64, error)" // NewSgReadyFromConfig creates an SG Ready configurable charger from generic config -func NewSgReadyFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSgReadyFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { embed `mapstructure:",squash"` SetMode plugin.Config diff --git a/charger/sigenergy.go b/charger/sigenergy.go index 2a70d246e..4aaa8be80 100644 --- a/charger/sigenergy.go +++ b/charger/sigenergy.go @@ -48,7 +48,7 @@ func init() { } // NewSigenergyFromConfig creates a new Sigenergy ModbusTCP charger -func NewSigenergyFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSigenergyFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 1, } diff --git a/charger/smaevcharger.go b/charger/smaevcharger.go index 9fd9f5d77..c3dae785a 100644 --- a/charger/smaevcharger.go +++ b/charger/smaevcharger.go @@ -50,7 +50,7 @@ func init() { } // NewSmaevchargerFromConfig creates a SMA EV Charger from generic config -func NewSmaevchargerFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewSmaevchargerFromConfig(other map[string]any) (api.Charger, error) { cc := struct { Uri string User string diff --git a/charger/smartevse.go b/charger/smartevse.go index a4d6a768e..dc219ad90 100644 --- a/charger/smartevse.go +++ b/charger/smartevse.go @@ -70,7 +70,7 @@ func init() { } // NewsmartEVSEFromConfig creates a new smartEVSE ModbusTCP charger -func NewsmartEVSEFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewsmartEVSEFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ ID: 1, } diff --git a/charger/solax.go b/charger/solax.go index 722a6bbb9..d52065355 100644 --- a/charger/solax.go +++ b/charger/solax.go @@ -63,16 +63,16 @@ func init() { registry.AddCtx("solax-g2", NewSolaxG2FromConfig) } -func NewSolaxG1FromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSolaxG1FromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { return NewSolaxFromConfig(ctx, other, true) } -func NewSolaxG2FromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSolaxG2FromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { return NewSolaxFromConfig(ctx, other, false) } // NewSolaxFromConfig creates a Solax charger from generic config -func NewSolaxFromConfig(ctx context.Context, other map[string]interface{}, isLegacyHw bool) (api.Charger, error) { +func NewSolaxFromConfig(ctx context.Context, other map[string]any, isLegacyHw bool) (api.Charger, error) { cc := modbus.Settings{ ID: 1, } diff --git a/charger/sungrow.go b/charger/sungrow.go index 493caaa6d..5e45be942 100644 --- a/charger/sungrow.go +++ b/charger/sungrow.go @@ -67,7 +67,7 @@ func init() { } // NewSungrowFromConfig creates a Sungrow charger from generic config -func NewSungrowFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSungrowFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.Settings{ ID: 248, } diff --git a/charger/switchsocket.go b/charger/switchsocket.go index cb0be805f..28f1971d5 100644 --- a/charger/switchsocket.go +++ b/charger/switchsocket.go @@ -21,7 +21,7 @@ type SwitchSocket struct { //go:generate go tool decorate -f decorateSwitchSocket -b *SwitchSocket -r api.Charger -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Battery,Soc,func() (float64, error)" -func NewSwitchSocketFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewSwitchSocketFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { var cc struct { embed `mapstructure:",squash"` Enabled plugin.Config diff --git a/charger/tapo.go b/charger/tapo.go index 2aa503f77..36b1e8436 100644 --- a/charger/tapo.go +++ b/charger/tapo.go @@ -17,7 +17,7 @@ func init() { } // NewTapoFromConfig creates a Tapo charger from generic config -func NewTapoFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewTapoFromConfig(other map[string]any) (api.Charger, error) { var cc struct { embed `mapstructure:",squash"` URI string diff --git a/charger/tasmota.go b/charger/tasmota.go index 37a05fd47..b446ffa4d 100644 --- a/charger/tasmota.go +++ b/charger/tasmota.go @@ -26,7 +26,7 @@ func init() { //go:generate go tool decorate -f decorateTasmota -b *Tasmota -r api.Charger -t "api.PhaseVoltages,Voltages,func() (float64, float64, float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" // NewTasmotaFromConfig creates a Tasmota charger from generic config -func NewTasmotaFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewTasmotaFromConfig(other map[string]any) (api.Charger, error) { cc := struct { embed `mapstructure:",squash"` URI string diff --git a/charger/template.go b/charger/template.go index e476d8a7c..da397b4d9 100644 --- a/charger/template.go +++ b/charger/template.go @@ -11,7 +11,7 @@ func init() { registry.AddCtx("template", NewChargerFromTemplateConfig) } -func NewChargerFromTemplateConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewChargerFromTemplateConfig(ctx context.Context, other map[string]any) (api.Charger, error) { instance, err := templates.RenderInstance(templates.Charger, other) if err != nil { return nil, err diff --git a/charger/tessie.go b/charger/tessie.go index c2676a56e..90feae559 100644 --- a/charger/tessie.go +++ b/charger/tessie.go @@ -24,7 +24,7 @@ func init() { registry.AddCtx("tessie", NewTessieFromConfig) } -func NewTessieFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewTessieFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { Vin string Token string diff --git a/charger/tplink.go b/charger/tplink.go index 6a4551788..27244f223 100644 --- a/charger/tplink.go +++ b/charger/tplink.go @@ -21,7 +21,7 @@ func init() { } // NewTPLinkFromConfig creates a TP-Link charger from generic config -func NewTPLinkFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewTPLinkFromConfig(other map[string]any) (api.Charger, error) { var cc struct { embed `mapstructure:",squash"` URI string diff --git a/charger/trydan.go b/charger/trydan.go index b8257a572..99e6dd827 100644 --- a/charger/trydan.go +++ b/charger/trydan.go @@ -52,7 +52,7 @@ func init() { } // NewTrydanFromConfig creates a Trydan charger from generic config -func NewTrydanFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewTrydanFromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string Cache time.Duration diff --git a/charger/twc3.go b/charger/twc3.go index 456992c9b..9d113dde5 100644 --- a/charger/twc3.go +++ b/charger/twc3.go @@ -55,7 +55,7 @@ type Vitals struct { } // NewTwc3FromConfig creates a new charger -func NewTwc3FromConfig(other map[string]interface{}) (api.Charger, error) { +func NewTwc3FromConfig(other map[string]any) (api.Charger, error) { cc := struct { URI string Cache time.Duration diff --git a/charger/vaillant.go b/charger/vaillant.go index 12f53a1bd..09148aae3 100644 --- a/charger/vaillant.go +++ b/charger/vaillant.go @@ -46,7 +46,7 @@ type Vaillant struct { //go:generate go tool decorate -f decorateVaillant -b *Vaillant -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.Battery,Soc,func() (float64, error)" // NewVaillantFromConfig creates an Vaillant configurable charger from generic config -func NewVaillantFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewVaillantFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { embed `mapstructure:",squash"` User, Password string diff --git a/charger/vehicle-api.go b/charger/vehicle-api.go index 5932c575a..dbc2cb9e2 100644 --- a/charger/vehicle-api.go +++ b/charger/vehicle-api.go @@ -25,7 +25,7 @@ func init() { } // NewVehicleApiFromConfig creates a new vehicle-api charger -func NewVehicleApiFromConfig(other map[string]interface{}) (api.Charger, error) { +func NewVehicleApiFromConfig(other map[string]any) (api.Charger, error) { cc := struct { GeofenceEnabled bool `mapstructure:"geofence_enabled"` Lat float64 `mapstructure:"lat"` diff --git a/charger/versicharge.go b/charger/versicharge.go index 1a2a70350..7eef4da12 100644 --- a/charger/versicharge.go +++ b/charger/versicharge.go @@ -60,7 +60,7 @@ func init() { } // NewVersichargeFromConfig creates a Versicharge charger from generic config -func NewVersichargeFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewVersichargeFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 2, } diff --git a/charger/vestel.go b/charger/vestel.go index 832d75c34..6833c811f 100644 --- a/charger/vestel.go +++ b/charger/vestel.go @@ -72,7 +72,7 @@ func init() { //go:generate go tool decorate -f decorateVestel -b *Vestel -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.PhaseGetter,GetPhases,func() (int, error)" -t "api.Identifier,Identify,func() (string, error)" // NewVestelFromConfig creates a Vestel charger from generic config -func NewVestelFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewVestelFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 255, } diff --git a/charger/victron.go b/charger/victron.go index 6f9d8ec2d..42090db7a 100644 --- a/charger/victron.go +++ b/charger/victron.go @@ -73,17 +73,17 @@ func init() { } // NewVictronGXFromConfig creates a ABB charger from generic config -func NewVictronGXFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewVictronGXFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { return NewVictronFromConfig(ctx, other, victronGX) } // NewVictronEVCSFromConfig creates a ABB charger from generic config -func NewVictronEVCSFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewVictronEVCSFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { return NewVictronFromConfig(ctx, other, victronEVCS) } // NewVictronFromConfig creates a ABB charger from generic config -func NewVictronFromConfig(ctx context.Context, other map[string]interface{}, regs victronRegs) (api.Charger, error) { +func NewVictronFromConfig(ctx context.Context, other map[string]any, regs victronRegs) (api.Charger, error) { cc := modbus.TcpSettings{ ID: cast.ToUint8(regs.isGX) * 100, } diff --git a/charger/wallbe.go b/charger/wallbe.go index 4a73f99fb..4a7f25c2e 100644 --- a/charger/wallbe.go +++ b/charger/wallbe.go @@ -44,7 +44,7 @@ func init() { //go:generate go tool decorate -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(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewWallbeFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { URI string Legacy bool diff --git a/charger/warp2.go b/charger/warp2.go index 754fd6b0c..0b606002b 100644 --- a/charger/warp2.go +++ b/charger/warp2.go @@ -39,7 +39,7 @@ func init() { //go:generate go tool decorate -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" -t "api.PhaseGetter,GetPhases,func() (int, error)" // NewWarpFromConfig creates a new configurable charger -func NewWarp2FromConfig(other map[string]interface{}) (api.Charger, error) { +func NewWarp2FromConfig(other map[string]any) (api.Charger, error) { cc := struct { mqtt.Config `mapstructure:",squash"` Topic string diff --git a/charger/webasto-next.go b/charger/webasto-next.go index 455b9e67e..ddce64f28 100644 --- a/charger/webasto-next.go +++ b/charger/webasto-next.go @@ -56,7 +56,7 @@ func init() { } // NewWebastoNextFromConfig creates a WebastoNext charger from generic config -func NewWebastoNextFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewWebastoNextFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 255, } @@ -227,7 +227,7 @@ var _ api.PhaseCurrents = (*WebastoNext)(nil) // Currents implements the api.PhaseCurrents interface func (wb *WebastoNext) Currents() (float64, float64, float64, error) { var res [3]float64 - for l := uint16(0); l < 3; l++ { + for l := range uint16(3) { b, err := wb.conn.ReadInputRegisters(tqRegCurrents+2*l, 1) if err != nil { return 0, 0, 0, err diff --git a/charger/weidmüller.go b/charger/weidmüller.go index 0a1d08570..ca8c0ed14 100644 --- a/charger/weidmüller.go +++ b/charger/weidmüller.go @@ -58,7 +58,7 @@ func init() { } // NewWeidmüllerFromConfig creates a Weidmüller charger from generic config -func NewWeidmüllerFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewWeidmüllerFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := modbus.TcpSettings{ ID: 255, } diff --git a/charger/zaptec.go b/charger/zaptec.go index acdb06b6b..683bba0f4 100644 --- a/charger/zaptec.go +++ b/charger/zaptec.go @@ -58,7 +58,7 @@ func init() { //go:generate go tool decorate -f decorateZaptec -b *Zaptec -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" // NewZaptecFromConfig creates a Zaptec Pro charger from generic config -func NewZaptecFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) { +func NewZaptecFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) { cc := struct { User, Password string Id string diff --git a/cmd/configure/devicetest.go b/cmd/configure/devicetest.go index b035648ed..b5852fd4c 100644 --- a/cmd/configure/devicetest.go +++ b/cmd/configure/devicetest.go @@ -24,7 +24,7 @@ const ( type DeviceTest struct { DeviceCategory DeviceCategory Template templates.Template - ConfigValues map[string]interface{} + ConfigValues map[string]any } // Test returns: @@ -52,7 +52,7 @@ func (d *DeviceTest) Test() (DeviceTestResult, error) { } // configure creates a configured device from a template so we can test it -func (d *DeviceTest) configure() (interface{}, error) { +func (d *DeviceTest) configure() (any, error) { b, _, err := d.Template.RenderResult(templates.RenderModeInstance, d.ConfigValues) if err != nil { return nil, err @@ -60,14 +60,14 @@ func (d *DeviceTest) configure() (interface{}, error) { var instance struct { Type string - Other map[string]interface{} `yaml:",inline"` + Other map[string]any `yaml:",inline"` } if err := yaml.Unmarshal(b, &instance); err != nil { return nil, err } - var v interface{} + var v any ctx := context.TODO() switch DeviceCategories[d.DeviceCategory].class { @@ -83,7 +83,7 @@ func (d *DeviceTest) configure() (interface{}, error) { } // testCharger tests a charger device -func (d *DeviceTest) testCharger(v interface{}) (DeviceTestResult, error) { +func (d *DeviceTest) testCharger(v any) (DeviceTestResult, error) { c, ok := v.(api.Charger) if !ok { return DeviceTestResultInvalid, errors.New("selected device is not a wallbox") @@ -105,7 +105,7 @@ func (d *DeviceTest) testCharger(v interface{}) (DeviceTestResult, error) { } // testMeter tests a meter device -func (d *DeviceTest) testMeter(deviceCategory DeviceCategory, v interface{}) (DeviceTestResult, error) { +func (d *DeviceTest) testMeter(deviceCategory DeviceCategory, v any) (DeviceTestResult, error) { m, ok := v.(api.Meter) if !ok { return DeviceTestResultInvalid, errors.New("selected device is not a meter") @@ -145,7 +145,7 @@ func (d *DeviceTest) testMeter(deviceCategory DeviceCategory, v interface{}) (De } // testVehicle tests a vehicle device -func (d *DeviceTest) testVehicle(v interface{}) (DeviceTestResult, error) { +func (d *DeviceTest) testVehicle(v any) (DeviceTestResult, error) { vv, ok := v.(api.Vehicle) if !ok { return DeviceTestResultInvalid, errors.New("selected device is not a vehicle") diff --git a/cmd/configure/eebus.go b/cmd/configure/eebus.go index 5a48e322d..bba5e2a8e 100644 --- a/cmd/configure/eebus.go +++ b/cmd/configure/eebus.go @@ -9,7 +9,7 @@ import ( ) // configureEEBus setup EEBus -func (c *CmdConfigure) configureEEBus(other map[string]interface{}) error { +func (c *CmdConfigure) configureEEBus(other map[string]any) error { conf := eebus.Config{ URI: ":4712", } @@ -29,8 +29,8 @@ func (c *CmdConfigure) configureEEBus(other map[string]interface{}) error { } // eebusCertificate creates EEBUS certificate and returns private/public key -func (c *CmdConfigure) eebusCertificate() (map[string]interface{}, error) { - var eebusConfig map[string]interface{} +func (c *CmdConfigure) eebusCertificate() (map[string]any, error) { + var eebusConfig map[string]any cert, err := eebus.CreateCertificate() if err != nil { @@ -42,7 +42,7 @@ func (c *CmdConfigure) eebusCertificate() (map[string]interface{}, error) { return eebusConfig, fmt.Errorf("%s", c.localizedString("Error_EEBUS_Certificate_Use")) } - eebusConfig = map[string]interface{}{ + eebusConfig = map[string]any{ "certificate": map[string]string{ "public": pubKey, "private": privKey, diff --git a/cmd/configure/flow.go b/cmd/configure/flow.go index 9ae3b487d..5f6ebe16e 100644 --- a/cmd/configure/flow.go +++ b/cmd/configure/flow.go @@ -15,7 +15,7 @@ import ( func (c *CmdConfigure) configureDeviceGuidedSetup() { var err error - var values map[string]interface{} + var values map[string]any var deviceCategory DeviceCategory var supportedDeviceCategories []DeviceCategory var templateItem templates.Template diff --git a/cmd/configure/helper.go b/cmd/configure/helper.go index d09540f83..7a10769e1 100644 --- a/cmd/configure/helper.go +++ b/cmd/configure/helper.go @@ -32,7 +32,7 @@ func (c *CmdConfigure) processDeviceSelection(deviceCategory DeviceCategory) (te // processDeviceValues processes the user provided values, creates // a device configuration and check if it is a valid device -func (c *CmdConfigure) processDeviceValues(values map[string]interface{}, templateItem templates.Template, device device, deviceCategory DeviceCategory) (device, error) { +func (c *CmdConfigure) processDeviceValues(values map[string]any, templateItem templates.Template, device device, deviceCategory DeviceCategory) (device, error) { c.addedDeviceIndex++ device.Name = fmt.Sprintf("%s%d", DeviceCategories[deviceCategory].defaultName, c.addedDeviceIndex) @@ -226,7 +226,7 @@ func (c *CmdConfigure) askSponsortoken(required, feature bool) error { return err } -func (c *CmdConfigure) configureMQTT(_ templates.Template) (map[string]interface{}, error) { +func (c *CmdConfigure) configureMQTT(_ templates.Template) (map[string]any, error) { fmt.Println() fmt.Println("-- MQTT Broker ----------------------------") @@ -255,7 +255,7 @@ func (c *CmdConfigure) configureMQTT(_ templates.Template) (map[string]interface broker := fmt.Sprintf("%s:%s", host, port) - mqttConfig := map[string]interface{}{ + mqttConfig := map[string]any{ "broker": broker, "user": user, "password": password, @@ -351,7 +351,7 @@ func (c *CmdConfigure) paramChoiceValues(params []templates.Param, name string) // processConfig processes an EVCC configuration item // Returns a map with param name and values -func (c *CmdConfigure) processConfig(templateItem *templates.Template, deviceCategory DeviceCategory) map[string]interface{} { +func (c *CmdConfigure) processConfig(templateItem *templates.Template, deviceCategory DeviceCategory) map[string]any { fmt.Println() fmt.Println(c.localizedString("Config_Title")) fmt.Println() @@ -362,10 +362,10 @@ func (c *CmdConfigure) processConfig(templateItem *templates.Template, deviceCat } // process a list of params -func (c *CmdConfigure) processParams(templateItem *templates.Template, deviceCategory DeviceCategory) map[string]interface{} { +func (c *CmdConfigure) processParams(templateItem *templates.Template, deviceCategory DeviceCategory) map[string]any { usageFilter := DeviceCategories[deviceCategory].categoryFilter - additionalConfig := make(map[string]interface{}) + additionalConfig := make(map[string]any) for _, param := range templateItem.Params { switch param.Name { @@ -491,7 +491,7 @@ func (c *CmdConfigure) processModbusConfig(templateItem *templates.Template) { index, _ = c.askChoice(c.localizedString("Config_ModbusInterface"), choices) } - values := make(map[string]interface{}) + values := make(map[string]any) templateItem.Params[modbusIndex].Value = choiceTypes[index] // add the interface type specific modbus params diff --git a/cmd/configure/survey.go b/cmd/configure/survey.go index a256fa7aa..6055adfd2 100644 --- a/cmd/configure/survey.go +++ b/cmd/configure/survey.go @@ -17,7 +17,7 @@ import ( ) // surveyAskOne asks the user for input -func (c *CmdConfigure) surveyAskOne(p survey.Prompt, response interface{}, opts ...survey.AskOpt) error { +func (c *CmdConfigure) surveyAskOne(p survey.Prompt, response any, opts ...survey.AskOpt) error { opts = append(opts, survey.WithIcons(func(icons *survey.IconSet) { icons.Question.Text = "" })) @@ -180,7 +180,7 @@ func (c *CmdConfigure) askValue(q question) string { return chargingModes[modeChoice] } - validate := func(val interface{}) error { + validate := func(val any) error { value := val.(string) if q.invalidValues != nil && slices.Contains(q.invalidValues, value) { return errors.New(c.localizedString("ValueError_Used")) diff --git a/cmd/configure/types.go b/cmd/configure/types.go index c8c6fd61a..646b9642c 100644 --- a/cmd/configure/types.go +++ b/cmd/configure/types.go @@ -76,4 +76,4 @@ var DeviceCategories = map[DeviceCategory]DeviceCategoryData{ }, } -type localizeMap map[string]interface{} +type localizeMap map[string]any diff --git a/cmd/detect/analyze.go b/cmd/detect/analyze.go index 2c4ff63e9..c983b440b 100644 --- a/cmd/detect/analyze.go +++ b/cmd/detect/analyze.go @@ -2,7 +2,7 @@ package detect import "github.com/evcc-io/evcc/cmd/detect/tasks" -type Criteria map[string]interface{} +type Criteria map[string]any type TypeSummary struct { Results []tasks.Result diff --git a/cmd/detect/definitions.go b/cmd/detect/definitions.go index f3c025923..fa3c771c2 100644 --- a/cmd/detect/definitions.go +++ b/cmd/detect/definitions.go @@ -64,7 +64,7 @@ func init() { ID: TaskModbus, Type: tasks.Tcp, Depends: TaskPing, - Config: map[string]interface{}{ + Config: map[string]any{ "ports": []int{502, 1502}, }, }) @@ -73,7 +73,7 @@ func init() { ID: TaskSunspec, Type: tasks.Modbus, Depends: TaskModbus, - Config: map[string]interface{}{ + Config: map[string]any{ "ids": sunspecIDs, "models": []int{1}, "point": "Mn", @@ -84,7 +84,7 @@ func init() { ID: taskInverter, Type: tasks.Modbus, Depends: TaskSunspec, - Config: map[string]interface{}{ + Config: map[string]any{ "ids": sunspecIDs, "models": []int{101, 103}, "point": "W", @@ -96,7 +96,7 @@ func init() { ID: taskStrings, Type: tasks.Modbus, Depends: TaskSunspec, - Config: map[string]interface{}{ + Config: map[string]any{ "ids": sunspecIDs, "models": []int{160}, "point": "N", @@ -108,7 +108,7 @@ func init() { ID: taskBattery, Type: tasks.Modbus, Depends: TaskSunspec, - Config: map[string]interface{}{ + Config: map[string]any{ "ids": sunspecIDs, "models": []int{124}, "point": "ChaSt", @@ -120,7 +120,7 @@ func init() { ID: taskMeter, Type: tasks.Modbus, Depends: TaskSunspec, - Config: map[string]interface{}{ + Config: map[string]any{ "ids": sunspecIDs, "models": []int{201, 203, 211, 213}, "point": "W", @@ -131,7 +131,7 @@ func init() { ID: taskE3DC, Type: tasks.Modbus, Depends: TaskModbus, - Config: map[string]interface{}{ + Config: map[string]any{ "ids": []int{1, 2, 3, 4, 5, 6}, "address": 40000, "type": "holding", @@ -144,7 +144,7 @@ func init() { ID: taskWallbe, Type: tasks.Modbus, Depends: TaskModbus, - Config: map[string]interface{}{ + Config: map[string]any{ "ids": []int{255}, "address": 100, "type": "input", @@ -157,7 +157,7 @@ func init() { ID: taskPhoenixEMEth, Type: tasks.Modbus, Depends: TaskModbus, - Config: map[string]interface{}{ + Config: map[string]any{ "ids": []int{180}, "address": 100, "type": "input", @@ -170,7 +170,7 @@ func init() { ID: taskPhoenixEVEth, Type: tasks.Modbus, Depends: TaskModbus, - Config: map[string]interface{}{ + Config: map[string]any{ "ids": []int{255}, "address": 100, "type": "input", @@ -183,7 +183,7 @@ func init() { ID: taskOpenwb, Type: tasks.Mqtt, Depends: TaskPing, - Config: map[string]interface{}{ + Config: map[string]any{ "topic": "openWB", }, }) @@ -192,7 +192,7 @@ func init() { ID: TaskHttp, Type: tasks.Tcp, Depends: TaskPing, - Config: map[string]interface{}{ + Config: map[string]any{ "ports": []int{80, 443}, }, }) @@ -201,7 +201,7 @@ func init() { ID: taskGoE, Type: tasks.Http, Depends: TaskHttp, - Config: map[string]interface{}{ + Config: map[string]any{ "path": "/status", "jq": ".car", }, @@ -211,7 +211,7 @@ func init() { ID: taskEVSEWifi, Type: tasks.Http, Depends: TaskHttp, - Config: map[string]interface{}{ + Config: map[string]any{ "path": "/getParameters", "jq": ".type", }, @@ -221,7 +221,7 @@ func init() { ID: taskSonnen, Type: tasks.Http, Depends: TaskPing, - Config: map[string]interface{}{ + Config: map[string]any{ "port": 8080, "path": "/api/v1/status", "jq": ".GridFeedIn_W", @@ -232,7 +232,7 @@ func init() { ID: taskPowerwall, Type: tasks.Http, Depends: TaskHttp, - Config: map[string]interface{}{ + Config: map[string]any{ "path": "/api/meters/aggregates", "jq": ".load", }, @@ -242,7 +242,7 @@ func init() { ID: taskFroniusWeb, Type: tasks.Http, Depends: TaskHttp, - Config: map[string]interface{}{ + Config: map[string]any{ "path": "/solar_api/GetAPIVersion.cgi", "jq": ".BaseURL", }, @@ -252,7 +252,7 @@ func init() { ID: taskTasmota, Type: tasks.Http, Depends: TaskHttp, - Config: map[string]interface{}{ + Config: map[string]any{ "path": "/cm?cmnd=Module", "jq": ".Module", }, @@ -273,7 +273,7 @@ func init() { ID: "volkszähler", Type: tasks.Http, Depends: TaskHttp, - Config: map[string]interface{}{ + Config: map[string]any{ "path": "/middleware.php/entity.json", "jq": ".version", }, @@ -283,7 +283,7 @@ func init() { ID: taskShelly, Type: tasks.Http, Depends: TaskHttp, - Config: map[string]interface{}{ + Config: map[string]any{ "path": "/shelly", "jq": ".type", }, diff --git a/cmd/detect/tasks/http.go b/cmd/detect/tasks/http.go index 794bb8733..7d24dc976 100644 --- a/cmd/detect/tasks/http.go +++ b/cmd/detect/tasks/http.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "net/http" + "slices" "strings" "time" @@ -19,10 +20,10 @@ func init() { } type HttpResult struct { - Jq interface{} + Jq any } -func HttpHandlerFactory(conf map[string]interface{}) (TaskHandler, error) { +func HttpHandlerFactory(conf map[string]any) (TaskHandler, error) { handler := HttpHandler{ Schema: "http", Method: "GET", @@ -93,15 +94,7 @@ func (h *HttpHandler) Test(log *util.Logger, in ResultDetails) []ResultDetails { defer resp.Body.Close() if len(h.Codes) > 0 { - var status bool - for _, code := range h.Codes { - if resp.StatusCode == code { - status = true - break - } - } - - if !status { + if !slices.Contains(h.Codes, resp.StatusCode) { return nil } } diff --git a/cmd/detect/tasks/keba.go b/cmd/detect/tasks/keba.go index fc1b40500..12c1c994e 100644 --- a/cmd/detect/tasks/keba.go +++ b/cmd/detect/tasks/keba.go @@ -18,7 +18,7 @@ type KebaResult struct { Addr, Serial string } -func KEBAHandlerFactory(conf map[string]interface{}) (TaskHandler, error) { +func KEBAHandlerFactory(conf map[string]any) (TaskHandler, error) { handler := KEBAHandler{ Timeout: 5 * timeout, } diff --git a/cmd/detect/tasks/modbus.go b/cmd/detect/tasks/modbus.go index 7548c019b..5769ad5d5 100644 --- a/cmd/detect/tasks/modbus.go +++ b/cmd/detect/tasks/modbus.go @@ -23,14 +23,14 @@ func init() { type ModbusResult struct { SlaveID uint8 - Model int `json:",omitempty"` - Point string `json:",omitempty"` - Value interface{} `json:",omitempty"` + Model int `json:",omitempty"` + Point string `json:",omitempty"` + Value any `json:",omitempty"` } -func (r *ModbusResult) Configuration(handler TaskHandler, res Result) map[string]interface{} { +func (r *ModbusResult) Configuration(handler TaskHandler, res Result) map[string]any { port := handler.(*ModbusHandler).Port - cc := map[string]interface{}{ + cc := map[string]any{ "uri": net.JoinHostPort(res.ResultDetails.IP, strconv.Itoa(port)), "model": "sunspec", "id": r.SlaveID, @@ -39,7 +39,7 @@ func (r *ModbusResult) Configuration(handler TaskHandler, res Result) map[string return cc } -func ModbusHandlerFactory(conf map[string]interface{}) (TaskHandler, error) { +func ModbusHandlerFactory(conf map[string]any) (TaskHandler, error) { handler := ModbusHandler{ // Port: 502, IDs: []uint8{1}, diff --git a/cmd/detect/tasks/mqtt.go b/cmd/detect/tasks/mqtt.go index 70db7b105..f7d5c3f9b 100644 --- a/cmd/detect/tasks/mqtt.go +++ b/cmd/detect/tasks/mqtt.go @@ -16,7 +16,7 @@ func init() { registry.Add(Mqtt, MqttHandlerFactory) } -func MqttHandlerFactory(conf map[string]interface{}) (TaskHandler, error) { +func MqttHandlerFactory(conf map[string]any) (TaskHandler, error) { handler := MqttHandler{ Port: 1883, Timeout: timeout, diff --git a/cmd/detect/tasks/ping.go b/cmd/detect/tasks/ping.go index 255908afb..58c2d904f 100644 --- a/cmd/detect/tasks/ping.go +++ b/cmd/detect/tasks/ping.go @@ -14,7 +14,7 @@ func init() { registry.Add(Ping, PingHandlerFactory) } -func PingHandlerFactory(conf map[string]interface{}) (TaskHandler, error) { +func PingHandlerFactory(conf map[string]any) (TaskHandler, error) { handler := PingHandler{ Count: 1, Timeout: timeout, diff --git a/cmd/detect/tasks/registry.go b/cmd/detect/tasks/registry.go index 01f24f830..3e7bd026e 100644 --- a/cmd/detect/tasks/registry.go +++ b/cmd/detect/tasks/registry.go @@ -4,11 +4,11 @@ import ( "fmt" ) -type TaskHandlerRegistry map[TaskType]func(map[string]interface{}) (TaskHandler, error) +type TaskHandlerRegistry map[TaskType]func(map[string]any) (TaskHandler, error) -var registry TaskHandlerRegistry = make(map[TaskType]func(map[string]interface{}) (TaskHandler, error)) +var registry TaskHandlerRegistry = make(map[TaskType]func(map[string]any) (TaskHandler, error)) -func (r TaskHandlerRegistry) Add(name TaskType, factory func(map[string]interface{}) (TaskHandler, error)) { +func (r TaskHandlerRegistry) Add(name TaskType, factory func(map[string]any) (TaskHandler, error)) { if _, exists := r[name]; exists { panic(fmt.Sprintf("cannot register duplicate charger type: %s", name)) } @@ -23,7 +23,7 @@ func (r TaskHandlerRegistry) Add(name TaskType, factory func(map[string]interfac // return factory, nil // } -func Get(name TaskType) (func(map[string]interface{}) (TaskHandler, error), error) { +func Get(name TaskType) (func(map[string]any) (TaskHandler, error), error) { factory, exists := registry[name] if !exists { return nil, fmt.Errorf("charger type not registered: %s", name) diff --git a/cmd/detect/tasks/sma.go b/cmd/detect/tasks/sma.go index bd208a391..a3c91ef76 100644 --- a/cmd/detect/tasks/sma.go +++ b/cmd/detect/tasks/sma.go @@ -23,7 +23,7 @@ type SmaResult struct { Http bool } -func SMAHandlerFactory(conf map[string]interface{}) (TaskHandler, error) { +func SMAHandlerFactory(conf map[string]any) (TaskHandler, error) { handler := SMAHandler{ Timeout: 5 * time.Second, Password: "0000", diff --git a/cmd/detect/tasks/tcp.go b/cmd/detect/tasks/tcp.go index f1f1392d9..38a578af4 100644 --- a/cmd/detect/tasks/tcp.go +++ b/cmd/detect/tasks/tcp.go @@ -15,7 +15,7 @@ func init() { registry.Add(Tcp, TcpHandlerFactory) } -func TcpHandlerFactory(conf map[string]interface{}) (TaskHandler, error) { +func TcpHandlerFactory(conf map[string]any) (TaskHandler, error) { handler := TcpHandler{ Timeout: timeout, } diff --git a/cmd/detect/tasks/types.go b/cmd/detect/tasks/types.go index 759360e6a..36d222eb5 100644 --- a/cmd/detect/tasks/types.go +++ b/cmd/detect/tasks/types.go @@ -16,7 +16,7 @@ type ResultDetails struct { type Result struct { Task ResultDetails - Attributes map[string]interface{} // TODO remove, only used for post-processing + Attributes map[string]any // TODO remove, only used for post-processing } type TaskType string @@ -25,7 +25,7 @@ type Task struct { ID string Type TaskType Depends string - Config map[string]interface{} + Config map[string]any TaskHandler } diff --git a/cmd/detect/work.go b/cmd/detect/work.go index 0653180e9..3e0fcfc76 100644 --- a/cmd/detect/work.go +++ b/cmd/detect/work.go @@ -70,7 +70,7 @@ func postProcess(res []tasks.Result) []tasks.Result { // hit.Host = sma.Addr // } - hit.Attributes = make(map[string]interface{}) + hit.Attributes = make(map[string]any) flat, _ := flatten.Flatten(structs.Map(hit), "", flatten.DotStyle) for k, v := range flat { hit.Attributes[strings.ToLower(k)] = v diff --git a/cmd/dumper.go b/cmd/dumper.go index 197dc43a6..16e4b33c3 100644 --- a/cmd/dumper.go +++ b/cmd/dumper.go @@ -24,7 +24,7 @@ func (d *dumper) Header(name, underline string) { fmt.Println(strings.Repeat(underline, len(name))) } -func (d *dumper) DumpWithHeader(name string, device interface{}) { +func (d *dumper) DumpWithHeader(name string, device any) { if d.len > 1 { d.Header(name, "-") } @@ -62,7 +62,7 @@ func (d *dumper) measureTime(w *tabwriter.Writer, label string, fn func() (strin } } -func (d *dumper) Dump(name string, v interface{}) { +func (d *dumper) Dump(name string, v any) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) var isHeating bool @@ -303,7 +303,7 @@ func (d *dumper) Dump(name string, v interface{}) { w.Flush() } -func (d *dumper) DumpDiagnosis(v interface{}) { +func (d *dumper) DumpDiagnosis(v any) { w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0) if v, ok := v.(api.Diagnosis); ok { diff --git a/cmd/eebus.go b/cmd/eebus.go index 7a60723a9..808ad10b9 100644 --- a/cmd/eebus.go +++ b/cmd/eebus.go @@ -43,7 +43,7 @@ func generateEEBUSCert() { } t := template.Must(template.New("out").Funcs(sprig.FuncMap()).Parse(tmpl)) - if err := t.Execute(os.Stdout, map[string]interface{}{ + if err := t.Execute(os.Stdout, map[string]any{ "public": pubKey, "private": privKey, }); err != nil { diff --git a/cmd/helper.go b/cmd/helper.go index c09fd01aa..ae4a6a2e8 100644 --- a/cmd/helper.go +++ b/cmd/helper.go @@ -21,7 +21,7 @@ func parseLogLevels() { } var level string - for _, kv := range strings.Split(viper.GetString("log"), ",") { + for kv := range strings.SplitSeq(viper.GetString("log"), ",") { areaLevel := strings.SplitN(kv, ":", 2) if len(areaLevel) == 1 { level = areaLevel[0] diff --git a/cmd/setup.go b/cmd/setup.go index c15ec2497..e1a5a4c58 100644 --- a/cmd/setup.go +++ b/cmd/setup.go @@ -1056,7 +1056,7 @@ CONTINUE: return nil } -func configureSite(conf map[string]interface{}, loadpoints []*core.Loadpoint, tariffs *tariff.Tariffs) (*core.Site, error) { +func configureSite(conf map[string]any, loadpoints []*core.Loadpoint, tariffs *tariff.Tariffs) (*core.Site, error) { site, err := core.NewSiteFromConfig(conf) if err != nil { return site, err diff --git a/cmd/soc/main.go b/cmd/soc/main.go index 3f436b998..76b6e8e5c 100644 --- a/cmd/soc/main.go +++ b/cmd/soc/main.go @@ -34,7 +34,7 @@ func main() { log.Fatal("not enough arguments") } - params := make(map[string]interface{}) + params := make(map[string]any) params["brand"] = strings.ToLower(os.Args[1]) action := "soc" diff --git a/cmd/sunspec.go b/cmd/sunspec.go index d421182d2..e6bb9778a 100644 --- a/cmd/sunspec.go +++ b/cmd/sunspec.go @@ -31,7 +31,7 @@ func init() { slaveID = sunspecCmd.Flags().IntP("id", "i", 1, "Slave id") } -func pf(format string, v ...interface{}) { +func pf(format string, v ...any) { format = strings.TrimSuffix(format, "\n") + "\n" fmt.Printf(format, v...) } diff --git a/cmd/token_ford-connect.go b/cmd/token_ford-connect.go index 095ca1444..22a94c13b 100644 --- a/cmd/token_ford-connect.go +++ b/cmd/token_ford-connect.go @@ -16,7 +16,7 @@ func fordConnectToken(conf config.Named) (*oauth2.Token, error) { var cc struct { Credentials vehicle.ClientCredentials Tokens vehicle.Tokens - Other map[string]interface{} `mapstructure:",remain"` + Other map[string]any `mapstructure:",remain"` } if err := util.DecodeOther(conf.Other, &cc); err != nil { diff --git a/cmd/token_tronity.go b/cmd/token_tronity.go index a55b66048..209535da9 100644 --- a/cmd/token_tronity.go +++ b/cmd/token_tronity.go @@ -103,7 +103,7 @@ func tronityToken(conf globalconfig.All, vehicleConf config.Named) (*oauth2.Toke var cc struct { Credentials vehicle.ClientCredentials RedirectURI string - Other map[string]interface{} `mapstructure:",remain"` + Other map[string]any `mapstructure:",remain"` } if err := util.DecodeOther(vehicleConf.Other, &cc); err != nil { diff --git a/core/circuit/circuit.go b/core/circuit/circuit.go index 85ebea6ec..b40e7875d 100644 --- a/core/circuit/circuit.go +++ b/core/circuit/circuit.go @@ -43,7 +43,7 @@ type Circuit struct { } // NewFromConfig creates a new Circuit -func NewFromConfig(ctx context.Context, log *util.Logger, other map[string]interface{}) (api.Circuit, error) { +func NewFromConfig(ctx context.Context, log *util.Logger, other map[string]any) (api.Circuit, error) { cc := struct { Title string // title ParentRef string `mapstructure:"parent"` // parent circuit reference diff --git a/core/loadpoint.go b/core/loadpoint.go index 78f9b333a..d48475d01 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -179,7 +179,7 @@ type Loadpoint struct { } // NewLoadpointFromConfig creates a new loadpoint -func NewLoadpointFromConfig(log *util.Logger, settings settings.Settings, other map[string]interface{}) (*Loadpoint, error) { +func NewLoadpointFromConfig(log *util.Logger, settings settings.Settings, other map[string]any) (*Loadpoint, error) { lp := NewLoadpoint(log, settings) if err := util.DecodeOther(other, lp); err != nil { return nil, err @@ -440,7 +440,7 @@ func (lp *Loadpoint) pushEvent(event string) { } // publish sends values to UI and databases -func (lp *Loadpoint) publish(key string, val interface{}) { +func (lp *Loadpoint) publish(key string, val any) { // test helper if lp.uiChan == nil { return @@ -1368,10 +1368,7 @@ func (lp *Loadpoint) publishTimer(name string, delay time.Duration, action strin timer = lp.phaseTimer } - remaining := delay - lp.clock.Since(timer) - if remaining < 0 { - remaining = 0 - } + remaining := max(delay-lp.clock.Since(timer), 0) lp.publish(name+"Action", action) lp.publish(name+"Remaining", remaining) diff --git a/core/loadpoint_test.go b/core/loadpoint_test.go index a72d647c6..284518305 100644 --- a/core/loadpoint_test.go +++ b/core/loadpoint_test.go @@ -514,7 +514,7 @@ func TestSetModeAndSocAtDisconnect(t *testing.T) { } // cacheExpecter can be used to verify asynchronously written values from cache -func cacheExpecter(t *testing.T, lp *Loadpoint) (*util.ParamCache, func(key string, val interface{})) { +func cacheExpecter(t *testing.T, lp *Loadpoint) (*util.ParamCache, func(key string, val any)) { t.Helper() // attach cache for verifying values @@ -524,7 +524,7 @@ func cacheExpecter(t *testing.T, lp *Loadpoint) (*util.ParamCache, func(key stri cache := util.NewParamCache() go cache.Run(paramC) - expect := func(key string, val interface{}) { + expect := func(key string, val any) { time.Sleep(100 * time.Millisecond) // wait for cache to catch up p := cache.Get(key) diff --git a/core/optimizer.md b/core/optimizer.md new file mode 100644 index 000000000..beaa753a1 --- /dev/null +++ b/core/optimizer.md @@ -0,0 +1,41 @@ +# Optimizer + +Optimizer uses mixed integer linear programming (MILP) to minize a cost function. The optimizer model implementation honors: + +- energy consumption/ feed-in costs +- solar forecast +- base load (aka home) energy demand +- end of forecast commercial value +- strategy- either "charge before export" (charge loads as soon as possible) or "attenuate grid peaks" +- home battery or loadpoint/vehicle... + - capacity, soc and charge goals + - charge/discharge power limits and efficiency + +Optimization spans N slots with N being minimum of available forecast data. + +## Parameters + +### Energy consumption/ feed-in costs/ Solar forecast + +Grid/ feed-in/ solar tariff data. + +TODO + +- [ ] make feed-in optional +- [ ] make solar optional + +### Base load energy demand + +Collected 15min energy profile averaged over the last 30 days. + +### End of forecast commercial value + +Use minimum of energy consumption cost. + +### Home Battery + +### Loadpoint and Vehicles + +- home battery or loadpoint/vehicle... + - capacity, soc and charge goals + - charge/discharge power limits and efficiency diff --git a/core/session/db.go b/core/session/db.go index b1d785bdd..0765ebeca 100644 --- a/core/session/db.go +++ b/core/session/db.go @@ -52,7 +52,7 @@ func (s *DB) New(meter float64) *Session { } // Persist creates or updates a transaction in the database -func (s *DB) Persist(session interface{}) { +func (s *DB) Persist(session any) { if err := s.db.Save(session).Error; err != nil { s.log.ERROR.Printf("persist: %v", err) } @@ -68,7 +68,7 @@ func (s *DB) Sessions() (Sessions, error) { func (s *DB) ClosePendingSessionsInHistory(chargeMeterTotal float64) error { var res Sessions - if tx := s.db.Find(&res, map[string]interface{}{"finished": "0001-01-01 00:00:00+00:00", "Loadpoint": s.name}); tx.Error != nil { + if tx := s.db.Find(&res, map[string]any{"finished": "0001-01-01 00:00:00+00:00", "Loadpoint": s.name}); tx.Error != nil { return tx.Error } diff --git a/core/site.go b/core/site.go index 933115347..3199d3455 100644 --- a/core/site.go +++ b/core/site.go @@ -136,7 +136,7 @@ type MetersConfig struct { } // NewSiteFromConfig creates a new site -func NewSiteFromConfig(other map[string]interface{}) (*Site, error) { +func NewSiteFromConfig(other map[string]any) (*Site, error) { site := NewSite() // TODO remove @@ -483,7 +483,7 @@ func (site *Site) DumpConfig() { } // publish sends values to UI and databases -func (site *Site) publish(key string, val interface{}) { +func (site *Site) publish(key string, val any) { // test helper if site.uiChan == nil { return diff --git a/core/stats.go b/core/stats.go index d224e357e..cba371c3b 100644 --- a/core/stats.go +++ b/core/stats.go @@ -12,7 +12,7 @@ import ( // publisher gives access to the site's publish function type publisher interface { - publish(key string, val interface{}) + publish(key string, val any) } // Publishes long term charging statistics @@ -48,7 +48,7 @@ func (s *Stats) Update(p publisher) { func (s *Stats) calculate(fromDate time.Time) map[string]float64 { result := make(map[string]float64) - executeQuery := func(selectClause string, whereClause string, fromDate time.Time, dest interface{}) { + executeQuery := func(selectClause string, whereClause string, fromDate time.Time, dest any) { query := fmt.Sprintf(` SELECT COALESCE(%s, 0) FROM sessions diff --git a/hems/config.go b/hems/config.go index 4f7e9f5dc..4032ff189 100644 --- a/hems/config.go +++ b/hems/config.go @@ -16,7 +16,7 @@ type HEMS interface { } // NewFromConfig creates new HEMS from config -func NewFromConfig(ctx context.Context, typ string, other map[string]interface{}, site site.API) (HEMS, error) { +func NewFromConfig(ctx context.Context, typ string, other map[string]any, site site.API) (HEMS, error) { switch strings.ToLower(typ) { case "sma", "shm", "semp": return nil, errors.New("breaking change: Sunny Home Manager integration is always on. See https://github.com/evcc-io/evcc/releases and https://docs.evcc.io/en/docs/integrations/sma-sunny-home-manager") diff --git a/hems/eebus/eebus.go b/hems/eebus/eebus.go index 5bf3d12de..33fabf18f 100644 --- a/hems/eebus/eebus.go +++ b/hems/eebus/eebus.go @@ -44,7 +44,7 @@ type Limits struct { } // NewFromConfig creates an EEBus HEMS from generic config -func NewFromConfig(ctx context.Context, other map[string]interface{}, site site.API) (*EEBus, error) { +func NewFromConfig(ctx context.Context, other map[string]any, site site.API) (*EEBus, error) { cc := struct { Ski string Limits `mapstructure:",squash"` diff --git a/hems/relay/relay.go b/hems/relay/relay.go index 583f3fcc6..55dc51767 100644 --- a/hems/relay/relay.go +++ b/hems/relay/relay.go @@ -23,7 +23,7 @@ type Relay struct { } // NewFromConfig creates an Relay HEMS from generic config -func NewFromConfig(ctx context.Context, other map[string]interface{}, site site.API) (*Relay, error) { +func NewFromConfig(ctx context.Context, other map[string]any, site site.API) (*Relay, error) { cc := struct { MaxPower float64 Limit plugin.Config diff --git a/hems/shm/shm.go b/hems/shm/shm.go index 11a55f8ea..1f6ab010f 100644 --- a/hems/shm/shm.go +++ b/hems/shm/shm.go @@ -173,7 +173,7 @@ func (s *SEMP) handlers(router *mux.Router) { postRouter.HandleFunc("/", s.deviceControlHandler) } -func (s *SEMP) writeXML(w http.ResponseWriter, msg interface{}) { +func (s *SEMP) writeXML(w http.ResponseWriter, msg any) { s.log.TRACE.Printf("send: %+v", msg) b, err := xml.MarshalIndent(msg, "", " ") diff --git a/meter/bosch_bpts5_hybrid.go b/meter/bosch_bpts5_hybrid.go index 184b5f154..257e9dce9 100644 --- a/meter/bosch_bpts5_hybrid.go +++ b/meter/bosch_bpts5_hybrid.go @@ -49,7 +49,7 @@ func init() { //go:generate go tool decorate -f decorateBoschBpts5Hybrid -b api.Meter -t "api.Battery,Soc,func() (float64, error)" -t "api.BatteryCapacity,Capacity,func() float64" // NewBoschBpts5HybridFromConfig creates a Bosch BPT-S 5 Hybrid Meter from generic config -func NewBoschBpts5HybridFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewBoschBpts5HybridFromConfig(other map[string]any) (api.Meter, error) { var cc struct { batteryCapacity `mapstructure:",squash"` URI string diff --git a/meter/cfos.go b/meter/cfos.go index f5c9fc496..c350ef95f 100644 --- a/meter/cfos.go +++ b/meter/cfos.go @@ -28,7 +28,7 @@ func init() { } // NewCfosPowerBrainFromConfig creates a cFos meter from generic config -func NewCfosPowerBrainFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) { +func NewCfosPowerBrainFromConfig(ctx context.Context, other map[string]any) (api.Meter, error) { cc := modbus.TcpSettings{ ID: 1, } diff --git a/meter/config.go b/meter/config.go index 0810f0127..07d8c01c9 100644 --- a/meter/config.go +++ b/meter/config.go @@ -15,6 +15,6 @@ func Types() []string { } // NewFromConfig creates meter from configuration -func NewFromConfig(ctx context.Context, typ string, other map[string]interface{}) (api.Meter, error) { +func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.Meter, error) { return config.NewFromConfig(ctx, typ, other) } diff --git a/meter/config/config.go b/meter/config/config.go index 1ba8895c8..e8e593e5d 100644 --- a/meter/config/config.go +++ b/meter/config/config.go @@ -12,7 +12,7 @@ import ( var Registry = reg.New[api.Meter]("meter") // NewFromConfig creates meter from configuration -func NewFromConfig(ctx context.Context, typ string, other map[string]interface{}) (api.Meter, error) { +func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.Meter, error) { factory, err := Registry.Get(strings.ToLower(typ)) if err != nil { return nil, err diff --git a/meter/discovergy.go b/meter/discovergy.go index 5b4fb9e84..1c4c28bdb 100644 --- a/meter/discovergy.go +++ b/meter/discovergy.go @@ -22,7 +22,7 @@ type Discovergy struct { } // NewDiscovergyFromConfig creates a new configurable meter -func NewDiscovergyFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewDiscovergyFromConfig(other map[string]any) (api.Meter, error) { cc := struct { User string Password string diff --git a/meter/dsmr.go b/meter/dsmr.go index 9cca6eae1..8e0e65853 100644 --- a/meter/dsmr.go +++ b/meter/dsmr.go @@ -74,7 +74,7 @@ func init() { //go:generate go tool decorate -f decorateDsmr -b api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" // NewDsmrFromConfig creates a DSMR meter from generic config -func NewDsmrFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewDsmrFromConfig(other map[string]any) (api.Meter, error) { cc := struct { URI string Energy string diff --git a/meter/e3dc.go b/meter/e3dc.go index 8cc564b2a..118eefa49 100644 --- a/meter/e3dc.go +++ b/meter/e3dc.go @@ -31,7 +31,7 @@ func init() { //go:generate go tool decorate -f decorateE3dc -b *E3dc -r api.Meter -t "api.Battery,Soc,func() (float64, error)" -t "api.BatteryCapacity,Capacity,func() float64" -t "api.BatteryController,SetBatteryMode,func(api.BatteryMode) error" -t "api.MaxACPowerGetter,MaxACPower,func() float64" -func NewE3dcFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewE3dcFromConfig(other map[string]any) (api.Meter, error) { cc := struct { batteryCapacity `mapstructure:",squash"` pvMaxACPower `mapstructure:",squash"` diff --git a/meter/eebus.go b/meter/eebus.go index 2a8d83099..94c15df49 100644 --- a/meter/eebus.go +++ b/meter/eebus.go @@ -43,7 +43,7 @@ func init() { } // NewEEBusFromConfig creates an EEBus meter from generic config -func NewEEBusFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) { +func NewEEBusFromConfig(ctx context.Context, other map[string]any) (api.Meter, error) { cc := struct { Ski string Ip string diff --git a/meter/fritzdect.go b/meter/fritzdect.go index 925a13468..1a3f97d6c 100644 --- a/meter/fritzdect.go +++ b/meter/fritzdect.go @@ -14,7 +14,7 @@ func init() { } // NewFritzDECTFromConfig creates a fritzdect meter from generic config -func NewFritzDECTFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewFritzDECTFromConfig(other map[string]any) (api.Meter, error) { var cc fritzdect.Settings if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/goodwe-wifi.go b/meter/goodwe-wifi.go index fb123131a..402523395 100644 --- a/meter/goodwe-wifi.go +++ b/meter/goodwe-wifi.go @@ -22,7 +22,7 @@ func init() { // TODO deprecated remove -func NewGoodWeWifiFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewGoodWeWifiFromConfig(other map[string]any) (api.Meter, error) { cc := struct { batteryCapacity `mapstructure:",squash"` URI, Usage string diff --git a/meter/homeassistant.go b/meter/homeassistant.go index 3dcab2826..6dc31dda0 100644 --- a/meter/homeassistant.go +++ b/meter/homeassistant.go @@ -22,7 +22,7 @@ func init() { } // NewHomeAssistantFromConfig creates a HomeAssistant meter from generic config -func NewHomeAssistantFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewHomeAssistantFromConfig(other map[string]any) (api.Meter, error) { cc := struct { URI string Token string diff --git a/meter/homematic.go b/meter/homematic.go index 3b8f2b3b5..ef71a453d 100644 --- a/meter/homematic.go +++ b/meter/homematic.go @@ -19,7 +19,7 @@ func init() { } // NewCCUFromConfig creates a Homematic meter from generic config -func NewCCUFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewCCUFromConfig(other map[string]any) (api.Meter, error) { cc := struct { URI string Device string diff --git a/meter/homewizard.go b/meter/homewizard.go index 73233b4f1..7e72b7cd8 100644 --- a/meter/homewizard.go +++ b/meter/homewizard.go @@ -19,7 +19,7 @@ func init() { } // NewHomeWizardFromConfig creates a HomeWizard meter from generic config -func NewHomeWizardFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewHomeWizardFromConfig(other map[string]any) (api.Meter, error) { cc := struct { URI string Usage string diff --git a/meter/homewizard/connection.go b/meter/homewizard/connection.go index fde273f0d..526712ef9 100644 --- a/meter/homewizard/connection.go +++ b/meter/homewizard/connection.go @@ -67,7 +67,7 @@ func NewConnection(uri string, usage string, cache time.Duration) (*Connection, // Enable implements the api.Charger interface func (c *Connection) Enable(enable bool) error { var res StateResponse - data := map[string]interface{}{ + data := map[string]any{ "power_on": enable, } diff --git a/meter/lgess.go b/meter/lgess.go index 6a102d325..4962bbba8 100644 --- a/meter/lgess.go +++ b/meter/lgess.go @@ -24,16 +24,16 @@ func init() { //go:generate go tool decorate -f decorateLgEss -b *LgEss -r api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.BatteryCapacity,Capacity,func() float64" -t "api.Battery,Soc,func() (float64, error)" -t "api.BatterySocLimiter,GetSocLimits,func() (float64, float64)" -t "api.BatteryController,SetBatteryMode,func(api.BatteryMode) error" -func NewLgEss8FromConfig(other map[string]interface{}) (api.Meter, error) { +func NewLgEss8FromConfig(other map[string]any) (api.Meter, error) { return NewLgEssFromConfig(other, lgpcs.LgEss8) } -func NewLgEss15FromConfig(other map[string]interface{}) (api.Meter, error) { +func NewLgEss15FromConfig(other map[string]any) (api.Meter, error) { return NewLgEssFromConfig(other, lgpcs.LgEss15) } // NewLgEssFromConfig creates an LgEss Meter from generic config -func NewLgEssFromConfig(other map[string]interface{}, essType lgpcs.Model) (api.Meter, error) { +func NewLgEssFromConfig(other map[string]any, essType lgpcs.Model) (api.Meter, error) { cc := struct { batteryCapacity `mapstructure:",squash"` batterySocLimits `mapstructure:",squash"` diff --git a/meter/lgpcs/lgpcs.go b/meter/lgpcs/lgpcs.go index 3346809ba..bc4da3d0e 100644 --- a/meter/lgpcs/lgpcs.go +++ b/meter/lgpcs/lgpcs.go @@ -83,7 +83,7 @@ func (m *Com) Login() error { return errors.New("neither registration nor password provided - at least one needed") } - data := map[string]interface{}{ + data := map[string]any{ "password": m.password, } uri := fmt.Sprintf("%s/v1/user/setting/login", m.uri) diff --git a/meter/mbmd.go b/meter/mbmd.go index 848b27549..4ae89dd90 100644 --- a/meter/mbmd.go +++ b/meter/mbmd.go @@ -31,7 +31,7 @@ func init() { //go:generate go tool decorate -f decorateModbusMbmd -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" // NewModbusMbmdFromConfig creates api.Meter from config -func NewModbusMbmdFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) { +func NewModbusMbmdFromConfig(ctx context.Context, other map[string]any) (api.Meter, error) { cc := struct { Model string batteryCapacity `mapstructure:",squash"` diff --git a/meter/meter.go b/meter/meter.go index 6d5fc3c39..cd0fff31e 100644 --- a/meter/meter.go +++ b/meter/meter.go @@ -17,7 +17,7 @@ func init() { //go:generate go tool decorate -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.BatterySocLimiter,GetSocLimits,func() (float64, float64)" -t "api.BatteryPowerLimiter,GetPowerLimits,func() (float64, float64)" -t "api.BatteryController,SetBatteryMode,func(api.BatteryMode) error" -t "api.MaxACPowerGetter,MaxACPower,func() float64" // NewConfigurableFromConfig creates api.Meter from config -func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) { +func NewConfigurableFromConfig(ctx context.Context, other map[string]any) (api.Meter, error) { cc := struct { measurement.Energy `mapstructure:",squash"` // energy optional measurement.Phases `mapstructure:",squash"` // optional diff --git a/meter/meter_average.go b/meter/meter_average.go index 37605675d..d0a740e4c 100644 --- a/meter/meter_average.go +++ b/meter/meter_average.go @@ -12,13 +12,13 @@ func init() { } // NewMovingAverageFromConfig creates api.Meter from config -func NewMovingAverageFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) { +func NewMovingAverageFromConfig(ctx context.Context, other map[string]any) (api.Meter, error) { cc := struct { Decay float64 Meter struct { batteryCapacity `mapstructure:",squash"` Type string - Other map[string]interface{} `mapstructure:",remain"` + Other map[string]any `mapstructure:",remain"` } }{ Decay: 0.1, diff --git a/meter/mystrom.go b/meter/mystrom.go index cba5ac44c..293ff3808 100644 --- a/meter/mystrom.go +++ b/meter/mystrom.go @@ -14,7 +14,7 @@ func init() { } // NewMyStromFromConfig creates a myStrom meter from generic config -func NewMyStromFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewMyStromFromConfig(other map[string]any) (api.Meter, error) { var cc struct { URI string } diff --git a/meter/openwb.go b/meter/openwb.go index f93e3a908..8f5942af4 100644 --- a/meter/openwb.go +++ b/meter/openwb.go @@ -19,7 +19,7 @@ func init() { } // NewOpenWBFromConfig creates a new configurable meter -func NewOpenWBFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewOpenWBFromConfig(other map[string]any) (api.Meter, error) { cc := struct { mqtt.Config `mapstructure:",squash"` Topic string diff --git a/meter/powerwall.go b/meter/powerwall.go index d3ba54e86..a87bca9a8 100644 --- a/meter/powerwall.go +++ b/meter/powerwall.go @@ -34,7 +34,7 @@ func init() { //go:generate go tool decorate -f decoratePowerWall -b *PowerWall -r api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Battery,Soc,func() (float64, error)" -t "api.BatteryCapacity,Capacity,func() float64" -t "api.BatterySocLimiter,GetSocLimits,func() (float64, float64)" -t "api.BatteryPowerLimiter,GetPowerLimits,func() (float64, float64)" -t "api.BatteryController,SetBatteryMode,func(api.BatteryMode) error" // NewPowerWallFromConfig creates a PowerWall Powerwall Meter from generic config -func NewPowerWallFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewPowerWallFromConfig(other map[string]any) (api.Meter, error) { cc := struct { URI, Usage, User, Password string Cache time.Duration diff --git a/meter/rct.go b/meter/rct.go index cde79c50e..d1908af07 100644 --- a/meter/rct.go +++ b/meter/rct.go @@ -36,7 +36,7 @@ func init() { //go:generate go tool decorate -f decorateRCT -b *RCT -r api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Battery,Soc,func() (float64, error)" -t "api.BatterySocLimiter,GetSocLimits,func() (float64, float64)" -t "api.BatteryController,SetBatteryMode,func(api.BatteryMode) error" -t "api.BatteryCapacity,Capacity,func() float64" // NewRCTFromConfig creates an RCT from generic config -func NewRCTFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) { +func NewRCTFromConfig(ctx context.Context, other map[string]any) (api.Meter, error) { cc := struct { batteryCapacity `mapstructure:",squash"` batterySocLimits `mapstructure:",squash"` diff --git a/meter/sma.go b/meter/sma.go index 05dd8f21a..2ea449436 100644 --- a/meter/sma.go +++ b/meter/sma.go @@ -27,7 +27,7 @@ func init() { //go:generate go tool decorate -f decorateSMA -b *SMA -r api.Meter -t "api.Battery,Soc,func() (float64, error)" -t "api.BatteryCapacity,Capacity,func() float64" // NewSMAFromConfig creates an SMA meter from generic config -func NewSMAFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewSMAFromConfig(other map[string]any) (api.Meter, error) { cc := struct { batteryCapacity `mapstructure:",squash"` URI, Password, Interface string diff --git a/meter/tapo.go b/meter/tapo.go index 83c75d715..78b7fd627 100644 --- a/meter/tapo.go +++ b/meter/tapo.go @@ -12,7 +12,7 @@ func init() { } // NewTapoFromConfig creates a tapo meter from generic config -func NewTapoFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewTapoFromConfig(other map[string]any) (api.Meter, error) { var cc struct { URI string User string diff --git a/meter/template.go b/meter/template.go index 9a0d0f66c..5217d4759 100644 --- a/meter/template.go +++ b/meter/template.go @@ -11,7 +11,7 @@ func init() { registry.AddCtx("template", NewMeterFromTemplateConfig) } -func NewMeterFromTemplateConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) { +func NewMeterFromTemplateConfig(ctx context.Context, other map[string]any) (api.Meter, error) { instance, err := templates.RenderInstance(templates.Meter, other) if err != nil { return nil, err diff --git a/meter/tibber-pulse.go b/meter/tibber-pulse.go index 181c0b7fe..b094051c3 100644 --- a/meter/tibber-pulse.go +++ b/meter/tibber-pulse.go @@ -47,7 +47,7 @@ type Tibber struct { data *util.Monitor[tibber.LiveMeasurement] } -func NewTibberFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) { +func NewTibberFromConfig(ctx context.Context, other map[string]any) (api.Meter, error) { cc := struct { Token string HomeID string diff --git a/meter/tplink.go b/meter/tplink.go index 86b429d94..6aa89b84e 100644 --- a/meter/tplink.go +++ b/meter/tplink.go @@ -11,7 +11,7 @@ func init() { } // NewTPLinkFromConfig creates a tapo meter from generic config -func NewTPLinkFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewTPLinkFromConfig(other map[string]any) (api.Meter, error) { var cc struct { URI string } diff --git a/meter/tplink/connection.go b/meter/tplink/connection.go index 1c31c2f21..cd7c2d316 100644 --- a/meter/tplink/connection.go +++ b/meter/tplink/connection.go @@ -32,7 +32,7 @@ func NewConnection(uri string) (*Connection, error) { } // ExecCmd executes an TP-Link Smart Home Protocol command and provides the response -func (d *Connection) ExecCmd(cmd string, res interface{}) error { +func (d *Connection) ExecCmd(cmd string, res any) error { // encode command message buf := bytes.NewBuffer([]byte{0, 0, 0, 0}) var key byte = 171 // initialization vector diff --git a/meter/tq-em.go b/meter/tq-em.go index 1392e33af..ac7c8aa36 100644 --- a/meter/tq-em.go +++ b/meter/tq-em.go @@ -57,7 +57,7 @@ type TqEm struct { //go:generate go tool decorate -f decorateTqEm -b api.Meter -t "api.PhaseCurrents,Currents,func() (float64, float64, float64, error)" // NewTqEmFromConfig creates a new configurable meter -func NewTqEmFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewTqEmFromConfig(other map[string]any) (api.Meter, error) { cc := struct { URI string Password string diff --git a/meter/tq-em420.go b/meter/tq-em420.go index 4697c7680..450efd547 100644 --- a/meter/tq-em420.go +++ b/meter/tq-em420.go @@ -93,7 +93,7 @@ type TqEM420 struct { } // NewTqEm420FromConfig creates a new configurable meter -func NewTqEm420FromConfig(other map[string]interface{}) (api.Meter, error) { +func NewTqEm420FromConfig(other map[string]any) (api.Meter, error) { cc := struct { URI string Token string diff --git a/meter/zendure.go b/meter/zendure.go index 295245a17..5c9c82f0e 100644 --- a/meter/zendure.go +++ b/meter/zendure.go @@ -22,7 +22,7 @@ type Zendure struct { //go:generate go tool decorate -f decorateZendure -b *Zendure -r api.Meter -t "api.Battery,Soc,func() (float64, error)" -t "api.BatteryCapacity,Capacity,func() float64" // NewZendureFromConfig creates a Zendure meter from generic config -func NewZendureFromConfig(other map[string]interface{}) (api.Meter, error) { +func NewZendureFromConfig(other map[string]any) (api.Meter, error) { cc := struct { batteryCapacity `mapstructure:",squash"` Usage, Account, Serial, Region string diff --git a/plugin/calc.go b/plugin/calc.go index 48d374543..c14d20f00 100644 --- a/plugin/calc.go +++ b/plugin/calc.go @@ -19,7 +19,7 @@ func init() { } // NewCalcFromConfig creates calc provider -func NewCalcFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewCalcFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Add []Config Mul []Config diff --git a/plugin/charger.go b/plugin/charger.go index 07e2f4a31..256e97713 100644 --- a/plugin/charger.go +++ b/plugin/charger.go @@ -19,7 +19,7 @@ func init() { } // NewChargerEnableFromConfig creates type conversion provider -func NewChargerEnableFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewChargerEnableFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Config config.Typed } diff --git a/plugin/combined.go b/plugin/combined.go index c43b111ea..04c817a6c 100644 --- a/plugin/combined.go +++ b/plugin/combined.go @@ -19,7 +19,7 @@ type combinedPlugin struct { } // NewCombinedFromConfig creates combined provider -func NewCombinedFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewCombinedFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Plugged, Charging Config } diff --git a/plugin/config.go b/plugin/config.go index 7a9425477..47d7453ab 100644 --- a/plugin/config.go +++ b/plugin/config.go @@ -12,7 +12,7 @@ var registry = reg.New[Plugin]("plugin") // plugin types type ( - Plugin interface{} + Plugin any Getters interface { StringGetter FloatGetter diff --git a/plugin/const.go b/plugin/const.go index c5ea8be5d..1805e5f49 100644 --- a/plugin/const.go +++ b/plugin/const.go @@ -21,7 +21,7 @@ func init() { } // NewConstFromConfig creates const provider -func NewConstFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewConstFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Value string pipeline.Settings `mapstructure:",squash"` diff --git a/plugin/const_test.go b/plugin/const_test.go index 193b45b93..b0b1fff4a 100644 --- a/plugin/const_test.go +++ b/plugin/const_test.go @@ -8,7 +8,7 @@ import ( ) func TestConst(t *testing.T) { - p, err := NewConstFromConfig(context.TODO(), map[string]interface{}{"value": nil}) + p, err := NewConstFromConfig(context.TODO(), map[string]any{"value": nil}) assert.NoError(t, err) { diff --git a/plugin/convert.go b/plugin/convert.go index 9418a861e..59e6cd939 100644 --- a/plugin/convert.go +++ b/plugin/convert.go @@ -19,7 +19,7 @@ func init() { } // NewConvertFromConfig creates type conversion provider -func NewConvertFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewConvertFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { cc := convertPlugin{ ctx: ctx, } diff --git a/plugin/error.go b/plugin/error.go index 15babc2cd..a4aecd7c1 100644 --- a/plugin/error.go +++ b/plugin/error.go @@ -15,7 +15,7 @@ func init() { } // NewErrorFromConfig creates error provider -func NewErrorFromConfig(other map[string]interface{}) (Plugin, error) { +func NewErrorFromConfig(other map[string]any) (Plugin, error) { var cc struct { Error string } diff --git a/plugin/go.go b/plugin/go.go index d1ca2fa57..b2ad53022 100644 --- a/plugin/go.go +++ b/plugin/go.go @@ -25,7 +25,7 @@ func init() { } // NewGoPluginFromConfig creates a Go provider -func NewGoPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewGoPluginFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { VM string Script string diff --git a/plugin/helper.go b/plugin/helper.go index b1048d980..8718c22d9 100644 --- a/plugin/helper.go +++ b/plugin/helper.go @@ -11,12 +11,12 @@ import ( ) // setFormattedValue formats a message template or returns the value formatted as %v if the message template is empty -func setFormattedValue(message, param string, v interface{}) (string, error) { +func setFormattedValue(message, param string, v any) (string, error) { if message == "" { return fmt.Sprintf("%v", v), nil } - return util.ReplaceFormatted(message, map[string]interface{}{ + return util.ReplaceFormatted(message, map[string]any{ param: v, }) } diff --git a/plugin/http.go b/plugin/http.go index 40641d646..edb7263cf 100644 --- a/plugin/http.go +++ b/plugin/http.go @@ -35,7 +35,7 @@ func init() { var mc = httpcache.NewMemoryCache() // NewHTTPPluginFromConfig creates a HTTP provider -func NewHTTPPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewHTTPPluginFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { cc := struct { URI, Method string Headers map[string]string @@ -197,7 +197,7 @@ func (p *HTTP) StringGetter() (func() (string, error), error) { }, nil } -func (p *HTTP) set(param string, val interface{}) error { +func (p *HTTP) set(param string, val any) error { url, err := setFormattedValue(p.url, param, val) if err != nil { return err diff --git a/plugin/ignore.go b/plugin/ignore.go index 1ec72b84e..9481c43b5 100644 --- a/plugin/ignore.go +++ b/plugin/ignore.go @@ -18,7 +18,7 @@ func init() { } // NewIgnoreFromConfig creates const provider -func NewIgnoreFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewIgnoreFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Error string Set Config diff --git a/plugin/javascript.go b/plugin/javascript.go index 89d38184f..3730a8423 100644 --- a/plugin/javascript.go +++ b/plugin/javascript.go @@ -24,7 +24,7 @@ func init() { } // NewJavascriptPluginFromConfig creates a Javascript provider -func NewJavascriptPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewJavascriptPluginFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { VM string Script string diff --git a/plugin/map.go b/plugin/map.go index de6c240c2..880285617 100644 --- a/plugin/map.go +++ b/plugin/map.go @@ -18,7 +18,7 @@ func init() { } // NewMapFromConfig creates type conversion provider -func NewMapFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewMapFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Values map[int64]int64 Get, Set Config diff --git a/plugin/meter.go b/plugin/meter.go index a423a11cf..99e3fbec8 100644 --- a/plugin/meter.go +++ b/plugin/meter.go @@ -21,7 +21,7 @@ func init() { } // NewMeterFromConfig creates type conversion provider -func NewMeterFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewMeterFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { cc := struct { Config config.Typed Method diff --git a/plugin/modbus.go b/plugin/modbus.go index f73f95e69..a3154b9bd 100644 --- a/plugin/modbus.go +++ b/plugin/modbus.go @@ -26,7 +26,7 @@ func init() { } // NewModbusFromConfig creates Modbus plugin -func NewModbusFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewModbusFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { cc := struct { modbus.Settings `mapstructure:",squash"` Register modbus.Register diff --git a/plugin/mqtt.go b/plugin/mqtt.go index 4abb66a2f..91f1617e7 100644 --- a/plugin/mqtt.go +++ b/plugin/mqtt.go @@ -26,7 +26,7 @@ func init() { } // NewMqttPluginFromConfig creates Mqtt provider -func NewMqttPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewMqttPluginFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { cc := struct { mqtt.Config `mapstructure:",squash"` Topic, Payload string // Payload only applies to setters diff --git a/plugin/mqtt/client.go b/plugin/mqtt/client.go index 8feb1f0bf..4afc5adba 100644 --- a/plugin/mqtt/client.go +++ b/plugin/mqtt/client.go @@ -173,7 +173,7 @@ func (m *Client) Cleanup(topic string, retained bool) error { } // Publish asynchronously publishes payload using client qos -func (m *Client) Publish(topic string, retained bool, payload interface{}) { +func (m *Client) Publish(topic string, retained bool, payload any) { go func() { ctx, cancel := context.WithTimeout(context.Background(), request.Timeout) defer cancel() diff --git a/plugin/pipeline/pipeline.go b/plugin/pipeline/pipeline.go index 1e2e1bc1a..5503a2960 100644 --- a/plugin/pipeline/pipeline.go +++ b/plugin/pipeline/pipeline.go @@ -195,13 +195,13 @@ func (p *Pipeline) Process(in []byte) ([]byte, error) { if p.jq != nil { if p.quote { - b = []byte(fmt.Sprintf("%q", string(b))) + b = fmt.Appendf(nil, "%q", string(b)) } v, err := jq.Query(p.jq, b) if err != nil { return b, backoff.Permanent(err) } - b = []byte(fmt.Sprintf("%v", v)) + b = fmt.Appendf(nil, "%v", v) } if p.unpack != "" { @@ -209,7 +209,7 @@ func (p *Pipeline) Process(in []byte) ([]byte, error) { if err != nil { return b, err } - b = []byte(fmt.Sprintf("%v", v)) + b = fmt.Appendf(nil, "%v", v) } if p.decode != "" { diff --git a/plugin/prometheus.go b/plugin/prometheus.go index 625978ee0..d3b8047c3 100644 --- a/plugin/prometheus.go +++ b/plugin/prometheus.go @@ -26,7 +26,7 @@ func init() { registry.Add("prometheus", NewPrometheusFromConfig) } -func NewPrometheusFromConfig(other map[string]interface{}) (Plugin, error) { +func NewPrometheusFromConfig(other map[string]any) (Plugin, error) { cc := struct { Uri, Query string Timeout time.Duration diff --git a/plugin/random.go b/plugin/random.go index 5b6040a75..f2a5ca497 100644 --- a/plugin/random.go +++ b/plugin/random.go @@ -18,7 +18,7 @@ func init() { } // NewRandomFromConfig creates random provider -func NewRandomFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewRandomFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Set Config } diff --git a/plugin/script.go b/plugin/script.go index bb523c3b8..a3c311ae0 100644 --- a/plugin/script.go +++ b/plugin/script.go @@ -31,7 +31,7 @@ func init() { } // NewScriptPluginFromConfig creates a script plugin. -func NewScriptPluginFromConfig(other map[string]interface{}) (Plugin, error) { +func NewScriptPluginFromConfig(other map[string]any) (Plugin, error) { cc := struct { Cmd string pipeline.Settings `mapstructure:",squash"` @@ -128,7 +128,7 @@ func (p *Script) StringGetter() (func() (string, error), error) { func scriptSetter[T any](p *Script, param string) (func(T) error, error) { return func(val T) error { - cmd, err := util.ReplaceFormatted(p.script, map[string]interface{}{ + cmd, err := util.ReplaceFormatted(p.script, map[string]any{ param: val, }) diff --git a/plugin/sequence.go b/plugin/sequence.go index 151099f92..4ebfb2db8 100644 --- a/plugin/sequence.go +++ b/plugin/sequence.go @@ -16,7 +16,7 @@ func init() { } // NewSequenceFromConfig creates sequence provider -func NewSequenceFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewSequenceFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Set []Config } diff --git a/plugin/sleep.go b/plugin/sleep.go index 2bba311b3..dd3c14d3e 100644 --- a/plugin/sleep.go +++ b/plugin/sleep.go @@ -16,7 +16,7 @@ func init() { } // NewSleepFromConfig creates sleep provider -func NewSleepFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewSleepFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Duration time.Duration } diff --git a/plugin/sma.go b/plugin/sma.go index 4a1399981..4dc2c3e00 100644 --- a/plugin/sma.go +++ b/plugin/sma.go @@ -21,7 +21,7 @@ func init() { } // NewSMAFromConfig creates SMA provider -func NewSMAFromConfig(other map[string]interface{}) (Plugin, error) { +func NewSMAFromConfig(other map[string]any) (Plugin, error) { cc := struct { URI, Password, Interface string Serial uint32 diff --git a/plugin/socket.go b/plugin/socket.go index ea3278550..4c11d4337 100644 --- a/plugin/socket.go +++ b/plugin/socket.go @@ -33,7 +33,7 @@ func init() { } // NewSocketPluginFromConfig creates a HTTP provider -func NewSocketPluginFromConfig(other map[string]interface{}) (Plugin, error) { +func NewSocketPluginFromConfig(other map[string]any) (Plugin, error) { cc := struct { URI string Headers map[string]string diff --git a/plugin/sunspec.go b/plugin/sunspec.go index 1813fbbb2..301cb56e9 100644 --- a/plugin/sunspec.go +++ b/plugin/sunspec.go @@ -29,7 +29,7 @@ func init() { } // NewModbusSunspecFromConfig creates Modbus plugin -func NewModbusSunspecFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewModbusSunspecFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { cc := struct { modbus.Settings `mapstructure:",squash"` Value []string diff --git a/plugin/switch.go b/plugin/switch.go index 7ba482fee..1f143226a 100644 --- a/plugin/switch.go +++ b/plugin/switch.go @@ -24,7 +24,7 @@ func init() { } // NewSwitchFromConfig creates switch provider -func NewSwitchFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewSwitchFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Switch []Case Default *Config diff --git a/plugin/timeseries.go b/plugin/timeseries.go index fe9ecb213..3c7fb1abd 100644 --- a/plugin/timeseries.go +++ b/plugin/timeseries.go @@ -16,7 +16,7 @@ func init() { } // TimeSeriesFromConfig creates timeseries plugin -func TimeSeriesFromConfig(_ context.Context, _ map[string]interface{}) (Plugin, error) { +func TimeSeriesFromConfig(_ context.Context, _ map[string]any) (Plugin, error) { return new(timeseriesPlugin), nil } diff --git a/plugin/valid.go b/plugin/valid.go index 32c30b359..a739d3de5 100644 --- a/plugin/valid.go +++ b/plugin/valid.go @@ -20,7 +20,7 @@ type validPlugin struct { } // NewValidFromConfig creates valid provider -func NewValidFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewValidFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Valid, Value Config } diff --git a/plugin/watchdog.go b/plugin/watchdog.go index 308efa377..4a2cf9872 100644 --- a/plugin/watchdog.go +++ b/plugin/watchdog.go @@ -27,7 +27,7 @@ func init() { } // NewWatchDogFromConfig creates watchDog provider -func NewWatchDogFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) { +func NewWatchDogFromConfig(ctx context.Context, other map[string]any) (Plugin, error) { var cc struct { Reset []string Initial *string diff --git a/push/config.go b/push/config.go index 364f39f0f..5d149e53c 100644 --- a/push/config.go +++ b/push/config.go @@ -16,7 +16,7 @@ type Messenger interface { var registry = reg.New[Messenger]("messenger") // NewFromConfig creates messenger from configuration -func NewFromConfig(ctx context.Context, typ string, other map[string]interface{}) (Messenger, error) { +func NewFromConfig(ctx context.Context, typ string, other map[string]any) (Messenger, error) { factory, err := registry.Get(strings.ToLower(typ)) if err != nil { return nil, err diff --git a/push/hub.go b/push/hub.go index 64c0fcc67..ba760edb9 100644 --- a/push/hub.go +++ b/push/hub.go @@ -63,7 +63,7 @@ func (h *Hub) Add(sender Messenger) { // apply applies the event template to the content to produce the actual message func (h *Hub) apply(ev Event, tmpl string) (string, error) { - attr := make(map[string]interface{}) + attr := make(map[string]any) // loadpoint id if ev.Loadpoint != nil { diff --git a/push/ntfy.go b/push/ntfy.go index c024ab5a5..d2a1331cf 100644 --- a/push/ntfy.go +++ b/push/ntfy.go @@ -22,7 +22,7 @@ type Ntfy struct { } // NewNtfyFromConfig creates new Ntfy messenger -func NewNtfyFromConfig(other map[string]interface{}) (Messenger, error) { +func NewNtfyFromConfig(other map[string]any) (Messenger, error) { var cc struct { URI string Priority string diff --git a/push/push.go b/push/push.go index e5949fe22..e882e8fdc 100644 --- a/push/push.go +++ b/push/push.go @@ -17,7 +17,7 @@ func init() { } // NewConfigurableFromConfig creates Messenger from config -func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (Messenger, error) { +func NewConfigurableFromConfig(ctx context.Context, other map[string]any) (Messenger, error) { var cc struct { Send plugin.Config Encoding string diff --git a/push/pushover.go b/push/pushover.go index 502e0b1da..b3d0a482e 100644 --- a/push/pushover.go +++ b/push/pushover.go @@ -21,7 +21,7 @@ type PushOver struct { } // NewPushOverFromConfig creates new pushover messenger -func NewPushOverFromConfig(other map[string]interface{}) (Messenger, error) { +func NewPushOverFromConfig(other map[string]any) (Messenger, error) { var cc struct { App string Recipients []string diff --git a/push/shoutrrr.go b/push/shoutrrr.go index 0c7414940..542a53a1c 100644 --- a/push/shoutrrr.go +++ b/push/shoutrrr.go @@ -19,7 +19,7 @@ type Shoutrrr struct { } // NewShoutrrrFromConfig creates new Shoutrrr messenger -func NewShoutrrrFromConfig(other map[string]interface{}) (Messenger, error) { +func NewShoutrrrFromConfig(other map[string]any) (Messenger, error) { var cc struct { URI string } diff --git a/push/telegram.go b/push/telegram.go index adecb8b43..5952b8e81 100644 --- a/push/telegram.go +++ b/push/telegram.go @@ -24,7 +24,7 @@ type Telegram struct { } // NewTelegramFromConfig creates new pushover messenger -func NewTelegramFromConfig(ctx context.Context, other map[string]interface{}) (Messenger, error) { +func NewTelegramFromConfig(ctx context.Context, other map[string]any) (Messenger, error) { var cc struct { Token string Chats []int64 @@ -43,7 +43,7 @@ func NewTelegramFromConfig(ctx context.Context, other map[string]interface{}) (M bot, err := bot.New(cc.Token, bot.WithDefaultHandler(m.handler), bot.WithErrorsHandler(func(err error) { log.ERROR.Println(err) - }), bot.WithDebugHandler(func(format string, args ...interface{}) { + }), bot.WithDebugHandler(func(format string, args ...any) { log.TRACE.Printf(format, args...) })) if err != nil { diff --git a/server/db/cache/cache.go b/server/db/cache/cache.go index e4175621d..5c7980613 100644 --- a/server/db/cache/cache.go +++ b/server/db/cache/cache.go @@ -21,7 +21,7 @@ func Init() error { return db.Instance.AutoMigrate(new(Cache)) } -func Put(key string, value interface{}) error { +func Put(key string, value any) error { data, err := json.Marshal(value) if err != nil { return err @@ -33,7 +33,7 @@ func Put(key string, value interface{}) error { }).Error } -func Get(key string, result interface{}) error { +func Get(key string, result any) error { var cacheEntry Cache err := db.Instance.First(&cacheEntry, "key = ?", key).Error diff --git a/server/db/log.go b/server/db/log.go index ed9ebf79f..4988a9dd8 100644 --- a/server/db/log.go +++ b/server/db/log.go @@ -16,15 +16,15 @@ func (l *Logger) LogMode(logger.LogLevel) logger.Interface { return l } -func (l *Logger) Info(_ context.Context, msg string, val ...interface{}) { +func (l *Logger) Info(_ context.Context, msg string, val ...any) { l.log.INFO.Printf(msg, val...) } -func (l *Logger) Warn(_ context.Context, msg string, val ...interface{}) { +func (l *Logger) Warn(_ context.Context, msg string, val ...any) { l.log.WARN.Printf(msg, val...) } -func (l *Logger) Error(_ context.Context, msg string, val ...interface{}) { +func (l *Logger) Error(_ context.Context, msg string, val ...any) { l.log.ERROR.Printf(msg, val...) } diff --git a/server/eebus/certificate.go b/server/eebus/certificate.go index 32509c818..f45c2fb3f 100644 --- a/server/eebus/certificate.go +++ b/server/eebus/certificate.go @@ -19,7 +19,7 @@ func CreateCertificate() (tls.Certificate, error) { } // pemBlockForKey marshals private key into pem block -func pemBlockForKey(priv interface{}) (*pem.Block, error) { +func pemBlockForKey(priv any) (*pem.Block, error) { switch k := priv.(type) { case *rsa.PrivateKey: return &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(k)}, nil diff --git a/server/eebus/eebus.go b/server/eebus/eebus.go index 4e97bb068..f3f340fef 100644 --- a/server/eebus/eebus.go +++ b/server/eebus/eebus.go @@ -306,34 +306,34 @@ func (c *EEBus) ServicePairingDetailUpdate(ski string, detail *shipapi.Connectio // EEBUS Logging interface -func (c *EEBus) Trace(args ...interface{}) { +func (c *EEBus) Trace(args ...any) { c.log.TRACE.Println(args...) } -func (c *EEBus) Tracef(format string, args ...interface{}) { +func (c *EEBus) Tracef(format string, args ...any) { c.log.TRACE.Printf(format, args...) } -func (c *EEBus) Debug(args ...interface{}) { +func (c *EEBus) Debug(args ...any) { c.log.DEBUG.Println(args...) } -func (c *EEBus) Debugf(format string, args ...interface{}) { +func (c *EEBus) Debugf(format string, args ...any) { c.log.DEBUG.Printf(format, args...) } -func (c *EEBus) Info(args ...interface{}) { +func (c *EEBus) Info(args ...any) { c.log.INFO.Println(args...) } -func (c *EEBus) Infof(format string, args ...interface{}) { +func (c *EEBus) Infof(format string, args ...any) { c.log.INFO.Printf(format, args...) } -func (c *EEBus) Error(args ...interface{}) { +func (c *EEBus) Error(args ...any) { c.log.ERROR.Println(args...) } -func (c *EEBus) Errorf(format string, args ...interface{}) { +func (c *EEBus) Errorf(format string, args ...any) { c.log.ERROR.Printf(format, args...) } diff --git a/server/http_config_device_handler.go b/server/http_config_device_handler.go index f3315233e..41732db63 100644 --- a/server/http_config_device_handler.go +++ b/server/http_config_device_handler.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "maps" "net/http" "reflect" "strconv" @@ -108,10 +109,7 @@ func deviceConfigMap[T any](class templates.Class, dev config.Device[T]) (map[st dc["config"] = params } else { // custom device, no masking - config := make(map[string]any) - for k, v := range conf.Other { - config[k] = v - } + config := maps.Clone(conf.Other) // extract title & icon if possible (user-defined vehicle embeds) if yamlStr, ok := conf.Other["yaml"].(string); ok && config["title"] == nil && config["icon"] == nil { @@ -299,7 +297,7 @@ func newDeviceHandler(w http.ResponseWriter, r *http.Request) { conf, err = newDevice(ctx, class, req, vehicle.NewFromConfig, config.Vehicles(), force) case templates.Circuit: - conf, err = newDevice(ctx, class, req, func(ctx context.Context, _ string, other map[string]interface{}) (api.Circuit, error) { + conf, err = newDevice(ctx, class, req, func(ctx context.Context, _ string, other map[string]any) (api.Circuit, error) { return circuit.NewFromConfig(ctx, util.NewLogger("circuit"), other) }, config.Circuits(), force) } @@ -380,7 +378,7 @@ func updateDeviceHandler(w http.ResponseWriter, r *http.Request) { err = updateDevice(ctx, id, class, req, vehicle.NewFromConfig, config.Vehicles(), force) case templates.Circuit: - err = updateDevice(ctx, id, class, req, func(ctx context.Context, _ string, other map[string]interface{}) (api.Circuit, error) { + err = updateDevice(ctx, id, class, req, func(ctx context.Context, _ string, other map[string]any) (api.Circuit, error) { return circuit.NewFromConfig(ctx, util.NewLogger("circuit"), other) }, config.Circuits(), force) } diff --git a/server/http_loadpoint_handler.go b/server/http_loadpoint_handler.go index 240faa428..a8deae57c 100644 --- a/server/http_loadpoint_handler.go +++ b/server/http_loadpoint_handler.go @@ -122,7 +122,7 @@ func repeatingPlanPreviewHandler(lp loadpoint.API) http.HandlerFunc { tz := vars["tz"] var weekdays []int - for _, weekdayStr := range strings.Split(vars["weekdays"], ",") { + for weekdayStr := range strings.SplitSeq(vars["weekdays"], ",") { weekday, err := strconv.Atoi(weekdayStr) if err != nil { jsonError(w, http.StatusBadRequest, fmt.Errorf("invalid weekdays format")) diff --git a/server/http_session_handler.go b/server/http_session_handler.go index 3fded984a..06697dfd2 100644 --- a/server/http_session_handler.go +++ b/server/http_session_handler.go @@ -119,13 +119,13 @@ func updateSessionHandler(w http.ResponseWriter, r *http.Request) { id := mux.Vars(r)["id"] - var data map[string]interface{} + var data map[string]any if err := json.NewDecoder(r.Body).Decode(&data); err != nil { jsonError(w, http.StatusBadRequest, errors.New("invalid JSON")) return } - updates := map[string]interface{}{} + updates := map[string]any{} for _, field := range []string{"vehicle", "loadpoint"} { if val, ok := data[field]; ok { updates[field] = val diff --git a/server/http_site_handler.go b/server/http_site_handler.go index 9d183af2a..f79cb1e38 100644 --- a/server/http_site_handler.go +++ b/server/http_site_handler.go @@ -62,7 +62,7 @@ func indexHandler(customCss bool) http.HandlerFunc { defaultLang := getPreferredLanguage(r.Header.Get("Accept-Language")) - if err := t.Execute(w, map[string]interface{}{ + if err := t.Execute(w, map[string]any{ "Version": util.Version, "Commit": util.Commit, "DefaultLang": defaultLang, @@ -81,7 +81,7 @@ func jsonHandler(h http.Handler) http.Handler { }) } -func jsonWrite(w http.ResponseWriter, data interface{}) { +func jsonWrite(w http.ResponseWriter, data any) { if err := json.NewEncoder(w).Encode(data); err != nil { log.ERROR.Printf("httpd: failed to encode JSON: %v", err) } diff --git a/server/modbus/handler.go b/server/modbus/handler.go index c972a8aaf..1d504f594 100644 --- a/server/modbus/handler.go +++ b/server/modbus/handler.go @@ -82,7 +82,7 @@ func (h *handler) bytesToBoolResult(op string, qty uint16, b []byte, err error) LOOP: for _, bb := range b { - for bit := 0; bit < 8; bit++ { + for bit := range 8 { if len(res) >= int(qty) { break LOOP } diff --git a/server/modbus/proxy_test.go b/server/modbus/proxy_test.go index 3c298de3a..313b75f1d 100644 --- a/server/modbus/proxy_test.go +++ b/server/modbus/proxy_test.go @@ -44,7 +44,7 @@ func TestConcurrentRead(t *testing.T) { require.NoError(t, err) if err == nil { - for u := uint16(0); u < qty; u++ { + for u := range qty { assert.Equal(t, addr^uint16(id)^u, binary.BigEndian.Uint16(b[2*u:])) } } diff --git a/server/mqtt.go b/server/mqtt.go index c1b60c7b1..d3556916c 100644 --- a/server/mqtt.go +++ b/server/mqtt.go @@ -53,7 +53,7 @@ func NewMQTT(root string, site site.API) (*MQTT, error) { return m, err } -func (m *MQTT) encode(v interface{}) string { +func (m *MQTT) encode(v any) string { // nil should erase the value if v == nil { return "" @@ -79,7 +79,7 @@ func (m *MQTT) encode(v interface{}) string { } } -func (m *MQTT) publishComplex(topic string, retained bool, payload interface{}) { +func (m *MQTT) publishComplex(topic string, retained bool, payload any) { if _, ok := payload.(fmt.Stringer); ok || payload == nil { m.publishSingleValue(topic, retained, payload) return @@ -157,11 +157,11 @@ func (m *MQTT) publishString(topic string, retained bool, payload string) { m.Handler.Publish(topic, retained, m.encode(payload)) } -func (m *MQTT) publishSingleValue(topic string, retained bool, payload interface{}) { +func (m *MQTT) publishSingleValue(topic string, retained bool, payload any) { m.publisher(topic, retained, m.encode(payload)) } -func (m *MQTT) publish(topic string, retained bool, payload interface{}) { +func (m *MQTT) publish(topic string, retained bool, payload any) { // publish phase values if slice, ok := payload.([]float64); ok && len(slice) == 3 { var total float64 diff --git a/server/mqtt_test.go b/server/mqtt_test.go index dca291425..4e1822cbe 100644 --- a/server/mqtt_test.go +++ b/server/mqtt_test.go @@ -36,7 +36,7 @@ type mqttSuite struct { topics, payloads []string } -func (suite *mqttSuite) publish(topic string, retained bool, payload interface{}) { +func (suite *mqttSuite) publish(topic string, retained bool, payload any) { suite.MQTT.publish(topic, retained, payload) } diff --git a/server/providerauth/handler.go b/server/providerauth/handler.go index da223a4db..a105f90a3 100644 --- a/server/providerauth/handler.go +++ b/server/providerauth/handler.go @@ -22,7 +22,7 @@ type loginResponse struct { } // jsonWrite writes a JSON response -func jsonWrite(w http.ResponseWriter, data interface{}) { +func jsonWrite(w http.ResponseWriter, data any) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(data) } diff --git a/server/socket_test.go b/server/socket_test.go index 5817c1284..c375335d9 100644 --- a/server/socket_test.go +++ b/server/socket_test.go @@ -13,7 +13,7 @@ func TestEncode(t *testing.T) { now := time.Now() tc := []struct { - in interface{} + in any out string }{ {int64(1), "1"}, @@ -35,7 +35,7 @@ func TestEncode(t *testing.T) { func TestEncodeSlice(t *testing.T) { tc := []struct { - in interface{} + in any out string }{ {[]string{"a", "b"}, `["a","b"]`}, diff --git a/server/updater/watch.go b/server/updater/watch.go index 41995d9f2..2b73d9e5e 100644 --- a/server/updater/watch.go +++ b/server/updater/watch.go @@ -20,7 +20,7 @@ type watch struct { repo *Repo } -func (u *watch) Send(key string, val interface{}) { +func (u *watch) Send(key string, val any) { u.outChan <- util.Param{ Key: key, Val: val, diff --git a/tariff/amber.go b/tariff/amber.go index f5b97a073..1df6588f1 100644 --- a/tariff/amber.go +++ b/tariff/amber.go @@ -31,7 +31,7 @@ func init() { registry.Add("amber", NewAmberFromConfig) } -func NewAmberFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewAmberFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { embed `mapstructure:",squash"` Token string diff --git a/tariff/awattar.go b/tariff/awattar.go index 036211928..9327d8d19 100644 --- a/tariff/awattar.go +++ b/tariff/awattar.go @@ -27,7 +27,7 @@ func init() { registry.Add("awattar", NewAwattarFromConfig) } -func NewAwattarFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewAwattarFromConfig(other map[string]any) (api.Tariff, error) { cc := struct { embed `mapstructure:",squash"` Region string diff --git a/tariff/config.go b/tariff/config.go index 650573531..96c1f6b9e 100644 --- a/tariff/config.go +++ b/tariff/config.go @@ -17,7 +17,7 @@ func Types() []string { } // NewFromConfig creates tariff from configuration -func NewFromConfig(ctx context.Context, typ string, other map[string]interface{}) (api.Tariff, error) { +func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.Tariff, error) { factory, err := registry.Get(strings.ToLower(typ)) if err != nil { return nil, err diff --git a/tariff/edf-tempo.go b/tariff/edf-tempo.go index 531b97bdc..3f0749e99 100644 --- a/tariff/edf-tempo.go +++ b/tariff/edf-tempo.go @@ -35,7 +35,7 @@ func init() { registry.Add("edf-tempo", NewEdfTempoFromConfig) } -func NewEdfTempoFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewEdfTempoFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { embed `mapstructure:",squash"` ClientID string diff --git a/tariff/electricitymaps.go b/tariff/electricitymaps.go index 132aa40da..fdf7ac9a0 100644 --- a/tariff/electricitymaps.go +++ b/tariff/electricitymaps.go @@ -40,7 +40,7 @@ func init() { registry.Add("electricitymaps", NewElectricityMapsFromConfig) } -func NewElectricityMapsFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewElectricityMapsFromConfig(other map[string]any) (api.Tariff, error) { cc := struct { Uri string Token string diff --git a/tariff/elering.go b/tariff/elering.go index cfa728856..f32d57ca3 100644 --- a/tariff/elering.go +++ b/tariff/elering.go @@ -29,7 +29,7 @@ func init() { registry.Add("elering", NewEleringFromConfig) } -func NewEleringFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewEleringFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { embed `mapstructure:",squash"` Region string diff --git a/tariff/entsoe.go b/tariff/entsoe.go index a7f2a9e30..a6152f733 100644 --- a/tariff/entsoe.go +++ b/tariff/entsoe.go @@ -32,7 +32,7 @@ func init() { registry.Add("entsoe", NewEntsoeFromConfig) } -func NewEntsoeFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewEntsoeFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { embed `mapstructure:",squash"` Securitytoken string diff --git a/tariff/fixed.go b/tariff/fixed.go index d0a5684ea..4c3e42e45 100644 --- a/tariff/fixed.go +++ b/tariff/fixed.go @@ -24,7 +24,7 @@ func init() { registry.Add("fixed", NewFixedFromConfig) } -func NewFixedFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewFixedFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { Price float64 Zones []struct { diff --git a/tariff/fixed/day.go b/tariff/fixed/day.go index 1dbcfb706..157f22955 100644 --- a/tariff/fixed/day.go +++ b/tariff/fixed/day.go @@ -71,7 +71,7 @@ func ParseDay(s string) (Day, error) { func ParseDays(s string) ([]Day, error) { var res []Day - for _, segment := range strings.Split(s, ",") { + for segment := range strings.SplitSeq(s, ",") { fromto := strings.SplitN(segment, "-", 2) if len(fromto) == 0 { return nil, fmt.Errorf("invalid day range: %s", segment) diff --git a/tariff/fixed/month.go b/tariff/fixed/month.go index 2bd1c6195..ea439578b 100644 --- a/tariff/fixed/month.go +++ b/tariff/fixed/month.go @@ -86,7 +86,7 @@ func ParseMonth(s string) (Month, error) { func ParseMonths(s string) ([]Month, error) { var res []Month - for _, segment := range strings.Split(s, ",") { + for segment := range strings.SplitSeq(s, ",") { fromto := strings.SplitN(segment, "-", 2) if len(fromto) == 0 { return nil, fmt.Errorf("invalid month range: %s", segment) diff --git a/tariff/fixed/timerange.go b/tariff/fixed/timerange.go index 310c11a41..a5396d1d2 100644 --- a/tariff/fixed/timerange.go +++ b/tariff/fixed/timerange.go @@ -85,7 +85,7 @@ func ParseTimeRange(s string) (TimeRange, error) { func ParseTimeRanges(s string) ([]TimeRange, error) { var res []TimeRange - for _, segment := range strings.Split(s, ",") { + for segment := range strings.SplitSeq(s, ",") { tr, err := ParseTimeRange(segment) if err != nil { return nil, err diff --git a/tariff/fixed/zone.go b/tariff/fixed/zone.go index 7f68f1c03..fe464040e 100644 --- a/tariff/fixed/zone.go +++ b/tariff/fixed/zone.go @@ -60,7 +60,7 @@ func (r Zones) TimeTableMarkers() []HourMin { HOURS: // 1hr intervals - for hour := 0; hour < 24; hour++ { + for hour := range 24 { for _, m := range res { if m.Hour == hour && m.Min == 0 { continue HOURS diff --git a/tariff/fixed_test.go b/tariff/fixed_test.go index ae340855b..ca56e2348 100644 --- a/tariff/fixed_test.go +++ b/tariff/fixed_test.go @@ -21,10 +21,10 @@ func TestFixed(t *testing.T) { } var expect api.Rates - for dow := 0; dow < 7; dow++ { + for dow := range 7 { dayStart := now.With(tf.clock.Now()).BeginningOfDay().AddDate(0, 0, dow) - for hour := 0; hour < 24; hour++ { + for hour := range 24 { expect = append(expect, api.Rate{ Value: 0.3, Start: dayStart.Add(time.Hour * time.Duration(hour)), @@ -39,7 +39,7 @@ func TestFixed(t *testing.T) { } func TestFixedSplitZones(t *testing.T) { - at, err := NewFixedFromConfig(map[string]interface{}{ + at, err := NewFixedFromConfig(map[string]any{ "price": 0.5, "zones": []struct { Price float64 @@ -58,7 +58,7 @@ func TestFixedSplitZones(t *testing.T) { dayStart := now.With(tf.clock.Now()).BeginningOfDay().AddDate(0, 0, i) // 00:00-05:00 0.1 - for hour := 0; hour < 5; hour++ { + for hour := range 5 { expect = append(expect, api.Rate{ Value: 0.1, Start: dayStart.Add(time.Hour * time.Duration(hour)), diff --git a/tariff/groupe-e.go b/tariff/groupe-e.go index b85cd4d64..246568ec9 100644 --- a/tariff/groupe-e.go +++ b/tariff/groupe-e.go @@ -24,7 +24,7 @@ func init() { registry.Add("groupe-e", NewGroupeEFromConfig) } -func NewGroupeEFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewGroupeEFromConfig(other map[string]any) (api.Tariff, error) { t := &GroupeE{ log: util.NewLogger("groupe-e"), data: util.NewMonitor[api.Rates](2 * time.Hour), diff --git a/tariff/gruenstromindex.go b/tariff/gruenstromindex.go index 0544387e3..e35541dfd 100644 --- a/tariff/gruenstromindex.go +++ b/tariff/gruenstromindex.go @@ -28,7 +28,7 @@ func init() { registry.Add("grünstromindex", NewGrünStromIndexFromConfig) } -func NewGrünStromIndexFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewGrünStromIndexFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { Zip string Token string diff --git a/tariff/ngeso.go b/tariff/ngeso.go index b678f9e5c..1c61df43f 100644 --- a/tariff/ngeso.go +++ b/tariff/ngeso.go @@ -26,7 +26,7 @@ func init() { registry.Add("ngeso", NewNgesoFromConfig) } -func NewNgesoFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewNgesoFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { Region string Postcode string diff --git a/tariff/octopus.go b/tariff/octopus.go index 3f717865e..0958ca460 100644 --- a/tariff/octopus.go +++ b/tariff/octopus.go @@ -34,7 +34,7 @@ func init() { } // NewOctopusFromConfig creates the tariff provider from the given config map, and runs it. -func NewOctopusFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewOctopusFromConfig(other map[string]any) (api.Tariff, error) { t, err := buildOctopusFromConfig(other) if err != nil { return nil, err @@ -45,7 +45,7 @@ func NewOctopusFromConfig(other map[string]interface{}) (api.Tariff, error) { // buildOctopusFromConfig creates the Tariff provider from the given config map. // Split out to allow for testing. -func buildOctopusFromConfig(other map[string]interface{}) (*Octopus, error) { +func buildOctopusFromConfig(other map[string]any) (*Octopus, error) { var cc struct { Region string Tariff string // DEPRECATED: use ProductCode diff --git a/tariff/octopus/graphql/api.go b/tariff/octopus/graphql/api.go index e7b332b84..1371013a5 100644 --- a/tariff/octopus/graphql/api.go +++ b/tariff/octopus/graphql/api.go @@ -83,7 +83,7 @@ func (c *OctopusGraphQLClient) refreshToken() error { defer cancel() var q krakenTokenAuthentication - if err := c.Client.Mutate(ctx, &q, map[string]interface{}{"apiKey": c.apikey}); err != nil { + if err := c.Client.Mutate(ctx, &q, map[string]any{"apiKey": c.apikey}); err != nil { return err } @@ -149,7 +149,7 @@ func (c *OctopusGraphQLClient) TariffCode(direction TariffDirection) (string, er defer cancel() var q krakenAccountElectricityAgreements - if err := c.Client.Query(ctx, &q, map[string]interface{}{"accountNumber": acc}); err != nil { + if err := c.Client.Query(ctx, &q, map[string]any{"accountNumber": acc}); err != nil { return "", err } diff --git a/tariff/octopus_test.go b/tariff/octopus_test.go index ef8fa8638..272f278a9 100644 --- a/tariff/octopus_test.go +++ b/tariff/octopus_test.go @@ -11,7 +11,7 @@ func TestOctopusConfigParse(t *testing.T) { test.SkipCI(t) // This test will start failing if you remove the deprecated "tariff" config var. - validTariffConfig := map[string]interface{}{ + validTariffConfig := map[string]any{ "region": "H", "tariff": "GO-22-03-29", "directDebit": "True", @@ -20,7 +20,7 @@ func TestOctopusConfigParse(t *testing.T) { _, err := buildOctopusFromConfig(validTariffConfig) require.NoError(t, err) - validProductCodeConfig := map[string]interface{}{ + validProductCodeConfig := map[string]any{ "region": "H", "productcode": "GO-22-03-29", "directDebit": "False", @@ -29,7 +29,7 @@ func TestOctopusConfigParse(t *testing.T) { _, err = buildOctopusFromConfig(validProductCodeConfig) require.NoError(t, err) - invalidApiAndProductCodeConfig := map[string]interface{}{ + invalidApiAndProductCodeConfig := map[string]any{ "region": "H", "productcode": "GO-22-03-29", "tariffDirection": "import", @@ -38,14 +38,14 @@ func TestOctopusConfigParse(t *testing.T) { _, err = buildOctopusFromConfig(invalidApiAndProductCodeConfig) require.Error(t, err) - invalidTariffDirectionConfig := map[string]interface{}{ + invalidTariffDirectionConfig := map[string]any{ "tariffDirection": "invalid", "apikey": "test", } _, err = buildOctopusFromConfig(invalidTariffDirectionConfig) require.Errorf(t, err, "invalid tariff type") - validApiExportConfig := map[string]interface{}{ + validApiExportConfig := map[string]any{ "tariffDirection": "export", "apikey": "test", } diff --git a/tariff/ostrom.go b/tariff/ostrom.go index 343ee691c..d047eb3ae 100644 --- a/tariff/ostrom.go +++ b/tariff/ostrom.go @@ -57,7 +57,7 @@ func ensureContractEx(cid int64, contracts []ostrom.Contract) (ostrom.Contract, return zero, errors.New("cannot find contract") } -func NewOstromFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewOstromFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { ClientId string ClientSecret string diff --git a/tariff/pun.go b/tariff/pun.go index 6bac5468b..fa86988e2 100644 --- a/tariff/pun.go +++ b/tariff/pun.go @@ -48,7 +48,7 @@ func init() { registry.Add("pun", NewPunFromConfig) } -func NewPunFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewPunFromConfig(other map[string]any) (api.Tariff, error) { var cc embed if err := util.DecodeOther(other, &cc); err != nil { diff --git a/tariff/smartenergy.go b/tariff/smartenergy.go index bfd493774..fe3d29084 100644 --- a/tariff/smartenergy.go +++ b/tariff/smartenergy.go @@ -24,7 +24,7 @@ func init() { registry.Add("smartenergy", NewSmartEnergyFromConfig) } -func NewSmartEnergyFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewSmartEnergyFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { embed `mapstructure:",squash"` } diff --git a/tariff/solcast.go b/tariff/solcast.go index 20ff395ea..eb6bb3ef4 100644 --- a/tariff/solcast.go +++ b/tariff/solcast.go @@ -30,7 +30,7 @@ func init() { registry.Add("solcast", NewSolcastFromConfig) } -func NewSolcastFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewSolcastFromConfig(other map[string]any) (api.Tariff, error) { cc := struct { Site string Token string diff --git a/tariff/stekker.go b/tariff/stekker.go index 15391682d..b803ff935 100644 --- a/tariff/stekker.go +++ b/tariff/stekker.go @@ -42,7 +42,7 @@ func init() { const stekkerURI = "https://stekker.app/epex-forecast" // NewStekkerFromConfig creates provider from config -func NewStekkerFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewStekkerFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { embed `mapstructure:",squash"` Region string @@ -120,7 +120,7 @@ func (t *Stekker) run(done chan error) { raw := strings.ReplaceAll(val, """, "\"") - var data []map[string]interface{} + var data []map[string]any if err := json.Unmarshal([]byte(raw), &data); err != nil { once.Do(func() { done <- err }) t.log.ERROR.Println("unmarshal error:", err) @@ -134,8 +134,8 @@ func (t *Stekker) run(done chan error) { continue } - xs, _ := series["x"].([]interface{}) - ys, _ := series["y"].([]interface{}) + xs, _ := series["x"].([]any) + ys, _ := series["y"].([]any) for i := range xs { xt, ok1 := xs[i].(string) diff --git a/tariff/tariff.go b/tariff/tariff.go index e7424f10d..0add9df1a 100644 --- a/tariff/tariff.go +++ b/tariff/tariff.go @@ -28,7 +28,7 @@ func init() { registry.AddCtx(api.Custom, NewConfigurableFromConfig) } -func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Tariff, error) { +func NewConfigurableFromConfig(ctx context.Context, other map[string]any) (api.Tariff, error) { cc := struct { embed `mapstructure:",squash"` Price *plugin.Config diff --git a/tariff/template.go b/tariff/template.go index 2cd097451..4e29f1d34 100644 --- a/tariff/template.go +++ b/tariff/template.go @@ -11,7 +11,7 @@ func init() { registry.AddCtx("template", NewTariffFromTemplateConfig) } -func NewTariffFromTemplateConfig(ctx context.Context, other map[string]interface{}) (api.Tariff, error) { +func NewTariffFromTemplateConfig(ctx context.Context, other map[string]any) (api.Tariff, error) { instance, err := templates.RenderInstance(templates.Tariff, other) if err != nil { return nil, err diff --git a/tariff/tibber.go b/tariff/tibber.go index ad26a5038..9429a74af 100644 --- a/tariff/tibber.go +++ b/tariff/tibber.go @@ -28,7 +28,7 @@ func init() { registry.Add("tibber", NewTibberFromConfig) } -func NewTibberFromConfig(other map[string]interface{}) (api.Tariff, error) { +func NewTibberFromConfig(other map[string]any) (api.Tariff, error) { var cc struct { embed `mapstructure:",squash"` Token string @@ -72,7 +72,7 @@ func NewTibberFromConfig(other map[string]interface{}) (api.Tariff, error) { func (t *Tibber) run(done chan error) { var once sync.Once - v := map[string]interface{}{ + v := map[string]any{ "id": graphql.ID(t.homeID), } diff --git a/tariff/wrapper.go b/tariff/wrapper.go index 70b430e51..8a073271a 100644 --- a/tariff/wrapper.go +++ b/tariff/wrapper.go @@ -9,12 +9,12 @@ import ( // Wrapper wraps an api.Tariff to capture initialization errors type Wrapper struct { typ string - config map[string]interface{} + config map[string]any err error } // NewWrapper creates an offline tariff wrapper -func NewWrapper(typ string, other map[string]interface{}, err error) api.Tariff { +func NewWrapper(typ string, other map[string]any, err error) api.Tariff { v := &Wrapper{ typ: typ, config: other, @@ -25,7 +25,7 @@ func NewWrapper(typ string, other map[string]interface{}, err error) api.Tariff } // WrappedConfig indicates a device with wrapped configuration -func (v *Wrapper) WrappedConfig() (string, map[string]interface{}) { +func (v *Wrapper) WrappedConfig() (string, map[string]any) { return v.typ, v.config } diff --git a/util/auth/auth.go b/util/auth/auth.go index 873c71349..aec57202e 100644 --- a/util/auth/auth.go +++ b/util/auth/auth.go @@ -144,7 +144,7 @@ func (a *auth) ValidateJwtToken(tokenString string) (bool, error) { // read token var claims jwt.RegisteredClaims - if _, err := jwt.ParseWithClaims(tokenString, &claims, func(token *jwt.Token) (interface{}, error) { + if _, err := jwt.ParseWithClaims(tokenString, &claims, func(token *jwt.Token) (any, error) { return jwtSecret, nil }, jwt.WithSubject(admin)); err != nil { return false, err diff --git a/util/decoder.go b/util/decoder.go index 04fd62661..b1879b7f7 100644 --- a/util/decoder.go +++ b/util/decoder.go @@ -10,7 +10,7 @@ import ( var validate = validator.New() // DecodeOther uses mapstructure to decode into target structure. Unused keys cause errors. -func DecodeOther(other, cc interface{}) error { +func DecodeOther(other, cc any) error { decoderConfig := &mapstructure.DecoderConfig{ Result: cc, ErrorUnused: true, diff --git a/util/format.go b/util/format.go index 5adaec3b8..35b58d5d0 100644 --- a/util/format.go +++ b/util/format.go @@ -17,7 +17,7 @@ import ( var re = regexp.MustCompile(`(?i)\${(\w+)(:([a-zA-Z0-9%.]+))?}`) // FormatValue will apply specific formatting in addition to standard sprintf -func FormatValue(format string, val interface{}) string { +func FormatValue(format string, val any) string { switch typed := val.(type) { case bool: if format == "%d" { @@ -47,7 +47,7 @@ func FormatValue(format string, val interface{}) string { } // ReplaceFormatted replaces all occurrences of ${key} with formatted val from the kv map -func ReplaceFormatted(s string, kv map[string]interface{}) (string, error) { +func ReplaceFormatted(s string, kv map[string]any) (string, error) { // Enhanced golang template logic tpl, err := template.New("base"). Funcs(sprig.TxtFuncMap()). diff --git a/util/format_test.go b/util/format_test.go index ba6fea758..3a9db235a 100644 --- a/util/format_test.go +++ b/util/format_test.go @@ -12,7 +12,7 @@ import ( func TestReplace(t *testing.T) { cases := []struct { k string - v interface{} + v any fmt, expected string }{ // regex tests @@ -26,7 +26,7 @@ func TestReplace(t *testing.T) { } for _, c := range cases { - s, err := ReplaceFormatted(c.fmt, map[string]interface{}{ + s, err := ReplaceFormatted(c.fmt, map[string]any{ c.k: c.v, }) @@ -36,7 +36,7 @@ func TestReplace(t *testing.T) { } func TestReplaceMulti(t *testing.T) { - s, err := ReplaceFormatted("${foo}-${bar}", map[string]interface{}{ + s, err := ReplaceFormatted("${foo}-${bar}", map[string]any{ "foo": "bar", "bar": "baz", }) @@ -47,7 +47,7 @@ func TestReplaceMulti(t *testing.T) { } func TestReplaceNoMatch(t *testing.T) { - s, err := ReplaceFormatted("${foo}", map[string]interface{}{ + s, err := ReplaceFormatted("${foo}", map[string]any{ "bar": "baz", }) @@ -69,7 +69,7 @@ func TestReplaceTemplate(t *testing.T) { } for _, tc := range tc { - s, err := ReplaceFormatted(tc.in, map[string]interface{}{ + s, err := ReplaceFormatted(tc.in, map[string]any{ tc.key: tc.val, }) diff --git a/util/jq/jq.go b/util/jq/jq.go index 2cd6694bb..0f801bbd6 100644 --- a/util/jq/jq.go +++ b/util/jq/jq.go @@ -9,8 +9,8 @@ import ( ) // Query executes a compiled jq query against given json. It expects a single result only. -func Query(query *gojq.Query, input []byte) (interface{}, error) { - var j interface{} +func Query(query *gojq.Query, input []byte) (any, error) { + var j any if err := json.Unmarshal(input, &j); err != nil { return j, err } diff --git a/util/logstash/log_test.go b/util/logstash/log_test.go index 31caad9e9..9240a85ff 100644 --- a/util/logstash/log_test.go +++ b/util/logstash/log_test.go @@ -44,7 +44,7 @@ func BenchmarkLog(b *testing.B) { log.Write([]byte(s2)) log.Write([]byte(s3)) - for i := 0; i < b.N; i++ { + for b.Loop() { log.All(nil, jww.LevelTrace, 1) } } diff --git a/util/modbus/functions.go b/util/modbus/functions.go index be8325dbe..25cef833a 100644 --- a/util/modbus/functions.go +++ b/util/modbus/functions.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "errors" "fmt" + "slices" "strconv" "strings" "time" @@ -71,10 +72,8 @@ func decodeBool16(mask uint64) func(b []byte) float64 { func decodeNaN16(f func(b []byte) float64, nan ...uint16) func(b []byte) float64 { return func(b []byte) float64 { u := binary.BigEndian.Uint16(b) - for _, nan := range nan { - if u == nan { - return 0 - } + if slices.Contains(nan, u) { + return 0 } return f(b) } @@ -83,10 +82,8 @@ func decodeNaN16(f func(b []byte) float64, nan ...uint16) func(b []byte) float64 func decodeNaN32(f func(b []byte) float64, nan ...uint32) func(b []byte) float64 { return func(b []byte) float64 { u := binary.BigEndian.Uint32(b) - for _, nan := range nan { - if u == nan { - return 0 - } + if slices.Contains(nan, u) { + return 0 } return f(b) } @@ -95,10 +92,8 @@ func decodeNaN32(f func(b []byte) float64, nan ...uint32) func(b []byte) float64 func decodeNaN64(f func(b []byte) float64, nan ...uint64) func(b []byte) float64 { return func(b []byte) float64 { u := binary.BigEndian.Uint64(b) - for _, nan := range nan { - if u == nan { - return 0 - } + if slices.Contains(nan, u) { + return 0 } return f(b) } diff --git a/util/modbus/log.go b/util/modbus/log.go index 08043e7cd..20d718b72 100644 --- a/util/modbus/log.go +++ b/util/modbus/log.go @@ -28,7 +28,7 @@ func (l *logger) WithLogger(logger modbus.Logger, fun func() ([]byte, error)) ([ // Printf implements modbus.Logger interface. // Must always be called while being wrapped in WithLogger, hence the lock is held. -func (l *logger) Printf(format string, v ...interface{}) { +func (l *logger) Printf(format string, v ...any) { if l.logger != nil { l.logger.Printf(format, v...) } diff --git a/util/pipe/limiter.go b/util/pipe/limiter.go index 726f04fff..d54c5c790 100644 --- a/util/pipe/limiter.go +++ b/util/pipe/limiter.go @@ -15,14 +15,14 @@ type Piper interface { type cacheItem struct { updated time.Time - val interface{} + val any } // Deduplicator allows filtering of channel data by given criteria type Deduplicator struct { clock clock.Clock interval time.Duration - filter map[string]interface{} + filter map[string]any cache map[string]cacheItem } @@ -31,7 +31,7 @@ func NewDeduplicator(interval time.Duration, filter ...string) Piper { l := &Deduplicator{ clock: clock.New(), interval: interval, - filter: make(map[string]interface{}), + filter: make(map[string]any), cache: make(map[string]cacheItem), } diff --git a/util/request/functions.go b/util/request/functions.go index fe8882c78..9486a3db7 100644 --- a/util/request/functions.go +++ b/util/request/functions.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "net/http" + "slices" "github.com/cenkalti/backoff/v4" ) @@ -65,12 +66,7 @@ func (e *StatusError) StatusCode() int { // HasStatus returns true if the response's status code matches any of the given codes func (e *StatusError) HasStatus(codes ...int) bool { - for _, code := range codes { - if e.resp.StatusCode == code { - return true - } - } - return false + return slices.Contains(codes, e.resp.StatusCode) } // ResponseError turns an HTTP status code into an error diff --git a/util/request/helper.go b/util/request/helper.go index c9c065627..bf3f047f9 100644 --- a/util/request/helper.go +++ b/util/request/helper.go @@ -54,7 +54,7 @@ func (r *Helper) GetBody(url string) ([]byte, error) { } // decodeJSON reads HTTP response and decodes JSON body if error is nil -func decodeJSON(resp *http.Response, res interface{}) error { +func decodeJSON(resp *http.Response, res any) error { if err := ResponseError(resp); err != nil { _ = json.NewDecoder(resp.Body).Decode(&res) return err @@ -64,7 +64,7 @@ func decodeJSON(resp *http.Response, res interface{}) error { } // decodeXML reads HTTP response and decodes XML body if error is nil -func decodeXML(resp *http.Response, res interface{}) error { +func decodeXML(resp *http.Response, res any) error { if err := ResponseError(resp); err != nil { _ = xml.NewDecoder(resp.Body).Decode(&res) return err @@ -75,7 +75,7 @@ func decodeXML(resp *http.Response, res interface{}) error { // DoJSON executes HTTP request and decodes JSON response. // It returns a StatusError on response codes other than HTTP 2xx. -func (r *Helper) DoJSON(req *http.Request, res interface{}) error { +func (r *Helper) DoJSON(req *http.Request, res any) error { resp, err := r.Do(req) if err != nil { return err @@ -91,7 +91,7 @@ func (r *Helper) DoJSON(req *http.Request, res interface{}) error { // GetJSON executes HTTP GET request and decodes JSON response. // It returns a StatusError on response codes other than HTTP 2xx. -func (r *Helper) GetJSON(url string, res interface{}) error { +func (r *Helper) GetJSON(url string, res any) error { req, err := New(http.MethodGet, url, nil, AcceptJSON) if err != nil { return err @@ -102,7 +102,7 @@ func (r *Helper) GetJSON(url string, res interface{}) error { // DoXML executes HTTP request and decodes XML response. // It returns a StatusError on response codes other than HTTP 2xx. -func (r *Helper) DoXML(req *http.Request, res interface{}) error { +func (r *Helper) DoXML(req *http.Request, res any) error { resp, err := r.Do(req) if err != nil { return err @@ -118,7 +118,7 @@ func (r *Helper) DoXML(req *http.Request, res interface{}) error { // GetXML executes HTTP GET request and decodes XML response. // It returns a StatusError on response codes other than HTTP 2xx. -func (r *Helper) GetXML(url string, res interface{}) error { +func (r *Helper) GetXML(url string, res any) error { req, err := New(http.MethodGet, url, nil, AcceptXML) if err != nil { return err diff --git a/util/request/json.go b/util/request/json.go index 1e68619fb..1d7bc4777 100644 --- a/util/request/json.go +++ b/util/request/json.go @@ -20,7 +20,7 @@ func (r *errorReader) Seek(offset int64, whence int) (int64, error) { } // MarshalJSON marshals JSON into an io.ReadSeeker -func MarshalJSON(data interface{}) io.ReadSeeker { +func MarshalJSON(data any) io.ReadSeeker { if data == nil { return nil } diff --git a/util/request/xml.go b/util/request/xml.go index ba8a39de8..4b23200ce 100644 --- a/util/request/xml.go +++ b/util/request/xml.go @@ -7,7 +7,7 @@ import ( ) // MarshalXML marshals XML into an io.ReadSeeker -func MarshalXML(data interface{}) io.ReadSeeker { +func MarshalXML(data any) io.ReadSeeker { if data == nil { return nil } diff --git a/util/templates/documentation.go b/util/templates/documentation.go index fabb39896..04c2a73b9 100644 --- a/util/templates/documentation.go +++ b/util/templates/documentation.go @@ -43,7 +43,7 @@ func (t *Template) RenderDocumentation(product Product, lang string) ([]byte, er } var modbusRender string - modbusData := make(map[string]interface{}) + modbusData := make(map[string]any) if modbusChoices := t.ModbusChoices(); len(modbusChoices) > 0 { if i, _ := t.ParamByName(ParamModbus); i > -1 { modbusTmpl, err := template.New("yaml").Funcs(sprig.FuncMap()).Parse(documentationModbusTmpl) @@ -89,7 +89,7 @@ func (t *Template) RenderDocumentation(product Product, lang string) ([]byte, er return 0 }) - data := map[string]interface{}{ + data := map[string]any{ "Template": t.Template, "ProductIdentifier": product.Identifier(), "ProductBrand": product.Brand, diff --git a/util/templates/render_instance.go b/util/templates/render_instance.go index 551097ed5..ebde89e58 100644 --- a/util/templates/render_instance.go +++ b/util/templates/render_instance.go @@ -12,14 +12,14 @@ import ( // Instance is an actual instantiated template type Instance struct { Type string - Other map[string]interface{} `yaml:",inline"` + Other map[string]any `yaml:",inline"` } // RenderInstance renders an actual configuration instance -func RenderInstance(class Class, other map[string]interface{}) (*Instance, error) { +func RenderInstance(class Class, other map[string]any) (*Instance, error) { var cc struct { Template string - Other map[string]interface{} `mapstructure:",remain"` + Other map[string]any `mapstructure:",remain"` } if err := util.DecodeOther(other, &cc); err != nil { diff --git a/util/templates/render_testing.go b/util/templates/render_testing.go index 3d88f3b11..6bb00c137 100644 --- a/util/templates/render_testing.go +++ b/util/templates/render_testing.go @@ -9,7 +9,7 @@ import ( ) // test renders and instantiates plus yaml-parses the template per usage -func test(t *testing.T, tmpl Template, values map[string]interface{}, cb func(values map[string]interface{})) { +func test(t *testing.T, tmpl Template, values map[string]any, cb func(values map[string]any)) { t.Helper() b, _, err := tmpl.RenderResult(RenderModeInstance, values) @@ -19,7 +19,7 @@ func test(t *testing.T, tmpl Template, values map[string]interface{}, cb func(va return } - var instance interface{} + var instance any if err := yaml.Unmarshal(b, &instance); err != nil { t.Log(string(b)) t.Error(err) @@ -34,7 +34,7 @@ func test(t *testing.T, tmpl Template, values map[string]interface{}, cb func(va cb(values) } -func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values map[string]interface{})) { +func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values map[string]any)) { t.Parallel() for _, tmpl := range ByClass(class, WithDeprecated()) { @@ -65,7 +65,7 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values t.Run(tmpl.Template, func(t *testing.T) { t.Parallel() - test(t, tmpl, values, func(values map[string]interface{}) { + test(t, tmpl, values, func(values map[string]any) { instantiate(t, values) }) }) @@ -82,7 +82,7 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values t.Run(tmpl.Template+"/"+u, func(t *testing.T) { t.Parallel() - test(t, tmpl, usageValues, func(values map[string]interface{}) { + test(t, tmpl, usageValues, func(values map[string]any) { instantiate(t, values) }) }) diff --git a/util/templates/template.go b/util/templates/template.go index c5301a4dd..f462701d2 100644 --- a/util/templates/template.go +++ b/util/templates/template.go @@ -175,8 +175,8 @@ func (t *Template) GroupTitle(lang string) string { } // Defaults returns a map of default values for the template -func (t *Template) Defaults(renderMode int) map[string]interface{} { - values := make(map[string]interface{}) +func (t *Template) Defaults(renderMode int) map[string]any { + values := make(map[string]any) for _, p := range t.Params { values[p.Name] = p.DefaultValue(renderMode) } @@ -226,7 +226,7 @@ func (t *Template) ModbusChoices() []string { var proxyTmpl string // RenderProxyWithValues renders the proxy template -func (t *Template) RenderProxyWithValues(values map[string]interface{}, lang string) ([]byte, error) { +func (t *Template) RenderProxyWithValues(values map[string]any, lang string) ([]byte, error) { tmpl, err := template.New("yaml").Funcs(sprig.FuncMap()).Parse(proxyTmpl) if err != nil { panic(err) @@ -276,7 +276,7 @@ func (t *Template) RenderProxyWithValues(values map[string]interface{}, lang str t.Params = newParams out := new(bytes.Buffer) - data := map[string]interface{}{ + data := map[string]any{ "Template": t.Template, "Params": t.Params, } @@ -294,7 +294,7 @@ func (t *Template) RenderResult(renderMode int, other map[string]any) ([]byte, m t.ModbusValues(renderMode, values) - res := make(map[string]interface{}) + res := make(map[string]any) // TODO this is an utterly horrible hack // @@ -325,12 +325,12 @@ func (t *Template) RenderResult(renderMode int, other map[string]any) ([]byte, m // TODO move yamlQuote to explicit quoting in templates, see https://github.com/evcc-io/evcc/issues/10742 switch typed := val.(type) { - case []interface{}: + case []any: var list []string for _, v := range typed { list = append(list, p.yamlQuote(fmt.Sprintf("%v", v))) } - if res[out] == nil || len(res[out].([]interface{})) == 0 { + if res[out] == nil || len(res[out].([]any)) == 0 { res[out] = list } diff --git a/util/templates/template_modbus.go b/util/templates/template_modbus.go index 4fe43d745..36b766361 100644 --- a/util/templates/template_modbus.go +++ b/util/templates/template_modbus.go @@ -11,7 +11,7 @@ import ( var modbusTmpl string // ModbusParams adds the modbus parameters' default values -func (t *Template) ModbusParams(modbusType string, values map[string]interface{}) { +func (t *Template) ModbusParams(modbusType string, values map[string]any) { if len(t.ModbusChoices()) == 0 { return } @@ -36,7 +36,7 @@ func (t *Template) ModbusParams(modbusType string, values map[string]interface{} } // ModbusValues adds the values required for modbus.tpl to the value map -func (t *Template) ModbusValues(renderMode int, values map[string]interface{}) { +func (t *Template) ModbusValues(renderMode int, values map[string]any) { choices := t.ModbusChoices() if len(choices) == 0 { return diff --git a/util/templates/types.go b/util/templates/types.go index aac55b363..ffa6c1bd0 100644 --- a/util/templates/types.go +++ b/util/templates/types.go @@ -199,7 +199,7 @@ type Param struct { } // DefaultValue returns a default or example value depending on the renderMode -func (p *Param) DefaultValue(renderMode int) interface{} { +func (p *Param) DefaultValue(renderMode int) any { // return empty list to allow iterating over in template if p.Type == TypeList { return []string{} diff --git a/util/templates/utils.go b/util/templates/utils.go index c6558bf4f..11945be99 100644 --- a/util/templates/utils.go +++ b/util/templates/utils.go @@ -59,7 +59,7 @@ func FuncMap(tmpl *template.Template) *template.Template { funcMap := template.FuncMap{ // include function // copied from: https://github.com/helm/helm/blob/8648ccf5d35d682dcd5f7a9c2082f0aaf071e817/pkg/engine/engine.go#L147-L154 - "include": func(name string, data interface{}) (string, error) { + "include": func(name string, data any) (string, error) { buf := bytes.NewBuffer(nil) if err := tmpl.ExecuteTemplate(buf, name, data); err != nil { return "", err diff --git a/util/time.go b/util/time.go index d1463fbdd..44771842e 100644 --- a/util/time.go +++ b/util/time.go @@ -2,6 +2,7 @@ package util import ( "fmt" + "slices" "time" ) @@ -34,7 +35,7 @@ func GetNextOccurrence(weekdays []int, timeStr string, tz string) (time.Time, er // Check the next 7 days for a valid match for range 7 { weekday := int(target.Weekday()) - if contains(weekdays, weekday) { + if slices.Contains(weekdays, weekday) { return target, nil } target = target.AddDate(0, 0, 1) @@ -42,13 +43,3 @@ func GetNextOccurrence(weekdays []int, timeStr string, tz string) (time.Time, er return time.Time{}, fmt.Errorf("no valid weekday found") } - -// helper function to check if a slice contains a value -func contains(slice []int, val int) bool { - for _, item := range slice { - if item == val { - return true - } - } - return false -} diff --git a/vehicle/aiways.go b/vehicle/aiways.go index b0b462e88..72c3003d3 100644 --- a/vehicle/aiways.go +++ b/vehicle/aiways.go @@ -24,7 +24,7 @@ func init() { } // NewAiwaysFromConfig creates a new vehicle -func NewAiwaysFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewAiwaysFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/aiways/types.go b/vehicle/aiways/types.go index b65e7626d..8639948d4 100644 --- a/vehicle/aiways/types.go +++ b/vehicle/aiways/types.go @@ -4,16 +4,16 @@ type User struct { Code int64 `json:"code"` Message string `json:"message"` Data *struct { - Email string `json:"email"` - HeadURL string `json:"headUrl"` - IsFirstLogin int64 `json:"isFirstLogin"` - Mobile interface{} `json:"mobile"` - Nickname string `json:"nickname"` - Sex interface{} `json:"sex"` - Token string `json:"token"` - UserID int64 `json:"userId"` - UserType int64 `json:"userType"` - Username string `json:"username"` + Email string `json:"email"` + HeadURL string `json:"headUrl"` + IsFirstLogin int64 `json:"isFirstLogin"` + Mobile any `json:"mobile"` + Nickname string `json:"nickname"` + Sex any `json:"sex"` + Token string `json:"token"` + UserID int64 `json:"userId"` + UserType int64 `json:"userType"` + Username string `json:"username"` } `json:"data"` Timestamp int64 `json:"timestamp"` } diff --git a/vehicle/audi.go b/vehicle/audi.go index 755a1916a..e44d9b549 100644 --- a/vehicle/audi.go +++ b/vehicle/audi.go @@ -29,7 +29,7 @@ func init() { } // NewAudiFromConfig creates a new vehicle -func NewAudiFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewAudiFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/bluelink.go b/vehicle/bluelink.go index 2d267af38..91f1c4703 100644 --- a/vehicle/bluelink.go +++ b/vehicle/bluelink.go @@ -23,7 +23,7 @@ func init() { } // NewHyundaiFromConfig creates a new vehicle -func NewHyundaiFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewHyundaiFromConfig(other map[string]any) (api.Vehicle, error) { settings := bluelink.Config{ URI: "https://prd.eu-ccapi.hyundai.com:8080", CCSPServiceID: "6d477c38-3ca4-4cf3-9557-2a1929a94654", @@ -40,7 +40,7 @@ func NewHyundaiFromConfig(other map[string]interface{}) (api.Vehicle, error) { } // NewKiaFromConfig creates a new vehicle -func NewKiaFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewKiaFromConfig(other map[string]any) (api.Vehicle, error) { settings := bluelink.Config{ URI: "https://prd.eu-ccapi.kia.com:8080", CCSPServiceID: "fdc85c00-0a2f-4c64-bcb4-2cfb1500730a", @@ -57,7 +57,7 @@ func NewKiaFromConfig(other map[string]interface{}) (api.Vehicle, error) { } // newBluelinkFromConfig creates a new Vehicle -func newBluelinkFromConfig(brand string, other map[string]interface{}, settings bluelink.Config) (api.Vehicle, error) { +func newBluelinkFromConfig(brand string, other map[string]any, settings bluelink.Config) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password string diff --git a/vehicle/bluelink/identity.go b/vehicle/bluelink/identity.go index 63522e6a4..8a7ce661c 100644 --- a/vehicle/bluelink/identity.go +++ b/vehicle/bluelink/identity.go @@ -69,7 +69,7 @@ func (v *Identity) getDeviceID() (string, error) { } uuid := uuid.NewString() - data := map[string]interface{}{ + data := map[string]any{ "pushRegId": lo.RandomString(64, []rune("0123456789ABCDEF")), "pushType": v.config.PushType, "uuid": uuid, diff --git a/vehicle/bmw/cardata/provider_test.go b/vehicle/bmw/cardata/provider_test.go index 0eef5ff31..601f21c30 100644 --- a/vehicle/bmw/cardata/provider_test.go +++ b/vehicle/bmw/cardata/provider_test.go @@ -1,7 +1,6 @@ package cardata import ( - "context" "testing" "time" @@ -11,8 +10,7 @@ import ( ) func TestCardataStreaming(t *testing.T) { - ctx, cancel := context.WithCancel(context.TODO()) - defer cancel() + ctx := t.Context() p := NewProvider(ctx, util.NewLogger("foo"), nil, oauth2.StaticTokenSource(&oauth2.Token{ AccessToken: "at", diff --git a/vehicle/bmw_deprecated.go b/vehicle/bmw_deprecated.go index 159682a33..48b9c7fdc 100644 --- a/vehicle/bmw_deprecated.go +++ b/vehicle/bmw_deprecated.go @@ -20,17 +20,17 @@ func init() { } // NewBMWFromConfig creates a new vehicle -func NewBMWFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewBMWFromConfig(other map[string]any) (api.Vehicle, error) { return NewBMWMiniFromConfig("bmw", other) } // NewMiniFromConfig creates a new vehicle -func NewMiniFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewMiniFromConfig(other map[string]any) (api.Vehicle, error) { return NewBMWMiniFromConfig("mini", other) } // NewBMWMiniFromConfig creates a new vehicle -func NewBMWMiniFromConfig(brand string, other map[string]interface{}) (api.Vehicle, error) { +func NewBMWMiniFromConfig(brand string, other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/cardata.go b/vehicle/cardata.go index dfe281ef1..43dcad10c 100644 --- a/vehicle/cardata.go +++ b/vehicle/cardata.go @@ -25,7 +25,7 @@ func init() { } // NewCardataFromConfig creates a new BMW/Mini CarData vehicle -func NewCardataFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) { +func NewCardataFromConfig(ctx context.Context, other map[string]any) (api.Vehicle, error) { var cc struct { embed `mapstructure:",squash"` ClientID, VIN string diff --git a/vehicle/carwings.go b/vehicle/carwings.go index e5ac36f65..b24284ff6 100644 --- a/vehicle/carwings.go +++ b/vehicle/carwings.go @@ -35,7 +35,7 @@ func init() { } // NewCarWingsFromConfig creates a new vehicle -func NewCarWingsFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewCarWingsFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, Region, VIN string diff --git a/vehicle/cloud.go b/vehicle/cloud.go index 373daf3c8..453dd2624 100644 --- a/vehicle/cloud.go +++ b/vehicle/cloud.go @@ -29,7 +29,7 @@ func init() { } // NewCloudFromConfig creates a new vehicle -func NewCloudFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewCloudFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` Brand string diff --git a/vehicle/config.go b/vehicle/config.go index 08da6129d..15c1cce88 100644 --- a/vehicle/config.go +++ b/vehicle/config.go @@ -24,10 +24,10 @@ func Types() []string { } // NewFromConfig creates vehicle from configuration -func NewFromConfig(ctx context.Context, typ string, other map[string]interface{}) (api.Vehicle, error) { +func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.Vehicle, error) { var cc struct { Cloud bool - Other map[string]interface{} `mapstructure:",remain"` + Other map[string]any `mapstructure:",remain"` } if err := util.DecodeOther(other, &cc); err != nil { diff --git a/vehicle/fiat.go b/vehicle/fiat.go index 24d1345f9..93e46227f 100644 --- a/vehicle/fiat.go +++ b/vehicle/fiat.go @@ -24,7 +24,7 @@ func init() { } // NewFiatFromConfig creates a new vehicle -func NewFiatFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) { +func NewFiatFromConfig(ctx context.Context, other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN, PIN string diff --git a/vehicle/ford-connect.go b/vehicle/ford-connect.go index f87a24024..f0fb158c6 100644 --- a/vehicle/ford-connect.go +++ b/vehicle/ford-connect.go @@ -21,7 +21,7 @@ func init() { } // NewFordConnectFromConfig creates a new vehicle -func NewFordConnectFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewFordConnectFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` Credentials ClientCredentials diff --git a/vehicle/ford.go b/vehicle/ford.go index 77ed1892d..f774a898d 100644 --- a/vehicle/ford.go +++ b/vehicle/ford.go @@ -25,7 +25,7 @@ func init() { } // NewFordFromConfig creates a new vehicle -func NewFordFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewFordFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/jlr.go b/vehicle/jlr.go index 41b3cf9cd..a300f2b79 100644 --- a/vehicle/jlr.go +++ b/vehicle/jlr.go @@ -27,7 +27,7 @@ func init() { } // NewJLRFromConfig creates a new vehicle -func NewJLRFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewJLRFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/jlr/api.go b/vehicle/jlr/api.go index e3a150f7c..d2837a47f 100644 --- a/vehicle/jlr/api.go +++ b/vehicle/jlr/api.go @@ -133,13 +133,13 @@ func (v *API) AuthenticateVinService(vin, user, service string) (PinResponse, er } func (v *API) ChargeAction(vin, user string, start bool) error { - var data map[string]interface{} + var data map[string]any pin, err := v.AuthenticateVinService(vin, user, "CP") if err == nil { onoff := map[bool]string{false: "FORCE_OFF", true: "FORCE_ON"} - data = map[string]interface{}{ + data = map[string]any{ "token": pin.Token, "serviceParameters": []KeyValue{{"CHARGE_NOW_SETTING", onoff[start]}}, } diff --git a/vehicle/jlr/types.go b/vehicle/jlr/types.go index 9b2bffabb..601293156 100644 --- a/vehicle/jlr/types.go +++ b/vehicle/jlr/types.go @@ -49,7 +49,7 @@ type PositionResponse struct { Timestamp string Speed float64 Heading float64 - PositionQuality interface{} + PositionQuality any } } diff --git a/vehicle/mercedes.go b/vehicle/mercedes.go index 9eeab3f7f..836cbb145 100644 --- a/vehicle/mercedes.go +++ b/vehicle/mercedes.go @@ -16,16 +16,16 @@ type Mercedes struct { } func init() { - registry.Add("mercedes", func(other map[string]interface{}) (api.Vehicle, error) { + registry.Add("mercedes", func(other map[string]any) (api.Vehicle, error) { return newMercedesFromConfig("mercedes", other) }) - registry.Add("smart-eq", func(other map[string]interface{}) (api.Vehicle, error) { + registry.Add("smart-eq", func(other map[string]any) (api.Vehicle, error) { return newMercedesFromConfig("smart-eq", other) }) } // newMercedesFromConfig creates a new vehicle -func newMercedesFromConfig(brand string, other map[string]interface{}) (api.Vehicle, error) { +func newMercedesFromConfig(brand string, other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` Tokens Tokens diff --git a/vehicle/mg.go b/vehicle/mg.go index 82e61cccf..92cbd4975 100644 --- a/vehicle/mg.go +++ b/vehicle/mg.go @@ -20,7 +20,7 @@ func init() { } // NewBMWFromConfig creates a new vehicle -func NewMGFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewMGFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/nissan.go b/vehicle/nissan.go index a56f59787..9b0faf260 100644 --- a/vehicle/nissan.go +++ b/vehicle/nissan.go @@ -28,7 +28,7 @@ func init() { } // NewNissanFromConfig creates a new vehicle -func NewNissanFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewNissanFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/nissan/api.go b/vehicle/nissan/api.go index db06210fa..34e8e5b48 100644 --- a/vehicle/nissan/api.go +++ b/vehicle/nissan/api.go @@ -109,7 +109,7 @@ func (v *API) ChargingAction(vin string, action Action) (ActionResponse, error) data := Request{ Data: Payload{ Type: "ChargingStart", - Attributes: map[string]interface{}{ + Attributes: map[string]any{ "action": action, }, }, diff --git a/vehicle/nissan/types.go b/vehicle/nissan/types.go index 0919b687a..b0086860a 100644 --- a/vehicle/nissan/types.go +++ b/vehicle/nissan/types.go @@ -61,8 +61,8 @@ type Request struct { } type Payload struct { - Type string `json:"type"` - Attributes map[string]interface{} `json:"attributes,omitempty"` + Type string `json:"type"` + Attributes map[string]any `json:"attributes,omitempty"` } type Error struct { diff --git a/vehicle/niu.go b/vehicle/niu.go index 6053913df..c3a6c618a 100644 --- a/vehicle/niu.go +++ b/vehicle/niu.go @@ -31,7 +31,7 @@ func init() { } // NewFordFromConfig creates a new vehicle -func NewNiuFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewNiuFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, Serial string diff --git a/vehicle/ovms.go b/vehicle/ovms.go index 1f9a94fc3..5e129d95f 100644 --- a/vehicle/ovms.go +++ b/vehicle/ovms.go @@ -33,7 +33,7 @@ func init() { } // NewOVMSFromConfig creates a new vehicle -func NewOvmsFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewOvmsFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VehicleID, Server string diff --git a/vehicle/polestar.go b/vehicle/polestar.go index de863480e..8865c9e32 100644 --- a/vehicle/polestar.go +++ b/vehicle/polestar.go @@ -22,7 +22,7 @@ func init() { } // NewPolestarFromConfig creates a new vehicle -func NewPolestarFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewPolestarFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password string diff --git a/vehicle/porsche.go b/vehicle/porsche.go index 7792078ae..38f8347c7 100644 --- a/vehicle/porsche.go +++ b/vehicle/porsche.go @@ -21,7 +21,7 @@ func init() { } // NewPorscheFromConfig creates a new vehicle -func NewPorscheFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewPorscheFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/psa.go b/vehicle/psa.go index 6ecf58ff3..add433085 100644 --- a/vehicle/psa.go +++ b/vehicle/psa.go @@ -33,7 +33,7 @@ type PSA struct { } // newPSA creates a new vehicle -func newPSA(brand, realm string, other map[string]interface{}) (api.Vehicle, error) { +func newPSA(brand, realm string, other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` VIN string diff --git a/vehicle/psa/duration.go b/vehicle/psa/duration.go index 39203e5ba..570a1885c 100644 --- a/vehicle/psa/duration.go +++ b/vehicle/psa/duration.go @@ -15,7 +15,7 @@ type Duration struct { // UnmarshalJSON implements json.Unmarshaler func (d *Duration) UnmarshalJSON(b []byte) error { - var v interface{} + var v any if err := json.Unmarshal(b, &v); err != nil { return err } diff --git a/vehicle/renault.go b/vehicle/renault.go index 06c43e60a..ff7f14f1c 100644 --- a/vehicle/renault.go +++ b/vehicle/renault.go @@ -27,16 +27,16 @@ type Renault struct { } func init() { - registry.Add("dacia", func(other map[string]interface{}) (api.Vehicle, error) { + registry.Add("dacia", func(other map[string]any) (api.Vehicle, error) { return NewRenaultDaciaFromConfig("dacia", other) }) - registry.Add("renault", func(other map[string]interface{}) (api.Vehicle, error) { + registry.Add("renault", func(other map[string]any) (api.Vehicle, error) { return NewRenaultDaciaFromConfig("renault", other) }) } // NewRenaultDaciaFromConfig creates a new Renault/Dacia vehicle -func NewRenaultDaciaFromConfig(brand string, other map[string]interface{}) (api.Vehicle, error) { +func NewRenaultDaciaFromConfig(brand string, other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, Region, VIN string diff --git a/vehicle/renault/kamereon/api.go b/vehicle/renault/kamereon/api.go index 96595f89a..9ca26d228 100644 --- a/vehicle/renault/kamereon/api.go +++ b/vehicle/renault/kamereon/api.go @@ -126,10 +126,10 @@ func (v *API) Cockpit(accountID string, vin string) (Response, error) { func (v *API) WakeUp(accountID string, vin string) (Response, error) { uri := fmt.Sprintf("%s/commerce/v1/accounts/%s/kamereon/kcm/v1/vehicles/%s/charge/pause-resume", v.keys.Target, accountID, vin) - data := map[string]interface{}{ - "data": map[string]interface{}{ + data := map[string]any{ + "data": map[string]any{ "type": "ChargePauseResume", - "attributes": map[string]interface{}{ + "attributes": map[string]any{ "action": "resume", }, }, @@ -148,7 +148,7 @@ func (v *API) WakeUpMY24(accountID string, vin string) (Response, error) { ChargeTimeStart: "21:00", ChargeDuration: 1615, PreconditioningTemperature: 20.0, - Programs: []interface{}{}, + Programs: []any{}, } return v.request(uri, request.MarshalJSON(data)) @@ -162,10 +162,10 @@ func (v *API) Position(accountID string, vin string) (Response, error) { func (v *API) Action(accountID, action string, vin string) (Response, error) { uri := fmt.Sprintf("%s/commerce/v1/accounts/%s/kamereon/kca/car-adapter/v1/cars/%s/actions/charging-start", v.keys.Target, accountID, vin) - data := map[string]interface{}{ - "data": map[string]interface{}{ + data := map[string]any{ + "data": map[string]any{ "type": "ChargingStart", - "attributes": map[string]interface{}{ + "attributes": map[string]any{ "action": action, }, }, diff --git a/vehicle/renault/kamereon/types.go b/vehicle/renault/kamereon/types.go index aaac290c1..e4b1a2414 100644 --- a/vehicle/renault/kamereon/types.go +++ b/vehicle/renault/kamereon/types.go @@ -72,14 +72,14 @@ type attributes struct { } type EvSettingsRequest struct { - LastSettingsUpdateTimestamp string `json:"lastSettingsUpdateTimestamp"` - DelegatedActivated bool `json:"delegatedActivated"` - ChargeModeRq string `json:"chargeModeRq"` - ChargeTimeStart string `json:"chargeTimeStart"` - ChargeDuration int `json:"chargeDuration"` - PreconditioningTemperature float64 `json:"preconditioningTemperature"` - PreconditioningHeatedStrgWheel bool `json:"preconditioningHeatedStrgWheel"` - PreconditioningHeatedRightSeat bool `json:"preconditioningHeatedRightSeat"` - PreconditioningHeatedLeftSeat bool `json:"preconditioningHeatedLeftSeat"` - Programs []interface{} `json:"programs"` + LastSettingsUpdateTimestamp string `json:"lastSettingsUpdateTimestamp"` + DelegatedActivated bool `json:"delegatedActivated"` + ChargeModeRq string `json:"chargeModeRq"` + ChargeTimeStart string `json:"chargeTimeStart"` + ChargeDuration int `json:"chargeDuration"` + PreconditioningTemperature float64 `json:"preconditioningTemperature"` + PreconditioningHeatedStrgWheel bool `json:"preconditioningHeatedStrgWheel"` + PreconditioningHeatedRightSeat bool `json:"preconditioningHeatedRightSeat"` + PreconditioningHeatedLeftSeat bool `json:"preconditioningHeatedLeftSeat"` + Programs []any `json:"programs"` } diff --git a/vehicle/saic/requests/types.go b/vehicle/saic/requests/types.go index 49b40b6e1..d16bbd271 100644 --- a/vehicle/saic/requests/types.go +++ b/vehicle/saic/requests/types.go @@ -92,7 +92,7 @@ type LoginData struct { } type Answer struct { - Code int `json:"code"` - Data interface{} `json:"data,omitempty"` - Message string `json:"message"` + Code int `json:"code"` + Data any `json:"data,omitempty"` + Message string `json:"message"` } diff --git a/vehicle/seat-cupra.go b/vehicle/seat-cupra.go index b6e405b7b..ba130811f 100644 --- a/vehicle/seat-cupra.go +++ b/vehicle/seat-cupra.go @@ -24,7 +24,7 @@ func init() { } // NewCupraFromConfig creates a new vehicle -func NewCupraFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewCupraFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/seat.go b/vehicle/seat.go index 0d6673ed8..f8f106ce5 100644 --- a/vehicle/seat.go +++ b/vehicle/seat.go @@ -33,7 +33,7 @@ func init() { } // NewSeatFromConfig creates a new vehicle -func NewSeatFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewSeatFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/skoda.go b/vehicle/skoda.go index 7c99b5649..76b280d69 100644 --- a/vehicle/skoda.go +++ b/vehicle/skoda.go @@ -23,7 +23,7 @@ func init() { } // NewSkodaFromConfig creates a new vehicle -func NewSkodaFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewSkodaFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/smart-hello.go b/vehicle/smart-hello.go index 0c0b53dde..70f89c584 100644 --- a/vehicle/smart-hello.go +++ b/vehicle/smart-hello.go @@ -20,7 +20,7 @@ func init() { } // NewSmartHelloFromConfig creates a new vehicle -func NewSmartHelloFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewSmartHelloFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password string diff --git a/vehicle/template.go b/vehicle/template.go index 69141f6df..ede4e889f 100644 --- a/vehicle/template.go +++ b/vehicle/template.go @@ -11,7 +11,7 @@ func init() { registry.AddCtx("template", NewVehicleFromTemplateConfig) } -func NewVehicleFromTemplateConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) { +func NewVehicleFromTemplateConfig(ctx context.Context, other map[string]any) (api.Vehicle, error) { instance, err := templates.RenderInstance(templates.Vehicle, other) if err != nil { return nil, err diff --git a/vehicle/tesla.go b/vehicle/tesla.go index 59765df4a..05ec3cdc6 100644 --- a/vehicle/tesla.go +++ b/vehicle/tesla.go @@ -26,7 +26,7 @@ func init() { } // NewTeslaFromConfig creates a new vehicle -func NewTeslaFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewTeslaFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` Credentials ClientCredentials diff --git a/vehicle/toyota.go b/vehicle/toyota.go index 91da7b4f3..814c4b97e 100644 --- a/vehicle/toyota.go +++ b/vehicle/toyota.go @@ -20,7 +20,7 @@ func init() { } // NewToyotaFromConfig creates a new vehicle -func NewToyotaFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewToyotaFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/toyota/types.go b/vehicle/toyota/types.go index 3bab3320a..c2fab81c9 100644 --- a/vehicle/toyota/types.go +++ b/vehicle/toyota/types.go @@ -40,8 +40,8 @@ type AuthCallback struct { } type AuthCallbackValue struct { - Name string `json:"name"` - Value interface{} `json:"value"` + Name string `json:"name"` + Value any `json:"value"` } type Token struct { diff --git a/vehicle/tronity.go b/vehicle/tronity.go index 9f2b9c2e8..02ff7948a 100644 --- a/vehicle/tronity.go +++ b/vehicle/tronity.go @@ -51,7 +51,7 @@ func init() { //go:generate go tool decorate -f decorateTronity -b *Tronity -r api.Vehicle -t "api.ChargeState,Status,func() (api.ChargeStatus, error)" -t "api.VehicleOdometer,Odometer,func() (float64, error)" -t "api.ChargeController,ChargeEnable,func(bool) error" // NewTronityFromConfig creates a new vehicle -func NewTronityFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewTronityFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` Credentials ClientCredentials diff --git a/vehicle/vehicle.go b/vehicle/vehicle.go index 795b42299..46ffbeea1 100644 --- a/vehicle/vehicle.go +++ b/vehicle/vehicle.go @@ -23,7 +23,7 @@ func init() { } // NewConfigurableFromConfig creates a new Vehicle -func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) { +func NewConfigurableFromConfig(ctx context.Context, other map[string]any) (api.Vehicle, error) { var cc struct { embed `mapstructure:",squash"` Soc plugin.Config diff --git a/vehicle/volvo-connected.go b/vehicle/volvo-connected.go index 955a030b1..e6f0232cd 100644 --- a/vehicle/volvo-connected.go +++ b/vehicle/volvo-connected.go @@ -22,7 +22,7 @@ func init() { } // NewVolvoConnectedFromConfig creates a new VolvoConnected vehicle -func NewVolvoConnectedFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) { +func NewVolvoConnectedFromConfig(ctx context.Context, other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` VIN string diff --git a/vehicle/vw.go b/vehicle/vw.go index 28ce2a802..3b114f576 100644 --- a/vehicle/vw.go +++ b/vehicle/vw.go @@ -25,7 +25,7 @@ func init() { } // NewIDFromConfig creates a new vehicle -func NewIDFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewIDFromConfig(other map[string]any) (api.Vehicle, error) { cc := struct { embed `mapstructure:",squash"` User, Password, VIN string diff --git a/vehicle/vw/api.go b/vehicle/vw/api.go index 692eccc1b..baa6a4a0e 100644 --- a/vehicle/vw/api.go +++ b/vehicle/vw/api.go @@ -210,8 +210,8 @@ func (v *API) Action(vin, action, value string) error { } // Any implements any api response -func (v *API) Any(base, vin string) (interface{}, error) { - var res interface{} +func (v *API) Any(base, vin string) (any, error) { + var res any uri := fmt.Sprintf("%s/"+strings.TrimLeft(base, "/"), v.baseURI, v.brand, v.country, vin) err := v.GetJSON(uri, &res) return res, err diff --git a/vehicle/vw/id/api.go b/vehicle/vw/id/api.go index f668d62ee..86f08847d 100644 --- a/vehicle/vw/id/api.go +++ b/vehicle/vw/id/api.go @@ -95,7 +95,7 @@ func (v *API) Action(vin, action, value string) error { req, err := request.New(http.MethodPost, uri, nil, request.AcceptJSON) if err == nil { - var res interface{} + var res any err = v.DoJSON(req, &res) } @@ -103,14 +103,14 @@ func (v *API) Action(vin, action, value string) error { } // Any implements any api response -func (v *API) Any(uri, vin string) (interface{}, error) { +func (v *API) Any(uri, vin string) (any, error) { if strings.Contains(uri, "%s") { uri = fmt.Sprintf(uri, vin) } req, err := request.New(http.MethodGet, uri, nil, request.AcceptJSON) - var res interface{} + var res any if err == nil { err = v.DoJSON(req, &res) } diff --git a/vehicle/vw/id/types.go b/vehicle/vw/id/types.go index f53ccba41..c82ac3e29 100644 --- a/vehicle/vw/id/types.go +++ b/vehicle/vw/id/types.go @@ -66,9 +66,9 @@ type Status struct { } `json:"climatisationTimer"` ChargingProfiles *struct { Value struct { - CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` - TimeInCar string `json:"timeInCar"` - Profiles []interface{} `json:"profiles"` + CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` + TimeInCar string `json:"timeInCar"` + Profiles []any `json:"profiles"` } `json:"value"` } `json:"chargingProfiles"` } `json:"automation"` @@ -234,9 +234,9 @@ type Status struct { VehicleHealthWarnings *struct { WarningLights struct { Value struct { - CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` - MileageKm int `json:"mileage_km"` - WarningLights []interface{} `json:"warningLights"` + CarCapturedTimestamp Timestamp `json:"carCapturedTimestamp"` + MileageKm int `json:"mileage_km"` + WarningLights []any `json:"warningLights"` } `json:"value"` } `json:"warningLights"` } `json:"vehicleHealthWarnings"` @@ -277,8 +277,8 @@ type Status struct { StartTime string `json:"startTime"` EndTime string `json:"endTime"` } `json:"preferredChargingTimes"` - Timers []interface{} `json:"timers"` - MinSOCEnabled bool `json:"minSOC_enabled"` + Timers []any `json:"timers"` + MinSOCEnabled bool `json:"minSOC_enabled"` } `json:"profiles"` } `json:"value"` } `json:"chargingProfilesStatus"` diff --git a/vehicle/vw/types_rolesrights.go b/vehicle/vw/types_rolesrights.go index 4e090901b..1c7bcb2b9 100644 --- a/vehicle/vw/types_rolesrights.go +++ b/vehicle/vw/types_rolesrights.go @@ -27,7 +27,7 @@ type ServiceInfo struct { Status string } LicenseRequired bool - CumulatedLicense map[string]interface{} + CumulatedLicense map[string]any PrimaryUserRequired bool TermsAndConditionsRequired bool ServiceEol string @@ -35,5 +35,5 @@ type ServiceInfo struct { InvocationUrl struct { Content string } - Operation []map[string]interface{} + Operation []map[string]any } diff --git a/vehicle/wrapper.go b/vehicle/wrapper.go index 09485a9ae..eca428c04 100644 --- a/vehicle/wrapper.go +++ b/vehicle/wrapper.go @@ -12,15 +12,15 @@ import ( type Wrapper struct { embed typ string - config map[string]interface{} + config map[string]any err error } // NewWrapper creates an offline Vehicle wrapper -func NewWrapper(name, typ string, other map[string]interface{}, err error) api.Vehicle { +func NewWrapper(name, typ string, other map[string]any, err error) api.Vehicle { var cc struct { embed `mapstructure:",squash"` - Other map[string]interface{} `mapstructure:",remain"` + Other map[string]any `mapstructure:",remain"` } // try to decode vehicle-specific config and look for title attribute @@ -45,7 +45,7 @@ func NewWrapper(name, typ string, other map[string]interface{}, err error) api.V } // WrappedConfig indicates a device with wrapped configuration -func (v *Wrapper) WrappedConfig() (string, map[string]interface{}) { +func (v *Wrapper) WrappedConfig() (string, map[string]any) { return v.typ, v.config } diff --git a/vehicle/zeromotorcycles.go b/vehicle/zeromotorcycles.go index afd7f7d6e..6fc1513e2 100644 --- a/vehicle/zeromotorcycles.go +++ b/vehicle/zeromotorcycles.go @@ -19,7 +19,7 @@ func init() { } // NewZeroFromConfig creates a new vehicle -func NewZeroFromConfig(other map[string]interface{}) (api.Vehicle, error) { +func NewZeroFromConfig(other map[string]any) (api.Vehicle, error) { var res *zero.API var err error