From b53eaf7714236de4d216e37e297ec361efbda848 Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 19 Oct 2022 16:00:21 +0200 Subject: [PATCH 1/9] re-port fibaro_double_switch to parent/child --- .../SmartThings/zwave-switch/fingerprints.yml | 2 +- ...er-energy.yml => fibaro-double-switch.yml} | 48 +--- .../src/fibaro-double-switch/init.lua | 99 +++++-- .../src/test/test_fibaro_double_switch.lua | 242 +++++++----------- 4 files changed, 168 insertions(+), 223 deletions(-) rename drivers/SmartThings/zwave-switch/profiles/{switch-1-button-6-power-energy.yml => fibaro-double-switch.yml} (89%) diff --git a/drivers/SmartThings/zwave-switch/fingerprints.yml b/drivers/SmartThings/zwave-switch/fingerprints.yml index 50ea105190..aa26072a9b 100644 --- a/drivers/SmartThings/zwave-switch/fingerprints.yml +++ b/drivers/SmartThings/zwave-switch/fingerprints.yml @@ -336,7 +336,7 @@ zwaveManufacturer: deviceLabel: Fibaro Double Switch manufacturerId: 0x010F productType: 0x0203 - deviceProfileName: switch-1-button-6-power-energy + deviceProfileName: fibaro-double-switch - id: "Eaton/5740/0000" deviceLabel: Eaton 5-Scene Keypad manufacturerId: 0x001A diff --git a/drivers/SmartThings/zwave-switch/profiles/switch-1-button-6-power-energy.yml b/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml similarity index 89% rename from drivers/SmartThings/zwave-switch/profiles/switch-1-button-6-power-energy.yml rename to drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml index 3f1c889831..b907f3f975 100644 --- a/drivers/SmartThings/zwave-switch/profiles/switch-1-button-6-power-energy.yml +++ b/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml @@ -1,4 +1,4 @@ -name: switch-1-button-6-power-energy +name: fibaro-double-switch components: - id: main capabilities: @@ -14,52 +14,6 @@ components: version: 1 categories: - name: Switch - - id: switch1 - capabilities: - - id: switch - version: 1 - - id: powerMeter - version: 1 - - id: energyMeter - version: 1 - categories: - - name: Switch - - id: button1 - capabilities: - - id: button - version: 1 - categories: - - name: RemoteController - - id: button2 - capabilities: - - id: button - version: 1 - categories: - - name: RemoteController - - id: button3 - capabilities: - - id: button - version: 1 - categories: - - name: RemoteController - - id: button4 - capabilities: - - id: button - version: 1 - categories: - - name: RemoteController - - id: button5 - capabilities: - - id: button - version: 1 - categories: - - name: RemoteController - - id: button6 - capabilities: - - id: button - version: 1 - categories: - - name: RemoteController preferences: - name: "restoreState" title: "Restore state" diff --git a/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua b/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua index 49292cbaf8..9a46b7e372 100644 --- a/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua +++ b/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua @@ -12,13 +12,19 @@ -- See the License for the specific language governing permissions and -- limitations under the License. +local st_device = require "st.device" local capabilities = require "st.capabilities" ---- @type st.utils -local utils = require "st.utils" +local switch_defaults = require "st.zwave.defaults.switch" --- @type st.zwave.CommandClass local cc = require "st.zwave.CommandClass" --- @type st.zwave.CommandClass.CentralScene -local CentralScene = (require "st.zwave.CommandClass.CentralScene")({version=1}) +local CentralScene = (require "st.zwave.CommandClass.CentralScene")({version=1, strict = true}) +--- @type st.zwave.CommandClass.Basic +local Basic = (require "st.zwave.CommandClass.Basic")({ version = 1, strict = true }) +--- @type st.zwave.CommandClass.SwitchBinary +local SwitchBinary = (require "st.zwave.CommandClass.SwitchBinary")({ version = 2, strict = true }) +--- @type st.zwave.CommandClass.Meter +local Meter = (require "st.zwave.CommandClass.Meter")({ version = 3 }) local FIBARO_DOUBLE_SWITCH_FINGERPRINTS = { {mfr = 0x010F, prod = 0x0203, model = 0x1000}, -- Fibaro Switch @@ -45,42 +51,67 @@ local function central_scene_notification_handler(self, device, cmd) } local event = map_key_attribute_to_capability[cmd.args.key_attributes] - local button_number = 0 - if cmd.args.key_attributes == 0 or cmd.args.key_attributes == 1 or cmd.args.key_attributes == 2 then - button_number = cmd.args.scene_number - elseif cmd.args.key_attributes == 3 then - button_number = cmd.args.scene_number + 2 - elseif cmd.args.key_attributes == 4 then - button_number = cmd.args.scene_number + 4 - end + device:emit_event(event({state_change = true})) - local component = device.profile.components["button" .. button_number] +end - if component ~= nil then - device:emit_component_event(component, event({state_change = true})) +local function device_added(driver, device, event) + if device.network_type == st_device.NETWORK_TYPE_ZWAVE then + local name = string.format("%s %s", device.label, "(CH2)") + local metadata = { + type = "EDGE_CHILD", + label = name, + profile = "metering-switch", + parent_device_id = device.id, + parent_assigned_child_key = string.format("%02X", 2), + vendor_provided_label = name, + } + driver:try_create_device(metadata) end end -local function component_to_endpoint(device, component_id) - if component_id == "main" then - return {1} +local function find_child(parent, ep_id) + if ep_id == 1 then + return parent else - return {2} + return parent:get_child_by_parent_assigned_key(string.format("%02X", ep_id)) end end -local function endpoint_to_component(device, ep) - local switch_comp = string.format("switch%d", ep - 1) - if device.profile.components[switch_comp] ~= nil then - return switch_comp - else - return "main" +local function endpoint_to_component(device, endpoint) + return "main" +end + +local function component_to_endpoint(device, component) + return { 1 } +end + +local function device_init(driver, device, event) + if device.network_type == st_device.NETWORK_TYPE_ZWAVE then + device:set_find_child(find_child) + device:set_endpoint_to_component_fn(endpoint_to_component) + device:set_component_to_endpoint_fn(component_to_endpoint) end end -local device_init = function(self, device) - device:set_component_to_endpoint_fn(component_to_endpoint) - device:set_endpoint_to_component_fn(endpoint_to_component) +local function do_refresh(driver, device, command) + if device:is_cc_supported(cc.SWITCH_BINARY) then + device:send_to_component(SwitchBinary:Get({}), command.component) + elseif device:is_cc_supported(cc.BASIC) then + device:send_to_component(Basic:Get({}), command.component) + end + if device:supports_capability_by_id(capabilities.powerMeter.ID) or device:supports_capability_by_id(capabilities.energyMeter.ID) then + device:send_to_component(Meter:Get({ scale = Meter.scale.electric_meter.WATTS }), command.component) + device:send_to_component(Meter:Get({ scale = Meter.scale.electric_meter.KILOWATT_HOURS }), command.component) + end +end + +local function switch_report(driver, device, cmd) + switch_defaults.zwave_handlers[cc.SWITCH_BINARY][SwitchBinary.REPORT](driver, device, cmd) + + if device:supports_capability_by_id(capabilities.powerMeter.ID) then + device:send(Meter:Get({ scale = Meter.scale.electric_meter.WATTS }, { dst_channels = { cmd.src_channel } })) + end end local fibaro_double_switch = { @@ -88,10 +119,22 @@ local fibaro_double_switch = { zwave_handlers = { [cc.CENTRAL_SCENE] = { [CentralScene.NOTIFICATION] = central_scene_notification_handler + }, + [cc.BASIC] = { + [Basic.REPORT] = switch_report + }, + [cc.SWITCH_BINARY] = { + [SwitchBinary.REPORT] = switch_report + } + }, + capability_handlers = { + [capabilities.refresh.ID] = { + [capabilities.refresh.commands.refresh.NAME] = do_refresh } }, lifecycle_handlers = { - init = device_init + init = device_init, + added = device_added }, can_handle = can_handle_fibaro_double_switch, } diff --git a/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua b/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua index e1d324e2b1..510bfaa928 100644 --- a/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua +++ b/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua @@ -40,97 +40,47 @@ local sensor_endpoints = { {value = zw.SWITCH_MULTILEVEL}, {value = zw.METER} } - }, - { - command_classes = { - {value = zw.CENTRAL_SCENE} - } - }, - { - command_classes = { - {value = zw.CENTRAL_SCENE} - } - }, - { - command_classes = { - {value = zw.CENTRAL_SCENE} - } - }, - { - command_classes = { - {value = zw.CENTRAL_SCENE} - } - }, - { - command_classes = { - {value = zw.CENTRAL_SCENE} - } - }, - { - command_classes = { - {value = zw.CENTRAL_SCENE} - } - } -} - -local switch_endpoints = { - { - command_classes = { - {value = zw.SWITCH_BINARY} - } - }, - { - command_classes = { - {value = zw.SWITCH_BINARY} - } - }, - { - command_classes = { - {value = zw.SWITCH_BINARY} - } - }, - { - command_classes = { - {value = zw.SWITCH_BINARY} - } - }, - { - command_classes = { - {value = zw.SWITCH_BINARY} - } } } -local mock_device = test.mock_device.build_test_zwave_device({ - profile = t_utils.get_profile_definition("switch-1-button-6-power-energy.yml"), +local mock_parent = test.mock_device.build_test_zwave_device({ + profile = t_utils.get_profile_definition("fibaro-double-switch.yml"), zwave_endpoints = sensor_endpoints, zwave_manufacturer_id = 0x010F, zwave_product_type = 0x0203, zwave_product_id = 0x1000 }) -local function test_init() - test.mock_device.add_test_device(mock_device) +local mock_child = test.mock_device.build_test_child_device({ + profile = t_utils.get_profile_definition("metering-switch.yml"), + parent_device_id = mock_parent.id, + parent_assigned_child_key = string.format("%02X", 2) +}) + +local function test_init() + test.mock_device.add_test_device(mock_parent) + test.mock_device.add_test_device(mock_child) end + test.set_test_init_function(test_init) test.register_message_test( - "Switch Binary report ON_ENABLE should be handled by main componet", + "Switch Binary report ON_ENABLE should be handled by parent device", { { channel = "device_lifecycle", direction = "receive", - message = { mock_device.id, "init" } + message = { mock_parent.id, "init" } }, { channel = "zwave", direction = "receive", message = { - mock_device.id, + mock_parent.id, zw_test_utils.zwave_test_build_receive_command( SwitchBinary:Report( { - current_value=SwitchBinary.value.ON_ENABLE + target_value=SwitchBinary.value.ON_ENABLE }, { encap = zw.ENCAP.AUTO, @@ -144,13 +94,13 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("main", capabilities.switch.switch.on()) + message = mock_parent:generate_test_message("main", capabilities.switch.switch.on()) }, { channel = "zwave", direction = "send", message = zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Meter:Get({scale = Meter.scale.electric_meter.WATTS}, { encap = zw.ENCAP.AUTO, @@ -163,27 +113,27 @@ test.register_message_test( ) test.register_message_test( - "Switch Binary report ON_ENABLE should be handled by main switch1 component", + "Switch Binary report ON_ENABLE should be handled by child device", { { channel = "device_lifecycle", direction = "receive", - message = { mock_device.id, "init" } + message = { mock_child.id, "init" } }, { channel = "zwave", direction = "receive", message = { - mock_device.id, + mock_parent.id, zw_test_utils.zwave_test_build_receive_command( SwitchBinary:Report( { - current_value=SwitchBinary.value.ON_ENABLE + target_value=SwitchBinary.value.ON_ENABLE, }, { encap = zw.ENCAP.AUTO, src_channel = 2, - dst_channels={2} + dst_channels={0} } ) ) @@ -192,13 +142,13 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("switch1", capabilities.switch.switch.on()) + message = mock_child:generate_test_message("main", capabilities.switch.switch.on()) }, { channel = "zwave", direction = "send", message = zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Meter:Get({scale = Meter.scale.electric_meter.WATTS}, { encap = zw.ENCAP.AUTO, @@ -209,28 +159,27 @@ test.register_message_test( } } ) - test.register_message_test( - "Switch Binary report OFF_DISABLE should be handled by main componet", + "Switch Binary report OFF_DISABLE should be handled by parent device", { { channel = "device_lifecycle", direction = "receive", - message = { mock_device.id, "init" } + message = { mock_parent.id, "init" } }, { channel = "zwave", direction = "receive", message = { - mock_device.id, + mock_parent.id, zw_test_utils.zwave_test_build_receive_command( SwitchBinary:Report( { - current_value=SwitchBinary.value.OFF_DISABLE + target_value=SwitchBinary.value.OFF_DISABLE }, { encap = zw.ENCAP.AUTO, - src_channel = 0, + src_channel = 1, dst_channels={0} } ) @@ -240,13 +189,13 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("main", capabilities.switch.switch.off()) + message = mock_parent:generate_test_message("main", capabilities.switch.switch.off()) }, { channel = "zwave", direction = "send", message = zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Meter:Get({scale = Meter.scale.electric_meter.WATTS}, { encap = zw.ENCAP.AUTO, @@ -259,27 +208,27 @@ test.register_message_test( ) test.register_message_test( - "Switch Binary report OFF_DISABLE should be handled by main switch1 component", + "Switch Binary report OFF_DISABLE should be handled by child device", { { channel = "device_lifecycle", direction = "receive", - message = { mock_device.id, "init" } + message = { mock_parent.id, "init" } }, { channel = "zwave", direction = "receive", message = { - mock_device.id, + mock_parent.id, zw_test_utils.zwave_test_build_receive_command( SwitchBinary:Report( { - current_value=SwitchBinary.value.OFF_DISABLE + target_value=SwitchBinary.value.OFF_DISABLE }, { encap = zw.ENCAP.AUTO, src_channel = 2, - dst_channels={2} + dst_channels={0} } ) ) @@ -288,13 +237,13 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("switch1", capabilities.switch.switch.off()) + message = mock_child:generate_test_message("main", capabilities.switch.switch.off()) }, { channel = "zwave", direction = "send", message = zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Meter:Get({scale = Meter.scale.electric_meter.WATTS}, { encap = zw.ENCAP.AUTO, @@ -307,16 +256,16 @@ test.register_message_test( ) test.register_coroutine_test( - "Switch capability on commands should evoke the correct Z-Wave SETs and GETs", + "Switch capability on commands should evoke the correct Z-Wave SETs and GETs on parent device", function() test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot") test.socket.capability:__queue_receive({ - mock_device.id, + mock_parent.id, { capability = "switch", component = "main", command = "on", args = {} } }) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, SwitchBinary:Set({ target_value = SwitchBinary.value.ON_ENABLE, duration = 0 @@ -332,7 +281,7 @@ test.register_coroutine_test( test.mock_time.advance_time(1) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, SwitchBinary:Get({}, { encap = zw.ENCAP.AUTO, @@ -344,18 +293,17 @@ test.register_coroutine_test( end ) - test.register_coroutine_test( - "Switch capability on commands should evoke the correct Z-Wave SETs and GETs with dest_channel 1", + "Switch capability on commands should evoke the correct Z-Wave SETs and GETs on child device", function() test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot") test.socket.capability:__queue_receive({ - mock_device.id, - { capability = "switch", component = "switch1", command = "on", args = {} } + mock_child.id, + { capability = "switch", component = "main", command = "on", args = {} } }) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, SwitchBinary:Set({ target_value = SwitchBinary.value.ON_ENABLE, duration = 0 @@ -371,7 +319,7 @@ test.register_coroutine_test( test.mock_time.advance_time(1) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, SwitchBinary:Get({}, { encap = zw.ENCAP.AUTO, @@ -384,16 +332,16 @@ test.register_coroutine_test( ) test.register_coroutine_test( - "Switch capability off commands should evoke the correct Z-Wave SETs and GETs", + "Switch capability off commands should evoke the correct Z-Wave SETs and GETs on parent device", function() test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot") test.socket.capability:__queue_receive({ - mock_device.id, + mock_parent.id, { capability = "switch", component = "main", command = "off", args = {} } }) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, SwitchBinary:Set({ target_value = SwitchBinary.value.OFF_DISABLE, duration = 0 @@ -409,7 +357,7 @@ test.register_coroutine_test( test.mock_time.advance_time(1) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, SwitchBinary:Get({}, { encap = zw.ENCAP.AUTO, @@ -423,16 +371,16 @@ test.register_coroutine_test( test.register_coroutine_test( - "Switch capability off commands should evoke the correct Z-Wave SETs and GETs with dest_channel 1", + "Switch capability off commands should evoke the correct Z-Wave SETs and GETs on child device", function() test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot") test.socket.capability:__queue_receive({ - mock_device.id, - { capability = "switch", component = "switch1", command = "off", args = {} } + mock_child.id, + { capability = "switch", component = "main", command = "off", args = {} } }) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, SwitchBinary:Set({ target_value = SwitchBinary.value.OFF_DISABLE, duration = 0 @@ -448,7 +396,7 @@ test.register_coroutine_test( test.mock_time.advance_time(1) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, SwitchBinary:Get({}, { encap = zw.ENCAP.AUTO, @@ -466,7 +414,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 1, key_attributes=CentralScene.key_attributes.KEY_PRESSED_1_TIME})) } @@ -474,7 +422,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button1", capabilities.button.button.pushed({ + message = mock_parent:generate_test_message("main", capabilities.button.button.pushed({ state_change = true })) } } @@ -486,7 +434,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 1, key_attributes=CentralScene.key_attributes.KEY_RELEASED})) } @@ -494,7 +442,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button1", capabilities.button.button.held({ + message = mock_parent:generate_test_message("main", capabilities.button.button.held({ state_change = true })) } } @@ -506,7 +454,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 1, key_attributes=CentralScene.key_attributes.KEY_HELD_DOWN})) } @@ -514,7 +462,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button1", capabilities.button.button.down_hold({ + message = mock_parent:generate_test_message("main", capabilities.button.button.down_hold({ state_change = true })) } } @@ -526,7 +474,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 1, key_attributes=CentralScene.key_attributes.KEY_PRESSED_2_TIMES})) } @@ -534,7 +482,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button3", capabilities.button.button.double({ + message = mock_parent:generate_test_message("main", capabilities.button.button.double({ state_change = true })) } } @@ -546,7 +494,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 1, key_attributes=CentralScene.key_attributes.KEY_PRESSED_3_TIMES})) } @@ -554,7 +502,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button5", capabilities.button.button.pushed_3x({ + message = mock_parent:generate_test_message("main", capabilities.button.button.pushed_3x({ state_change = true })) } } @@ -566,7 +514,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 2, key_attributes=CentralScene.key_attributes.KEY_PRESSED_1_TIME})) } @@ -574,7 +522,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button2", capabilities.button.button.pushed({ + message = mock_parent:generate_test_message("main", capabilities.button.button.pushed({ state_change = true })) } } @@ -586,7 +534,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 2, key_attributes=CentralScene.key_attributes.KEY_RELEASED})) } @@ -594,7 +542,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button2", capabilities.button.button.held({ + message = mock_parent:generate_test_message("main", capabilities.button.button.held({ state_change = true })) } } @@ -606,7 +554,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 2, key_attributes=CentralScene.key_attributes.KEY_HELD_DOWN})) } @@ -614,7 +562,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button2", capabilities.button.button.down_hold({ + message = mock_parent:generate_test_message("main", capabilities.button.button.down_hold({ state_change = true })) } } @@ -626,7 +574,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 2, key_attributes=CentralScene.key_attributes.KEY_PRESSED_2_TIMES})) } @@ -634,7 +582,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button4", capabilities.button.button.double({ + message = mock_parent:generate_test_message("main", capabilities.button.button.double({ state_change = true })) } } @@ -646,7 +594,7 @@ test.register_message_test( { channel = "zwave", direction = "receive", - message = { mock_device.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ + message = { mock_parent.id, zw_test_utils.zwave_test_build_receive_command(CentralScene:Notification({ scene_number = 2, key_attributes=CentralScene.key_attributes.KEY_PRESSED_3_TIMES})) } @@ -654,7 +602,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_device:generate_test_message("button6", capabilities.button.button.pushed_3x({ + message = mock_parent:generate_test_message("main", capabilities.button.button.pushed_3x({ state_change = true })) } } @@ -664,7 +612,7 @@ test.register_coroutine_test( "infoChanged() should send the SET command for Configuation value", function() test.socket.zwave:__set_channel_ordering("relaxed") - test.socket.device_lifecycle():__queue_receive(mock_device:generate_info_changed( + test.socket.device_lifecycle():__queue_receive(mock_parent:generate_info_changed( { preferences = { restoreState = 0, @@ -690,119 +638,119 @@ test.register_coroutine_test( test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=9, size=1, configuration_value=0}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=10, size=1, configuration_value=2}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=11, size=1, configuration_value=2}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=12, size=2, configuration_value=500}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=13, size=2, configuration_value=50}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=15, size=1, configuration_value=4}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=16, size=1, configuration_value=2}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=17, size=2, configuration_value=600}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=18, size=1, configuration_value=90}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=20, size=1, configuration_value=0}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=21, size=1, configuration_value=1}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=28, size=1, configuration_value=2}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=29, size=1, configuration_value=3}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=53, size=2, configuration_value=500}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=57, size=2, configuration_value=1000}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=58, size=2, configuration_value=10}) ) ) test.socket.zwave:__expect_send( zw_test_utils.zwave_test_build_send_command( - mock_device, + mock_parent, Configuration:Set({parameter_number=59, size=2, configuration_value=600}) ) ) From 4727fda5ec93974ba5a43d8f35e08091195380f5 Mon Sep 17 00:00:00 2001 From: Nikita Date: Mon, 24 Oct 2022 11:14:35 +0200 Subject: [PATCH 2/9] buttons handling added --- .../profiles/fibaro-double-switch.yml | 36 +++++++++++++++++++ .../src/fibaro-double-switch/init.lua | 17 +++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml b/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml index b907f3f975..b59bc42c88 100644 --- a/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml +++ b/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml @@ -14,6 +14,42 @@ components: version: 1 categories: - name: Switch + - id: button1 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button2 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button3 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button4 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button5 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button6 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController preferences: - name: "restoreState" title: "Restore state" diff --git a/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua b/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua index 9a46b7e372..eb9727b0fe 100644 --- a/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua +++ b/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua @@ -49,10 +49,21 @@ local function central_scene_notification_handler(self, device, cmd) [CentralScene.key_attributes.KEY_PRESSED_2_TIMES] = capabilities.button.button.double, [CentralScene.key_attributes.KEY_PRESSED_3_TIMES] = capabilities.button.button.pushed_3x } - + local event = map_key_attribute_to_capability[cmd.args.key_attributes] - device:emit_event(event({state_change = true})) - + local button_number = 0 + if cmd.args.key_attributes == 0 or cmd.args.key_attributes == 1 or cmd.args.key_attributes == 2 then + button_number = cmd.args.scene_number + elseif cmd.args.key_attributes == 3 then + button_number = cmd.args.scene_number + 2 + elseif cmd.args.key_attributes == 4 then + button_number = cmd.args.scene_number + 4 + end + local component = device.profile.components["button" .. button_number] + + if component ~= nil then + device:emit_component_event(component, event({state_change = true})) + end end local function device_added(driver, device, event) From 374dbe45822e97ad1f4104818fac751cfe40ae58 Mon Sep 17 00:00:00 2001 From: Nikita Date: Mon, 24 Oct 2022 12:01:53 +0200 Subject: [PATCH 3/9] unit tests fix --- .../src/test/test_fibaro_double_switch.lua | 78 +++++++++++++++---- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua b/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua index 510bfaa928..a223df1c43 100644 --- a/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua +++ b/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua @@ -35,10 +35,60 @@ local sensor_endpoints = { }, { command_classes = { - {value = zw.BASIC}, - {value = zw.SWITCH_BINARY}, - {value = zw.SWITCH_MULTILEVEL}, - {value = zw.METER} + {value = zw.CENTRAL_SCENE} + } + }, + { + command_classes = { + {value = zw.CENTRAL_SCENE} + } + }, + { + command_classes = { + {value = zw.CENTRAL_SCENE} + } + }, + { + command_classes = { + {value = zw.CENTRAL_SCENE} + } + }, + { + command_classes = { + {value = zw.CENTRAL_SCENE} + } + }, + { + command_classes = { + {value = zw.CENTRAL_SCENE} + } + } +} + +local switch_endpoints = { + { + command_classes = { + {value = zw.SWITCH_BINARY} + } + }, + { + command_classes = { + {value = zw.SWITCH_BINARY} + } + }, + { + command_classes = { + {value = zw.SWITCH_BINARY} + } + }, + { + command_classes = { + {value = zw.SWITCH_BINARY} + } + }, + { + command_classes = { + {value = zw.SWITCH_BINARY} } } } @@ -422,7 +472,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.pushed({ + message = mock_parent:generate_test_message("button1", capabilities.button.button.pushed({ state_change = true })) } } @@ -442,7 +492,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.held({ + message = mock_parent:generate_test_message("button1", capabilities.button.button.held({ state_change = true })) } } @@ -462,7 +512,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.down_hold({ + message = mock_parent:generate_test_message("button1", capabilities.button.button.down_hold({ state_change = true })) } } @@ -482,7 +532,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.double({ + message = mock_parent:generate_test_message("button3", capabilities.button.button.double({ state_change = true })) } } @@ -502,7 +552,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.pushed_3x({ + message = mock_parent:generate_test_message("button5", capabilities.button.button.pushed_3x({ state_change = true })) } } @@ -522,7 +572,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.pushed({ + message = mock_parent:generate_test_message("button2", capabilities.button.button.pushed({ state_change = true })) } } @@ -542,7 +592,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.held({ + message = mock_parent:generate_test_message("button2", capabilities.button.button.held({ state_change = true })) } } @@ -562,7 +612,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.down_hold({ + message = mock_parent:generate_test_message("button2", capabilities.button.button.down_hold({ state_change = true })) } } @@ -582,7 +632,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.double({ + message = mock_parent:generate_test_message("button4", capabilities.button.button.double({ state_change = true })) } } @@ -602,7 +652,7 @@ test.register_message_test( { channel = "capability", direction = "send", - message = mock_parent:generate_test_message("main", capabilities.button.button.pushed_3x({ + message = mock_parent:generate_test_message("button6", capabilities.button.button.pushed_3x({ state_change = true })) } } From 9a1b84bf3185bf4f38cd6ec05a87419f6717584b Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 25 Oct 2022 08:03:18 +0200 Subject: [PATCH 4/9] update due to remarks --- .../profiles/fibaro-double-switch.yml | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml b/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml index b59bc42c88..40f0e536dc 100644 --- a/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml +++ b/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml @@ -1,4 +1,4 @@ -name: fibaro-double-switch +name: fibaro_double_switch components: - id: main capabilities: @@ -16,40 +16,40 @@ components: - name: Switch - id: button1 capabilities: - - id: button - version: 1 + - id: button + version: 1 categories: - - name: RemoteController + - name: RemoteController - id: button2 capabilities: - - id: button - version: 1 + - id: button + version: 1 categories: - - name: RemoteController + - name: RemoteController - id: button3 capabilities: - - id: button - version: 1 + - id: button + version: 1 categories: - - name: RemoteController + - name: RemoteController - id: button4 capabilities: - - id: button - version: 1 + - id: button + version: 1 categories: - - name: RemoteController + - name: RemoteController - id: button5 capabilities: - - id: button - version: 1 + - id: button + version: 1 categories: - - name: RemoteController + - name: RemoteController - id: button6 capabilities: - - id: button - version: 1 + - id: button + version: 1 categories: - - name: RemoteController + - name: RemoteController preferences: - name: "restoreState" title: "Restore state" From 8f5ad58ce77dce50013f9cf980eff01efbfd1aed Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 26 Oct 2022 17:12:33 +0200 Subject: [PATCH 5/9] add constants and change refresh method --- .../src/fibaro-double-switch/init.lua | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua b/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua index eb9727b0fe..ca7bdc5560 100644 --- a/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua +++ b/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua @@ -26,6 +26,11 @@ local SwitchBinary = (require "st.zwave.CommandClass.SwitchBinary")({ version = --- @type st.zwave.CommandClass.Meter local Meter = (require "st.zwave.CommandClass.Meter")({ version = 3 }) +local ENDPOINTS = { + parent = 1, + child = 2 +} + local FIBARO_DOUBLE_SWITCH_FINGERPRINTS = { {mfr = 0x010F, prod = 0x0203, model = 0x1000}, -- Fibaro Switch {mfr = 0x010F, prod = 0x0203, model = 0x2000}, -- Fibaro Switch @@ -66,6 +71,14 @@ local function central_scene_notification_handler(self, device, cmd) end end +local function do_refresh(driver, device, command) + local component = command and command.component and command.component or "main" + device:send_to_component(SwitchBinary:Get({}), component) + device:send_to_component(Basic:Get({}), component) + device:send_to_component(Meter:Get({ scale = Meter.scale.electric_meter.WATTS }), component) + device:send_to_component(Meter:Get({ scale = Meter.scale.electric_meter.KILOWATT_HOURS }), component) +end + local function device_added(driver, device, event) if device.network_type == st_device.NETWORK_TYPE_ZWAVE then local name = string.format("%s %s", device.label, "(CH2)") @@ -74,11 +87,12 @@ local function device_added(driver, device, event) label = name, profile = "metering-switch", parent_device_id = device.id, - parent_assigned_child_key = string.format("%02X", 2), + parent_assigned_child_key = string.format("%02X", ENDPOINTS.child), vendor_provided_label = name, } driver:try_create_device(metadata) end + do_refresh(driver, device) end local function find_child(parent, ep_id) @@ -89,34 +103,17 @@ local function find_child(parent, ep_id) end end -local function endpoint_to_component(device, endpoint) - return "main" -end - local function component_to_endpoint(device, component) - return { 1 } + return { ENDPOINTS.parent } end local function device_init(driver, device, event) if device.network_type == st_device.NETWORK_TYPE_ZWAVE then device:set_find_child(find_child) - device:set_endpoint_to_component_fn(endpoint_to_component) device:set_component_to_endpoint_fn(component_to_endpoint) end end -local function do_refresh(driver, device, command) - if device:is_cc_supported(cc.SWITCH_BINARY) then - device:send_to_component(SwitchBinary:Get({}), command.component) - elseif device:is_cc_supported(cc.BASIC) then - device:send_to_component(Basic:Get({}), command.component) - end - if device:supports_capability_by_id(capabilities.powerMeter.ID) or device:supports_capability_by_id(capabilities.energyMeter.ID) then - device:send_to_component(Meter:Get({ scale = Meter.scale.electric_meter.WATTS }), command.component) - device:send_to_component(Meter:Get({ scale = Meter.scale.electric_meter.KILOWATT_HOURS }), command.component) - end -end - local function switch_report(driver, device, cmd) switch_defaults.zwave_handlers[cc.SWITCH_BINARY][SwitchBinary.REPORT](driver, device, cmd) From a62c8ff76ab5fb1c2f508e8357035b1760d72984 Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 27 Oct 2022 11:36:33 +0200 Subject: [PATCH 6/9] cleanup --- .../SmartThings/zwave-switch/src/fibaro-double-switch/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua b/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua index ca7bdc5560..0994e88485 100644 --- a/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua +++ b/drivers/SmartThings/zwave-switch/src/fibaro-double-switch/init.lua @@ -96,7 +96,7 @@ local function device_added(driver, device, event) end local function find_child(parent, ep_id) - if ep_id == 1 then + if ep_id == ENDPOINTS.parent then return parent else return parent:get_child_by_parent_assigned_key(string.format("%02X", ep_id)) From 7259221518aeae3ca9676b06dfab8cb2d0d6625b Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 27 Oct 2022 11:58:36 +0200 Subject: [PATCH 7/9] add fibaro-double-switch profile as new file --- .../profiles/fibaro-double-switch.yml | 2 +- .../switch-1-button-6-power-energy.yml | 312 ++++++++++++++++++ 2 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 drivers/SmartThings/zwave-switch/profiles/switch-1-button-6-power-energy.yml diff --git a/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml b/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml index 40f0e536dc..d225d60860 100644 --- a/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml +++ b/drivers/SmartThings/zwave-switch/profiles/fibaro-double-switch.yml @@ -1,4 +1,4 @@ -name: fibaro_double_switch +name: fibaro-double-switch components: - id: main capabilities: diff --git a/drivers/SmartThings/zwave-switch/profiles/switch-1-button-6-power-energy.yml b/drivers/SmartThings/zwave-switch/profiles/switch-1-button-6-power-energy.yml new file mode 100644 index 0000000000..3f1c889831 --- /dev/null +++ b/drivers/SmartThings/zwave-switch/profiles/switch-1-button-6-power-energy.yml @@ -0,0 +1,312 @@ +name: switch-1-button-6-power-energy +components: + - id: main + capabilities: + - id: switch + version: 1 + - id: powerMeter + version: 1 + - id: energyMeter + version: 1 + - id: button + version: 1 + - id: refresh + version: 1 + categories: + - name: Switch + - id: switch1 + capabilities: + - id: switch + version: 1 + - id: powerMeter + version: 1 + - id: energyMeter + version: 1 + categories: + - name: Switch + - id: button1 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button2 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button3 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button4 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button5 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController + - id: button6 + capabilities: + - id: button + version: 1 + categories: + - name: RemoteController +preferences: + - name: "restoreState" + title: "Restore state" + description: "This parameter determines if the device will return to state prior to the power failure after power is restored" + required: false + preferenceType: enumeration + definition: + options: + 0: "power off after power failure" + 1: "restore state" + default: 1 + - name: "ch1OperatingMode" + title: "Ch1 operating mode" + description: "This parameter allows to choose operating for the 1st channel controlled by the S1 switch" + required: false + preferenceType: enumeration + definition: + options: + 0: "standard operation" + 1: "delay ON" + 2: "delay OFF" + 3: "auto ON" + 4: "auto OFF" + 5: "flashing mode" + default: 0 + - name: "ch1ReactionToSwitch" + title: "Ch1 reaction to switch" + description: "This parameter determines how the device in timed mode reacts to pushing the switch connected to the S1 terminal" + required: false + preferenceType: enumeration + definition: + options: + 0: "cancel and set target state" + 1: "no reaction" + 2: "reset timer" + default: 0 + - name: "ch1TimeParameter" + title: "Ch1 time parameter" + description: "First channel - Time parameter for delay/auto ON/OFF modes" + required: false + preferenceType: number + definition: + minimum: 0 + maximum: 32000 + default: 50 + - name: "ch1PulseTime" + title: "Ch1 pulse time" + description: "This parameter allows to set time of switching to opposite state in flashing mode" + required: false + preferenceType: enumeration + definition: + options: + 1: "0.1 s" + 5: "0.5 s" + 10: "1 s" + 20: "2 s" + 30: "3 s" + 40: "4 s" + 50: "5 s" + 60: "6 s" + 70: "7 s" + 80: "8 s" + 90: "9 s" + 100: "10 s" + 300: "30 s" + 600: "60 s" + 6000: "600 s" + default: 5 + - name: "ch2OperatingMode" + title: "Ch2 operating mode" + description: "his parameter allows to choose operating for the 1st channel controlled by the S2 switch" + required: false + preferenceType: enumeration + definition: + options: + 0: "standard operation" + 1: "delay ON" + 2: "delay OFF" + 3: "auto ON" + 4: "auto OFF" + 5: "flashing mode" + default: 0 + - name: "ch2ReactionToSwitch" + title: "Ch2 reaction to switch" + description: "This parameter determines how the device in timed mode reacts to pushing the switch connected to the S2 terminal" + required: false + preferenceType: enumeration + definition: + options: + 0: "cancel and set target state" + 1: "no reaction" + 2: "reset timer" + default: 0 + - name: "ch2TimeParameter" + title: "Ch2 time parameter" + description: "Second channel - Time parameter for delay/auto ON/OFF modes" + required: false + preferenceType: number + definition: + minimum: 0 + maximum: 32000 + default: 50 + - name: "ch2PulseTime" + title: "Ch2 pulse time" + description: "This parameter allows to set time of switching to opposite state in flashing mode" + required: false + preferenceType: enumeration + definition: + options: + 1: "0.1 s" + 5: "0.5 s" + 10: "1 s" + 20: "2 s" + 30: "3 s" + 40: "4 s" + 50: "5 s" + 60: "6 s" + 70: "7 s" + 80: "8 s" + 90: "9 s" + 100: "10 s" + 300: "30 s" + 600: "60 s" + 6000: "600 s" + default: 5 + - name: "switchType" + title: "Switch type" + description: "Parameter defines as what type the device should treat the switch connected to the S1 and S2 terminals" + required: false + preferenceType: enumeration + definition: + options: + 0: "momentary switch" + 1: "toggle sw. (ON/OFF)" + 2: "toggle sw. synced with switch status" + default: 2 + - name: "flashingReports" + title: "Flashing reports" + description: "This parameter allows to define if the device sends reports during the flashing mode" + required: false + preferenceType: enumeration + definition: + options: + 0: "do not send reports" + 1: "sends reports" + default: 0 + - name: "s1ScenesSent" + title: "S1 scenes sent" + description: "This parameter determines which actions result in sending scene IDs assigned to them" + required: false + preferenceType: enumeration + definition: + options: + 0: "do not send scenes" + 1: "key pressed 1 time" + 2: "key pressed 2 times" + 3: "key pressed 1 & 2 times" + 4: "key pressed 3 times" + 5: "key pressed 1 & 3 times" + 6: "key pressed 2 & 3 times" + 7: "key pressed 1, 2 & 3 times" + 8: "key held & released" + 9: "key Pressed 1 time & held" + 10: "key pressed 2 times & held" + 11: "key pressed 1, 2 times & held" + 12: "key pressed 3 times & held" + 13: "key pressed 1, 3 times & held" + 14: "key pressed 2, 3 times & held" + 15: "key pressed 1, 2, 3 times & held" + default: 0 + - name: "s2ScenesSent" + title: "S2 scenes sent" + description: "This parameter determines which actions result in sending scene IDs assigned to them" + required: false + preferenceType: enumeration + definition: + options: + 0: "do not send scenes" + 1: "key pressed 1 time" + 2: "key pressed 2 times" + 3: "key pressed 1 & 2 times" + 4: "key pressed 3 times" + 5: "key pressed 1 & 3 times" + 6: "key pressed 2 & 3 times" + 7: "key pressed 1, 2 & 3 times" + 8: "key held & released" + 9: "key Pressed 1 time & held" + 10: "key pressed 2 times & held" + 11: "key pressed 1, 2 times & held" + 12: "key pressed 3 times & held" + 13: "key pressed 1, 3 times & held" + 14: "key pressed 2, 3 times & held" + 15: "key pressed 1, 2, 3 times & held" + default: 0 + - name: "ch1EnergyReports" + title: "Ch1 energy reports" + description: "This parameter determines the min. change in consumed power that will result in sending power report" + required: false + preferenceType: enumeration + definition: + options: + 1: "0.01 kWh" + 10: "0.1 kWh" + 50: "0.5 kWh" + 100: "1 kWh" + 500: "5 kWh" + 1000: "10 kWh" + default: 100 + - name: "ch2EnergyReports" + title: "Ch2 energy reports" + description: "This parameter determines the min. change in consumed power that will result in sending power report" + required: false + preferenceType: enumeration + definition: + options: + 1: "0.01 kWh" + 10: "0.1 kWh" + 50: "0.5 kWh" + 100: "1 kWh" + 500: "5 kWh" + 1000: "10 kWh" + default: 100 + - name: "periodicPowerReports" + title: "Periodic power reports" + description: "This parameter defines in what time interval the periodic power reports are sent" + required: false + preferenceType: enumeration + definition: + options: + 1: "1 s" + 5: "5 s" + 10: "10 s" + 600: "600 s" + 3600: "3600 s" + 32000: "32000 s" + default: 3600 + - name: "periodicEnergyReports" + title: "Periodic energy reports" + description: "This parameter determines in what time interval the periodic Energy reports are sent" + required: false + preferenceType: enumeration + definition: + options: + 1: "1 s" + 5: "5 s" + 10: "10 s" + 600: "600 s" + 3600: "3600 s" + 32000: "32000 s" + default: 3600 \ No newline at end of file From f47be640a2ee7e7750f705392ff5f6b33cf7bd07 Mon Sep 17 00:00:00 2001 From: Nikita Date: Fri, 28 Oct 2022 16:48:01 +0200 Subject: [PATCH 8/9] fix tests --- .../zwave-switch/src/test/test_fibaro_double_switch.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua b/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua index a223df1c43..edf955d19f 100644 --- a/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua +++ b/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua @@ -130,7 +130,8 @@ test.register_message_test( zw_test_utils.zwave_test_build_receive_command( SwitchBinary:Report( { - target_value=SwitchBinary.value.ON_ENABLE + target_value=SwitchBinary.value.ON_ENABLE, + current_value=SwitchBinary.value.ON_ENABLE, }, { encap = zw.ENCAP.AUTO, @@ -179,6 +180,7 @@ test.register_message_test( SwitchBinary:Report( { target_value=SwitchBinary.value.ON_ENABLE, + current_value=SwitchBinary.value.ON_ENABLE }, { encap = zw.ENCAP.AUTO, From 32caef5fef93bcc4ab8e1cfb5865b9ba8bf3d597 Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 2 Nov 2022 13:56:09 +0100 Subject: [PATCH 9/9] cleanup in tests --- .../src/test/test_fibaro_double_switch.lua | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua b/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua index edf955d19f..1a5180e40f 100644 --- a/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua +++ b/drivers/SmartThings/zwave-switch/src/test/test_fibaro_double_switch.lua @@ -22,7 +22,6 @@ local Meter = (require "st.zwave.CommandClass.Meter")({version=3}) local CentralScene = (require "st.zwave.CommandClass.CentralScene")({version=1}) local Configuration = (require "st.zwave.CommandClass.Configuration")({version=1}) --- supported comand classes local sensor_endpoints = { { command_classes = { @@ -65,34 +64,6 @@ local sensor_endpoints = { } } -local switch_endpoints = { - { - command_classes = { - {value = zw.SWITCH_BINARY} - } - }, - { - command_classes = { - {value = zw.SWITCH_BINARY} - } - }, - { - command_classes = { - {value = zw.SWITCH_BINARY} - } - }, - { - command_classes = { - {value = zw.SWITCH_BINARY} - } - }, - { - command_classes = { - {value = zw.SWITCH_BINARY} - } - } -} - local mock_parent = test.mock_device.build_test_zwave_device({ profile = t_utils.get_profile_definition("fibaro-double-switch.yml"), zwave_endpoints = sensor_endpoints,