Fix template handling with modbus params
This commit is contained in:
parent
f4c501c241
commit
a83d696926
5 changed files with 17 additions and 19 deletions
|
|
@ -53,7 +53,7 @@ func (c *CmdConfigure) configureDeviceGuidedSetup() {
|
|||
// we only ask for the configuration for the first usage
|
||||
deviceCategory = supportedDeviceCategories[0]
|
||||
|
||||
values = c.processConfig(templateItem, deviceCategory)
|
||||
values = c.processConfig(&templateItem, deviceCategory)
|
||||
|
||||
deviceItem, err = c.processDeviceValues(values, templateItem, deviceItem, deviceCategory)
|
||||
if err != nil {
|
||||
|
|
@ -158,7 +158,7 @@ func (c *CmdConfigure) configureLinkedTemplate(templateItem templates.Template,
|
|||
for ok := true; ok; {
|
||||
deviceItem := device{}
|
||||
|
||||
values := c.processConfig(templateItem, category)
|
||||
values := c.processConfig(&templateItem, category)
|
||||
deviceItem, err := c.processDeviceValues(values, templateItem, deviceItem, category)
|
||||
if err != nil {
|
||||
if !errors.Is(err, c.errDeviceNotValid) {
|
||||
|
|
@ -206,8 +206,7 @@ func (c *CmdConfigure) configureDeviceCategory(deviceCategory DeviceCategory) (d
|
|||
|
||||
deviceDescription = templateItem.Title()
|
||||
capabilities = templateItem.Capabilities
|
||||
values := c.processConfig(templateItem, deviceCategory)
|
||||
|
||||
values := c.processConfig(&templateItem, deviceCategory)
|
||||
device, err = c.processDeviceValues(values, templateItem, device, deviceCategory)
|
||||
if err != nil {
|
||||
if err != c.errDeviceNotValid {
|
||||
|
|
|
|||
|
|
@ -340,23 +340,23 @@ func (c *CmdConfigure) paramChoiceValues(params []templates.Param, name string)
|
|||
// processConfig processes an EVCC configuration item
|
||||
// Returns:
|
||||
// a map with param name and values
|
||||
func (c *CmdConfigure) processConfig(templateItem templates.Template, deviceCategory DeviceCategory) map[string]interface{} {
|
||||
func (c *CmdConfigure) processConfig(templateItem *templates.Template, deviceCategory DeviceCategory) map[string]interface{} {
|
||||
fmt.Println()
|
||||
fmt.Println(c.localizedString("Config_Title", nil))
|
||||
fmt.Println()
|
||||
|
||||
c.processModbusConfig(&templateItem, deviceCategory)
|
||||
c.processModbusConfig(templateItem, deviceCategory)
|
||||
|
||||
return c.processParams(templateItem, templateItem.Params, deviceCategory)
|
||||
return c.processParams(templateItem, deviceCategory)
|
||||
}
|
||||
|
||||
// process a list of params
|
||||
func (c *CmdConfigure) processParams(templateItem templates.Template, params []templates.Param, deviceCategory DeviceCategory) map[string]interface{} {
|
||||
func (c *CmdConfigure) processParams(templateItem *templates.Template, deviceCategory DeviceCategory) map[string]interface{} {
|
||||
usageFilter := DeviceCategories[deviceCategory].categoryFilter
|
||||
|
||||
additionalConfig := make(map[string]interface{})
|
||||
|
||||
for _, param := range params {
|
||||
for _, param := range templateItem.Params {
|
||||
if param.Dependencies != nil {
|
||||
valid := true
|
||||
for _, dep := range param.Dependencies {
|
||||
|
|
@ -507,5 +507,5 @@ func (c *CmdConfigure) processModbusConfig(templateItem *templates.Template, dev
|
|||
// add the interface type specific modbus params
|
||||
templateItem.ModbusParams(choiceTypes[index], values)
|
||||
// Update the modbus default values
|
||||
templateItem.ModbusValues(templates.TemplateRenderModeInstance, values)
|
||||
_ = templateItem.ModbusValues(templates.TemplateRenderModeInstance, true, values)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ func (t *Template) RenderResult(renderMode string, other map[string]interface{})
|
|||
return nil, values, err
|
||||
}
|
||||
|
||||
t.ModbusValues(renderMode, values)
|
||||
values = t.ModbusValues(renderMode, false, values)
|
||||
|
||||
// add the common templates
|
||||
for _, v := range t.ConfigDefaults.Config.Presets {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func (t *Template) RenderDocumentation(product Product, values map[string]interf
|
|||
}
|
||||
|
||||
modbusData := map[string]interface{}{}
|
||||
t.ModbusValues(TemplateRenderModeDocs, modbusData)
|
||||
modbusData = t.ModbusValues(TemplateRenderModeDocs, true, modbusData)
|
||||
|
||||
modbusOut := new(bytes.Buffer)
|
||||
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ func (t *Template) ModbusParams(modbusType string, values map[string]interface{}
|
|||
}
|
||||
|
||||
// set the modbus values required from modbus.tpl and and the template to the render
|
||||
func (t *Template) ModbusValues(renderMode string, values map[string]interface{}) {
|
||||
func (t *Template) ModbusValues(renderMode string, setDefaults bool, values map[string]interface{}) map[string]interface{} {
|
||||
choices := t.ModbusChoices()
|
||||
if len(choices) == 0 {
|
||||
return
|
||||
return values
|
||||
}
|
||||
|
||||
// only add the template once, when testing multiple usages, it might already be present
|
||||
|
|
@ -40,11 +40,8 @@ func (t *Template) ModbusValues(renderMode string, values map[string]interface{}
|
|||
t.Render = fmt.Sprintf("%s\n%s", t.Render, modbusTmpl)
|
||||
}
|
||||
|
||||
// either modbus param is defined, which means it ran through configuration
|
||||
// or defaults for all modbus choices need to be set for rendering all cases for documentation
|
||||
if modbusValue := values[ParamModbus]; renderMode != TemplateRenderModeInstance && modbusValue != nil && modbusValue != "" {
|
||||
values[fmt.Sprintf("%s", modbusValue)] = true
|
||||
return
|
||||
if !setDefaults {
|
||||
return values
|
||||
}
|
||||
|
||||
modbusConfig := t.ConfigDefaults.Config.Modbus
|
||||
|
|
@ -96,4 +93,6 @@ func (t *Template) ModbusValues(renderMode string, values map[string]interface{}
|
|||
values[iface] = true
|
||||
}
|
||||
}
|
||||
|
||||
return values
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue