diff --git a/templates/definition/charger/daheimladen.yaml b/templates/definition/charger/daheimladen.yaml index c028f0c7c..2916e6fae 100644 --- a/templates/definition/charger/daheimladen.yaml +++ b/templates/definition/charger/daheimladen.yaml @@ -1,4 +1,5 @@ template: daheimladen +deprecated: true products: - brand: DaheimLaden description: diff --git a/templates/definition/charger/keba-udp.yaml b/templates/definition/charger/keba-udp.yaml index 5c0bd9a99..27f56928e 100644 --- a/templates/definition/charger/keba-udp.yaml +++ b/templates/definition/charger/keba-udp.yaml @@ -1,4 +1,5 @@ template: keba +deprecated: true products: - brand: KEBA description: diff --git a/templates/definition/charger/wallbe-meter.yaml b/templates/definition/charger/wallbe-meter.yaml index 5e8b4cffc..e76915e39 100644 --- a/templates/definition/charger/wallbe-meter.yaml +++ b/templates/definition/charger/wallbe-meter.yaml @@ -1,4 +1,5 @@ template: wallbe-meter +deprecated: true products: - brand: Wallbe description: diff --git a/templates/definition/charger/wallbe-pre2019-meter.yaml b/templates/definition/charger/wallbe-pre2019-meter.yaml index ff591d73a..26c6dbd65 100644 --- a/templates/definition/charger/wallbe-pre2019-meter.yaml +++ b/templates/definition/charger/wallbe-pre2019-meter.yaml @@ -1,4 +1,5 @@ template: wallbe-pre2019-meter +deprecated: true products: - brand: Wallbe description: diff --git a/templates/definition/charger/wallbe-pre2019.yaml b/templates/definition/charger/wallbe-pre2019.yaml index 6fbaeddbb..2d29e3282 100644 --- a/templates/definition/charger/wallbe-pre2019.yaml +++ b/templates/definition/charger/wallbe-pre2019.yaml @@ -1,4 +1,5 @@ template: wallbe-pre2019 +deprecated: true products: - brand: Wallbe description: diff --git a/templates/definition/charger/wallbe.yaml b/templates/definition/charger/wallbe.yaml index f5e20ed6a..8560d24bb 100644 --- a/templates/definition/charger/wallbe.yaml +++ b/templates/definition/charger/wallbe.yaml @@ -1,4 +1,5 @@ template: wallbe +deprecated: true products: - brand: Wallbe description: diff --git a/util/templates/init.go b/util/templates/init.go index 5dccb3524..65a9461c6 100644 --- a/util/templates/init.go +++ b/util/templates/init.go @@ -11,6 +11,7 @@ import ( "text/template" "github.com/evcc-io/evcc/templates/definition" + "github.com/samber/lo" "gopkg.in/yaml.v3" ) @@ -109,10 +110,32 @@ func EncoderLanguage(lang string) { encoderLanguage = lang } -func ByClass(class Class) []Template { - return templates[class] +type filterFunc func([]Template) []Template + +// WithDeprecated returns a filterFunc that includes all templates +func WithDeprecated() filterFunc { + return func(t []Template) []Template { + return t + } } +// ByClass returns templates for class excluding deprecated templates +func ByClass(class Class, opt ...filterFunc) []Template { + res := templates[class] + if len(opt) == 0 { + opt = append(opt, func(t []Template) []Template { + return lo.Filter(t, func(t Template, _ int) bool { + return !t.Deprecated + }) + }) + } + for _, o := range opt { + res = o(res) + } + return res +} + +// ByClass returns templates for class and name including deprecated templates func ByName(class Class, name string) (Template, error) { for _, tmpl := range templates[class] { if tmpl.Template == name || slices.Contains(tmpl.Covers, name) { diff --git a/util/templates/render_testing.go b/util/templates/render_testing.go index a37db319d..17b272c88 100644 --- a/util/templates/render_testing.go +++ b/util/templates/render_testing.go @@ -36,7 +36,7 @@ func test(t *testing.T, tmpl Template, values map[string]interface{}, cb func(va func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values map[string]interface{})) { t.Parallel() - for _, tmpl := range ByClass(class) { + for _, tmpl := range ByClass(class, WithDeprecated()) { tmpl := tmpl // set default values for all params diff --git a/util/templates/types.go b/util/templates/types.go index a1fc6c395..42c7158e7 100644 --- a/util/templates/types.go +++ b/util/templates/types.go @@ -253,6 +253,7 @@ func (p Product) Title(lang string) string { // TemplateDefinition contains properties of a device template type TemplateDefinition struct { Template string + Deprecated bool `json:"-"` Group string `json:",omitempty"` // the group this template belongs to, references groupList entries Covers []string `json:",omitempty"` // list of covered outdated template names Products []Product `json:",omitempty"` // list of products this template is compatible with