Revert "Tariff: qualify db device log names with the configured title (#32747)"
This reverts commit a142f3a759.
This commit is contained in:
parent
3e2e0fa806
commit
da3ac6b97c
2 changed files with 4 additions and 32 deletions
14
cmd/setup.go
14
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:<id> 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue