-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathtest_aqara_button.lua
More file actions
399 lines (376 loc) · 16.2 KB
/
test_aqara_button.lua
File metadata and controls
399 lines (376 loc) · 16.2 KB
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
-- Copyright 2024 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0
local test = require "integration_test"
local t_utils = require "integration_test.utils"
local zigbee_test_utils = require "integration_test.zigbee_test_utils"
local capabilities = require "st.capabilities"
local clusters = require "st.zigbee.zcl.clusters"
local cluster_base = require "st.zigbee.cluster_base"
local data_types = require "st.zigbee.data_types"
local MULTISTATE_INPUT_CLUSTER_ID = 0x0012
local PRESENT_ATTRIBUTE_ID = 0x0055
local PowerConfiguration = clusters.PowerConfiguration
local MFG_CODE = 0x115F
local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTRIBUTE_ID_T1 = 0x0009
local PRIVATE_ATTRIBUTE_ID_E1 = 0x0125
local PRIVATE_ATTRIBUTE_ID_ALIVE = 0x00F7
local MODE_CHANGE = "stse.allowOperationModeChange"
local COMP_LIST = { "button1", "button2", "all" }
local mock_device_h1_single = test.mock_device.build_test_zigbee_device(
{
profile = t_utils.get_profile_definition("aqara-single-button-mode.yml"),
zigbee_endpoints = {
[1] = {
id = 1,
manufacturer = "LUMI",
model = "lumi.remote.b18ac1",
server_clusters = { 0x0001, 0x0012 }
}
}
}
)
local COMP_LIST = { "button1", "button2", "all" }
local mock_device_e1 = test.mock_device.build_test_zigbee_device(
{
profile = t_utils.get_profile_definition("one-button-batteryLevel.yml"),
zigbee_endpoints = {
[1] = {
id = 1,
manufacturer = "LUMI",
model = "lumi.remote.acn003",
server_clusters = { 0x0001, 0x0012 }
}
}
}
)
local mock_device_h1_double_rocker = test.mock_device.build_test_zigbee_device(
{
profile = t_utils.get_profile_definition("aqara-double-buttons-mode.yml"),
zigbee_endpoints = {
[1] = {
id = 1,
manufacturer = "LUMI",
model = "lumi.remote.b286acn03",
server_clusters = { 0x0001, 0x0012 }
}
}
}
)
zigbee_test_utils.prepare_zigbee_env_info()
local function test_init()
test.mock_device.add_test_device(mock_device_h1_single)
test.mock_device.add_test_device(mock_device_e1)
test.mock_device.add_test_device(mock_device_h1_double_rocker)
end
test.set_test_init_function(test_init)
test.register_coroutine_test(
"Handle added lifecycle - T1 double rocker",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device_h1_double_rocker.id, "added" })
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.supportedButtonValues({ "pushed", "held", "double" }, { visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.numberOfButtons({ value = 1 })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.button.pushed({ state_change = false })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.batteryLevel.battery.normal()))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.batteryLevel.type("CR2032")))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.batteryLevel.quantity(1)))
for i = 1, 3 do
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message(COMP_LIST[i],
capabilities.button.supportedButtonValues({ "pushed", "held", "double" }, { visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message(COMP_LIST[i],
capabilities.button.numberOfButtons({ value = 1 })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message(COMP_LIST[i],
capabilities.button.button.pushed({ state_change = false })))
end
end,
{
min_api_version = 19
}
)
test.register_coroutine_test(
"Handle doConfigure lifecycle -- e1",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device_e1.id, "doConfigure" })
test.socket.zigbee:__expect_send({
mock_device_e1.id,
zigbee_test_utils.build_bind_request(mock_device_e1, zigbee_test_utils.mock_hub_eui, PowerConfiguration.ID)
})
test.socket.zigbee:__expect_send({
mock_device_e1.id,
PowerConfiguration.attributes.BatteryVoltage:configure_reporting(mock_device_e1, 30, 3600, 1)
})
test.socket.zigbee:__expect_send({
mock_device_e1.id,
zigbee_test_utils.build_bind_request(mock_device_e1, zigbee_test_utils.mock_hub_eui, MULTISTATE_INPUT_CLUSTER_ID)
})
test.socket.zigbee:__expect_send({
mock_device_e1.id,
zigbee_test_utils.build_attr_config(mock_device_e1, MULTISTATE_INPUT_CLUSTER_ID, PRESENT_ATTRIBUTE_ID, 0x0003,
0x1C20, data_types.Uint16, 0x0001)
})
test.socket.zigbee:__expect_send({ mock_device_e1.id,
cluster_base.write_manufacturer_specific_attribute(mock_device_e1, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_E1,
MFG_CODE,
data_types.Uint8, 2) })
mock_device_e1:expect_metadata_update({ provisioning_state = "PROVISIONED" })
end,
{
min_api_version = 19
}
)
test.register_coroutine_test(
"Handle doConfigure lifecycle -- t1",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device_h1_double_rocker.id, "doConfigure" })
test.socket.zigbee:__expect_send({
mock_device_h1_double_rocker.id,
zigbee_test_utils.build_bind_request(mock_device_h1_double_rocker, zigbee_test_utils.mock_hub_eui,
PowerConfiguration.ID)
})
test.socket.zigbee:__expect_send({
mock_device_h1_double_rocker.id,
PowerConfiguration.attributes.BatteryVoltage:configure_reporting(mock_device_h1_double_rocker, 30, 3600, 1)
})
test.socket.zigbee:__expect_send({
mock_device_h1_double_rocker.id,
zigbee_test_utils.build_bind_request(mock_device_h1_double_rocker, zigbee_test_utils.mock_hub_eui,
MULTISTATE_INPUT_CLUSTER_ID)
})
test.socket.zigbee:__expect_send({
mock_device_h1_double_rocker.id,
zigbee_test_utils.build_attr_config(mock_device_h1_double_rocker, MULTISTATE_INPUT_CLUSTER_ID, PRESENT_ATTRIBUTE_ID,
0x0003, 0x1C20, data_types.Uint16, 0x0001)
})
test.socket.zigbee:__expect_send({ mock_device_h1_double_rocker.id,
cluster_base.write_manufacturer_specific_attribute(mock_device_h1_double_rocker, PRIVATE_CLUSTER_ID,
PRIVATE_ATTRIBUTE_ID_T1, MFG_CODE,
data_types.Uint8, 1) })
mock_device_h1_double_rocker:expect_metadata_update({ provisioning_state = "PROVISIONED" })
end,
{
min_api_version = 19
}
)
test.register_coroutine_test(
"Reported button should be handled: pushed true",
function()
local attr_report_data = {
{ PRESENT_ATTRIBUTE_ID, data_types.Uint16.ID, 0x0001 }
}
test.socket.zigbee:__queue_receive({
mock_device_h1_double_rocker.id,
zigbee_test_utils.build_attribute_report(mock_device_h1_double_rocker, MULTISTATE_INPUT_CLUSTER_ID,
attr_report_data, MFG_CODE)
})
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.button.pushed({ state_change = true })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("button1",
capabilities.button.button.pushed({ state_change = true })))
end,
{
min_api_version = 19
}
)
test.register_coroutine_test(
"Reported button should be handled: double true",
function()
local attr_report_data = {
{ PRESENT_ATTRIBUTE_ID, data_types.Uint16.ID, 0x0002 }
}
test.socket.zigbee:__queue_receive({
mock_device_h1_double_rocker.id,
zigbee_test_utils.build_attribute_report(mock_device_h1_double_rocker, MULTISTATE_INPUT_CLUSTER_ID,
attr_report_data, MFG_CODE)
})
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.button.double({ state_change = true })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("button1",
capabilities.button.button.double({ state_change = true })))
end,
{
min_api_version = 19
}
)
test.register_coroutine_test(
"Reported button should be handled: held true",
function()
local attr_report_data = {
{ PRESENT_ATTRIBUTE_ID, data_types.Uint16.ID, 0x0000 }
}
test.socket.zigbee:__queue_receive({
mock_device_h1_double_rocker.id,
zigbee_test_utils.build_attribute_report(mock_device_h1_double_rocker, MULTISTATE_INPUT_CLUSTER_ID,
attr_report_data, MFG_CODE)
})
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.button.held({ state_change = true })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("button1",
capabilities.button.button.held({ state_change = true })))
end,
{
min_api_version = 19
}
)
test.register_message_test(
"Battery Level - Normal",
{
{
channel = "zigbee",
direction = "receive",
message = { mock_device_e1.id, PowerConfiguration.attributes.BatteryVoltage:build_test_attr_report(mock_device_e1, 30) }
},
{
channel = "capability",
direction = "send",
message = mock_device_e1:generate_test_message("main", capabilities.batteryLevel.battery("normal"))
}
},
{
min_api_version = 19
}
)
test.register_message_test(
"Battery Level - Warning",
{
{
channel = "zigbee",
direction = "receive",
message = { mock_device_e1.id, PowerConfiguration.attributes.BatteryVoltage:build_test_attr_report(mock_device_e1, 27) }
},
{
channel = "capability",
direction = "send",
message = mock_device_e1:generate_test_message("main", capabilities.batteryLevel.battery("warning"))
}
},
{
min_api_version = 19
}
)
test.register_message_test(
"Battery Level - Critical",
{
{
channel = "zigbee",
direction = "receive",
message = { mock_device_e1.id, PowerConfiguration.attributes.BatteryVoltage:build_test_attr_report(mock_device_e1, 20) }
},
{
channel = "capability",
direction = "send",
message = mock_device_e1:generate_test_message("main", capabilities.batteryLevel.battery("critical"))
}
},
{
min_api_version = 19
}
)
test.register_coroutine_test(
"Wireless Remote Switch H1 Mode Change",
function()
local mode = 2
local updates = {
preferences = {
[MODE_CHANGE] = true
}
}
test.socket.device_lifecycle:__queue_receive(mock_device_h1_double_rocker:generate_info_changed(updates))
mock_device_h1_double_rocker:set_field("devicemode", 1, { persist = true })
local attr_report_data = {
{ PRIVATE_ATTRIBUTE_ID_ALIVE, data_types.OctetString.ID, "\x01\x21\xB8\x0B\x03\x28\x19\x04\x21\xA8\x13\x05\x21\x45\x08\x06\x24\x07\x00\x00\x00\x00\x08\x21\x15\x01\x0A\x21\xF5\x65\x0C\x20\x01\x64\x20\x01\x66\x20\x03\x67\x20\x01\x68\x21\xA8\x00" }
}
test.wait_for_events()
test.socket.zigbee:__queue_receive({
mock_device_h1_double_rocker.id,
zigbee_test_utils.build_attribute_report(mock_device_h1_double_rocker, PRIVATE_CLUSTER_ID, attr_report_data,
MFG_CODE)
})
test.socket.zigbee:__expect_send({ mock_device_h1_double_rocker.id, cluster_base
.write_manufacturer_specific_attribute(mock_device_h1_double_rocker, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_E1,
MFG_CODE, data_types.Uint8, mode) })
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.supportedButtonValues({ "pushed", "held", "double" }, { visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.numberOfButtons({ value = 1 })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.button.pushed({ state_change = false })))
for i = 1, 3 do
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message(COMP_LIST[i],
capabilities.button.supportedButtonValues({ "pushed", "held", "double" }, { visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message(COMP_LIST[i],
capabilities.button.numberOfButtons({ value = 1 })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message(COMP_LIST[i],
capabilities.button.button.pushed({ state_change = false })))
end
end,
{
min_api_version = 19
}
)
test.register_coroutine_test(
"Handle added lifecycle - H1 single rocker (sets mode=1)",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device_h1_single.id, "added" })
test.socket.capability:__expect_send(mock_device_h1_single:generate_test_message("main",
capabilities.button.supportedButtonValues({ "pushed" }, { visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device_h1_single:generate_test_message("main",
capabilities.button.numberOfButtons({ value = 1 })))
test.socket.capability:__expect_send(mock_device_h1_single:generate_test_message("main",
capabilities.button.button.pushed({ state_change = false })))
test.socket.capability:__expect_send(mock_device_h1_single:generate_test_message("main",
capabilities.batteryLevel.battery.normal()))
test.socket.capability:__expect_send(mock_device_h1_single:generate_test_message("main",
capabilities.batteryLevel.type("CR2450")))
test.socket.capability:__expect_send(mock_device_h1_single:generate_test_message("main",
capabilities.batteryLevel.quantity(1)))
end,
{
min_api_version = 19
}
)
test.register_coroutine_test(
"Wireless Remote Switch H1 Mode Change",
function()
local mode = 2
local updates = {
preferences = {
[MODE_CHANGE] = true
}
}
test.socket.device_lifecycle:__queue_receive(mock_device_h1_double_rocker:generate_info_changed(updates))
mock_device_h1_double_rocker:set_field("devicemode", 1, { persist = true })
local attr_report_data = {
{ PRIVATE_ATTRIBUTE_ID_ALIVE, data_types.OctetString.ID, "\x01\x21\xB8\x0B\x03\x28\x19\x04\x21\xA8\x13\x05\x21\x45\x08\x06\x24\x07\x00\x00\x00\x00\x08\x21\x15\x01\x0A\x21\xF5\x65\x0C\x20\x01\x64\x20\x01\x66\x20\x03\x67\x20\x01\x68\x21\xA8\x00" }
}
test.wait_for_events()
test.socket.zigbee:__queue_receive({
mock_device_h1_double_rocker.id,
zigbee_test_utils.build_attribute_report(mock_device_h1_double_rocker, PRIVATE_CLUSTER_ID, attr_report_data,
MFG_CODE)
})
test.socket.zigbee:__expect_send({ mock_device_h1_double_rocker.id, cluster_base
.write_manufacturer_specific_attribute(mock_device_h1_double_rocker, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_E1,
MFG_CODE, data_types.Uint8, mode) })
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.supportedButtonValues({ "pushed", "held", "double" }, { visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.numberOfButtons({ value = 1 })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message("main",
capabilities.button.button.pushed({ state_change = false })))
for i = 1, 3 do
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message(COMP_LIST[i],
capabilities.button.supportedButtonValues({ "pushed", "held", "double" }, { visibility = { displayed = false } })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message(COMP_LIST[i],
capabilities.button.numberOfButtons({ value = 1 })))
test.socket.capability:__expect_send(mock_device_h1_double_rocker:generate_test_message(COMP_LIST[i],
capabilities.button.button.pushed({ state_change = false })))
end
end
)
test.run_registered_tests()