Skip to content

Commit

Permalink
Avoid native handling for zwave devices with odd endpoint layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
cjswedes committed Nov 13, 2024
1 parent 307fe1c commit 3d0a6fd
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ local function do_refresh(driver, device, command) -- should be deleted when v46
end
end

-- Do not use native handlers due to unique component to endpoint mapping
local function switch_on_handler(driver, device, cmd)
switchDefaults.capability_handlers[capabilities.switch.commands.on](driver, device, cmd, false)
end

local function switch_off_handler(driver, device, cmd)
switchDefaults.capability_handlers[capabilities.switch.commands.off](driver, device, cmd, false)
end

local function set_level_handler(driver, device, cmd)
local defaults = require "st.zwave.defaults.switchLevel"
defaults.capability_handlers[capabilities.switchLevel.commands.setLevel](driver, device, cmd, false)
end

local function meter_report_handler(driver, device, cmd)
-- We got a meter report from the root node, so refresh all children
-- endpoint 0 should have its reports dropped
Expand Down Expand Up @@ -161,7 +175,14 @@ local multi_metering_switch = {
},
[capabilities.energyMeter.ID] = {
[capabilities.energyMeter.commands.resetEnergyMeter.NAME] = reset
}
},
[capabilities.switch.ID] = {
[capabilities.switch.commands.on.NAME] = switch_on_handler,
[capabilities.switch.commands.off.NAME] = switch_off_handler,
},
[capabilities.switchLevel.ID] = {
[capabilities.switchLevel.commands.setLevel.NAME] = set_level_handler,
},
},
zwave_handlers = {
[cc.METER] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,6 @@ test.register_message_test(
{ capability = "switch", command = "on", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_parent_device.id, capability_id = "switch", capability_cmd_id = "on" }
}
},
{
channel = "zwave",
direction = "send",
Expand All @@ -270,14 +262,6 @@ test.register_message_test(
{ capability = "switch", command = "on", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_child_device.id, capability_id = "switch", capability_cmd_id = "on" }
}
},
{
channel = "zwave",
direction = "send",
Expand All @@ -303,14 +287,6 @@ test.register_message_test(
{ capability = "switch", command = "off", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_parent_device.id, capability_id = "switch", capability_cmd_id = "off" }
}
},
{
channel = "zwave",
direction = "send",
Expand All @@ -336,14 +312,6 @@ test.register_message_test(
{ capability = "switch", command = "off", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_child_device.id, capability_id = "switch", capability_cmd_id = "off" }
}
},
{
channel = "zwave",
direction = "send",
Expand Down Expand Up @@ -606,7 +574,6 @@ test.register_coroutine_test(
mock_parent_device.id,
{ capability = "switch", command = "off", component = "main", args = {} }
})
mock_parent_device:expect_native_cmd_handler_registration("switch", "off")
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock_parent_device,
Expand Down Expand Up @@ -637,7 +604,6 @@ test.register_coroutine_test(
mock_child_device.id,
{ capability = "switch", command = "off", component = "main", args = {} }
})
mock_child_device:expect_native_cmd_handler_registration("switch", "off")
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock_parent_device,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,6 @@ test.register_message_test(
{ capability = "switch", command = "on", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_parent_device.id, capability_id = "switch", capability_cmd_id = "on" }
}
},
{
channel = "zwave",
direction = "send",
Expand All @@ -269,14 +261,6 @@ test.register_message_test(
{ capability = "switch", command = "on", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_child_device.id, capability_id = "switch", capability_cmd_id = "on" }
}
},
{
channel = "zwave",
direction = "send",
Expand All @@ -302,14 +286,6 @@ test.register_message_test(
{ capability = "switch", command = "off", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_parent_device.id, capability_id = "switch", capability_cmd_id = "off" }
}
},
{
channel = "zwave",
direction = "send",
Expand All @@ -335,14 +311,6 @@ test.register_message_test(
{ capability = "switch", command = "off", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_child_device.id, capability_id = "switch", capability_cmd_id = "off" }
}
},
{
channel = "zwave",
direction = "send",
Expand Down Expand Up @@ -559,7 +527,6 @@ test.register_coroutine_test(
mock_parent_device.id,
{ capability = "switch", command = "off", component = "main", args = {} }
})
mock_parent_device:expect_native_cmd_handler_registration("switch", "off")
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock_parent_device,
Expand Down Expand Up @@ -590,7 +557,6 @@ test.register_coroutine_test(
mock_child_device.id,
{ capability = "switch", command = "off", component = "main", args = {} }
})
mock_child_device:expect_native_cmd_handler_registration("switch", "off")
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock_parent_device,
Expand Down
34 changes: 0 additions & 34 deletions drivers/SmartThings/zwave-switch/src/test/test_wyfy_touch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ test.register_message_test(
{ capability = "switch", command = "on", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_parent_device.id, capability_id = "switch", capability_cmd_id = "on" }
}
},
{
channel = "zwave",
direction = "send",
Expand All @@ -127,14 +119,6 @@ test.register_message_test(
{ capability = "switch", command = "on", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_child_device.id, capability_id = "switch", capability_cmd_id = "on" }
}
},
{
channel = "zwave",
direction = "send",
Expand All @@ -160,14 +144,6 @@ test.register_message_test(
{ capability = "switch", command = "off", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_parent_device.id, capability_id = "switch", capability_cmd_id = "off" }
}
},
{
channel = "zwave",
direction = "send",
Expand All @@ -193,14 +169,6 @@ test.register_message_test(
{ capability = "switch", command = "off", component = "main", args = {} }
}
},
{
channel = "devices",
direction = "send",
message = {
"register_native_capability_cmd_handler",
{ device_uuid = mock_child_device.id, capability_id = "switch", capability_cmd_id = "off" }
}
},
{
channel = "zwave",
direction = "send",
Expand Down Expand Up @@ -283,7 +251,6 @@ test.register_coroutine_test(
mock_parent_device.id,
{ capability = "switch", command = "off", component = "main", args = {} }
})
mock_parent_device:expect_native_cmd_handler_registration("switch", "off")

test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
Expand Down Expand Up @@ -315,7 +282,6 @@ test.register_coroutine_test(
mock_child_device.id,
{ capability = "switch", command = "off", component = "main", args = {} }
})
mock_child_device:expect_native_cmd_handler_registration("switch", "off")
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock_parent_device,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ test.register_coroutine_test(
mock_parent.id,
{ capability = "switch", component = "main", command = "on", args = {} }
})
mock_parent:expect_native_cmd_handler_registration("switch", "on")

test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
Expand Down Expand Up @@ -505,7 +504,6 @@ test.register_coroutine_test(
mock_child.id,
{ capability = "switch", component = "main", command = "on", args = {} }
})
mock_child:expect_native_cmd_handler_registration("switch", "on")

test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
Expand Down Expand Up @@ -543,7 +541,6 @@ test.register_coroutine_test(
mock_parent.id,
{ capability = "switch", component = "main", command = "off", args = {} }
})
mock_parent:expect_native_cmd_handler_registration("switch", "off")

test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
Expand Down Expand Up @@ -581,7 +578,6 @@ test.register_coroutine_test(
mock_child.id,
{ capability = "switch", component = "main", command = "off", args = {} }
})
mock_child:expect_native_cmd_handler_registration("switch", "off")

test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
Expand Down
23 changes: 22 additions & 1 deletion drivers/SmartThings/zwave-switch/src/zwave-dual-switch/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ local function do_refresh(driver, device, command)
end
end

-- Do not use native handlers due to unique component to endpoint mapping
local function switch_on_handler(driver, device, cmd)
switch_defaults.capability_handlers[capabilities.switch.commands.on](driver, device, cmd, false)
end

local function switch_off_handler(driver, device, cmd)
switch_defaults.capability_handlers[capabilities.switch.commands.off](driver, device, cmd, false)
end

local function set_level_handler(driver, device, cmd)
local defaults = require "st.zwave.defaults.switchLevel"
defaults.capability_handlers[capabilities.switchLevel.commands.setLevel](driver, device, cmd, false)
end

local function switch_report(driver, device, cmd)
switch_defaults.zwave_handlers[cc.SWITCH_BINARY][SwitchBinary.REPORT](driver, device, cmd)

Expand All @@ -139,7 +153,14 @@ local zwave_dual_switch = {
capability_handlers = {
[capabilities.refresh.ID] = {
[capabilities.refresh.commands.refresh.NAME] = do_refresh
}
},
[capabilities.switch.ID] = {
[capabilities.switch.commands.on.NAME] = switch_on_handler,
[capabilities.switch.commands.off.NAME] = switch_off_handler,
},
[capabilities.switchLevel.ID] = {
[capabilities.switchLevel.commands.setLevel.NAME] = set_level_handler,
},
},
lifecycle_handlers = {
added = device_added,
Expand Down

0 comments on commit 3d0a6fd

Please sign in to comment.