Skip to content

Commit

Permalink
Fix interfaces with pointers (#7411)
Browse files Browse the repository at this point in the history
  • Loading branch information
dynek authored Apr 27, 2020
1 parent be1dc49 commit 7ee776d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions plugins/inputs/fibaro/fibaro.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ type Devices struct {
Type string `json:"type"`
Enabled bool `json:"enabled"`
Properties struct {
BatteryLevel interface{} `json:"batteryLevel"`
Dead interface{} `json:"dead"`
Energy interface{} `json:"energy"`
Power interface{} `json:"power"`
BatteryLevel *string `json:"batteryLevel"`
Dead string `json:"dead"`
Energy *string `json:"energy"`
Power *string `json:"power"`
Value interface{} `json:"value"`
Value2 interface{} `json:"value2"`
Value2 *string `json:"value2"`
} `json:"properties"`
}

Expand Down Expand Up @@ -176,19 +176,19 @@ 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 {
if fValue, err := strconv.ParseFloat(*device.Properties.BatteryLevel, 64); err == nil {
fields["batteryLevel"] = fValue
}
}

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

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
}
}
Expand All @@ -208,7 +208,7 @@ func (f *Fibaro) Gather(acc telegraf.Accumulator) error {
}

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
}
}
Expand Down

0 comments on commit 7ee776d

Please sign in to comment.