diff options
author | Sean E. Russell <ser@ser1.net> | 2021-05-03 11:43:13 -0500 |
---|---|---|
committer | Sean E. Russell <ser@ser1.net> | 2021-05-03 11:43:13 -0500 |
commit | 162ed50189ea602c857738789f5a8dd4adb11180 (patch) | |
tree | 2be775575b881213e00dc446b09dc18aa3727a83 /devices/temp_darwin.go | |
parent | e3cd3ebe5e960896b9515df054cea75df6ce2c89 (diff) | |
parent | 5a063376b0d63bfe57f35169dc1c754d3f7d16b0 (diff) |
Merge branch 'go1.16'
Diffstat (limited to 'devices/temp_darwin.go')
-rw-r--r-- | devices/temp_darwin.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/devices/temp_darwin.go b/devices/temp_darwin.go index ecdc9f1..414e761 100644 --- a/devices/temp_darwin.go +++ b/devices/temp_darwin.go @@ -4,9 +4,11 @@ package devices import ( "bytes" + _ "embed" "encoding/csv" "github.com/shirou/gopsutil/host" "io" + "log" ) // All possible thermometers @@ -19,7 +21,7 @@ func devs() []string { ids := loadIDs() sensors, err := host.SensorsTemperatures() if err != nil { - // FIXME log an error here + log.Printf("error getting sensor list for temps: %s", err) return []string{} } rv := make([]string, 0, len(sensors)) @@ -30,7 +32,7 @@ func devs() []string { continue } if label, ok := ids[sensor.SensorKey]; ok { - sensorMap[sensor.SensorKey] = label + sensorMap[sensor.SensorKey] = label rv = append(rv, label) } } @@ -46,22 +48,25 @@ func defs() []string { return rv } +//go:embed "smc.tsv" +var smcData []byte + // loadIDs parses the embedded smc.tsv data that maps Darwin SMC // sensor IDs to their human-readable labels into an array and returns the // array. The array keys are the 4-letter sensor keys; the values are the // human labels. func loadIDs() map[string]string { rv := make(map[string]string) - data, err := Asset("smc.tsv") - parser := csv.NewReader(bytes.NewReader(data)) + parser := csv.NewReader(bytes.NewReader(smcData)) parser.Comma = '\t' var line []string + var err error for { if line, err = parser.Read(); err == io.EOF { break } if err != nil { - // FIXME log an error here + log.Printf("error parsing SMC tags for temp widget: %s", err) break } // The line is malformed if len(line) != 2, but because the asset is static |