From 3b1d9090456fb73124257cc58377d685207a9173 Mon Sep 17 00:00:00 2001 From: Cooper Towns Date: Mon, 2 Feb 2026 18:11:00 -0600 Subject: [PATCH] Create 2 duplicate child devices on matter switch init --- .../SmartThings/matter-switch/src/init.lua | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/SmartThings/matter-switch/src/init.lua b/drivers/SmartThings/matter-switch/src/init.lua index e8d1b8330a..5d452e4fad 100644 --- a/drivers/SmartThings/matter-switch/src/init.lua +++ b/drivers/SmartThings/matter-switch/src/init.lua @@ -17,6 +17,7 @@ local attribute_handlers = require "switch_handlers.attribute_handlers" local event_handlers = require "switch_handlers.event_handlers" local capability_handlers = require "switch_handlers.capability_handlers" local embedded_cluster_utils = require "switch_utils.embedded_cluster_utils" +local report_error = _envlibrequire("util.report_error") -- Include driver-side definitions when lua libs api version is < 11 if version.api < 11 then @@ -109,6 +110,52 @@ function SwitchLifecycleHandlers.device_init(driver, device) device:extend_device("subscribe", switch_utils.subscribe) device:subscribe() + -- Create two duplicate child devices + device.log.info_with({hub_logs = true}, "Creating duplicate child devices on matter switch init") + local success, error_msg = driver:try_create_device({ + type = "EDGE_CHILD", + label = "Test Child Device", + profile = "switch-binary", + parent_device_id = device.id, + parent_assigned_child_key = "1", + vendor_provided_label = "Test" + }) + + device.log.info_with({hub_logs = true}, string.format("Create Child Device 1 #1 - success: %s, error_msg: %s", success, error_msg)) + + driver:try_create_device({ + type = "EDGE_CHILD", + label = "Test Child Device", + profile = "switch-binary", + parent_device_id = device.id, + parent_assigned_child_key = "1", + vendor_provided_label = "Test" + }) + + device.log.info_with({hub_logs = true}, string.format("Create Child Device 1 #2 - success: %s, error_msg: %s", success, error_msg)) + + local success, error_msg = driver:try_create_device({ + type = "EDGE_CHILD", + label = "Test Child Device", + profile = "switch-binary", + parent_device_id = device.id, + parent_assigned_child_key = "2", + vendor_provided_label = "Test" + }) + + device.log.info_with({hub_logs = true}, string.format("Create Child Device 2 #1 - success: %s, error_msg: %s", success, error_msg)) + + driver:try_create_device({ + type = "EDGE_CHILD", + label = "Test Child Device", + profile = "switch-binary", + parent_device_id = device.id, + parent_assigned_child_key = "2", + vendor_provided_label = "Test" + }) + + device.log.info_with({hub_logs = true}, string.format("Create Child Device 2 #2 - success: %s, error_msg: %s", success, error_msg)) + -- device energy reporting must be handled cumulatively, periodically, or by both simultaneously. -- To ensure a single source of truth, we only handle a device's periodic reporting if cumulative reporting is not supported. if #embedded_cluster_utils.get_endpoints(device, clusters.ElectricalEnergyMeasurement.ID,