diff options
author | Sean E. Russell <ser@ser1.net> | 2020-06-09 09:03:58 -0500 |
---|---|---|
committer | Sean E. Russell <ser@ser1.net> | 2020-06-09 09:54:10 -0500 |
commit | 1181b94bd228f5f081d49f6c7c9a9ee9c26557ed (patch) | |
tree | 6c56836eefc5e5ec256ff8a3adfb674562a28f29 /devices/temp_nix.go | |
parent | 5590679cb4cc4dcd6ccb4694780eda38326bc4c5 (diff) |
Closes #131, SMC GPL issue on OSX; consequently removes need to CGO in darwin.v4.0.1
Diffstat (limited to 'devices/temp_nix.go')
-rw-r--r-- | devices/temp_nix.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/devices/temp_nix.go b/devices/temp_nix.go new file mode 100644 index 0000000..0015e1d --- /dev/null +++ b/devices/temp_nix.go @@ -0,0 +1,30 @@ +// +build linux darwin + +package devices + +import ( + "github.com/shirou/gopsutil/host" +) + +func init() { + devs() // Populate the sensorMap + RegisterTemp(getTemps) + RegisterDeviceList(Temperatures, devs, defs) +} + +func getTemps(temps map[string]int) map[string]error { + sensors, err := host.SensorsTemperatures() + if err != nil { + return map[string]error{"gopsutil host": err} + } + for _, sensor := range sensors { + label := sensorMap[sensor.SensorKey] + if _, ok := temps[label]; ok { + temps[label] = int(sensor.Temperature) + } + } + return nil +} + +// Optimization to avoid string manipulation every update +var sensorMap map[string]string |