Fibaro input: for battery operated devices, add battery level scraping (#7319)

This commit is contained in:
Pierrick Brossin 2020-04-20 16:58:50 +02:00 committed by GitHub
parent 73ef0bcba2
commit 52a3f5d404
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -30,6 +30,7 @@ Those values could be true (1) or false (0) for switches, percentage for dimmers
- name (device name)
- type (device type)
- fields:
- batteryLevel (float, when available from device)
- energy (float, when available from device)
- power (float, when available from device)
- value (float)
@ -52,4 +53,5 @@ fibaro,deviceId=220,host=vm1,name=CO2\ (ppm),room=Salon,section=Pièces\ commune
fibaro,deviceId=221,host=vm1,name=Humidité\ (%),room=Salon,section=Pièces\ communes,type=com.fibaro.humiditySensor value=61 1529996807000000000
fibaro,deviceId=222,host=vm1,name=Pression\ (mb),room=Salon,section=Pièces\ communes,type=com.fibaro.multilevelSensor value=1013.7 1529996807000000000
fibaro,deviceId=223,host=vm1,name=Bruit\ (db),room=Salon,section=Pièces\ communes,type=com.fibaro.multilevelSensor value=44 1529996807000000000
fibaro,deviceId=248,host=vm1,name=Température,room=Garage,section=Extérieur,type=com.fibaro.temperatureSensor batteryLevel=85,value=10.8 1529996807000000000
```

View File

@ -69,11 +69,12 @@ type Devices struct {
Type string `json:"type"`
Enabled bool `json:"enabled"`
Properties struct {
Dead interface{} `json:"dead"`
Energy interface{} `json:"energy"`
Power interface{} `json:"power"`
Value interface{} `json:"value"`
Value2 interface{} `json:"value2"`
BatteryLevel interface{} `json:"batteryLevel"`
Dead interface{} `json:"dead"`
Energy interface{} `json:"energy"`
Power interface{} `json:"power"`
Value interface{} `json:"value"`
Value2 interface{} `json:"value2"`
} `json:"properties"`
}
@ -174,6 +175,12 @@ func (f *Fibaro) Gather(acc telegraf.Accumulator) error {
}
fields := make(map[string]interface{})
if device.Properties.BatteryLevel != nil {
if fValue, err := strconv.ParseFloat(device.Properties.BatteryLevel.(string), 64); err == nil {
fields["batteryLevel"] = fValue
}
}
if device.Properties.Energy != nil {
if fValue, err := strconv.ParseFloat(device.Properties.Energy.(string), 64); err == nil {
fields["energy"] = fValue

View File

@ -107,6 +107,7 @@ const devicesJSON = `
"type": "com.fibaro.temperatureSensor",
"enabled": true,
"properties": {
"batteryLevel": "100",
"dead": "false",
"value": "22.80"
},
@ -196,7 +197,7 @@ func TestJSONSuccess(t *testing.T) {
// Ensure fields / values are correct - Device 4
tags = map[string]string{"deviceId": "4", "section": "Section 3", "room": "Room 4", "name": "Device 4", "type": "com.fibaro.temperatureSensor"}
fields = map[string]interface{}{"value": float64(22.8)}
fields = map[string]interface{}{"batteryLevel": float64(100), "value": float64(22.8)}
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
// Ensure fields / values are correct - Device 5