Honor advanced setting in templates defaults.yaml (#5965)
This commit is contained in:
parent
1ebbd60221
commit
28d60a5993
14 changed files with 140 additions and 65 deletions
|
|
@ -418,11 +418,11 @@ func (c *CmdConfigure) processParams(templateItem *templates.Template, deviceCat
|
|||
}
|
||||
|
||||
default:
|
||||
if param.Advanced && !c.advancedMode || param.Deprecated {
|
||||
if param.IsAdvanced() && !c.advancedMode || param.IsDeprecated() {
|
||||
continue
|
||||
}
|
||||
|
||||
if param.Hidden && param.Default != "" {
|
||||
if param.IsHidden() && param.Default != "" {
|
||||
additionalConfig[param.Name] = param.Default
|
||||
continue
|
||||
}
|
||||
|
|
@ -495,8 +495,8 @@ func (c *CmdConfigure) processInputConfig(param templates.Param) string {
|
|||
help: help,
|
||||
valueType: param.ValueType,
|
||||
validValues: param.ValidValues,
|
||||
mask: param.Mask,
|
||||
required: param.Required,
|
||||
mask: param.IsMask(),
|
||||
required: param.IsRequired(),
|
||||
})
|
||||
|
||||
if param.ValueType == templates.ParamValueTypeBool && value == "true" {
|
||||
|
|
|
|||
|
|
@ -359,7 +359,6 @@ presets:
|
|||
params:
|
||||
- name: ski
|
||||
- name: ip
|
||||
required: false
|
||||
render: |
|
||||
{{define "eebus-meter"}}
|
||||
type: eebus
|
||||
|
|
@ -371,7 +370,6 @@ presets:
|
|||
params:
|
||||
- name: ski
|
||||
- name: ip
|
||||
required: false
|
||||
render: |
|
||||
{{define "eebus-no-meter"}}
|
||||
type: eebus
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ description: |
|
|||
Die Wallbox muss sich im "Power" Modus befinden.
|
||||
render:
|
||||
- default: |
|
||||
type: template
|
||||
template: etrel-duo
|
||||
host: 192.0.2.2 # IP-Adresse oder Hostname
|
||||
port: 502 # Port # Optional
|
||||
advanced: |
|
||||
type: template
|
||||
template: etrel-duo
|
||||
connector: 1 # Optional
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ render:
|
|||
type: template
|
||||
template: openwb
|
||||
host: 192.0.2.2 # IP-Adresse oder Hostname
|
||||
connector: 1 # Optional
|
||||
advanced: |
|
||||
type: template
|
||||
template: openwb
|
||||
|
|
|
|||
|
|
@ -20,6 +20,28 @@ render:
|
|||
host: 192.0.2.2 # Hostname
|
||||
port: 502 # Port
|
||||
|
||||
# Modbus TCP
|
||||
modbus: tcpip
|
||||
id: 1
|
||||
host: 192.0.2.2 # Hostname
|
||||
port: 502 # Port
|
||||
advanced: |
|
||||
type: template
|
||||
template: pracht-alpha
|
||||
|
||||
# RS485 via adapter (Modbus RTU)
|
||||
modbus: rs485serial
|
||||
id: 1
|
||||
device: /dev/ttyUSB0 # USB-RS485 Adapter Adresse
|
||||
baudrate: 9600 # Prüfe die Geräteeinstellungen, typische Werte sind 9600, 19200, 38400, 57600, 115200
|
||||
comset: "8N1" # Kommunikationsparameter für den Adapter
|
||||
|
||||
# RS485 via TCP/IP (Modbus RTU)
|
||||
modbus: rs485tcpip
|
||||
id: 1
|
||||
host: 192.0.2.2 # Hostname
|
||||
port: 502 # Port
|
||||
|
||||
# Modbus TCP
|
||||
modbus: tcpip
|
||||
id: 1
|
||||
|
|
|
|||
|
|
@ -8,6 +8,11 @@ render:
|
|||
template: sma-energy-meter
|
||||
usage: grid
|
||||
host: 192.0.2.2 # IP-Adresse oder Hostname
|
||||
advanced: |
|
||||
type: template
|
||||
template: sma-energy-meter
|
||||
usage: grid
|
||||
host: 192.0.2.2 # IP-Adresse oder Hostname
|
||||
interface: eth0 # Netzwerkinterface # Optional
|
||||
- usage: pv
|
||||
default: |
|
||||
|
|
@ -15,4 +20,9 @@ render:
|
|||
template: sma-energy-meter
|
||||
usage: pv
|
||||
host: 192.0.2.2 # IP-Adresse oder Hostname
|
||||
advanced: |
|
||||
type: template
|
||||
template: sma-energy-meter
|
||||
usage: pv
|
||||
host: 192.0.2.2 # IP-Adresse oder Hostname
|
||||
interface: eth0 # Netzwerkinterface # Optional
|
||||
|
|
|
|||
|
|
@ -9,4 +9,9 @@ render:
|
|||
template: sma-home-manager
|
||||
usage: grid
|
||||
host: 192.0.2.2 # IP-Adresse oder Hostname
|
||||
advanced: |
|
||||
type: template
|
||||
template: sma-home-manager
|
||||
usage: grid
|
||||
host: 192.0.2.2 # IP-Adresse oder Hostname
|
||||
interface: eth0 # Netzwerkinterface # Optional
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ render:
|
|||
id: 1
|
||||
host: 192.0.2.2 # Hostname
|
||||
port: 1502 # Port
|
||||
timeout: 10s # Optional
|
||||
advanced: |
|
||||
type: template
|
||||
template: solaredge-hybrid
|
||||
|
|
@ -78,7 +77,6 @@ render:
|
|||
id: 1
|
||||
host: 192.0.2.2 # Hostname
|
||||
port: 1502 # Port
|
||||
timeout: 10s # Optional
|
||||
advanced: |
|
||||
type: template
|
||||
template: solaredge-hybrid
|
||||
|
|
@ -128,7 +126,6 @@ render:
|
|||
id: 1
|
||||
host: 192.0.2.2 # Hostname
|
||||
port: 1502 # Port
|
||||
timeout: 10s # Optional
|
||||
advanced: |
|
||||
type: template
|
||||
template: solaredge-hybrid
|
||||
|
|
|
|||
|
|
@ -23,6 +23,29 @@ render:
|
|||
host: 192.0.2.2 # Hostname
|
||||
port: 1502 # Port
|
||||
|
||||
# Modbus TCP
|
||||
modbus: tcpip
|
||||
id: 1
|
||||
host: 192.0.2.2 # Hostname
|
||||
port: 1502 # Port
|
||||
advanced: |
|
||||
type: template
|
||||
template: solaredge-inverter
|
||||
usage: grid
|
||||
|
||||
# RS485 via adapter (Modbus RTU)
|
||||
modbus: rs485serial
|
||||
id: 1
|
||||
device: /dev/ttyUSB0 # USB-RS485 Adapter Adresse
|
||||
baudrate: 9600 # Prüfe die Geräteeinstellungen, typische Werte sind 9600, 19200, 38400, 57600, 115200
|
||||
comset: "8N1" # Kommunikationsparameter für den Adapter
|
||||
|
||||
# RS485 via TCP/IP (Modbus RTU)
|
||||
modbus: rs485tcpip
|
||||
id: 1
|
||||
host: 192.0.2.2 # Hostname
|
||||
port: 1502 # Port
|
||||
|
||||
# Modbus TCP
|
||||
modbus: tcpip
|
||||
id: 1
|
||||
|
|
@ -48,6 +71,29 @@ render:
|
|||
host: 192.0.2.2 # Hostname
|
||||
port: 1502 # Port
|
||||
|
||||
# Modbus TCP
|
||||
modbus: tcpip
|
||||
id: 1
|
||||
host: 192.0.2.2 # Hostname
|
||||
port: 1502 # Port
|
||||
advanced: |
|
||||
type: template
|
||||
template: solaredge-inverter
|
||||
usage: pv
|
||||
|
||||
# RS485 via adapter (Modbus RTU)
|
||||
modbus: rs485serial
|
||||
id: 1
|
||||
device: /dev/ttyUSB0 # USB-RS485 Adapter Adresse
|
||||
baudrate: 9600 # Prüfe die Geräteeinstellungen, typische Werte sind 9600, 19200, 38400, 57600, 115200
|
||||
comset: "8N1" # Kommunikationsparameter für den Adapter
|
||||
|
||||
# RS485 via TCP/IP (Modbus RTU)
|
||||
modbus: rs485tcpip
|
||||
id: 1
|
||||
host: 192.0.2.2 # Hostname
|
||||
port: 1502 # Port
|
||||
|
||||
# Modbus TCP
|
||||
modbus: tcpip
|
||||
id: 1
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func (c *ConfigDefaults) LoadDefaults() {
|
|||
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 {
|
||||
if p.IsReference() {
|
||||
finalName := p.Name
|
||||
referencedItemName := p.Name
|
||||
if p.Referencename != "" {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ render:
|
|||
{{- range $.Params }}
|
||||
{{- if eq .Name "modbus" -}}
|
||||
{{ $.Modbus | indent 6 -}}
|
||||
{{- else if ne .Advanced true }}
|
||||
{{- else if ne .IsAdvanced true }}
|
||||
{{ .Name }}:
|
||||
{{- if len .Value }} {{ .Value }} {{- end }}
|
||||
{{- if ne (len .Values) 0 }}
|
||||
|
|
@ -36,7 +36,7 @@ render:
|
|||
- {{ . }}
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
{{- if .Help.DE }} # {{ .Help.DE }}{{ end }}{{ if ne .Required true }} # Optional{{ end }}
|
||||
{{- if .Help.DE }} # {{ .Help.DE }}{{ end }}{{ if eq .IsRequired false }} # Optional{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $.AdvancedParams }}
|
||||
|
|
@ -55,7 +55,7 @@ render:
|
|||
- {{ . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if .Help.DE }} # {{ .Help.DE }}{{ end }}{{ if ne .Required true }} # Optional{{ end }}
|
||||
{{- if .Help.DE }} # {{ .Help.DE }}{{ end }}{{ if ne .IsRequired true }} # Optional{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
||||
|
|
@ -67,7 +67,7 @@ render:
|
|||
{{- range $.Params }}
|
||||
{{- if eq .Name "modbus" -}}
|
||||
{{ $.Modbus | indent 6 -}}
|
||||
{{- else if ne .Advanced true }}
|
||||
{{- else if ne .IsAdvanced true }}
|
||||
{{ .Name }}:
|
||||
{{- if len .Value }} {{ .Value }} {{- end }}
|
||||
{{- if ne (len .Values) 0 }}
|
||||
|
|
@ -75,7 +75,7 @@ render:
|
|||
- {{ . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if .Help.DE }} # {{ .Help.DE }}{{ end }}{{ if ne .Required true }} # Optional{{ end }}
|
||||
{{- if .Help.DE }} # {{ .Help.DE }}{{ end }}{{ if ne .IsRequired true }} # Optional{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $.AdvancedParams }}
|
||||
|
|
@ -93,7 +93,7 @@ render:
|
|||
- {{ . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if .Help.DE }} # {{ .Help.DE }}{{ end }}{{ if ne .Required true }} # Optional{{ end }}
|
||||
{{- if .Help.DE }} # {{ .Help.DE }}{{ end }}{{ if ne .IsRequired true }} # Optional{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ type Template struct {
|
|||
// GuidedSetupEnabled returns true if there are linked templates or >1 usage
|
||||
func (t *Template) GuidedSetupEnabled() bool {
|
||||
_, p := t.ParamByName(ParamUsage)
|
||||
return len(t.Linked) > 0 || (len(p.Choice) > 1 && p.AllInOne)
|
||||
return len(t.Linked) > 0 || (len(p.Choice) > 1 && p.IsAllInOne())
|
||||
}
|
||||
|
||||
// UpdateParamWithDefaults adds default values to specific param name entries
|
||||
|
|
@ -137,7 +137,9 @@ func (t *Template) ResolvePresets() error {
|
|||
}
|
||||
|
||||
if i, _ := t.ParamByName(p.Name); i > -1 {
|
||||
t.Params[i].OverwriteProperties(p)
|
||||
// take the preset values as a base and overwrite it with param values
|
||||
p.OverwriteProperties(t.Params[i])
|
||||
t.Params[i] = p
|
||||
} else {
|
||||
t.Params = append(t.Params, p)
|
||||
}
|
||||
|
|
@ -251,7 +253,7 @@ func (t *Template) RenderProxyWithValues(values map[string]interface{}, lang str
|
|||
// remove params with no values
|
||||
var newParams []Param
|
||||
for _, param := range t.Params {
|
||||
if !param.Required {
|
||||
if !param.IsRequired() {
|
||||
switch param.ValueType {
|
||||
case ParamValueTypeStringList:
|
||||
if len(param.Values) == 0 {
|
||||
|
|
@ -315,7 +317,7 @@ func (t *Template) RenderResult(renderMode string, other map[string]interface{})
|
|||
if !slices.Contains(predefinedTemplateProperties, out) {
|
||||
return nil, values, fmt.Errorf("invalid key: %s", key)
|
||||
}
|
||||
} else if p.Deprecated {
|
||||
} else if p.IsDeprecated() {
|
||||
continue
|
||||
} else {
|
||||
out = p.Name
|
||||
|
|
|
|||
|
|
@ -68,11 +68,11 @@ func (t *Template) RenderDocumentation(product Product, values map[string]interf
|
|||
var hasAdvancedParam bool
|
||||
var newParams []Param
|
||||
for _, param := range t.Params {
|
||||
if param.Deprecated || param.Name == ParamUsage {
|
||||
if param.IsDeprecated() || param.Name == ParamUsage {
|
||||
continue
|
||||
}
|
||||
|
||||
if param.Advanced {
|
||||
if param.IsAdvanced() {
|
||||
hasAdvancedParam = true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@ package templates
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -171,16 +172,16 @@ type LinkedTemplate struct {
|
|||
// 3. defaults.yaml modbus section
|
||||
// 4. template
|
||||
type Param struct {
|
||||
Reference bool // if this is references another param definition
|
||||
Reference *bool // if this is references another param definition
|
||||
Referencename string // name of the referenced param if it is not identical to the defined name
|
||||
Preset string // Reference a predefined set of params
|
||||
Name string // Param name which is used for assigning defaults properties and referencing in render
|
||||
Description TextLanguage // language specific titles (presented in UI instead of Name)
|
||||
Required bool // cli if the user has to provide a non empty value
|
||||
Mask bool // cli if the value should be masked, e.g. for passwords
|
||||
Advanced bool // cli if the user does not need to be asked. Requires a "Default" to be defined.
|
||||
Hidden bool // cli if the parameter should not be presented in the cli, the default value be assigned
|
||||
Deprecated bool // if the parameter is deprecated and thus should not be presented in the cli or docs
|
||||
Required *bool // cli if the user has to provide a non empty value
|
||||
Mask *bool // cli if the value should be masked, e.g. for passwords
|
||||
Advanced *bool // cli if the user does not need to be asked. Requires a "Default" to be defined.
|
||||
Hidden *bool // cli if the parameter should not be presented in the cli, the default value be assigned
|
||||
Deprecated *bool // if the parameter is deprecated and thus should not be presented in the cli or docs
|
||||
Default string // default value if no user value is provided in the configuration
|
||||
Example string // cli example value
|
||||
Help TextLanguage // cli configuration help
|
||||
|
|
@ -190,7 +191,7 @@ type Param struct {
|
|||
ValueType string // string representation of the value type, "string" is default
|
||||
ValidValues []string // list of valid values the user can provide
|
||||
Choice []string // defines a set of choices, e.g. "grid", "pv", "battery", "charge" for "usage"
|
||||
AllInOne bool // defines if the defined usages can all be present in a single device
|
||||
AllInOne *bool // defines if the defined usages can all be present in a single device
|
||||
Requirements Requirements // requirements for this param to be usable, only supported via ValueType "bool"
|
||||
|
||||
Baudrate int // device specific default for modbus RS485 baudrate
|
||||
|
|
@ -213,49 +214,39 @@ func (p *Param) DefaultValue(renderMode string) interface{} {
|
|||
return p.Default
|
||||
}
|
||||
|
||||
// overwrite specific properties by using values from another param
|
||||
//
|
||||
// always overwrites if not provided empty: description, valuetype, default, mask, required
|
||||
//
|
||||
// only overwrite if not provided empty and empty in param: help, example, requirements
|
||||
// OverwriteProperties merges properties from parameter definition
|
||||
func (p *Param) OverwriteProperties(withParam Param) {
|
||||
// always overwrite if defined
|
||||
p.Description.Update(withParam.Description, true)
|
||||
|
||||
if len(p.Usages) == 0 {
|
||||
p.Usages = withParam.Usages
|
||||
if err := mergo.Merge(p, &withParam); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if withParam.ValueType != "" {
|
||||
p.ValueType = withParam.ValueType
|
||||
}
|
||||
func (p *Param) IsReference() bool {
|
||||
return p.Reference != nil && *p.Reference
|
||||
}
|
||||
|
||||
if withParam.Required {
|
||||
p.Required = withParam.Required
|
||||
}
|
||||
func (p *Param) IsAdvanced() bool {
|
||||
return p.Advanced != nil && *p.Advanced
|
||||
}
|
||||
|
||||
if withParam.Default != "" {
|
||||
p.Default = withParam.Default
|
||||
}
|
||||
func (p *Param) IsHidden() bool {
|
||||
return p.Hidden != nil && *p.Hidden
|
||||
}
|
||||
|
||||
if withParam.Mask {
|
||||
p.Mask = withParam.Mask
|
||||
}
|
||||
func (p *Param) IsMask() bool {
|
||||
return p.Mask != nil && *p.Mask
|
||||
}
|
||||
|
||||
// only set if empty
|
||||
p.Help.Update(withParam.Help, false)
|
||||
func (p *Param) IsRequired() bool {
|
||||
return p.Required != nil && *p.Required
|
||||
}
|
||||
|
||||
if p.Example == "" && withParam.Example != "" {
|
||||
p.Example = withParam.Example
|
||||
}
|
||||
func (p *Param) IsDeprecated() bool {
|
||||
return p.Deprecated != nil && *p.Deprecated
|
||||
}
|
||||
|
||||
if p.ValidValues == nil && withParam.ValidValues != nil {
|
||||
p.ValidValues = withParam.ValidValues
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(p.Requirements, Requirements{}) {
|
||||
p.Requirements = withParam.Requirements
|
||||
}
|
||||
func (p *Param) IsAllInOne() bool {
|
||||
return p.AllInOne != nil && *p.AllInOne
|
||||
}
|
||||
|
||||
// Product contains naming information about a product a template supports
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue