Skip to content

Commit ddaf944

Browse files
committed
remove commented code, add and update tests
1 parent 5adeb1b commit ddaf944

File tree

3 files changed

+58
-73
lines changed

3 files changed

+58
-73
lines changed

drivers/SmartThings/matter-switch/src/switch_utils/utils.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ end
432432
--- @param checked_device any a Matter device object, either a parent or child device, so not necessarily the same as device
433433
--- @param subscribe_request table a subscribe request that will be appended to as needed for the device
434434
--- @param capabilities_seen any a list of capabilities that have already been checked by already checked devices
435-
-- @param matter_elements_seen table a list of attribute and event ids that have been added already
436435
--- @param subscribed_attributes table key-value pairs mapping capability ids to subscribed attributes
437436
--- @param subscribed_events table key-value pairs mapping capability ids to subscribed events
438437
function utils.populate_subscribe_request_for_device(checked_device, subscribe_request, capabilities_seen, attributes_seen, events_seen, subscribed_attributes, subscribed_events)

drivers/SmartThings/matter-switch/src/test/test_matter_multi_button_switch_mcd.lua

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,18 @@ local child_data = {
166166
local mock_child = test.mock_device.build_test_child_device(child_data)
167167

168168
-- add device for each mock device
169-
local CLUSTER_SUBSCRIBE_LIST ={
169+
local CLUSTER_SUBSCRIBE_LIST_NO_CHILD ={
170+
clusters.OnOff.attributes.OnOff,
171+
clusters.LevelControl.attributes.CurrentLevel,
172+
clusters.LevelControl.attributes.MaxLevel,
173+
clusters.LevelControl.attributes.MinLevel,
174+
clusters.Switch.server.events.InitialPress,
175+
clusters.Switch.server.events.LongPress,
176+
clusters.Switch.server.events.ShortRelease,
177+
clusters.Switch.server.events.MultiPressComplete,
178+
}
179+
180+
local CLUSTER_SUBSCRIBE_LIST_WITH_CHILD ={
170181
clusters.OnOff.attributes.OnOff,
171182
clusters.LevelControl.attributes.CurrentLevel,
172183
clusters.LevelControl.attributes.MaxLevel,
@@ -202,11 +213,10 @@ local function test_init()
202213
-- so we can set the proper expectations on those events.
203214
test.disable_startup_messages()
204215
test.mock_device.add_test_device(mock_device) -- make sure the cache is populated
205-
test.mock_device.add_test_device(mock_child)
206216

207217
-- added sets a bunch of fields on the device, and calls init
208-
local subscribe_request = CLUSTER_SUBSCRIBE_LIST[1]:subscribe(mock_device)
209-
for i, clus in ipairs(CLUSTER_SUBSCRIBE_LIST) do
218+
local subscribe_request = CLUSTER_SUBSCRIBE_LIST_NO_CHILD[1]:subscribe(mock_device)
219+
for i, clus in ipairs(CLUSTER_SUBSCRIBE_LIST_NO_CHILD) do
210220
if i > 1 then subscribe_request:merge(clus:subscribe(mock_device)) end
211221
end
212222
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
@@ -350,63 +360,45 @@ test.register_coroutine_test(
350360
end
351361
)
352362

353-
test.register_message_test(
363+
test.register_coroutine_test(
354364
"Switch child device: Set color temperature should send the appropriate commands",
355-
{
356-
{
357-
channel = "capability",
358-
direction = "receive",
359-
message = {
360-
mock_child.id,
361-
{ capability = "colorTemperature", component = "main", command = "setColorTemperature", args = {1800} }
362-
}
363-
},
364-
{
365-
channel = "matter",
366-
direction = "send",
367-
message = {
368-
mock_device.id,
369-
clusters.ColorControl.server.commands.MoveToColorTemperature(mock_device, mock_device_ep5, 556, TRANSITION_TIME, OPTIONS_MASK, OPTIONS_OVERRIDE)
370-
}
371-
},
372-
{
373-
channel = "matter",
374-
direction = "receive",
375-
message = {
376-
mock_device.id,
377-
clusters.ColorControl.server.commands.MoveToColorTemperature:build_test_command_response(mock_device, mock_device_ep5)
378-
}
379-
},
380-
{
381-
channel = "matter",
382-
direction = "receive",
383-
message = {
384-
mock_device.id,
385-
clusters.ColorControl.attributes.ColorTemperatureMireds:build_test_report_data(mock_device, mock_device_ep5, 556)
386-
}
387-
},
388-
{
389-
channel = "capability",
390-
direction = "send",
391-
message = mock_child:generate_test_message("main", capabilities.colorTemperature.colorTemperature(1800))
392-
},
393-
}
365+
function()
366+
test.mock_device.add_test_device(mock_child)
367+
test.wait_for_events()
368+
test.socket.capability:__queue_receive({
369+
mock_child.id,
370+
{ capability = "colorTemperature", component = "main", command = "setColorTemperature", args = {1800} }
371+
})
372+
test.socket.matter:__expect_send({
373+
mock_device.id,
374+
clusters.ColorControl.server.commands.MoveToColorTemperature(mock_device, mock_device_ep5, 556, TRANSITION_TIME, OPTIONS_MASK, OPTIONS_OVERRIDE)
375+
})
376+
test.socket.matter:__queue_receive({
377+
mock_device.id,
378+
clusters.ColorControl.server.commands.MoveToColorTemperature:build_test_command_response(mock_device, mock_device_ep5)
379+
})
380+
test.wait_for_events()
381+
test.socket.matter:__queue_receive({
382+
mock_device.id,
383+
clusters.ColorControl.attributes.ColorTemperatureMireds:build_test_report_data(mock_device, mock_device_ep5, 556)
384+
})
385+
test.socket.capability:__expect_send(mock_child:generate_test_message("main", capabilities.colorTemperature.colorTemperature(1800)))
386+
end
394387
)
395388

396389
test.register_coroutine_test(
397390
"Test MCD configuration not including switch for unsupported switch device type, create child device instead",
398391
function()
399392
local unsup_mock_device = mock_device_mcd_unsupported_switch_device_type
400393
-- added sets a bunch of fields on the device, and calls init
401-
local cluster_subscribe_list = {
402-
-- clusters.OnOff.attributes.OnOff,
394+
local CLUSTER_SUBSCRIBE_LIST = {
403395
clusters.Switch.server.events.InitialPress,
404396
clusters.Switch.server.events.LongPress,
405397
clusters.Switch.server.events.ShortRelease,
406398
clusters.Switch.server.events.MultiPressComplete,
407399
}
408-
local subscribe_request = cluster_subscribe_list[1]:subscribe(unsup_mock_device)
409-
for _, cluster in ipairs(cluster_subscribe_list) do
400+
local subscribe_request = CLUSTER_SUBSCRIBE_LIST[1]:subscribe(unsup_mock_device)
401+
for _, cluster in ipairs(CLUSTER_SUBSCRIBE_LIST) do
410402
subscribe_request:merge(cluster:subscribe(unsup_mock_device))
411403
end
412404
test.socket.device_lifecycle:__queue_receive({ unsup_mock_device.id, "added" })
@@ -433,15 +425,14 @@ test.register_coroutine_test(
433425
local updated_device_profile = t_utils.get_profile_definition("2-button.yml")
434426
test.socket.device_lifecycle:__queue_receive(unsup_mock_device:generate_info_changed({ profile = updated_device_profile }))
435427

436-
local cluster_subscribe_list = {
437-
-- clusters.OnOff.attributes.OnOff,
428+
local CLUSTER_SUBSCRIBE_LIST = {
438429
clusters.Switch.server.events.InitialPress,
439430
clusters.Switch.server.events.LongPress,
440431
clusters.Switch.server.events.ShortRelease,
441432
clusters.Switch.server.events.MultiPressComplete,
442433
}
443-
local subscribe_request = cluster_subscribe_list[1]:subscribe(unsup_mock_device)
444-
for i, cluster in ipairs(cluster_subscribe_list) do
434+
local subscribe_request = CLUSTER_SUBSCRIBE_LIST[1]:subscribe(unsup_mock_device)
435+
for i, cluster in ipairs(CLUSTER_SUBSCRIBE_LIST) do
445436
if i > 1 then
446437
subscribe_request:merge(cluster:subscribe(unsup_mock_device))
447438
end
@@ -474,11 +465,11 @@ test.register_coroutine_test(
474465
)
475466

476467
test.register_coroutine_test(
477-
"Test infoChanged event",
468+
"Test infoChanged event for parent device",
478469
function ()
479470
-- simulate the profile change update taking affect and the device info changing
480-
local subscribe_request = CLUSTER_SUBSCRIBE_LIST[1]:subscribe(mock_device)
481-
for i, clus in ipairs(CLUSTER_SUBSCRIBE_LIST) do
471+
local subscribe_request = CLUSTER_SUBSCRIBE_LIST_NO_CHILD[1]:subscribe(mock_device)
472+
for i, clus in ipairs(CLUSTER_SUBSCRIBE_LIST_NO_CHILD) do
482473
if i > 1 then subscribe_request:merge(clus:subscribe(mock_device)) end
483474
end
484475
local device_info_copy = utils.deep_copy(mock_device.raw_st_data)
@@ -487,9 +478,20 @@ test.register_coroutine_test(
487478
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
488479
expect_configure_buttons()
489480
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "infoChanged", device_info_json })
481+
end
482+
)
483+
484+
test.register_coroutine_test(
485+
"Test child device initialization, and that subscriptions are initialized correctly",
486+
function ()
487+
test.mock_device.add_test_device(mock_child)
490488
test.socket.matter:__expect_send({mock_device.id, clusters.OnOff.attributes.OnOff:read(mock_device)})
491489
test.socket.device_lifecycle:__queue_receive({ mock_child.id, "added" })
492490
test.socket.device_lifecycle:__queue_receive({ mock_child.id, "init" })
491+
local subscribe_request = CLUSTER_SUBSCRIBE_LIST_WITH_CHILD[1]:subscribe(mock_device)
492+
for i, clus in ipairs(CLUSTER_SUBSCRIBE_LIST_WITH_CHILD) do
493+
if i > 1 then subscribe_request:merge(clus:subscribe(mock_device)) end
494+
end
493495
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
494496
mock_child:expect_metadata_update({ provisioning_state = "PROVISIONED" })
495497
test.socket.device_lifecycle:__queue_receive({ mock_child.id, "doConfigure" })

drivers/SmartThings/matter-switch/src/test/test_matter_switch_device_types.lua

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -584,25 +584,9 @@ end
584584
local function test_init_parent_child_different_types()
585585
test.mock_device.add_test_device(mock_device_parent_child_different_types)
586586
local cluster_subscribe_list = {
587-
clusters.OnOff.attributes.OnOff,
588-
-- clusters.LevelControl.attributes.CurrentLevel,
589-
-- clusters.LevelControl.attributes.MaxLevel,
590-
-- clusters.LevelControl.attributes.MinLevel,
591-
-- clusters.ColorControl.attributes.ColorTemperatureMireds,
592-
-- clusters.ColorControl.attributes.ColorTempPhysicalMaxMireds,
593-
-- clusters.ColorControl.attributes.ColorTempPhysicalMinMireds,
594-
-- clusters.ColorControl.attributes.CurrentHue,
595-
-- clusters.ColorControl.attributes.CurrentSaturation,
596-
-- clusters.ColorControl.attributes.CurrentX,
597-
-- clusters.ColorControl.attributes.CurrentY,
598-
-- clusters.ColorControl.attributes.ColorMode,
587+
clusters.OnOff.attributes.OnOff
599588
}
600589
local subscribe_request = cluster_subscribe_list[1]:subscribe(mock_device_parent_child_different_types)
601-
for i, cluster in ipairs(cluster_subscribe_list) do
602-
if i > 1 then
603-
subscribe_request:merge(cluster:subscribe(mock_device_parent_child_different_types))
604-
end
605-
end
606590
test.socket.device_lifecycle:__queue_receive({ mock_device_parent_child_different_types.id, "added" })
607591
test.socket.matter:__expect_send({mock_device_parent_child_different_types.id, subscribe_request})
608592

0 commit comments

Comments
 (0)