Skip to content

Commit 8c7c11b

Browse files
authored
Merge pull request #2442 from kdbang/main
Add test case to enhance code coverage for zigbee switch
2 parents 32685fb + 7e7c9cc commit 8c7c11b

File tree

13 files changed

+911
-277
lines changed

13 files changed

+911
-277
lines changed

drivers/SmartThings/zigbee-switch/src/inovelli-vzm31-sn/init.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ local function info_changed(driver, device, event, args)
150150
local preferences = preference_map
151151
if args.old_st_store.preferences["notificationChild"] ~= device.preferences.notificationChild and args.old_st_store.preferences["notificationChild"] == false and device.preferences.notificationChild == true then
152152
if not device:get_child_by_parent_assigned_key('notification') then
153-
add_child(driver,device,'rgbw-bulb-2700K-6500K','notificaiton')
153+
add_child(driver,device,'rgbw-bulb-2700K-6500K','notification')
154154
end
155155
end
156156
for id, value in pairs(device.preferences) do
@@ -229,10 +229,10 @@ local device_init = function(self, device)
229229
end
230230
device:send(cluster_base.read_attribute(device, data_types.ClusterId(0x0000), 0x4000))
231231
else
232-
switch_utils.emit_event_if_latest_state_missing(device, "main", capabilities.colorControl.NAME, capabilities.colorControl.hue.NAME, capabilities.colorControl.hue(1))
233-
switch_utils.emit_event_if_latest_state_missing(device, "main", capabilities.colorControl.NAME, capabilities.colorControl.saturation.NAME, capabilities.colorControl.saturation(1))
234-
switch_utils.emit_event_if_latest_state_missing(device, "main", capabilities.colorTemperature.NAME, capabilities.colorTemperature.colorTemperature.NAME, capabilities.colorTemperature.colorTemperature(6500))
235-
switch_utils.emit_event_if_latest_state_missing(device, "main", capabilities.switchLevel.NAME, capabilities.switchLevel.level.NAME, capabilities.switchLevel.level(100))
232+
switch_utils.emit_event_if_latest_state_missing(device, "main", capabilities.colorControl, capabilities.colorControl.hue.NAME, capabilities.colorControl.hue(1))
233+
switch_utils.emit_event_if_latest_state_missing(device, "main", capabilities.colorControl, capabilities.colorControl.saturation.NAME, capabilities.colorControl.saturation(1))
234+
switch_utils.emit_event_if_latest_state_missing(device, "main", capabilities.colorTemperature, capabilities.colorTemperature.colorTemperature.NAME, capabilities.colorTemperature.colorTemperature(6500))
235+
switch_utils.emit_event_if_latest_state_missing(device, "main", capabilities.switchLevel, capabilities.switchLevel.level.NAME, capabilities.switchLevel.level(100))
236236
switch_utils.emit_event_if_latest_state_missing(device, "main", capabilities.switch, capabilities.switch.switch.NAME, capabilities.switch.switch("off"))
237237
end
238238
end

drivers/SmartThings/zigbee-switch/src/test/test_aqara_switch_no_power.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ local PRIVATE_MODE = "PRIVATE_MODE"
3737

3838
local mock_device = test.mock_device.build_test_zigbee_device(
3939
{
40+
label = "Aqara Smart Wall Switch H1 EU (No Neutral, Double Rocker) 1",
41+
profile = t_utils.get_profile_definition("aqara-switch-no-power.yml"),
42+
fingerprinted_endpoint_id = 0x01,
43+
zigbee_endpoints = {
44+
[1] = {
45+
id = 1,
46+
manufacturer = "LUMI",
47+
model = "lumi.switch.l2aeu1",
48+
server_clusters = { 0x0006 }
49+
}
50+
}
51+
}
52+
)
53+
54+
local mock_base_device = test.mock_device.build_test_zigbee_device(
55+
{
56+
label = "Aqara Smart Wall Switch H1 EU (No Neutral, Double Rocker) 1",
4057
profile = t_utils.get_profile_definition("aqara-switch-no-power.yml"),
4158
fingerprinted_endpoint_id = 0x01,
4259
zigbee_endpoints = {
@@ -62,6 +79,7 @@ zigbee_test_utils.prepare_zigbee_env_info()
6279

6380
local function test_init()
6481
test.mock_device.add_test_device(mock_device)
82+
test.mock_device.add_test_device(mock_base_device)
6583
test.mock_device.add_test_device(mock_child)
6684
end
6785

@@ -114,6 +132,30 @@ test.register_coroutine_test(
114132
end
115133
)
116134

135+
test.register_coroutine_test(
136+
"Lifecycle - added test",
137+
function()
138+
-- The initial switch event should be send during the device's first time onboarding
139+
test.socket.zigbee:__set_channel_ordering("relaxed")
140+
test.socket.device_lifecycle:__queue_receive({ mock_base_device.id, "added" })
141+
mock_base_device:expect_device_create({
142+
type = "EDGE_CHILD",
143+
label = "Aqara Smart Wall Switch H1 EU (No Neutral, Double Rocker) 2",
144+
profile = "aqara-switch-child",
145+
parent_device_id = mock_base_device.id,
146+
parent_assigned_child_key = "02"
147+
})
148+
test.socket.capability:__expect_send(mock_base_device:generate_test_message("main", capabilities.button.numberOfButtons({ value = 2 },
149+
{ visibility = { displayed = false } })))
150+
test.socket.zigbee:__expect_send({ mock_base_device.id,
151+
cluster_base.write_manufacturer_specific_attribute(mock_base_device, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE,
152+
data_types.Uint8, 1) })
153+
test.socket.capability:__expect_send(mock_base_device:generate_test_message("main", capabilities.button.supportedButtonValues({ "pushed" },
154+
{ visibility = { displayed = false } })))
155+
test.socket.capability:__expect_send(mock_base_device:generate_test_message("main", capabilities.button.button.pushed({ state_change = false })))
156+
end
157+
)
158+
117159
test.register_coroutine_test(
118160
"Refresh device",
119161
function()

drivers/SmartThings/zigbee-switch/src/test/test_enbrighten_metering_dimmer.lua

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
local test = require "integration_test"
1616
local clusters = require "st.zigbee.zcl.clusters"
17+
local ElectricalMeasurementCluster = clusters.ElectricalMeasurement
1718
local OnOffCluster = clusters.OnOff
1819
local LevelCluster = clusters.Level
1920
local SimpleMeteringCluster = clusters.SimpleMetering
2021
local capabilities = require "st.capabilities"
2122
local t_utils = require "integration_test.utils"
23+
local zigbee_test_utils = require "integration_test.zigbee_test_utils"
2224

2325
local mock_device = test.mock_device.build_test_zigbee_device({
2426
profile = t_utils.get_profile_definition("switch-dimmer-power-energy.yml"),
@@ -27,19 +29,119 @@ local mock_device = test.mock_device.build_test_zigbee_device({
2729
id = 1,
2830
manufacturer = "Jasco Products",
2931
model = "43082",
30-
server_clusters = { 0x0000, 0x0003, 0x0004, 0x0005, 0x0006, 0x0008, 0x0702, 0x0B05 },
32+
server_clusters = { 0x0000, 0x0003, 0x0004, 0x0005, 0x0006, 0x0008, 0x0702, 0x0B04 },
3133
client_clusters = { 0x000A, 0x0019 }
3234
}
3335
}
3436
})
3537

38+
zigbee_test_utils.prepare_zigbee_env_info()
39+
3640
local function test_init()
3741
mock_device:set_field("_configuration_version", 1, {persist = true})
3842
test.mock_device.add_test_device(mock_device)
3943
end
4044

4145
test.set_test_init_function(test_init)
4246

47+
test.register_coroutine_test(
48+
"lifecycle configure event should configure device",
49+
function ()
50+
test.socket.zigbee:__set_channel_ordering("relaxed")
51+
test.socket.device_lifecycle:__queue_receive({mock_device.id, "doConfigure"})
52+
test.socket.zigbee:__expect_send({
53+
mock_device.id,
54+
zigbee_test_utils.build_bind_request(mock_device,
55+
zigbee_test_utils.mock_hub_eui,
56+
ElectricalMeasurementCluster.ID)
57+
})
58+
test.socket.zigbee:__expect_send({
59+
mock_device.id,
60+
zigbee_test_utils.build_bind_request(mock_device,
61+
zigbee_test_utils.mock_hub_eui,
62+
OnOffCluster.ID)
63+
})
64+
test.socket.zigbee:__expect_send({
65+
mock_device.id,
66+
zigbee_test_utils.build_bind_request(mock_device,
67+
zigbee_test_utils.mock_hub_eui,
68+
LevelCluster.ID)
69+
})
70+
test.socket.zigbee:__expect_send({
71+
mock_device.id,
72+
zigbee_test_utils.build_bind_request(mock_device,
73+
zigbee_test_utils.mock_hub_eui,
74+
SimpleMeteringCluster.ID)
75+
})
76+
test.socket.zigbee:__expect_send({
77+
mock_device.id,
78+
ElectricalMeasurementCluster.attributes.ActivePower:read(mock_device)
79+
})
80+
test.socket.zigbee:__expect_send({
81+
mock_device.id,
82+
ElectricalMeasurementCluster.attributes.ACPowerMultiplier:read(mock_device)
83+
})
84+
test.socket.zigbee:__expect_send({
85+
mock_device.id,
86+
ElectricalMeasurementCluster.attributes.ACPowerDivisor:read(mock_device)
87+
})
88+
test.socket.zigbee:__expect_send({
89+
mock_device.id,
90+
OnOffCluster.attributes.OnOff:read(mock_device)
91+
})
92+
test.socket.zigbee:__expect_send({
93+
mock_device.id,
94+
LevelCluster.attributes.CurrentLevel:read(mock_device)
95+
})
96+
test.socket.zigbee:__expect_send({
97+
mock_device.id,
98+
SimpleMeteringCluster.attributes.InstantaneousDemand:read(mock_device)
99+
})
100+
test.socket.zigbee:__expect_send({
101+
mock_device.id,
102+
SimpleMeteringCluster.attributes.CurrentSummationDelivered:read(mock_device)
103+
})
104+
test.socket.zigbee:__expect_send({
105+
mock_device.id,
106+
SimpleMeteringCluster.attributes.Multiplier:read(mock_device)
107+
})
108+
test.socket.zigbee:__expect_send({
109+
mock_device.id,
110+
SimpleMeteringCluster.attributes.Divisor:read(mock_device)
111+
})
112+
test.socket.zigbee:__expect_send({
113+
mock_device.id,
114+
ElectricalMeasurementCluster.attributes.ACPowerMultiplier:configure_reporting(mock_device, 1, 43200, 1)
115+
})
116+
test.socket.zigbee:__expect_send({
117+
mock_device.id,
118+
ElectricalMeasurementCluster.attributes.ACPowerDivisor:configure_reporting(mock_device, 1, 43200, 1)
119+
})
120+
test.socket.zigbee:__expect_send({
121+
mock_device.id,
122+
ElectricalMeasurementCluster.attributes.ActivePower:configure_reporting(mock_device, 5, 3600, 5)
123+
})
124+
test.socket.zigbee:__expect_send({
125+
mock_device.id,
126+
OnOffCluster.attributes.OnOff:configure_reporting(mock_device, 0, 300)
127+
})
128+
test.socket.zigbee:__expect_send({
129+
mock_device.id,
130+
LevelCluster.attributes.CurrentLevel:configure_reporting(mock_device, 1, 3600, 1)
131+
})
132+
test.socket.zigbee:__expect_send({
133+
mock_device.id,
134+
SimpleMeteringCluster.attributes.InstantaneousDemand:configure_reporting(mock_device, 5, 3600, 5)
135+
})
136+
test.socket.zigbee:__expect_send({
137+
mock_device.id,
138+
SimpleMeteringCluster.attributes.CurrentSummationDelivered:configure_reporting(mock_device, 5, 3600, 1)
139+
})
140+
141+
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
142+
end
143+
)
144+
43145
test.register_message_test(
44146
"Capability command On should be handled",
45147
{

0 commit comments

Comments
 (0)