Config UI: fix preserving modbus fields (#25029)
This commit is contained in:
parent
6591514456
commit
2a0429aa76
5 changed files with 119 additions and 19 deletions
|
|
@ -110,12 +110,21 @@ func templateForConfig(class templates.Class, conf map[string]any) (templates.Te
|
|||
func filterValidTemplateParams(tmpl *templates.Template, conf map[string]any) map[string]any {
|
||||
res := make(map[string]any)
|
||||
|
||||
// check if template has modbus capability
|
||||
hasModbus := len(tmpl.ModbusChoices()) > 0
|
||||
|
||||
for k, v := range conf {
|
||||
if k == "template" {
|
||||
res[k] = v
|
||||
continue
|
||||
}
|
||||
|
||||
// preserve modbus fields if template supports modbus
|
||||
if hasModbus && slices.Contains(templates.ModbusParams, k) {
|
||||
res[k] = v
|
||||
continue
|
||||
}
|
||||
|
||||
if i, _ := tmpl.ParamByName(k); i >= 0 {
|
||||
res[k] = v
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue