2020-02-18 03:00:52 +08:00
|
|
|
// +build linux
|
|
|
|
|
2020-02-28 08:51:28 +08:00
|
|
|
package devices
|
2018-05-16 04:48:26 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
psHost "github.com/shirou/gopsutil/host"
|
|
|
|
)
|
|
|
|
|
2020-02-28 08:51:28 +08:00
|
|
|
func init() {
|
|
|
|
RegisterTemp(getTemps)
|
2020-04-23 23:41:20 +08:00
|
|
|
RegisterDeviceList(Temperatures, devs)
|
2020-02-28 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func getTemps(temps map[string]int) map[string]error {
|
2018-12-05 13:44:25 +08:00
|
|
|
sensors, err := psHost.SensorsTemperatures()
|
|
|
|
if err != nil {
|
2020-02-28 08:51:28 +08:00
|
|
|
return map[string]error{"psHost": err}
|
2018-12-05 13:44:25 +08:00
|
|
|
}
|
2020-04-23 23:41:20 +08:00
|
|
|
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))
|
2018-05-16 04:48:26 +08:00
|
|
|
for _, sensor := range sensors {
|
|
|
|
// only sensors with input in their name are giving us live temp info
|
2018-11-30 09:37:41 +08:00
|
|
|
if strings.Contains(sensor.SensorKey, "input") && sensor.Temperature != 0 {
|
2018-05-16 04:48:26 +08:00
|
|
|
// removes '_input' from the end of the sensor name
|
|
|
|
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
|
2020-04-23 23:41:20 +08:00
|
|
|
rv = append(rv, label)
|
2018-05-16 04:48:26 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-23 23:41:20 +08:00
|
|
|
return rv
|
2018-05-16 04:48:26 +08:00
|
|
|
}
|