2020-02-28 08:51:28 +08:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package devices
|
|
|
|
|
|
|
|
import (
|
2024-09-13 15:08:35 +08:00
|
|
|
psHost "github.com/shirou/gopsutil/v3/host"
|
2020-02-28 08:51:28 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RegisterTemp(update)
|
2020-04-24 02:01:13 +08:00
|
|
|
RegisterDeviceList(Temperatures, devs, devs)
|
2020-02-28 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func update(temps map[string]int) map[string]error {
|
|
|
|
sensors, err := psHost.SensorsTemperatures()
|
|
|
|
if err != nil {
|
|
|
|
return map[string]error{"gopsutil": err}
|
|
|
|
}
|
|
|
|
for _, sensor := range sensors {
|
2020-04-23 23:41:20 +08:00
|
|
|
if _, ok := temps[sensor.SensorKey]; ok {
|
|
|
|
temps[sensor.SensorKey] = int(sensor.Temperature + 0.5)
|
2020-02-28 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2020-04-23 23:41:20 +08:00
|
|
|
|
|
|
|
func devs() []string {
|
|
|
|
sensors, err := psHost.SensorsTemperatures()
|
|
|
|
if err != nil {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
rv := make([]string, 0, len(sensors))
|
|
|
|
for _, sensor := range sensors {
|
|
|
|
if sensor.Temperature != 0 {
|
|
|
|
rv = append(rv, sensor.SensorKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv
|
|
|
|
}
|