Skip to content

Commit 7da9947

Browse files
Implement driverSwitched handler
Since init code is being moved to doConfigure, it wouldn't run following a driverSwitched event ordinarily, so doConfigure should be called from the driverSwitched event handler.
1 parent 7b62645 commit 7da9947

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

drivers/SmartThings/matter-switch/src/init.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,10 @@ local function do_configure(driver, device)
764764
end
765765
end
766766

767+
local function driver_switched(driver, device)
768+
do_configure(driver, device)
769+
end
770+
767771
local function device_removed(driver, device)
768772
log.info("device removed")
769773
delete_import_poll_schedule(device)
@@ -1446,7 +1450,8 @@ local matter_driver_template = {
14461450
added = device_added,
14471451
removed = device_removed,
14481452
infoChanged = info_changed,
1449-
doConfigure = do_configure
1453+
doConfigure = do_configure,
1454+
driverSwitched = driver_switched
14501455
},
14511456
matter_handlers = {
14521457
attr = {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,5 +408,21 @@ test.register_coroutine_test(
408408
{ test_init = test_init_mcd_unsupported_switch_device_type }
409409
)
410410

411+
test.register_coroutine_test(
412+
"Test driver switched event",
413+
function()
414+
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "driverSwitched" })
415+
mock_device:expect_metadata_update({ profile = "light-level-3-button" })
416+
configure_buttons()
417+
mock_device:expect_device_create({
418+
type = "EDGE_CHILD",
419+
label = "Matter Switch 2",
420+
profile = "light-color-level",
421+
parent_device_id = mock_device.id,
422+
parent_assigned_child_key = string.format("%d", mock_device_ep5)
423+
})
424+
end
425+
)
426+
411427
-- run the tests
412428
test.run_registered_tests()

0 commit comments

Comments
 (0)