@@ -21,7 +21,7 @@ local SwitchDeviceConfiguration = {}
2121local ButtonDeviceConfiguration = {}
2222local FanDeviceConfiguration = {}
2323
24- function ChildConfiguration .create_child_devices (driver , device , server_cluster_ep_ids , default_endpoint_id , assign_profile_fn )
24+ function ChildConfiguration .create_or_update_child_devices (driver , device , server_cluster_ep_ids , default_endpoint_id , assign_profile_fn )
2525 if # server_cluster_ep_ids == 1 and server_cluster_ep_ids [1 ] == default_endpoint_id then -- no children will be created
2626 return
2727 end
@@ -99,39 +99,6 @@ function SwitchDeviceConfiguration.assign_profile_for_onoff_ep(device, server_on
9999 return generic_profile or " switch-binary"
100100end
101101
102- function SwitchDeviceConfiguration .create_or_update_child_devices (driver , device , server_onoff_ep_ids , default_endpoint_id )
103- if # server_onoff_ep_ids == 1 and server_onoff_ep_ids [1 ] == default_endpoint_id then -- no children will be created
104- return
105- end
106-
107- table.sort (server_onoff_ep_ids )
108- for device_num , ep_id in ipairs (server_onoff_ep_ids ) do
109- if ep_id ~= default_endpoint_id then -- don't create a child device that maps to the main endpoint
110- local label_and_name = string.format (" %s %d" , device .label , device_num )
111- local child_profile = SwitchDeviceConfiguration .assign_profile_for_onoff_ep (device , ep_id , true )
112- local existing_child_device = device :get_field (fields .IS_PARENT_CHILD_DEVICE ) and switch_utils .find_child (device , ep_id )
113- if not existing_child_device then
114- driver :try_create_device ({
115- type = " EDGE_CHILD" ,
116- label = label_and_name ,
117- profile = child_profile ,
118- parent_device_id = device .id ,
119- parent_assigned_child_key = string.format (" %d" , ep_id ),
120- vendor_provided_label = label_and_name
121- })
122- else
123- existing_child_device :try_update_metadata ({
124- profile = child_profile
125- })
126- end
127- end
128- end
129-
130- -- Persist so that the find_child function is always set on each driver init.
131- device :set_field (fields .IS_PARENT_CHILD_DEVICE , true , {persist = true })
132- device :set_find_child (switch_utils .find_child )
133- end
134-
135102-- Per the spec, these attributes are "meant to be changed only during commissioning."
136103function SwitchDeviceConfiguration .set_device_control_options (device )
137104 for _ , ep in ipairs (device .endpoints ) do
@@ -245,7 +212,7 @@ function DeviceConfiguration.match_profile(driver, device)
245212
246213 local server_onoff_ep_ids = device :get_endpoints (clusters .OnOff .ID ) -- get_endpoints defaults to return EPs supporting SERVER or BOTH
247214 if # server_onoff_ep_ids > 0 then
248- ChildConfiguration .create_child_devices (driver , device , server_onoff_ep_ids , default_endpoint_id , SwitchDeviceConfiguration .assign_profile_for_onoff_ep )
215+ ChildConfiguration .create_or_update_child_devices (driver , device , server_onoff_ep_ids , default_endpoint_id , SwitchDeviceConfiguration .assign_profile_for_onoff_ep )
249216 end
250217
251218 if switch_utils .tbl_contains (server_onoff_ep_ids , default_endpoint_id ) then
0 commit comments