Skip to content

Commit

Permalink
fix(linux): 🐛 safely check for hsi properties
Browse files Browse the repository at this point in the history
- check if hsi summary and result exist before converting from dbus Variant to a value
- make sure summary and result are not default values before adding to sensor attributes
  • Loading branch information
joshuar committed Oct 9, 2024
1 parent 345cbfe commit 3bb3849
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/linux/system/fwupdmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,17 @@ func (w *fwupdWorker) Sensors(ctx context.Context) ([]sensor.Entity, error) {
result hsiResult
)

summary, _ = dbusx.VariantToValue[string](prop["Summary"])
result, _ = dbusx.VariantToValue[hsiResult](prop["HsiResult"])
if summaryRaw, found := prop["Summary"]; found {
summary, _ = dbusx.VariantToValue[string](summaryRaw)
}

hsiSensor.Attributes[summary] = result.String()
if resultRaw, found := prop["HsiResult"]; found {
result, _ = dbusx.VariantToValue[hsiResult](resultRaw)
}

if summary != "" && result != ResultUnknown {
hsiSensor.Attributes[summary] = result.String()
}
}

return []sensor.Entity{hsiSensor}, nil
Expand Down

0 comments on commit 3bb3849

Please sign in to comment.