From 8cb29815bd074754703b82a3ec853bfd8f415655 Mon Sep 17 00:00:00 2001 From: cjswedes Date: Wed, 31 Jul 2024 11:04:32 -0500 Subject: [PATCH] Enable native handlers for drivers that can use them only switch and switchLevel capabilities will be supported for Matter, Zigbee, and Z-Wave devices in the 0.54.x firmware. Using this functionality give a huge latency improvement for handling these capability commands which is important when a driver is handling several commands all at once (i.e. a routine is triggered that toggles a bunch of switches) --- drivers/SmartThings/matter-switch/src/init.lua | 9 +++++++++ drivers/SmartThings/zigbee-switch/src/init.lua | 2 +- drivers/SmartThings/zwave-bulb/src/init.lua | 2 +- drivers/SmartThings/zwave-switch/src/init.lua | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/SmartThings/matter-switch/src/init.lua b/drivers/SmartThings/matter-switch/src/init.lua index c588c3dbef..7876c61732 100644 --- a/drivers/SmartThings/matter-switch/src/init.lua +++ b/drivers/SmartThings/matter-switch/src/init.lua @@ -250,6 +250,9 @@ local function device_removed(driver, device) end local function handle_switch_on(driver, device, cmd) + if type(device.register_native_capability_cmd_handler) == "function" then + device:register_native_capability_cmd_handler(cmd.capability, cmd.command) + end local endpoint_id = device:component_to_endpoint(cmd.component) --TODO use OnWithRecallGlobalScene for devices with the LT feature local req = clusters.OnOff.server.commands.On(device, endpoint_id) @@ -257,12 +260,18 @@ local function handle_switch_on(driver, device, cmd) end local function handle_switch_off(driver, device, cmd) + if type(device.register_native_capability_cmd_handler) == "function" then + device:register_native_capability_cmd_handler(cmd.capability, cmd.command) + end local endpoint_id = device:component_to_endpoint(cmd.component) local req = clusters.OnOff.server.commands.Off(device, endpoint_id) device:send(req) end local function handle_set_level(driver, device, cmd) + if type(device.register_native_capability_cmd_handler) == "function" then + device:register_native_capability_cmd_handler(cmd.capability, cmd.command) + end local endpoint_id = device:component_to_endpoint(cmd.component) local level = math.floor(cmd.args.level/100.0 * 254) local req = clusters.LevelControl.server.commands.MoveToLevelWithOnOff(device, endpoint_id, level, cmd.args.rate or 0, 0 ,0) diff --git a/drivers/SmartThings/zigbee-switch/src/init.lua b/drivers/SmartThings/zigbee-switch/src/init.lua index d26da471fc..bd31c191bd 100644 --- a/drivers/SmartThings/zigbee-switch/src/init.lua +++ b/drivers/SmartThings/zigbee-switch/src/init.lua @@ -127,6 +127,6 @@ local zigbee_switch_driver_template = { } defaults.register_for_default_handlers(zigbee_switch_driver_template, - zigbee_switch_driver_template.supported_capabilities) + zigbee_switch_driver_template.supported_capabilities, {native_capability_cmds_enabled = true}) local zigbee_switch = ZigbeeDriver("zigbee_switch", zigbee_switch_driver_template) zigbee_switch:run() diff --git a/drivers/SmartThings/zwave-bulb/src/init.lua b/drivers/SmartThings/zwave-bulb/src/init.lua index 581f6ca466..62079594fa 100644 --- a/drivers/SmartThings/zwave-bulb/src/init.lua +++ b/drivers/SmartThings/zwave-bulb/src/init.lua @@ -37,7 +37,7 @@ local driver_template = { }, } -defaults.register_for_default_handlers(driver_template, driver_template.supported_capabilities) +defaults.register_for_default_handlers(driver_template, driver_template.supported_capabilities, {native_capability_cmds_enabled = true}) --- @type st.zwave.Driver local bulb = ZwaveDriver("zwave_bulb", driver_template) bulb:run() diff --git a/drivers/SmartThings/zwave-switch/src/init.lua b/drivers/SmartThings/zwave-switch/src/init.lua index ca73631808..4274c3cc97 100644 --- a/drivers/SmartThings/zwave-switch/src/init.lua +++ b/drivers/SmartThings/zwave-switch/src/init.lua @@ -172,7 +172,7 @@ local driver_template = { } } -defaults.register_for_default_handlers(driver_template, driver_template.supported_capabilities) +defaults.register_for_default_handlers(driver_template, driver_template.supported_capabilities, {native_capability_cmds_enabled = true}) --- @type st.zwave.Driver local switch = ZwaveDriver("zwave_switch", driver_template) switch:run()