diff --git a/cmd/setup.go b/cmd/setup.go index 69a0ffaab..6a77f1c24 100644 --- a/cmd/setup.go +++ b/cmd/setup.go @@ -316,19 +316,13 @@ func staticInstance[T any](typ string, cc config.Named, newFromConf newFromConfF return err } -// nameForConfig returns a sensible log name for a (custom) configurable device, -// qualifying the generic db: with the configured title where available -func nameForConfig(conf *config.Config) string { +// loggerForConfig creates a logger with sensible name for (custom) configurable device +func loggerForConfig(conf *config.Config) *util.Logger { res := conf.Named().Name if t := conf.Title; t != "" && t != res { res += "-" + t } - return res -} - -// loggerForConfig creates a logger with sensible name for (custom) configurable device -func loggerForConfig(conf *config.Config) *util.Logger { - return util.NewLogger(nameForConfig(conf)) + return util.NewLogger(res) } func configurableInstance[T any](typ string, conf *config.Config, newFromConf newFromConfFunc[T], h config.Handler[T]) error { @@ -1218,7 +1212,7 @@ func configureTariffs(conf *globalconfig.Tariffs, names ...string) (*tariff.Tari var instance api.Tariff if !conf.Disable { var err error - instance, err = tariffInstance(nameForConfig(&conf), config.Typed{Type: cc.Type, Other: cc.Other}) + instance, err = tariffInstance(cc.Name, config.Typed{Type: cc.Type, Other: cc.Other}) if err != nil { return err } diff --git a/cmd/setup_name_test.go b/cmd/setup_name_test.go deleted file mode 100644 index 766b8f780..000000000 --- a/cmd/setup_name_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package cmd - -import ( - "testing" - - "github.com/evcc-io/evcc/util/config" - "github.com/stretchr/testify/assert" -) - -func TestNameForConfig(t *testing.T) { - for _, tc := range []struct { - title string - expected string - }{ - {"", "db:8"}, - {"Solar Forecast 1. Dachseite", "db:8-Solar Forecast 1. Dachseite"}, - {"db:8", "db:8"}, // title equal to the generated name is not repeated - } { - conf := config.Config{ID: 8, Properties: config.Properties{Title: tc.title}} - assert.Equal(t, tc.expected, nameForConfig(&conf)) - } -}