2020-02-17 13:00:52 -06:00
|
|
|
// +build linux
|
|
|
|
|
2018-05-15 13:48:26 -07:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
2018-12-04 21:44:25 -08:00
|
|
|
"log"
|
2018-05-15 13:48:26 -07:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
psHost "github.com/shirou/gopsutil/host"
|
2019-02-03 20:11:35 -08:00
|
|
|
|
2020-02-13 16:26:28 -06:00
|
|
|
"github.com/xxxserxxx/gotop/utils"
|
2018-05-15 13:48:26 -07:00
|
|
|
)
|
|
|
|
|
2019-02-28 16:29:52 -08:00
|
|
|
func (self *TempWidget) update() {
|
2018-12-04 21:44:25 -08:00
|
|
|
sensors, err := psHost.SensorsTemperatures()
|
|
|
|
if err != nil {
|
2020-01-22 01:21:57 +08:00
|
|
|
log.Printf("error received from gopsutil: %v", err)
|
2018-12-04 21:44:25 -08:00
|
|
|
}
|
2018-05-15 13:48:26 -07:00
|
|
|
for _, sensor := range sensors {
|
|
|
|
// only sensors with input in their name are giving us live temp info
|
2018-11-29 17:37:41 -08:00
|
|
|
if strings.Contains(sensor.SensorKey, "input") && sensor.Temperature != 0 {
|
2018-05-15 13:48:26 -07:00
|
|
|
// removes '_input' from the end of the sensor name
|
|
|
|
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
|
2019-02-28 16:29:52 -08:00
|
|
|
switch self.TempScale {
|
|
|
|
case Fahrenheit:
|
2018-12-01 20:51:51 -08:00
|
|
|
self.Data[label] = utils.CelsiusToFahrenheit(int(sensor.Temperature))
|
2020-01-22 01:21:57 +08:00
|
|
|
case Celsius:
|
2018-11-13 12:29:09 -05:00
|
|
|
self.Data[label] = int(sensor.Temperature)
|
|
|
|
}
|
2018-05-15 13:48:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|