-
Notifications
You must be signed in to change notification settings - Fork 0
/
enums.go
181 lines (159 loc) · 3.24 KB
/
enums.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package powerwall
import (
"encoding/json"
"fmt"
)
type NetworkInterface int
const (
Ethernet NetworkInterface = iota
Cellular
Wifi
)
var stringToInterface = map[string]NetworkInterface{
"EthType": Ethernet,
"GsmType": Cellular,
"WifiType": Wifi,
}
func (n NetworkInterface) String() string {
switch n {
case Ethernet:
return "ethernet"
case Cellular:
return "cellular"
case Wifi:
return "wifi"
default:
return "unknownNetworkType"
}
}
func (n *NetworkInterface) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
var ok bool
*n, ok = stringToInterface[s]
if !ok {
return fmt.Errorf("unknown NetworkInterface %q", s)
}
return nil
}
type OperatingMode int
const (
Backup OperatingMode = iota
SelfConsumption
Autonomous
Scheduler
SiteControl
)
func (o OperatingMode) String() string {
switch o {
case Backup:
return "Backup"
case SelfConsumption:
return "Self Consumption"
case Autonomous:
return "Autonomous"
case Scheduler:
return "Scheduler"
case SiteControl:
return "SiteControl"
default:
return "UnknownOperatingMode"
}
}
var stringToOperatingMode = map[string]OperatingMode{
"backup": Backup,
"self_consumption": SelfConsumption,
"autonomous": Autonomous,
"scheduler": Scheduler,
"site_control": SiteControl,
}
func (n *OperatingMode) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
var ok bool
*n, ok = stringToOperatingMode[s]
if !ok {
return fmt.Errorf("unknown OperatingMode %q", s)
}
return nil
}
type SystemStatus int
const (
GridConnected SystemStatus = iota
IslandedReady
IslandedActive
TransitionToGrid
)
func (s SystemStatus) String() string {
switch s {
case GridConnected:
return "GridConnected"
case IslandedReady:
return "IslandedReady"
case IslandedActive:
return "IslandedActive"
case TransitionToGrid:
return "TransitionToGrid"
default:
return "UnknownSystemStatus"
}
}
var stringToSystemStatus = map[string]SystemStatus{
"SystemGridConnected": GridConnected,
"SystemIslandedReady": IslandedReady,
"SystemIslandedActive": IslandedActive,
"SystemTransitionToGrid": TransitionToGrid,
}
func (s *SystemStatus) UnmarshalJSON(b []byte) error {
var j string
if err := json.Unmarshal(b, &j); err != nil {
return err
}
var ok bool
*s, ok = stringToSystemStatus[j]
if !ok {
return fmt.Errorf("unknown SystemStatus %q", j)
}
return nil
}
type GridState int
const (
Compliant GridState = iota
Qualifying
Uncompliant
)
var stringToGridState = map[string]GridState{
"Grid_Compliant": Compliant,
"Grid_Qualifying": Qualifying,
"Grid_Uncompliant": Uncompliant,
}
func (g GridState) String() string {
switch g {
case Compliant:
return "Complaint"
case Qualifying:
return "Qualifying"
case Uncompliant:
return "Uncompliant"
default:
return "UnknownGridState"
}
}
func (g *GridState) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
var ok bool
*g, ok = stringToGridState[s]
if !ok {
return fmt.Errorf("unknown GridState %q", s)
}
return nil
}
// jrester code suggets values here include:
// Grid_Compliant, Grid_Qualifying, Grid_Uncompliant