Skip to content

Commit

Permalink
Enable native handlers for drivers that can use them
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
cjswedes committed Aug 12, 2024
1 parent 0b92605 commit 8cb2981
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions drivers/SmartThings/matter-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,28 @@ 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)
device:send(req)
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)
Expand Down
2 changes: 1 addition & 1 deletion drivers/SmartThings/zigbee-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion drivers/SmartThings/zwave-bulb/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion drivers/SmartThings/zwave-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 8cb2981

Please sign in to comment.