-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathtest_zwave_button.lua
More file actions
180 lines (164 loc) · 4.89 KB
/
test_zwave_button.lua
File metadata and controls
180 lines (164 loc) · 4.89 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
-- Copyright 2022 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0
local test = require "integration_test"
local capabilities = require "st.capabilities"
local zw = require "st.zwave"
local zw_test_utils = require "integration_test.zwave_test_utils"
local SceneActivation = (require "st.zwave.CommandClass.SceneActivation")({ version=1 })
local CentralScene = (require "st.zwave.CommandClass.CentralScene")({ version=1 })
--- @type st.zwave.CommandClass.WakeUp
local WakeUp = (require "st.zwave.CommandClass.WakeUp")({ version=1 })
--- @type st.zwave.CommandClass.Battery
local Battery = (require "st.zwave.CommandClass.Battery")({ version = 1 })
local t_utils = require "integration_test.utils"
local button_endpoints = {
{
command_classes = {
{value = zw.SCENE_ACTIVATION},
{value = zw.CENTRAL_SCENE},
{value = zw.BATTERY},
}
}
}
local mock= test.mock_device.build_test_zwave_device({
profile = t_utils.get_profile_definition("button-generic.yml"),
zwave_endpoints = button_endpoints
})
local function test_init()
test.mock_device.add_test_device(mock)
end
test.set_test_init_function(test_init)
test.register_message_test(
"Button Scene Activation should be handled",
{
{
channel = "zwave",
direction = "receive",
message = { mock.id, zw_test_utils.zwave_test_build_receive_command(SceneActivation:Set({scene_id = 1})) }
},
{
channel = "capability",
direction = "send",
message = mock:generate_test_message("main", capabilities.button.button.pushed({ state_change = true }))
}
},
{
min_api_version = 17
}
)
test.register_message_test(
"Button Scene Activation held should be handled",
{
{
channel = "zwave",
direction = "receive",
message = { mock.id, zw_test_utils.zwave_test_build_receive_command(SceneActivation:Set({scene_id = 2})) }
},
{
channel = "capability",
direction = "send",
message = mock:generate_test_message("main", capabilities.button.button.held({ state_change = true }))
}
},
{
min_api_version = 17
}
)
test.register_message_test(
"Central Scene notification Button pushed should be handled",
{
{
channel = "zwave",
direction = "receive",
message = { mock.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({
key_attributes=CentralScene.key_attributes.KEY_PRESSED_1_TIME}))
}
},
{
channel = "capability",
direction = "send",
message = mock:generate_test_message("main", capabilities.button.button.pushed({ state_change = true }))
}
},
{
min_api_version = 17
}
)
test.register_message_test(
"Central Scene notification button held should be handled",
{
{
channel = "zwave",
direction = "receive",
message = { mock.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({
key_attributes=CentralScene.key_attributes.KEY_HELD_DOWN}))
}
},
{
channel = "capability",
direction = "send",
message = mock:generate_test_message("main", capabilities.button.button.down_hold({ state_change = true }))
}
},
{
min_api_version = 17
}
)
test.register_coroutine_test(
"Device Add should bootstrap UI state",
function()
test.socket.capability:__set_channel_ordering("relaxed")
test.socket.device_lifecycle:__queue_receive({ mock.id, "added" })
test.socket.capability:__expect_send(
mock:generate_test_message(
"main",
capabilities.button.supportedButtonValues({"pushed", "held"}, {visibility = { displayed = false }})
)
)
test.socket.capability:__expect_send(
mock:generate_test_message(
"main",
capabilities.button.numberOfButtons({ value = 1 }, {visibility = { displayed = false }})
)
)
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock,
Battery:Get({})
)
)
end,
{
min_api_version = 17
}
)
test.register_message_test(
"WakeUp.Notification should evoke state refresh Z-Wave GETs",
{
{
channel = "zwave",
direction = "receive",
message = { mock.id, zw_test_utils.zwave_test_build_receive_command(WakeUp:Notification({})) }
},
{
channel = "zwave",
direction = "send",
message = zw_test_utils.zwave_test_build_send_command(
mock,
WakeUp:IntervalGet({})
)
},
{
channel = "zwave",
direction = "send",
message = zw_test_utils.zwave_test_build_send_command(
mock,
Battery:Get({})
)
},
},
{
min_api_version = 17
}
)
test.run_registered_tests()