Skip to content

Commit 75181de

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

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

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

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ local function device_init(driver, device)
242242
local preset_position = device.preferences.presetPosition or DEFAULT_PRESET_LEVEL
243243
device:emit_event(capabilities.windowShadePreset.position(preset_position, {visibility = {displayed = false}}))
244244
end
245-
device:subscribe()
245+
if device.network_type ~= device_lib.NETWORK_TYPE_CHILD then
246+
device:subscribe()
247+
end
246248
end
247249

248250
local function do_configure(driver, device)
@@ -298,8 +300,7 @@ local function handle_preset(driver, device, cmd)
298300
end
299301

300302
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))
303+
device:emit_event(capabilities.windowShadePreset.position(cmd.args.position))
303304
end
304305

305306
local function handle_close(driver, device, cmd)
@@ -399,7 +400,8 @@ end
399400
local function target_position_lift_percent_100ths_handler(driver, device, ib, response)
400401
if type(ib.data.value) == "number" then
401402
local target_lift_percent = 100 - math.floor(ib.data.value / 100)
402-
local latest_lift_percentage = device:get_latest_state(
403+
local state_device = find_child(device, ib.endpoint_id) or device
404+
local latest_lift_percentage = state_device:get_latest_state(
403405
"main",
404406
capabilities.windowShadeLevel.ID,
405407
capabilities.windowShadeLevel.shadeLevel.NAME
@@ -416,7 +418,8 @@ end
416418
local function target_position_tilt_percent_100ths_handler(driver, device, ib, response)
417419
if type(ib.data.value) == "number" then
418420
local target_tilt_percent = 100 - math.floor(ib.data.value / 100)
419-
local latest_tilt_percent = device:get_latest_state(
421+
local state_device = find_child(device, ib.endpoint_id) or device
422+
local latest_tilt_percent = state_device:get_latest_state(
420423
"main",
421424
capabilities.windowShadeTiltLevel.ID,
422425
capabilities.windowShadeTiltLevel.shadeTiltLevel.NAME
@@ -434,7 +437,7 @@ end
434437
local function operational_status_handler(driver, device, ib, response)
435438
if not ib.data.value then return end
436439
local global_op_status = ib.data.value & clusters.WindowCovering.types.OperationalStatus.GLOBAL
437-
local reverse = device.preferences.reverse
440+
local reverse = (find_child(device, ib.endpoint_id) or device).preferences.reverse
438441
local windowShade = capabilities.windowShade.windowShade
439442
local status_event
440443
if global_op_status == OP_STATUS_BITMAP.idle then

0 commit comments

Comments
 (0)