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"
|
|
|
|
|
2020-06-09 22:03:58 +08:00
|
|
|
"github.com/shirou/gopsutil/host"
|
2018-05-16 04:48:26 +08:00
|
|
|
)
|
|
|
|
|
2020-06-09 22:03:58 +08:00
|
|
|
// All possible thermometers
|
2020-04-23 23:41:20 +08:00
|
|
|
func devs() []string {
|
2020-04-24 02:01:13 +08:00
|
|
|
if sensorMap == nil {
|
|
|
|
sensorMap = make(map[string]string)
|
|
|
|
}
|
2020-06-09 22:03:58 +08:00
|
|
|
sensors, err := host.SensorsTemperatures()
|
2020-04-23 23:41:20 +08:00
|
|
|
if err != nil {
|
2020-06-12 23:22:23 +08:00
|
|
|
// FIXME report the error
|
2020-04-23 23:41:20 +08:00
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
rv := make([]string, 0, len(sensors))
|
2018-05-16 04:48:26 +08:00
|
|
|
for _, sensor := range sensors {
|
2020-04-24 02:01:13 +08:00
|
|
|
label := sensor.SensorKey
|
|
|
|
if strings.Contains(sensor.SensorKey, "input") {
|
|
|
|
label = sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
|
|
|
|
}
|
|
|
|
rv = append(rv, label)
|
|
|
|
sensorMap[sensor.SensorKey] = label
|
|
|
|
}
|
|
|
|
return rv
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only include sensors with input in their name; these are the only sensors
|
|
|
|
// returning live data
|
|
|
|
func defs() []string {
|
|
|
|
// MUST be called AFTER init()
|
|
|
|
rv := make([]string, 0)
|
|
|
|
for k, v := range sensorMap {
|
|
|
|
if k != v { // then it's an _input sensor
|
|
|
|
rv = append(rv, v)
|
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
|
|
|
}
|