Skip to content

Commit ad0bc7c

Browse files
committed
zwave-siren ZSE50 unit tests fixes
Added more units tests to increase coverage
1 parent 166b6b0 commit ad0bc7c

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

drivers/SmartThings/zwave-siren/src/test/test_zooz_zse50.lua

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local capabilities = require "st.capabilities"
66
local zw = require "st.zwave"
77
local zw_test_utils = require "integration_test.zwave_test_utils"
88
local Basic = (require "st.zwave.CommandClass.Basic")({ version = 1 })
9+
local Configuration = (require "st.zwave.CommandClass.Configuration")({ version = 4 })
910
local SoundSwitch = (require "st.zwave.CommandClass.SoundSwitch")({ version = 1 })
1011
local Notification = (require "st.zwave.CommandClass.Notification")({ version = 8 })
1112
local Version = (require "st.zwave.CommandClass.Version")({ version = 1 })
@@ -47,6 +48,138 @@ end
4748

4849
test.set_test_init_function(test_init)
4950

51+
test.register_coroutine_test(
52+
"init should rebuild tones when tone cache is missing",
53+
function()
54+
mock_siren:set_field("TONES_LIST", nil)
55+
mock_siren:set_field("TONE_DEFAULT", nil)
56+
57+
test.socket.device_lifecycle:__queue_receive({ mock_siren.id, "init" })
58+
test.socket.capability:__expect_send(
59+
mock_siren:generate_test_message("main", capabilities.mode.mode("Rebuild List"))
60+
)
61+
test.socket.zwave:__expect_send(
62+
zw_test_utils.zwave_test_build_send_command(
63+
mock_siren,
64+
SoundSwitch:TonesNumberGet({})
65+
)
66+
)
67+
end,
68+
{
69+
min_api_version = 17
70+
}
71+
)
72+
73+
test.register_coroutine_test(
74+
"added should set startup volume and refresh",
75+
function()
76+
test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot")
77+
test.socket.zwave:__set_channel_ordering("relaxed")
78+
79+
test.socket.device_lifecycle:__queue_receive({ mock_siren.id, "added" })
80+
81+
test.socket.zwave:__expect_send(
82+
zw_test_utils.zwave_test_build_send_command(
83+
mock_siren,
84+
SoundSwitch:ConfigurationSet({ volume = 10 })
85+
)
86+
)
87+
test.socket.zwave:__expect_send(
88+
zw_test_utils.zwave_test_build_send_command(
89+
mock_siren,
90+
Basic:Get({})
91+
)
92+
)
93+
test.socket.zwave:__expect_send(
94+
zw_test_utils.zwave_test_build_send_command(
95+
mock_siren,
96+
Version:Get({})
97+
)
98+
)
99+
test.socket.zwave:__expect_send(
100+
zw_test_utils.zwave_test_build_send_command(
101+
mock_siren,
102+
Notification:Get({
103+
notification_type = Notification.notification_type.POWER_MANAGEMENT,
104+
event = Notification.event.power_management.STATE_IDLE,
105+
v1_alarm_type = 0
106+
})
107+
)
108+
)
109+
test.socket.zwave:__expect_send(
110+
zw_test_utils.zwave_test_build_send_command(
111+
mock_siren,
112+
SoundSwitch:ConfigurationGet({})
113+
)
114+
)
115+
test.socket.zwave:__expect_send(
116+
zw_test_utils.zwave_test_build_send_command(
117+
mock_siren,
118+
SoundSwitch:TonePlayGet({})
119+
)
120+
)
121+
end,
122+
{
123+
min_api_version = 17
124+
}
125+
)
126+
127+
test.register_coroutine_test(
128+
"infoChanged should update config and send delayed Basic Set",
129+
function()
130+
test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot")
131+
132+
test.socket.device_lifecycle:__queue_receive(
133+
mock_siren:generate_info_changed({ preferences = { ledColor = 255 } })
134+
)
135+
test.socket.zwave:__expect_send(
136+
zw_test_utils.zwave_test_build_send_command(
137+
mock_siren,
138+
Configuration:Set({ parameter_number = 7, size = 1, configuration_value = -1 })
139+
)
140+
)
141+
142+
test.mock_time.advance_time(1)
143+
test.socket.zwave:__expect_send(
144+
zw_test_utils.zwave_test_build_send_command(
145+
mock_siren,
146+
Basic:Set({ value = 0x00 })
147+
)
148+
)
149+
end,
150+
{
151+
min_api_version = 17
152+
}
153+
)
154+
155+
test.register_coroutine_test(
156+
"infoChanged should update playbackDuration and send delayed Basic Set",
157+
function()
158+
test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot")
159+
160+
test.socket.device_lifecycle:__queue_receive(
161+
mock_siren:generate_info_changed({ preferences = { playbackDuration = 90 } })
162+
)
163+
test.socket.zwave:__expect_send(
164+
zw_test_utils.zwave_test_build_send_command(
165+
mock_siren,
166+
Configuration:Set({ parameter_number = 2, size = 2, configuration_value = 90 })
167+
)
168+
)
169+
170+
test.mock_time.advance_time(1)
171+
test.socket.zwave:__expect_send(
172+
zw_test_utils.zwave_test_build_send_command(
173+
mock_siren,
174+
Basic:Set({ value = 0x00 })
175+
)
176+
)
177+
end,
178+
{
179+
min_api_version = 17
180+
}
181+
)
182+
50183
test.register_message_test(
51184
"Version report should update firmware version",
52185
{

0 commit comments

Comments
 (0)