-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
139 lines (120 loc) · 4.59 KB
/
types.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
package smarthome
// EMeter response changed between firmware 1.0 and 1.1. Populate both sets of fields.
func normalizeEmeterResponse(emeter *GetRealtimeResponse) {
if emeter.CurrentMa == 0 {
emeter.CurrentMa = int(emeter.CurrentA * 1000)
} else {
emeter.CurrentA = float64(emeter.CurrentMa) / 1000
}
if emeter.PowerMw == 0 {
emeter.PowerMw = int(emeter.PowerW * 1000)
} else {
emeter.PowerW = float64(emeter.PowerMw) / 1000
}
if emeter.TotalWh == 0 {
emeter.TotalWh = int(emeter.TotalWhFloat)
} else {
emeter.TotalWhFloat = float64(emeter.TotalWh)
}
if emeter.VoltageMv == 0 {
emeter.VoltageMv = int(emeter.VoltageV * 1000)
} else {
emeter.VoltageV = float64(emeter.VoltageMv) / 1000
}
}
// Action is when the next action will occur.
type Action struct {
Type int `json:"type,omitempty"`
}
// SysInfoChild is a child device returned with the SysInfo response.
// For example, each plug on an HS300 is represented as a SysInfoChild entry.
type SysInfoChild struct {
ID string `json:"id,omitempty"`
State int `json:"state,omitempty"`
Alias string `json:"alias,omitempty"`
OnTime int `json:"on_time,omitempty"`
NextAction Action `json:"next_action,omitempty"`
}
// SysInfoResponse is the main device information response.
type SysInfoResponse struct {
ErrCode int `json:"err_code,omitempty"`
SwVer string `json:"sw_ver,omitempty"`
HwVer string `json:"hw_ver,omitempty"`
Type string `json:"type,omitempty"`
Model string `json:"model,omitempty"`
Mac string `json:"mac,omitempty"`
DeviceID string `json:"deviceId,omitempty"`
HwID string `json:"hwId,omitempty"`
FwID string `json:"fwId,omitempty"`
OemID string `json:"oemId,omitempty"`
Alias string `json:"alias,omitempty"`
DevName string `json:"dev_name,omitempty"`
IconHash string `json:"icon_hash,omitempty"`
RelayState int `json:"relay_state,omitempty"`
OnTime int `json:"on_time,omitempty"`
ActiveMode string `json:"active_mode,omitempty"`
Feature string `json:"feature,omitempty"`
Updating int `json:"updating,omitempty"`
Rssi int `json:"rssi,omitempty"`
LedOff int `json:"led_off,omitempty"`
Latitude int `json:"latitude,omitempty"`
Longitude int `json:"longitude,omitempty"`
MicType string `json:"mic_type,omitempty"`
Children []SysInfoChild `json:"children,omitempty"`
ChildNum int `json:"child_num,omitempty"`
}
// GetRealtimeResponse is the response for EMeter Get Realtime request.
type GetRealtimeResponse struct {
VoltageMv int `json:"voltage_mv,omitempty"`
CurrentMa int `json:"current_ma,omitempty"`
PowerMw int `json:"power_mw,omitempty"`
TotalWh int `json:"total_wh,omitempty"`
ErrCode int `json:"err_code,omitempty"`
// Older firmware
CurrentA float64 `json:"current,omitempty"`
VoltageV float64 `json:"voltage,omitempty"`
PowerW float64 `json:"power,omitempty"`
TotalWhFloat float64 `json:"total,omitempty"`
}
// EMeterResponse encapsulates all emeter category responses.
type EMeterResponse struct {
GetRealtime *GetRealtimeResponse `json:"get_realtime,omitempty"`
}
// SystemResponse encapsulates all system category responses.
type SystemResponse struct {
SysInfo *SysInfoResponse `json:"get_sysinfo,omitempty"`
}
// GenericResponse is the root object for all responses.
type GenericResponse struct {
System *SystemResponse `json:"system,omitempty"`
EMeter *EMeterResponse `json:"emeter,omitempty"`
}
// GetSysinfoRequest requests system info.
type GetSysinfoRequest struct {
}
// ResetRequest requests a device reset after Delay.
type ResetRequest struct {
Delay int `json:"delay,omitempty"`
}
// SystemRequests encapsulates all system requests.
type SystemRequests struct {
GetSysinfo *GetSysinfoRequest `json:"get_sysinfo,omitempty"`
Reset *ResetRequest `json:"reset,omitempty"`
}
// GetRealtimeRequest requests current power information.
type GetRealtimeRequest struct {
}
// EMeterRequests encapsulates all emeter requests.
type EMeterRequests struct {
GetRealtime *GetRealtimeRequest `json:"get_realtime,omitempty"`
}
// Context is used to query child devices.
type Context struct {
ChildIds []string `json:"child_ids,omitempty"`
}
// GenericRequest is the root for all requests.
type GenericRequest struct {
Context *Context `json:"context,omitempty"`
System *SystemRequests `json:"system,omitempty"`
EMeter *EMeterRequests `json:"emeter,omitempty"`
}