-
Notifications
You must be signed in to change notification settings - Fork 1
/
command_local.go
executable file
·294 lines (214 loc) · 7.81 KB
/
command_local.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
package cluster
// Local command is cluster-specific command and its arguments.
//
// E.G. CommandClusterAndId=(cluster=On/Off command=Off With Effect) and its arguments
// are struct fields EffectIdentifier and EffectVariant
type LocalCommand interface {
CommandClusterAndId() (ClusterId, uint8)
}
// These struct fields, their order and their sizes are defined by ZCL spec.
// E.G. for *TriggerEffectCommand* see ZCL spec section 3.5.2.3.3
//
// pro-tip: you can search below-mentioned ZCL spec section numbers from the spec:
// https://zigbeealliance.org/wp-content/uploads/2019/12/07-5123-06-zigbee-cluster-library-specification.pdf
type ResetToFactoryDefaultsCommand struct {
}
// -------- Cluster: Identify --------
type IdentifyCommand struct {
IdentifyTime uint16
}
type IdentifyQueryCommand struct{}
type EffectId uint8
const (
EffectIdBlink EffectId = 0x00 // Light is turned on/off once
EffectIdBreathe EffectId = 0x01 // Light turned on/off over 1 second and repeated 15 times.
EffectIdOkay EffectId = 0x02 // Colored light turns green for 1 second; noncolored light flashes twice
EffectIdChannelChange EffectId = 0x0b // Colored light turns orange for 8 seconds; noncolored light switches to maximum brightness for 0.5s and then minimum brightness for 7.5s.
EffectIdFinishEffect EffectId = 0xfe // Complete the current effect sequence before terminating. e.g., if in the middle of a breathe effect (as above), first complete the current 1s breathe effect and then terminate the effect
EffectIdStopEffect EffectId = 0xff // Terminate the effect as soon as possible
)
// ZCL spec section: 3.5.2.3.3
type GenIdentifyTriggerEffectCommand struct {
Effect EffectId
EffectVariant uint8 // variant of effect *EffectIdentifier*. usually zero
}
func (c *GenIdentifyTriggerEffectCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenIdentify, 0x40
}
var _ LocalCommand = (*GenIdentifyTriggerEffectCommand)(nil)
type IdentifyQueryResponse struct {
Timeout uint16
}
// -------- Cluster: GenOnOff --------
// ZCL spec section: 3.8.2.3.1
type GenOnOffOffCommand struct{}
func (c *GenOnOffOffCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenOnOff, 0x00
}
var _ LocalCommand = (*GenOnOffOffCommand)(nil)
// ZCL spec section: 3.8.2.3.2
type GenOnOffOnCommand struct{}
func (c *GenOnOffOnCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenOnOff, 0x01
}
var _ LocalCommand = (*GenOnOffOnCommand)(nil)
// ZCL spec section: 3.8.2.3.3
type GenOnOffToggleCommand struct{}
func (c *GenOnOffToggleCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenOnOff, 0x02
}
var _ LocalCommand = (*GenOnOffToggleCommand)(nil)
type OffWithEffectCommand struct {
EffectIdentifier uint8
EffectVariant uint8
}
type OnWithRecallGlobalSceneCommand struct{}
type OnWithTimedOffCommand struct {
OnOffControl uint8
OnTime uint16
OffWaitTime uint16
}
// -------- Cluster: IdGenLevelCtrl --------
// ZCL spec section: 3.10.2.4.1
type MoveToLevelCommand struct {
Level uint8 // valid range (0x00, 0xfe)
TransitionTime uint16 // [100ms], valid range (0x0000, 0xffff)
}
func (c *MoveToLevelCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenLevelCtrl, 0x00
}
var _ LocalCommand = (*MoveToLevelCommand)(nil)
// ZCL spec section: 3.10.2.4.2
type MoveCommand struct {
MoveMode uint8
Rate uint8
}
func (c *MoveCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenLevelCtrl, 0x01
}
var _ LocalCommand = (*MoveCommand)(nil)
// ZCL spec section: 3.10.2.4.3
type StepCommand struct {
StepMode uint8
StepSize uint8
TransitionTime uint16
}
func (c *StepCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenLevelCtrl, 0x02
}
var _ LocalCommand = (*StepCommand)(nil)
// ZCL spec section: 3.10.2.4.4
type StopCommand struct{}
func (c *StopCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenLevelCtrl, 0x03
}
var _ LocalCommand = (*StopCommand)(nil)
// ZCL spec section: 3.10.2.4.5
type MoveToLevelOnOffCommand struct {
Level uint8
TransitionTime uint16
}
func (c *MoveToLevelOnOffCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenLevelCtrl, 0x04
}
var _ LocalCommand = (*MoveToLevelOnOffCommand)(nil)
// ZCL spec section: 3.10.2.4.5
type MoveOnOffCommand struct {
MoveMode uint8
Rate uint8
}
func (c *MoveOnOffCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenLevelCtrl, 0x05
}
var _ LocalCommand = (*MoveOnOffCommand)(nil)
// ZCL spec section: 3.10.2.4.5
type StepOnOffCommand struct {
StepMode uint8
StepSize uint8
TransitionTime uint16
}
func (c *StepOnOffCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenLevelCtrl, 0x06
}
var _ LocalCommand = (*StepOnOffCommand)(nil)
// 0x07,StopOnOff, ZCL spec section: 3.10.2.4.5
type StopOnOffCommand struct{}
func (c *StopOnOffCommand) CommandClusterAndId() (ClusterId, uint8) {
return IdGenLevelCtrl, 0x07
}
var _ LocalCommand = (*StopOnOffCommand)(nil)
// -------- Cluster: LightingColorCtrl --------
// ZCL spec section: 5.2.2.3.10
type LightingColorCtrlMoveToColor struct {
X uint16
Y uint16
TransitionTime uint16
}
func (c *LightingColorCtrlMoveToColor) CommandClusterAndId() (ClusterId, uint8) {
return IdLightingColorCtrl, 0x07
}
var _ LocalCommand = (*LightingColorCtrlMoveToColor)(nil)
// ZCL spec section: 5.2.2.3.13
type LightingColorCtrlMoveToColorTemperature struct {
ColorTemperatureMireds uint16 // Blue sky = 40 mireds, photography flash = 200 mireds. Candle flame = 667. http://www.photokaboom.com/photography/learn/Photoshop_Elements/color/1_color_temperature_mired.htm valid range (0x0000, 0xfeff)
TransitionTime uint16
}
func (c *LightingColorCtrlMoveToColorTemperature) CommandClusterAndId() (ClusterId, uint8) {
return IdLightingColorCtrl, 0x0a
}
var _ LocalCommand = (*LightingColorCtrlMoveToColorTemperature)(nil)
// -------- Cluster: IdClosuresWindowCovering --------
// ZCL spec section: 7.4.2.2.1
type ClosuresWindowCoveringUp struct{}
func (c *ClosuresWindowCoveringUp) CommandClusterAndId() (ClusterId, uint8) {
return IdClosuresWindowCovering, 0x00
}
var _ LocalCommand = (*ClosuresWindowCoveringUp)(nil)
// ZCL spec section: 7.4.2.2.2
type ClosuresWindowCoveringDown struct{}
func (c *ClosuresWindowCoveringDown) CommandClusterAndId() (ClusterId, uint8) {
return IdClosuresWindowCovering, 0x01
}
var _ LocalCommand = (*ClosuresWindowCoveringDown)(nil)
// ZCL spec section: 7.4.2.2.3
type ClosuresWindowCoveringStop struct{}
func (c *ClosuresWindowCoveringStop) CommandClusterAndId() (ClusterId, uint8) {
return IdClosuresWindowCovering, 0x02
}
var _ LocalCommand = (*ClosuresWindowCoveringStop)(nil)
// ZCL spec section: 7.4.2.2.4
type ClosuresWindowCoveringGoToLiftPercentage struct {
Value uint8 // 0-100
}
func (c *ClosuresWindowCoveringGoToLiftPercentage) CommandClusterAndId() (ClusterId, uint8) {
return IdClosuresWindowCovering, 0x05
}
var _ LocalCommand = (*ClosuresWindowCoveringGoToLiftPercentage)(nil)
// -------- Cluster: Scenes --------
// undocumented in ZCL spec...........
type ScenesMysteryCommand7 struct {
DataRaw [4]byte
}
func (c *ScenesMysteryCommand7) CommandClusterAndId() (ClusterId, uint8) {
return IdGenOnOff, 0x07
}
func (c *ScenesMysteryCommand7) Left() bool {
// first byte 0x01 if going to "left" scene, 0x00 if "right"
return c.DataRaw[0] == 0x01
}
var _ LocalCommand = (*ScenesMysteryCommand7)(nil)
// the following are "generated" commands (end device -> coordinator direction)
type ZoneStatusChangeNotificationCommand struct {
ZoneStatus ZoneStatus
ExtendedStatus uint8 // "SHALL be set to zero"
ZoneID uint8
Delay uint16
}
// ZCL spec section: 8.2.2.2.1.3
type ZoneStatus uint16
func (z ZoneStatus) Alarm1() bool {
return z&0b1 != 0
}
func (z ZoneStatus) UnimplementedBitsSet() bool {
return z|0b1 != 1
}