diff --git a/internal/linux/system/hwmon.go b/internal/linux/system/hwmon.go index 9d37312ef..4408553a9 100644 --- a/internal/linux/system/hwmon.go +++ b/internal/linux/system/hwmon.go @@ -25,20 +25,19 @@ type hwSensor struct { hwType string name string id string + path string linux.Sensor } func (s *hwSensor) asBool(h *hwmon.Sensor) { - if v, err := strconv.ParseBool(fmt.Sprint(int(h.Value()))); err != nil { - s.Value = false - } else { - s.Value = v - } - if s.Value.(bool) { + // we don't care if the value cannot be parsed, treat it as false + value, _ := strconv.ParseBool(fmt.Sprint(int(h.Value()))) + if value { s.IconString = "mdi:alarm-light" } else { s.IconString = "mdi:alarm-light-off" } + s.Value = value s.IsBinary = true } @@ -68,11 +67,13 @@ func (s *hwSensor) Attributes() any { NativeUnit string `json:"native_unit_of_measurement,omitempty"` DataSource string `json:"Data Source"` SensorType string `json:"Sensor Type"` + HWMonPath string `json:"SysFS Path"` }{ NativeUnit: s.UnitsString, DataSource: linux.DataSrcSysfs, SensorType: s.hwType, Attributes: s.ExtraAttrs, + HWMonPath: s.path, } } @@ -81,6 +82,7 @@ func newHWSensor(s *hwmon.Sensor) *hwSensor { name: s.Name(), id: s.ID(), hwType: s.SensorType.String(), + path: s.SysFSPath, ExtraAttrs: make(map[string]float64), } hw.IsDiagnostic = true diff --git a/pkg/linux/hwmon/hwmon.go b/pkg/linux/hwmon/hwmon.go index e5784c989..a28bc1643 100644 --- a/pkg/linux/hwmon/hwmon.go +++ b/pkg/linux/hwmon/hwmon.go @@ -112,6 +112,7 @@ type Sensor struct { label string id string units string + SysFSPath string Attributes []Attribute scaleFactor float64 value float64 @@ -160,7 +161,7 @@ func (s *Sensor) Units() string { // String will format the sensor name and value as a pretty string. func (s *Sensor) String() string { var b strings.Builder - fmt.Fprintf(&b, "%s: %.3f %s [%s] (id: %s)", s.Name(), s.Value(), s.Units(), s.SensorType, s.ID()) + fmt.Fprintf(&b, "%s: %.3f %s [%s] (id: %s, path: %s)", s.Name(), s.Value(), s.Units(), s.SensorType, s.ID(), s.SysFSPath) for i, a := range s.Attributes { if i == 0 { fmt.Fprintf(&b, " (") @@ -335,6 +336,7 @@ func getSensors(path string) ([]*Sensor, error) { deviceModel: deviceModel, id: sensorFile.sensorType, SensorType: t, + SysFSPath: path, scaleFactor: sf, units: u, }