Skip to content

Commit ddbeecc

Browse files
committed
Add handling for the missing child case
Signed-off-by: Hunsup Jung <hunsup.jung@samsung.com>
1 parent 05fa702 commit ddbeecc

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

  • drivers/SmartThings/matter-window-covering/src

‎drivers/SmartThings/matter-window-covering/src/init.lua‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ local MatterDriver = require "st.matter.driver"
1111
local utils = require "st.utils"
1212

1313
local 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

1915
local 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
246244
end
247245

248246
local function do_configure(driver, device)
@@ -298,8 +296,7 @@ local function handle_preset(driver, device, cmd)
298296
end
299297

300298
local 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))
303300
end
304301

305302
local function handle_close(driver, device, cmd)
@@ -399,7 +396,8 @@ end
399396
local 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
@@ -416,7 +414,8 @@ end
416414
local 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
@@ -434,7 +433,7 @@ end
434433
local 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

Comments
 (0)