// set the modbus values required from modbus.tpl and and the template to the render
set the modbus values required from modbus.tpl and and the template to the render
// set the modbus values required from modbus . tpl and and the template to the render
func (t *Template) ModbusValues(values map[string]interface{}) {
	if len(t.ModbusChoices()) == 0 {
		return
	}
	hasModbusValues := false
	if values[ModbusRS485Serial] == nil && values[ModbusRS485TCPIP] == nil && values[ModbusTCPIP] == nil {
		for k, v := range values {
			if k != ParamModbus {
				continue
			}
			switch s := v.(string); s {
			case ModbusKeyRS485Serial, ModbusKeyRS485TCPIP, ModbusKeyTCPIP:
				hasModbusValues = true
				values[s] = true
			default:
			}
			break
		}
	}
	if !strings.Contains(t.Render, modbusTmpl) {
		t.Render = fmt.Sprintf("%s\n%s", t.Render, modbusTmpl)
	}
	if hasModbusValues {
		return
	}
	for k, v := range map[string]interface{}{
		ModbusParamNameId:       ModbusParamValueId,
		ModbusParamNameHost:     ModbusParamValueHost,
		ModbusParamNamePort:     ModbusParamValuePort,
		ModbusParamNameDevice:   ModbusParamValueDevice,
		ModbusParamNameBaudrate: ModbusParamValueBaudrate,
		ModbusParamNameComset:   ModbusParamValueComset,
	} {
		values[k] = v
	}
	for _, p := range t.Params {
		if p.Name != ParamModbus {
			continue
		}
		for _, choice := range p.Choice {
			if !funk.ContainsString([]string{ModbusChoiceRS485, ModbusChoiceTCPIP}, choice) {
				panic(errors.New("Invalid modbus choice: " + choice))
			}
		}
		if funk.ContainsString(p.Choice, ModbusChoiceRS485) {
			values[ModbusRS485Serial] = true
			values[ModbusRS485TCPIP] = true
		}
		if funk.ContainsString(p.Choice, ModbusChoiceTCPIP) {
			values[ModbusTCPIP] = true
		}
	}
}
func ( t * Template ) ModbusValues ( values map [ string ] interface { } ) { if len ( t . ModbusChoices ( ) ) == 0 { return } hasModbusValues := false if values [ ModbusRS485Serial ] == nil && values [ ModbusRS485TCPIP ] == nil && values [ ModbusTCPIP ] == nil { for k , v := range values { if k != ParamModbus { continue } switch s := v . ( string ) ; s { case ModbusKeyRS485Serial , ModbusKeyRS485TCPIP , ModbusKeyTCPIP : hasModbusValues = true values [ s ] = true default : } break } } if ! strings . Contains ( t . Render , modbusTmpl ) { t . Render = fmt . Sprintf ( " \n " , t . Render , modbusTmpl ) } if hasModbusValues { return } for k , v := range map [ string ] interface { } { ModbusParamNameId : ModbusParamValueId , ModbusParamNameHost : ModbusParamValueHost , ModbusParamNamePort : ModbusParamValuePort , ModbusParamNameDevice : ModbusParamValueDevice , ModbusParamNameBaudrate : ModbusParamValueBaudrate , ModbusParamNameComset : ModbusParamValueComset , } { values [ k ] = v } for _ , p := range t . Params { if p . Name != ParamModbus { continue } for _ , choice := range p . Choice { if ! funk . ContainsString ( [ ] string { ModbusChoiceRS485 , ModbusChoiceTCPIP } , choice ) { panic ( errors . New ( " " + choice ) ) } } if funk . ContainsString ( p . Choice , ModbusChoiceRS485 ) { values [ ModbusRS485Serial ] = true values [ ModbusRS485TCPIP ] = true } if funk . ContainsString ( p . Choice , ModbusChoiceTCPIP ) { values [ ModbusTCPIP ] = true } } }
set the modbus values required from modbus.tpl and and the template to the render
set the modbus values required from modbus . tpl and and the template to the render
// either modbus param is defined or defaults for all modbus choices need to be set // this happens during tests // only add the template once, when testing multiple usages, it might already be present // modbus defaults