@@ -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" ,
@@ -242,7 +238,9 @@ local function device_init(driver, device)
242238 local preset_position = device .preferences .presetPosition or DEFAULT_PRESET_LEVEL
243239 device :emit_event (capabilities .windowShadePreset .position (preset_position , {visibility = {displayed = false }}))
244240 end
245- device :subscribe ()
241+ if device .network_type ~= device_lib .NETWORK_TYPE_CHILD then
242+ device :subscribe ()
243+ end
246244end
247245
248246local function do_configure (driver , device )
@@ -298,8 +296,7 @@ local function handle_preset(driver, device, cmd)
298296end
299297
300298local 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 ))
299+ device :emit_event (capabilities .windowShadePreset .position (cmd .args .position ))
303300end
304301
305302local function handle_close (driver , device , cmd )
399396local function target_position_lift_percent_100ths_handler (driver , device , ib , response )
400397 if type (ib .data .value ) == " number" then
401398 local target_lift_percent = 100 - math.floor (ib .data .value / 100 )
402- local latest_lift_percentage = device :get_latest_state (
399+ local state_device = find_child (device , ib .endpoint_id ) or device
400+ local latest_lift_percentage = state_device :get_latest_state (
403401 " main" ,
404402 capabilities .windowShadeLevel .ID ,
405403 capabilities .windowShadeLevel .shadeLevel .NAME
416414local function target_position_tilt_percent_100ths_handler (driver , device , ib , response )
417415 if type (ib .data .value ) == " number" then
418416 local target_tilt_percent = 100 - math.floor (ib .data .value / 100 )
419- local latest_tilt_percent = device :get_latest_state (
417+ local state_device = find_child (device , ib .endpoint_id ) or device
418+ local latest_tilt_percent = state_device :get_latest_state (
420419 " main" ,
421420 capabilities .windowShadeTiltLevel .ID ,
422421 capabilities .windowShadeTiltLevel .shadeTiltLevel .NAME
434433local function operational_status_handler (driver , device , ib , response )
435434 if not ib .data .value then return end
436435 local global_op_status = ib .data .value & clusters .WindowCovering .types .OperationalStatus .GLOBAL
437- local reverse = device .preferences .reverse
436+ local reverse = ( find_child ( device , ib . endpoint_id ) or device ) .preferences .reverse
438437 local windowShade = capabilities .windowShade .windowShade
439438 local status_event
440439 if global_op_status == OP_STATUS_BITMAP .idle then
0 commit comments