Skip to content

Commit

Permalink
BUG-8651 Aeotec Nano Shutter: add missing event
Browse files Browse the repository at this point in the history
The stateless curtain power button needs to set its available command values before it will function correctly in the app. This was done in the DTH but was missed in the porting work.

I've added changes so that a refresh of the device should bring an already-installed device back to a good state. These changes can be removed at a later date as future installs will have them from the added handler changes.
  • Loading branch information
greens committed Sep 25, 2023
1 parent e394dd7 commit eae2020
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,26 @@ function capability_handlers.set_button(driver, device, cmd)
device:send(Basic:Set({ value = value }))
end

--- @param driver st.zwave.Driver
--- @param device st.zwave.Device
local function added_handler(driver, device)
device:emit_event(capabilities.statelessCurtainPowerButton.availableCurtainPowerButtons(
{SET_BUTTON_TO_OPEN, SET_BUTTON_TO_CLOSE, SET_BUTTON_TO_PAUSE},
{visibility = {displayed = false}})
)
end

--- @param driver st.zwave.Driver
--- @param device st.zwave.Device
local function refresh(driver, device)
-- if we've already got an added device that hasn't set this value, this should cause it to be set on refresh
-- this can be removed later
if device:get_latest_state(
"main",
capabilities.statelessCurtainPowerButton.ID,
capabilities.statelessCurtainPowerButton.availableCurtainPowerButtons.NAME) == nil then
added_handler(driver, device)
end
device:send(Basic:Get({}))
end

Expand All @@ -119,7 +136,8 @@ local aeotec_nano_shutter = {
}
},
lifecycle_handlers = {
doConfigure = do_configure
doConfigure = do_configure,
added = added_handler
},
NAME = "Aeotec nano shutter",
can_handle = can_handle_aeotec_nano_shutter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local zw_test_utils = require "integration_test.zwave_test_utils"
local Basic = (require "st.zwave.CommandClass.Basic")({ version = 1 })
local Configuration = (require "st.zwave.CommandClass.Configuration")({ version = 1 })
local t_utils = require "integration_test.utils"
local capabilities = require "st.capabilities"

local zwave_window_button_endpoint = {
{
Expand Down Expand Up @@ -147,23 +148,23 @@ test.register_coroutine_test(
function()
test.socket.device_lifecycle():__queue_receive(mock_window_button:generate_info_changed(
{
preferences = {
reverse = true
}
preferences = {
reverse = true
}
}
))
test.wait_for_events()
test.socket.capability:__queue_receive(
{
mock_window_button.id,
{ capability = "statelessCurtainPowerButton", command = "setButton", args = { "open" } }
}
{
mock_window_button.id,
{ capability = "statelessCurtainPowerButton", command = "setButton", args = { "open" } }
}
)
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock_window_button,
Basic:Set({ value = 0xFF })
)
zw_test_utils.zwave_test_build_send_command(
mock_window_button,
Basic:Set({ value = 0xFF })
)
)
end
)
Expand All @@ -173,23 +174,23 @@ test.register_coroutine_test(
function()
test.socket.device_lifecycle():__queue_receive(mock_window_button:generate_info_changed(
{
preferences = {
reverse = true
}
preferences = {
reverse = true
}
}
))
test.wait_for_events()
test.socket.capability:__queue_receive(
{
mock_window_button.id,
{ capability = "statelessCurtainPowerButton", command = "setButton", args = { "close" } }
}
test.socket.capability:__queue_receive(
{
mock_window_button.id,
{ capability = "statelessCurtainPowerButton", command = "setButton", args = { "close" } }
}
)
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock_window_button,
Basic:Set({ value = 0x00 })
)
zw_test_utils.zwave_test_build_send_command(
mock_window_button,
Basic:Set({ value = 0x00 })
)
)
end
)
Expand All @@ -199,9 +200,9 @@ test.register_coroutine_test(
function()
test.socket.device_lifecycle():__queue_receive(mock_window_button:generate_info_changed(
{
preferences = {
reverse = true
}
preferences = {
reverse = true
}
}
))
test.wait_for_events()
Expand Down Expand Up @@ -237,9 +238,9 @@ test.register_coroutine_test(
function()
test.socket.device_lifecycle():__queue_receive(mock_window_button:generate_info_changed(
{
preferences = {
reverse = true
}
preferences = {
reverse = true
}
}
))
test.wait_for_events()
Expand Down Expand Up @@ -277,14 +278,14 @@ test.register_coroutine_test(
)

test.register_coroutine_test(
"doConfigure lifecycle event should generate the correct commands",
function ()
test.socket.zwave:__set_channel_ordering("relaxed")
test.socket.device_lifecycle:__queue_receive({ mock_window_button.id, "doConfigure" })
test.socket.zwave:__expect_send(zw_test_utils.zwave_test_build_send_command(mock_window_button, Configuration:Set({parameter_number = 80, size = 1, configuration_value = 1})))
test.socket.zwave:__expect_send(zw_test_utils.zwave_test_build_send_command(mock_window_button, Configuration:Set({parameter_number = 85, size = 1, configuration_value = 1})))
mock_window_button:expect_metadata_update({ provisioning_state = "PROVISIONED" })
end
"doConfigure lifecycle event should generate the correct commands",
function ()
test.socket.zwave:__set_channel_ordering("relaxed")
test.socket.device_lifecycle:__queue_receive({ mock_window_button.id, "doConfigure" })
test.socket.zwave:__expect_send(zw_test_utils.zwave_test_build_send_command(mock_window_button, Configuration:Set({parameter_number = 80, size = 1, configuration_value = 1})))
test.socket.zwave:__expect_send(zw_test_utils.zwave_test_build_send_command(mock_window_button, Configuration:Set({parameter_number = 85, size = 1, configuration_value = 1})))
mock_window_button:expect_metadata_update({ provisioning_state = "PROVISIONED" })
end
)

test.register_message_test(
Expand All @@ -298,6 +299,14 @@ test.register_message_test(
{ capability = "refresh", command = "refresh", args = {} }
}
},
{
channel = "capability",
direction = "send",
message = mock_window_button:generate_test_message(
"main",
capabilities.statelessCurtainPowerButton.availableCurtainPowerButtons({"open", "close", "pause"},
{visibility = {displayed = false}}))
},
{
channel = "zwave",
direction = "send",
Expand All @@ -310,20 +319,32 @@ test.register_message_test(
)

test.register_coroutine_test(
"Set open close time preference should generated proper zwave commands",
function()
test.socket.device_lifecycle():__queue_receive(mock_window_button:generate_info_changed(
{
preferences = {
openCloseTiming = 100
}
}
))
test.socket.zwave:__expect_send(zw_test_utils.zwave_test_build_send_command(
mock_window_button,
Configuration:Set({parameter_number = 35, size = 1, configuration_value = 100})
))
end
"added lifecycle event should generate the correct events",
function ()
test.socket.device_lifecycle:__queue_receive({ mock_window_button.id, "added" })
test.socket.capability:__expect_send(mock_window_button:generate_test_message(
"main",
capabilities.statelessCurtainPowerButton.availableCurtainPowerButtons({"open", "close", "pause"},
{visibility = {displayed = false}}))
)
end
)

test.register_coroutine_test(
"Set open close time preference should generated proper zwave commands",
function()
test.socket.device_lifecycle():__queue_receive(mock_window_button:generate_info_changed(
{
preferences = {
openCloseTiming = 100
}
}
))
test.socket.zwave:__expect_send(zw_test_utils.zwave_test_build_send_command(
mock_window_button,
Configuration:Set({parameter_number = 35, size = 1, configuration_value = 100})
))
end
)

test.run_registered_tests()

0 comments on commit eae2020

Please sign in to comment.