@@ -163,43 +163,23 @@ local function component_to_endpoint(device, component_name)
163163 return find_default_endpoint (device , clusters .WindowCovering .ID )
164164end
165165
166- local function create_feature_table (lift_eps , tilt_eps )
167- local result = {}
168- local i , j = 1 , 1
169- while i <= # lift_eps or j <= # tilt_eps do
170- local lift_ep , tilt_ep = lift_eps [i ], tilt_eps [j ]
171- if tilt_ep == nil or (lift_ep ~= nil and lift_ep < tilt_ep ) then
172- result [# result + 1 ] = { endpoint = lift_ep , has_lift = true , has_tilt = false }
173- i = i + 1
174- elseif lift_ep == nil or tilt_ep < lift_ep then
175- result [# result + 1 ] = { endpoint = tilt_ep , has_lift = false , has_tilt = true }
176- j = j + 1
177- else -- lift_ep == tilt_ep
178- result [# result + 1 ] = { endpoint = lift_ep , has_lift = true , has_tilt = true }
179- i , j = i + 1 , j + 1
180- end
181- end
182- return result
183- end
184-
185- local function update_profile_table (device )
166+ local function match_profile (device , battery_supported )
186167 local lift_eps = device :get_endpoints (clusters .WindowCovering .ID , {feature_bitmap = clusters .WindowCovering .types .Feature .LIFT })
187168 local tilt_eps = device :get_endpoints (clusters .WindowCovering .ID , {feature_bitmap = clusters .WindowCovering .types .Feature .TILT })
188- table.sort (lift_eps )
189- table.sort (tilt_eps )
190- local feature_table = create_feature_table (lift_eps , tilt_eps )
191- local profile_table = {}
192-
193- for _ , entry in pairs (feature_table ) do
194- profile_table [entry .endpoint ] = " window-covering"
195- if entry .has_tilt then
196- profile_table [entry .endpoint ] = " window-covering-tilt"
197- if not entry .has_lift then
198- profile_table [entry .endpoint ] = " window-covering-tilt-only"
199- end
169+ local profile_name = " window-covering"
170+ if # tilt_eps > 0 then
171+ profile_name = profile_name .. " -tilt"
172+ if # lift_eps == 0 then
173+ profile_name = profile_name .. " -only"
200174 end
201175 end
202- return profile_table
176+
177+ if battery_supported == battery_support .BATTERY_PERCENTAGE then
178+ profile_name = profile_name .. " -battery"
179+ elseif battery_supported == battery_support .BATTERY_LEVEL then
180+ profile_name = profile_name .. " -batteryLevel"
181+ end
182+ device :try_update_metadata ({profile = profile_name })
203183end
204184
205185local function find_child (parent_device , ep_id )
@@ -208,19 +188,17 @@ local function find_child(parent_device, ep_id)
208188end
209189
210190local function create_or_update_multi_devices (driver , device , wc_cluster_eps )
211- local profile_table = update_profile_table (device )
212191 local default_endpoint_id = find_default_endpoint (device )
213192 table.sort (wc_cluster_eps )
214193 for device_num , ep_id in ipairs (wc_cluster_eps ) do
215194 if ep_id ~= default_endpoint_id then -- don't create a child device that maps to the main endpoint
216195 local label_and_name = string.format (" %s %d" , device .label , device_num )
217- local child_profile = profile_table [ep_id ] or " window-covering"
218196 local existing_child_device = device :get_field (IS_PARENT_CHILD_DEVICE ) and find_child (device , ep_id )
219197 if not existing_child_device then
220198 driver :try_create_device ({
221199 type = " EDGE_CHILD" ,
222200 label = label_and_name ,
223- profile = child_profile ,
201+ profile = " window-covering " ,
224202 parent_device_id = device .id ,
225203 parent_assigned_child_key = string.format (" %d" , ep_id ),
226204 vendor_provided_label = label_and_name
@@ -233,27 +211,6 @@ local function create_or_update_multi_devices(driver, device, wc_cluster_eps)
233211 -- Persist so that the find_child function is always set on each driver init.
234212 device :set_field (IS_PARENT_CHILD_DEVICE , true , {persist = true })
235213 device :set_find_child (find_child )
236- -- Update parent device's profile
237- device :try_update_metadata ({profile = profile_table [default_endpoint_id ] or " window-covering" })
238- end
239-
240- local function match_profile (device , battery_supported )
241- local lift_eps = device :get_endpoints (clusters .WindowCovering .ID , {feature_bitmap = clusters .WindowCovering .types .Feature .LIFT })
242- local tilt_eps = device :get_endpoints (clusters .WindowCovering .ID , {feature_bitmap = clusters .WindowCovering .types .Feature .TILT })
243- local profile_name = " window-covering"
244- if # tilt_eps > 0 then
245- profile_name = profile_name .. " -tilt"
246- if # lift_eps == 0 then
247- profile_name = profile_name .. " -only"
248- end
249- end
250-
251- if battery_supported == battery_support .BATTERY_PERCENTAGE then
252- profile_name = profile_name .. " -battery"
253- elseif battery_supported == battery_support .BATTERY_LEVEL then
254- profile_name = profile_name .. " -batteryLevel"
255- end
256- device :try_update_metadata ({profile = profile_name })
257214end
258215
259216local function device_init (driver , device )
@@ -277,15 +234,14 @@ local function do_configure(driver, device)
277234 local wc_cluster_eps = device :get_endpoints (clusters .WindowCovering .ID )
278235 if # wc_cluster_eps > 1 then
279236 create_or_update_multi_devices (driver , device , wc_cluster_eps )
237+ end
238+ local battery_feature_eps = device :get_endpoints (clusters .PowerSource .ID , {feature_bitmap = clusters .PowerSource .types .PowerSourceFeature .BATTERY })
239+ if # battery_feature_eps > 0 then
240+ local attribute_list_read = im .InteractionRequest (im .InteractionRequest .RequestType .READ , {})
241+ attribute_list_read :merge (clusters .PowerSource .attributes .AttributeList :read ())
242+ device :send (attribute_list_read )
280243 else
281- local battery_feature_eps = device :get_endpoints (clusters .PowerSource .ID , {feature_bitmap = clusters .PowerSource .types .PowerSourceFeature .BATTERY })
282- if # battery_feature_eps > 0 then
283- local attribute_list_read = im .InteractionRequest (im .InteractionRequest .RequestType .READ , {})
284- attribute_list_read :merge (clusters .PowerSource .attributes .AttributeList :read ())
285- device :send (attribute_list_read )
286- else
287- match_profile (device , battery_support .NO_BATTERY )
288- end
244+ match_profile (device , battery_support .NO_BATTERY )
289245 end
290246end
291247
0 commit comments