summaryrefslogtreecommitdiffstats
path: root/widgets/temp_linux.go
blob: 674599ea9fb0605d44e1894ad76c90818f1cbcb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package widgets

import (
	"log"
	"strings"

	psHost "github.com/shirou/gopsutil/host"

	"github.com/xxxserxxx/gotop/utils"
)

func (self *TempWidget) update() {
	sensors, err := psHost.SensorsTemperatures()
	if err != nil {
		log.Printf("error received from gopsutil: %v", err)
	}
	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")]
			switch self.TempScale {
			case Fahrenheit:
				self.Data[label] = utils.CelsiusToFahrenheit(int(sensor.Temperature))
			case Celsius:
				self.Data[label] = int(sensor.Temperature)
			}
		}
	}
}