35 lines
813 B
Go
35 lines
813 B
Go
package test
|
|
|
|
import (
|
|
"github.com/andig/evcc-config/registry"
|
|
_ "github.com/andig/evcc-config/templates" // import all config templates
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// ConfigTemplate is a configuration template from https://github.com/andig/evcc-config
|
|
type ConfigTemplate struct {
|
|
registry.Template
|
|
Config map[string]interface{}
|
|
}
|
|
|
|
// ConfigTemplates returns configuration templates for giving class
|
|
func ConfigTemplates(class string) (res []ConfigTemplate) {
|
|
templates := registry.TemplatesByClass(class)
|
|
|
|
for _, tmpl := range templates {
|
|
var conf map[string]interface{}
|
|
if err := yaml.Unmarshal([]byte(tmpl.Sample), &conf); err != nil {
|
|
// silently ignore errors here
|
|
continue
|
|
}
|
|
|
|
parsed := ConfigTemplate{
|
|
Template: tmpl,
|
|
Config: conf,
|
|
}
|
|
|
|
res = append(res, parsed)
|
|
}
|
|
|
|
return res
|
|
}
|