diff options
Diffstat (limited to 'devices/temp_linux.go')
-rw-r--r-- | devices/temp_linux.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/devices/temp_linux.go b/devices/temp_linux.go index ec4ff95..2ca01f5 100644 --- a/devices/temp_linux.go +++ b/devices/temp_linux.go @@ -10,6 +10,7 @@ import ( func init() { RegisterTemp(getTemps) + RegisterDeviceList(Temperatures, devs) } func getTemps(temps map[string]int) map[string]error { @@ -18,12 +19,31 @@ func getTemps(temps map[string]int) map[string]error { return map[string]error{"psHost": err} } for _, sensor := range sensors { + // removes '_input' from the end of the sensor name + idx := strings.Index(sensor.SensorKey, "_input") + if idx >= 0 { + label := sensor.SensorKey[:idx] + if _, ok := temps[label]; ok { + temps[label] = int(sensor.Temperature) + } + } + } + return nil +} + +func devs() []string { + sensors, err := psHost.SensorsTemperatures() + if err != nil { + return []string{} + } + rv := make([]string, 0, len(sensors)) + for _, sensor := range sensors { // only sensors with input in their name are giving us live temp info if strings.Contains(sensor.SensorKey, "input") && sensor.Temperature != 0 { // removes '_input' from the end of the sensor name label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")] - temps[label] = int(sensor.Temperature) + rv = append(rv, label) } } - return nil + return rv } |