-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwattpilot_mapping.go
82 lines (66 loc) · 2.06 KB
/
wattpilot_mapping.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package wattpilot
import (
"strconv"
)
type PostFunction func(interface{}) (string, error)
var PostProcess = map[string]struct {
key string
f PostFunction
}{
"voltage1": {"nrg", voltage1Process},
"voltage2": {"nrg", voltage2Process},
"voltage3": {"nrg", voltage3Process},
"voltageN": {"nrg", voltageNProcess},
"amps1": {"nrg", amps1Process},
"amps2": {"nrg", amps2Process},
"amps3": {"nrg", amps3Process},
"power1": {"nrg", power1Process},
"power2": {"nrg", power2Process},
"power3": {"nrg", power3Process},
"powerM": {"nrg", powerNProcess},
"power": {"nrg", powerProcess},
}
func voltage1Process(data interface{}) (string, error) {
return float2String(voltageData(data, 0)), nil
}
func voltage2Process(data interface{}) (string, error) {
return float2String(voltageData(data, 1)), nil
}
func voltage3Process(data interface{}) (string, error) {
return float2String(voltageData(data, 2)), nil
}
func voltageNProcess(data interface{}) (string, error) {
return float2String(voltageData(data, 3)), nil
}
func amps1Process(data interface{}) (string, error) {
return float2String(voltageData(data, 4)), nil
}
func amps2Process(data interface{}) (string, error) {
return float2String(voltageData(data, 5)), nil
}
func amps3Process(data interface{}) (string, error) {
return float2String(voltageData(data, 6)), nil
}
func power1Process(data interface{}) (string, error) {
return float2String(voltageData(data, 7)), nil
}
func power2Process(data interface{}) (string, error) {
return float2String(voltageData(data, 8)), nil
}
func power3Process(data interface{}) (string, error) {
return float2String(voltageData(data, 9)), nil
}
func powerNProcess(data interface{}) (string, error) {
return float2String(voltageData(data, 10)), nil
}
func powerProcess(data interface{}) (string, error) {
return float2String(voltageData(data, 11)), nil
}
func voltageData(data interface{}, idx int) float64 {
vars := data.([]interface{})
v := vars[idx].(float64)
return v
}
func float2String(value float64) string {
return strconv.FormatFloat(value, 'f', 2, 64)
}