feat(inputs.knx_listener): Add support for string data type (#15169)
This commit is contained in:
parent
47e4d454d0
commit
583e7cd46e
|
|
@ -187,6 +187,8 @@ func (kl *KNXListener) listen(acc telegraf.Accumulator) {
|
||||||
value = vi.Uint()
|
value = vi.Uint()
|
||||||
case reflect.Float32, reflect.Float64:
|
case reflect.Float32, reflect.Float64:
|
||||||
value = vi.Float()
|
value = vi.Float()
|
||||||
|
case reflect.String:
|
||||||
|
value = vi.String()
|
||||||
default:
|
default:
|
||||||
kl.Log.Errorf("Type conversion %v failed for address %q", vi.Kind(), ga)
|
kl.Log.Errorf("Type conversion %v failed for address %q", vi.Kind(), ga)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ func setValue(data dpt.DatapointValue, value interface{}) error {
|
||||||
d.SetInt(v)
|
d.SetInt(v)
|
||||||
case uint64:
|
case uint64:
|
||||||
d.SetUint(v)
|
d.SetUint(v)
|
||||||
|
case string:
|
||||||
|
d.SetString(v)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown type '%T' when setting value for DPT", value)
|
return fmt.Errorf("unknown type '%T' when setting value for DPT", value)
|
||||||
}
|
}
|
||||||
|
|
@ -104,6 +106,7 @@ func TestRegularReceives_DPT(t *testing.T) {
|
||||||
{"14/0/4", "14.004", false, 1.00794, 1.00794},
|
{"14/0/4", "14.004", false, 1.00794, 1.00794},
|
||||||
{"14/1/0", "14.010", false, 5963.78, 5963.78},
|
{"14/1/0", "14.010", false, 5963.78, 5963.78},
|
||||||
{"14/1/1", "14.011", false, 150.95, 150.95},
|
{"14/1/1", "14.011", false, 150.95, 150.95},
|
||||||
|
{"16/0/0", "16.000", false, "hello world", "hello world"},
|
||||||
}
|
}
|
||||||
acc := &testutil.Accumulator{}
|
acc := &testutil.Accumulator{}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue