-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvoltagesensor.go
63 lines (50 loc) · 1.18 KB
/
voltagesensor.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package lmsensors
import (
"strconv"
)
var _ Sensor = &VoltageSensor{}
// A VoltageSensor is a Sensor that detects voltage.
type VoltageSensor struct {
// The name of the sensor.
Name string
// A label that describes what the sensor is monitoring. Label may be
// empty.
Label string
// Whether or not the sensor has an alarm triggered.
Alarm bool
// Whether or not the sensor will sound an audible alarm when an alarm
// is triggered.
Beep bool
// The input voltage indicated by the sensor.
Input float64
// The maximum voltage threshold indicated by the sensor.
Maximum float64
}
func (s *VoltageSensor) name() string { return s.Name }
func (s *VoltageSensor) setName(name string) { s.Name = name }
func (s *VoltageSensor) parse(raw map[string]string) error {
for k, v := range raw {
switch k {
case "input", "max":
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return err
}
// Raw temperature values are scaled by 1000
f /= 1000
switch k {
case "input":
s.Input = f
case "max":
s.Maximum = f
}
case "alarm":
s.Alarm = v != "0"
case "beep":
s.Beep = v != "0"
case "label":
s.Label = v
}
}
return nil
}