Introduce covers attribute for obsolete templates (#3070)
This commit is contained in:
parent
786c4700b6
commit
2211582db3
12 changed files with 26 additions and 60 deletions
|
|
@ -21,7 +21,7 @@ func NewChargerFromTemplateConfig(other map[string]interface{}) (api.Charger, er
|
|||
return nil, err
|
||||
}
|
||||
|
||||
tmpl, err := templates.ByTemplate(cc.Template, templates.Charger)
|
||||
tmpl, err := templates.ByName(cc.Template, templates.Charger)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ func (c *CmdConfigure) configureLinkedTypes(templateItem templates.Template) {
|
|||
}
|
||||
}
|
||||
|
||||
linkedTemplateItem, err := templates.ByTemplate(linkedTemplate.Template, string(DeviceClassMeter))
|
||||
linkedTemplateItem, err := templates.ByName(linkedTemplate.Template, string(DeviceClassMeter))
|
||||
if err != nil {
|
||||
fmt.Println("Error: " + err.Error())
|
||||
return
|
||||
|
|
|
|||
|
|
@ -566,7 +566,7 @@ func (c *CmdConfigure) processModbusConfig(templateItem *templates.Template, dev
|
|||
return
|
||||
}
|
||||
|
||||
config := templateItem.ConfigDefaults.Config.Modbus
|
||||
config := templateItem.ConfigDefaults.Modbus
|
||||
|
||||
for _, choice := range modbusParam.Choice {
|
||||
if config.Interfaces[choice] == nil {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func NewMeterFromTemplateConfig(other map[string]interface{}) (api.Meter, error)
|
|||
return nil, err
|
||||
}
|
||||
|
||||
tmpl, err := templates.ByTemplate(cc.Template, templates.Meter)
|
||||
tmpl, err := templates.ByName(cc.Template, templates.Meter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
template: tinkerforge-warp-pro
|
||||
products:
|
||||
- brand: TinkerForge
|
||||
description:
|
||||
generic: WARP Charger Pro
|
||||
requirements:
|
||||
description:
|
||||
en: A MQTT Broker software needs to be running on a computer. The MQTT connection also needs to be configured in the wallbox.
|
||||
de: Es muss ein sogennanter MQTT Broker auf einem Computer installiert sein. Die MQTT Verbindung muss in der Wallbox eingerichtet sein.
|
||||
uri: https://docs.evcc.io/docs/devices/chargers#tinkerforge-warp-charger
|
||||
params:
|
||||
- name: host
|
||||
required: true
|
||||
example: 192.0.2.2
|
||||
help:
|
||||
de: Die IP Adresse oder der Hostname des MQTT Brokers
|
||||
en: The IP address or hostname of the MQTT broker
|
||||
- name: port
|
||||
default: 1883
|
||||
help:
|
||||
de: Der Port des MQTT Brokers
|
||||
en: The port of the MQTT broker
|
||||
- name: topic
|
||||
default: warp
|
||||
- name: timeout
|
||||
default: 30s
|
||||
render: |
|
||||
type: warp
|
||||
broker: {{ .host }}:{{ .port }}
|
||||
topic: {{ .topic }}
|
||||
timeout: {{ .timeout }}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
template: tinkerforge-warp
|
||||
covers:
|
||||
- tinkerforge-warp-pro
|
||||
products:
|
||||
- brand: TinkerForge
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type ConfigDefaultsDefinition struct {
|
||||
type ConfigDefaults struct {
|
||||
Params []Param // Default values for common parameters
|
||||
Presets map[string]struct {
|
||||
Params []Param
|
||||
|
|
@ -23,27 +23,20 @@ type ConfigDefaultsDefinition struct {
|
|||
DeviceGroups map[string]TextLanguage // Default device groups
|
||||
}
|
||||
|
||||
type ConfigDefaults struct {
|
||||
read bool
|
||||
|
||||
Config ConfigDefaultsDefinition
|
||||
}
|
||||
|
||||
// read the actual config into the struct, but only once
|
||||
func (c *ConfigDefaults) LoadDefaults() {
|
||||
if c.read {
|
||||
// if params are initialized, defaults have been loaded
|
||||
if c.Params != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := yaml.Unmarshal([]byte(definition.DefaultsContent), &c.Config); err != nil {
|
||||
if err := yaml.Unmarshal([]byte(definition.DefaultsContent), &c); err != nil {
|
||||
panic(fmt.Errorf("Error: failed to parse deviceGroupListDefinition: %v\n", err))
|
||||
}
|
||||
|
||||
c.read = true
|
||||
|
||||
// resolve modbus param references
|
||||
for k := range c.Config.Modbus.Types {
|
||||
for i, p := range c.Config.Modbus.Types[k].Params {
|
||||
for k := range c.Modbus.Types {
|
||||
for i, p := range c.Modbus.Types[k].Params {
|
||||
// if this is a reference, get the referenced values and then overwrite it with the values defined here
|
||||
if p.Reference {
|
||||
finalName := p.Name
|
||||
|
|
@ -55,7 +48,7 @@ func (c *ConfigDefaults) LoadDefaults() {
|
|||
referencedParam.OverwriteProperties(p)
|
||||
referencedParam.Name = finalName
|
||||
p = referencedParam
|
||||
c.Config.Modbus.Types[k].Params[i] = p
|
||||
c.Modbus.Types[k].Params[i] = p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -63,7 +56,7 @@ func (c *ConfigDefaults) LoadDefaults() {
|
|||
|
||||
// return the param with the given name
|
||||
func (c *ConfigDefaults) ParamByName(name string) (int, Param) {
|
||||
for i, param := range c.Config.Params {
|
||||
for i, param := range c.Params {
|
||||
if param.Name == name {
|
||||
return i, param
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"path"
|
||||
|
||||
"github.com/evcc-io/evcc/templates/definition"
|
||||
"golang.org/x/exp/slices"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
|
@ -79,14 +80,14 @@ func ByClass(class string) []Template {
|
|||
return templates[class]
|
||||
}
|
||||
|
||||
func ByTemplate(t, class string) (Template, error) {
|
||||
func ByName(name, class string) (Template, error) {
|
||||
loadTemplates(class)
|
||||
|
||||
for _, tmpl := range templates[class] {
|
||||
if tmpl.Template == t {
|
||||
if tmpl.Template == name || slices.Contains(tmpl.Covers, name) {
|
||||
return tmpl, nil
|
||||
}
|
||||
}
|
||||
|
||||
return Template{}, fmt.Errorf("template not found: %s", t)
|
||||
return Template{}, fmt.Errorf("template not found: %s", name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ func (t *Template) ResolvePresets() error {
|
|||
t.Params = []Param{}
|
||||
for _, p := range currentParams {
|
||||
if p.Preset != "" {
|
||||
base, ok := t.ConfigDefaults.Config.Presets[p.Preset]
|
||||
base, ok := t.ConfigDefaults.Presets[p.Preset]
|
||||
if !ok {
|
||||
return fmt.Errorf("Error: Could not find preset definition: %s\n", p.Preset)
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ func (t *Template) ResolveGroup() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
_, ok := t.ConfigDefaults.Config.DeviceGroups[t.Group]
|
||||
_, ok := t.ConfigDefaults.DeviceGroups[t.Group]
|
||||
if !ok {
|
||||
return fmt.Errorf("Error: Could not find devicegroup definition: %s\n", t.Group)
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ func (t *Template) ResolveGroup() error {
|
|||
|
||||
// return the language specific group title
|
||||
func (t *Template) GroupTitle() string {
|
||||
tl := t.ConfigDefaults.Config.DeviceGroups[t.Group]
|
||||
tl := t.ConfigDefaults.DeviceGroups[t.Group]
|
||||
return tl.String(t.Lang)
|
||||
}
|
||||
|
||||
|
|
@ -295,7 +295,7 @@ func (t *Template) RenderResult(renderMode string, other map[string]interface{})
|
|||
values = t.ModbusValues(renderMode, false, values)
|
||||
|
||||
// add the common templates
|
||||
for _, v := range t.ConfigDefaults.Config.Presets {
|
||||
for _, v := range t.ConfigDefaults.Presets {
|
||||
if !strings.Contains(t.Render, v.Render) {
|
||||
t.Render = fmt.Sprintf("%s\n%s", t.Render, v.Render)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func (t *Template) ModbusParams(modbusType string, values map[string]interface{}
|
|||
return
|
||||
}
|
||||
|
||||
modbusParams := t.ConfigDefaults.Config.Modbus.Types[values[ParamModbus].(string)].Params
|
||||
modbusParams := t.ConfigDefaults.Modbus.Types[values[ParamModbus].(string)].Params
|
||||
|
||||
// add the modbus params at the beginning
|
||||
t.Params = append(modbusParams, t.Params...)
|
||||
|
|
@ -50,7 +50,7 @@ func (t *Template) ModbusValues(renderMode string, setDefaults bool, values map[
|
|||
return values
|
||||
}
|
||||
|
||||
modbusConfig := t.ConfigDefaults.Config.Modbus
|
||||
modbusConfig := t.ConfigDefaults.Modbus
|
||||
_, modbusParam := t.ParamByName(ParamModbus)
|
||||
|
||||
modbusInterfaces := []string{}
|
||||
|
|
|
|||
|
|
@ -257,6 +257,7 @@ type Product struct {
|
|||
// TemplateDefinition contains properties of a device template
|
||||
type TemplateDefinition struct {
|
||||
Template string
|
||||
Covers []string // list of covered outdated tempate names
|
||||
Products []Product // list of products this template is compatible with
|
||||
Capabilities []string
|
||||
Requirements Requirements
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func NewVehicleFromTemplateConfig(other map[string]interface{}) (api.Vehicle, er
|
|||
return nil, err
|
||||
}
|
||||
|
||||
tmpl, err := templates.ByTemplate(cc.Template, templates.Vehicle)
|
||||
tmpl, err := templates.ByName(cc.Template, templates.Vehicle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue