Fix interfaces with pointers (#7411)

This commit is contained in:
Pierrick Brossin 2020-04-27 17:52:24 +02:00 committed by GitHub
parent be1dc49ad9
commit 7ee776d67a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

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