Config UI: fix preserving modbus fields (#25029)

This commit is contained in:
Michael Geers 2025-11-05 00:12:00 -08:00 • committed by GitHub
parent 6591514456
commit 2a0429aa76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 119 additions and 19 deletions

View file

@ -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
}