evcc-io/vehicle/template.go
Andreas Linde cfb174f9f5
Some checks failed
Default / Build (push) Failing after 2m0s
Default / Build UI (push) Failing after 13s
Release / Publish Docker :release (push) Has been cancelled
Release / call-build-workflow (push) Has been cancelled
Release / Publish Github & APT release (push) Has been cancelled
More template stuff (#2164)
- Configure now asks for the users knowledge level, so advanced mode can be reached without calling with `--advanced`
- Add template for solaredge inverter
- Add beta template for sungrow inverter
- Add template for MQTT based meter
- Add more template documentation
- Add check and error message for invalid config properties when using templates
- Option to specify language specific template descriptions
- Option to make params dependent on values of other params 
- Option to add sponsortoken in advanced mode
- Option to set minCurrent in advanced mode
- Remove sponsorship requirement from Daheimladen wallbox
- Multiple fixes (FritzDect meter, Kostsal Piko meter, ...)
2022-01-09 12:59:54 +01:00

44 lines
932 B
Go

package vehicle
import (
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/templates"
"gopkg.in/yaml.v3"
)
func init() {
registry.Add("template", NewVehicleFromTemplateConfig)
}
func NewVehicleFromTemplateConfig(other map[string]interface{}) (api.Vehicle, error) {
cc := struct {
Template string
Other map[string]interface{} `mapstructure:",remain"`
}{}
if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}
tmpl, err := templates.ByTemplate(cc.Template, templates.Vehicle)
if err != nil {
return nil, err
}
b, _, err := tmpl.RenderResult(templates.TemplateRenderModeInstance, other)
if err != nil {
return nil, err
}
var instance struct {
Type string
Other map[string]interface{} `yaml:",inline"`
}
if err := yaml.Unmarshal(b, &instance); err != nil {
return nil, err
}
return NewFromConfig(instance.Type, instance.Other)
}