@@ -11,10 +11,6 @@ local MatterDriver = require "st.matter.driver"
1111local utils = require " st.utils"
1212
1313local IS_PARENT_CHILD_DEVICE = " __is_parent_child_device"
14- --- If the ASSIGNED_CHILD_KEY field is populated for an endpoint, it should be
15- --- used as the key in the get_child_by_parent_assigned_key() function. This allows
16- --- multiple endpoints to associate with the same child device, though right now child
17- local ASSIGNED_CHILD_KEY = " __assigned_child_key"
1814
1915local battery_support = {
2016 NO_BATTERY = " NO_BATTERY" ,
229225local function device_init (driver , device )
230226 if device :get_field (IS_PARENT_CHILD_DEVICE ) then
231227 device :set_find_child (find_child )
228+ device :subscribe ()
232229 end
233230 -- set unused fields to nil. These field settings can be removed after a single driver update.
234231 device :set_field (" __preset_level_key" , nil )
@@ -242,7 +239,6 @@ local function device_init(driver, device)
242239 local preset_position = device .preferences .presetPosition or DEFAULT_PRESET_LEVEL
243240 device :emit_event (capabilities .windowShadePreset .position (preset_position , {visibility = {displayed = false }}))
244241 end
245- device :subscribe ()
246242end
247243
248244local function do_configure (driver , device )
@@ -298,8 +294,7 @@ local function handle_preset(driver, device, cmd)
298294end
299295
300296local function handle_set_preset (driver , device , cmd )
301- local endpoint_id = device :component_to_endpoint (cmd .component )
302- device :emit_event_for_endpoint (endpoint_id , capabilities .windowShadePreset .position (cmd .args .position ))
297+ device :emit_event (capabilities .windowShadePreset .position (cmd .args .position ))
303298end
304299
305300local function handle_close (driver , device , cmd )
399394local function target_position_lift_percent_100ths_handler (driver , device , ib , response )
400395 if type (ib .data .value ) == " number" then
401396 local target_lift_percent = 100 - math.floor (ib .data .value / 100 )
402- local latest_lift_percentage = device :get_latest_state (
397+ local state_device = find_child (device , ib .endpoint_id ) or device
398+ local latest_lift_percentage = state_device :get_latest_state (
403399 " main" ,
404400 capabilities .windowShadeLevel .ID ,
405401 capabilities .windowShadeLevel .shadeLevel .NAME
416412local function target_position_tilt_percent_100ths_handler (driver , device , ib , response )
417413 if type (ib .data .value ) == " number" then
418414 local target_tilt_percent = 100 - math.floor (ib .data .value / 100 )
419- local latest_tilt_percent = device :get_latest_state (
415+ local state_device = find_child (device , ib .endpoint_id ) or device
416+ local latest_tilt_percent = state_device :get_latest_state (
420417 " main" ,
421418 capabilities .windowShadeTiltLevel .ID ,
422419 capabilities .windowShadeTiltLevel .shadeTiltLevel .NAME
434431local function operational_status_handler (driver , device , ib , response )
435432 if not ib .data .value then return end
436433 local global_op_status = ib .data .value & clusters .WindowCovering .types .OperationalStatus .GLOBAL
437- local reverse = device .preferences .reverse
434+ local reverse = ( find_child ( device , ib . endpoint_id ) or device ) .preferences .reverse
438435 local windowShade = capabilities .windowShade .windowShade
439436 local status_event
440437 if global_op_status == OP_STATUS_BITMAP .idle then
0 commit comments