chore: deprecate templates (#13567)
This commit is contained in:
parent
1ef409b36b
commit
820579a356
9 changed files with 33 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
template: daheimladen
|
||||
deprecated: true
|
||||
products:
|
||||
- brand: DaheimLaden
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
template: keba
|
||||
deprecated: true
|
||||
products:
|
||||
- brand: KEBA
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
template: wallbe-meter
|
||||
deprecated: true
|
||||
products:
|
||||
- brand: Wallbe
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
template: wallbe-pre2019-meter
|
||||
deprecated: true
|
||||
products:
|
||||
- brand: Wallbe
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
template: wallbe-pre2019
|
||||
deprecated: true
|
||||
products:
|
||||
- brand: Wallbe
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
template: wallbe
|
||||
deprecated: true
|
||||
products:
|
||||
- brand: Wallbe
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue