From f8fbde843784f989f272c23422e3d95668fd0ba1 Mon Sep 17 00:00:00 2001 From: greens Date: Fri, 6 May 2022 13:21:54 -0700 Subject: [PATCH] CHAD-8368 Emit all component button events from main Add synthetic pushed event from main component on add --- .../zigbee-button/src/button_utils.lua | 21 + .../zigbee-button/src/dimming-remote/init.lua | 15 +- .../zigbee-button/src/frient/init.lua | 5 +- .../SmartThings/zigbee-button/src/init.lua | 3 + .../zigbee-button/src/iris/init.lua | 4 +- .../zigbee-button/src/pushButton/init.lua | 1 + .../src/test/test_aduro_button.lua | Bin 6507 -> 7596 bytes .../src/test/test_centralite_button.lua | Bin 9819 -> 11210 bytes .../src/test/test_dimming_remote.lua | Bin 8227 -> 9288 bytes .../src/test/test_heiman_button.lua | Bin 10314 -> 11109 bytes .../src/test/test_ikea_on_off.lua | 21 +- .../src/test/test_ikea_open_close.lua | Bin 7042 -> 7619 bytes .../src/test/test_ikea_remote_control.lua | Bin 9136 -> 10748 bytes .../src/test/test_iris_button.lua | Bin 8976 -> 9183 bytes .../src/test/test_push_only_button.lua | 7 + .../src/test/test_samjin_button.lua | 9 +- .../src/test/test_shinasystem_button.lua | Bin 8899 -> 10886 bytes .../src/test/test_somfy_situo_1_button.lua | 18 +- .../src/test/test_somfy_situo_4_button.lua | Bin 10331 -> 10562 bytes .../src/test/test_zigbee_button.lua | 10 +- .../src/test/test_zigbee_ecosmart_button.lua | 379 ++++++++++-------- .../zigbee-multi-button/adurosmart/init.lua | 27 +- .../zigbee-multi-button/centralite/init.lua | 6 +- .../src/zigbee-multi-button/ecosmart/init.lua | 1 + .../src/zigbee-multi-button/heiman/init.lua | 1 + .../ikea/TRADFRI_on_off_switch.lua | 24 +- .../ikea/TRADFRI_open_close_remote.lua | 20 +- .../ikea/TRADFRI_remote_control.lua | 30 +- .../src/zigbee-multi-button/ikea/init.lua | 1 + .../src/zigbee-multi-button/init.lua | 1 + .../zigbee-multi-button/shinasystems/init.lua | 3 + .../somfy/somfy_situo_1.lua | 23 +- 32 files changed, 334 insertions(+), 296 deletions(-) diff --git a/drivers/SmartThings/zigbee-button/src/button_utils.lua b/drivers/SmartThings/zigbee-button/src/button_utils.lua index f94afe2559..b7499684cd 100644 --- a/drivers/SmartThings/zigbee-button/src/button_utils.lua +++ b/drivers/SmartThings/zigbee-button/src/button_utils.lua @@ -52,10 +52,31 @@ button_utils.send_pushed_or_held_button_event_if_applicable = function(device, b local component = device.profile.components[button_name] if component ~= nil then device:emit_component_event(component, event) + if button_name ~= "main" then + device:emit_event(event) + end else log.warn("Attempted to emit button event for non-existing component: " .. button_name) end end end +button_utils.build_button_handler = function(button_name, pressed_type) + return function(driver, device, zb_rx) + local additional_fields = { + state_change = true + } + local event = pressed_type(additional_fields) + local comp = device.profile.components[button_name] + if comp ~= nil then + device:emit_component_event(comp, event) + if button_name ~= "main" then + device:emit_event(event) + end + else + log.warn("Attempted to emit button event for unknown button: " .. button_name) + end + end +end + return button_utils diff --git a/drivers/SmartThings/zigbee-button/src/dimming-remote/init.lua b/drivers/SmartThings/zigbee-button/src/dimming-remote/init.lua index cf81a620fc..c4966af0d2 100644 --- a/drivers/SmartThings/zigbee-button/src/dimming-remote/init.lua +++ b/drivers/SmartThings/zigbee-button/src/dimming-remote/init.lua @@ -47,16 +47,6 @@ local function button_released_handler(self, device, value, zb_rx) button_utils.send_pushed_or_held_button_event_if_applicable(device, 2) end -local function button_pressed_handler(button_number) - return function(self, device, value, zb_rx) - local additional_fields = {state_change = true} - local button_name = "button" .. button_number - local event = capabilities.button.button.pushed(additional_fields) - local component = device.profile.components[button_name] - device:emit_component_event(component, event) - end -end - local function added_handler(self, device) for _, component in pairs(device.profile.components) do local number_of_buttons = component.id == "main" and 2 or 1 @@ -64,6 +54,7 @@ local function added_handler(self, device) device:emit_component_event(component, capabilities.button.numberOfButtons({value = number_of_buttons})) end device:send(PowerConfiguration.attributes.BatteryVoltage:read(device)) + device:emit_event(capabilities.button.button.pushed({state_change = false})) end local function do_configure(self, device) @@ -88,8 +79,8 @@ local dimming_remote = { [Level.server.commands.Stop.ID] = button_released_handler }, [OnOff.ID] = { - [OnOff.server.commands.Off.ID] = button_pressed_handler(2), - [OnOff.server.commands.On.ID] = button_pressed_handler(1) + [OnOff.server.commands.Off.ID] = button_utils.build_button_handler("button2", capabilities.button.button.pushed), + [OnOff.server.commands.On.ID] = button_utils.build_button_handler("button1", capabilities.button.button.pushed) } } }, diff --git a/drivers/SmartThings/zigbee-button/src/frient/init.lua b/drivers/SmartThings/zigbee-button/src/frient/init.lua index 8739ff5b05..2af30603a2 100644 --- a/drivers/SmartThings/zigbee-button/src/frient/init.lua +++ b/drivers/SmartThings/zigbee-button/src/frient/init.lua @@ -34,14 +34,14 @@ local battery_table = { [0.00] = 0 } -local function present_value_attr_handler(ZigbeeDriver, ZigbeeDevice, value, zb_rx) +local function present_value_attr_handler(driver, device, value, zb_rx) local event local additional_fields = { state_change = true } if value.value == true then event = capabilities.button.button.pushed(additional_fields) - ZigbeeDevice:emit_event(event) + device:emit_event(event) end end @@ -52,6 +52,7 @@ end local function added_handler(self, device) device:emit_event(capabilities.button.supportedButtonValues({"pushed"})) device:emit_event(capabilities.button.numberOfButtons({value = 1})) + device:emit_event(capabilities.button.button.pushed({state_change = false})) end local configure_handler = function(self, device) diff --git a/drivers/SmartThings/zigbee-button/src/init.lua b/drivers/SmartThings/zigbee-button/src/init.lua index f0dec29e1d..aa4937ae13 100644 --- a/drivers/SmartThings/zigbee-button/src/init.lua +++ b/drivers/SmartThings/zigbee-button/src/init.lua @@ -34,6 +34,9 @@ local generate_event_from_zone_status = function(driver, device, zone_status, zb device:emit_event_for_endpoint( zb_rx.address_header.src_endpoint.value, event) + if device:get_component_id_for_endpoint(zb_rx.address_header.src_endpoint.value) ~= "main" then + device:emit_event(event) + end end end diff --git a/drivers/SmartThings/zigbee-button/src/iris/init.lua b/drivers/SmartThings/zigbee-button/src/iris/init.lua index 71b355ddfc..5b830b0597 100644 --- a/drivers/SmartThings/zigbee-button/src/iris/init.lua +++ b/drivers/SmartThings/zigbee-button/src/iris/init.lua @@ -19,6 +19,7 @@ local PowerConfiguration = zcl_clusters.PowerConfiguration local IASZone = zcl_clusters.IASZone local device_management = require "st.zigbee.device_management" local battery_defaults = require "st.zigbee.defaults.battery_defaults" +local button_utils = require "button_utils" local IRIS_BUTTON_FINGERPRINTS = { { mfr = "CentraLite", model = "3455-L" }, @@ -34,8 +35,6 @@ local function can_handle_iris_button(opts, driver, device, ...) return false end -local button_utils = require "button_utils" - local function button_pressed_handler(self, device, value, zb_rx) button_utils.init_button_press(device) end @@ -63,6 +62,7 @@ end local function added_handler(self, device) device:emit_event(capabilities.button.supportedButtonValues({"pushed", "held"})) device:emit_event(capabilities.button.numberOfButtons({value = 1})) + device:emit_event(capabilities.button.button.pushed({state_change = false})) device:send(PowerConfiguration.attributes.BatteryVoltage:read(device)) end diff --git a/drivers/SmartThings/zigbee-button/src/pushButton/init.lua b/drivers/SmartThings/zigbee-button/src/pushButton/init.lua index 8b528611c9..94f2b46ee8 100644 --- a/drivers/SmartThings/zigbee-button/src/pushButton/init.lua +++ b/drivers/SmartThings/zigbee-button/src/pushButton/init.lua @@ -28,6 +28,7 @@ local capabilities = require "st.capabilities" local function added_handler(self, device) device:emit_event(capabilities.button.supportedButtonValues({"pushed"})) device:emit_event(capabilities.button.numberOfButtons({value = 1})) + device:emit_event(capabilities.button.button.pushed({state_change = false})) end local push_button = { diff --git a/drivers/SmartThings/zigbee-button/src/test/test_aduro_button.lua b/drivers/SmartThings/zigbee-button/src/test/test_aduro_button.lua index 953bcada671dd9bde2033db1c5eb9aa3c1d7288a..c8bbc8812ed8a2c229af0732cdafac040140d70d 100644 GIT binary patch delta 209 zcmaEDw8nbFPWH)vIoKx$aJaJMCT8YM&f}Rl`2m~wWI2w5=n@Ym*Kn@H6g6SUJ8)=D66ctFMl{nbskEddKTk}Z0NKk&LjV8( delta 61 zcmZ2u{n}{5PWH(Y`28k7U=yFbk>encJ$LdVu9aZAng>FM@U7fDf!~c0C@8eKTJR#* IWNF!n07;M;n*aa+ diff --git a/drivers/SmartThings/zigbee-button/src/test/test_centralite_button.lua b/drivers/SmartThings/zigbee-button/src/test/test_centralite_button.lua index 3820e6636cf6c812e5fa8bd4f3b7a05cadfc582c..93e5f92969c84642c716095c083036bd3baf4b4e 100644 GIT binary patch delta 259 zcmccZb1HnpN{-2EMEzKD6EpKBPvH4K*-cnt^Ex43#>w+}Oi*QJi%LvhCp2U7Y|&B_ z$;}gZBAAeshHn1FHxEgKQS2|!Si#8x0uO=oa)eTl#B5QB#B5Q7#AZgZX(;-GC;#H( zo@}qiHd#hdYV#F|Z#n+a delta 149 zcmX>Ve%oimN{-3(B4;NbkQ11EfUjb*p0N02U9r;1^4ums@ja78B_$^NDRYA5{z>$J z#r>sF)&JvP2~;bz*-vmD)8=}SP$sBO!O3=@s(Zv+6rF&m-) diff --git a/drivers/SmartThings/zigbee-button/src/test/test_heiman_button.lua b/drivers/SmartThings/zigbee-button/src/test/test_heiman_button.lua index ba9505158fc768dd5a3a95261c99514f237a6cec..5d74fe961ce0dc788d65173e4fa15b8309e06b91 100644 GIT binary patch delta 162 zcmX>V@HA|LEXQOydG^T)T&^s+iJ5tmbGRN)-pjEPQ;>}dRd90-R}Uk)ve3y2yeymf zcveeK7U0sHtRTiQd9_NWNm6M^Nq(M^jzV!sVo9oktwOazSz=Bph^16eTAY!ZqNGsE Pr2qyHx>j@Y4)sX@taCCe delta 55 zcmaDFb}C?lEXU>z9G;AmH*hSNti!z$OmpypXrak=+Jci8h*@r4z?Uk`$TgW?-et0+ GwhsVcl@odZ diff --git a/drivers/SmartThings/zigbee-button/src/test/test_ikea_on_off.lua b/drivers/SmartThings/zigbee-button/src/test/test_ikea_on_off.lua index a642367331..3cc0702ef1 100644 --- a/drivers/SmartThings/zigbee-button/src/test/test_ikea_on_off.lua +++ b/drivers/SmartThings/zigbee-button/src/test/test_ikea_on_off.lua @@ -57,18 +57,30 @@ test.register_coroutine_test( test.socket.capability:__expect_send( mock_device:generate_test_message("button1", (button_attr.pushed({ state_change = true }))) ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) test.socket.zigbee:__queue_receive({ mock_device.id, OnOff.server.commands.On.build_test_rx(mock_device) }) test.socket.capability:__expect_send( mock_device:generate_test_message("button2", (button_attr.pushed({ state_change = true }))) ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) test.socket.zigbee:__queue_receive({ mock_device.id, Level.server.commands.Move.build_test_rx(mock_device) }) test.socket.capability:__expect_send( mock_device:generate_test_message("button1", (button_attr.held({ state_change = true }))) ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.held({ state_change = true })) + ) test.socket.zigbee:__queue_receive({ mock_device.id, Level.server.commands.MoveWithOnOff.build_test_rx(mock_device) }) test.socket.capability:__expect_send( mock_device:generate_test_message("button2", (button_attr.held({ state_change = true }))) ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.held({ state_change = true })) + ) end ) @@ -116,7 +128,7 @@ test.register_coroutine_test( test.register_coroutine_test( "ZDO Message handler and adding hub to group", function() - local binding_table = mgmt_bind_response.BindingTableListRecord("j����^��", 0x01, 0x0006, 0x01, 0xB9F2) + local binding_table = mgmt_bind_response.BindingTableListRecord("\x6A\x9D\xC0\xFE\xFF\x5E\xCF\xD0", 0x01, 0x0006, 0x01, 0xB9F2) local response = mgmt_bind_response.MgmtBindResponse({ status = 0x00, total_binding_table_entry_count = 0x01, @@ -170,6 +182,13 @@ test.register_coroutine_test( }) end end + test.socket.capability:__expect_send({ + mock_device.id, + { + capability_id = "button", component_id = "main", + attribute_id = "button", state = { value = "pushed" } + } + }) test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) test.socket.zigbee:__expect_send({ diff --git a/drivers/SmartThings/zigbee-button/src/test/test_ikea_open_close.lua b/drivers/SmartThings/zigbee-button/src/test/test_ikea_open_close.lua index f4363bd1864466f3bd60c5776192219470de5f99..20391095a7edc78ed7bbf2c279a557948098dba7 100644 GIT binary patch delta 253 zcmZoNKWx3hn`82M4yDOg*_Byx6EpKR|7VY3oNUX%hax)pKfB%LXwG1Eg_sI6$CwIB zmzWA?gP008S0HwasW1i7&OqA5VDmPC>r4?b6$U_A1E4B1peRTMNTm^wHnfbXFgI4x zQ81`5Fa(nZ24-N|SVut#sKx@Q2dK}|9BPIUgth?MYHqf9tMGER$qU&vCtr|~o17vZ zY?4%3Qj(tsG_SZMu_RT&R-syz2oM3Yg$h##2x^_c{{LRj(6jgv*8&It4R8PcFBx-_?-Upa VC~cPj0sxA3vnLg&2D6T7_a~U diff --git a/drivers/SmartThings/zigbee-button/src/test/test_ikea_remote_control.lua b/drivers/SmartThings/zigbee-button/src/test/test_ikea_remote_control.lua index a1d5b075655951c41ce378f13c8b5d2e4c062bdc..1a2052657933b18397b584955a1569019fadab17 100644 GIT binary patch delta 439 zcmdns{wH{Y6UStKPNB(mGLn-g2yssS$*DX!PMLl37QW)ibsUc|#DxVdC-3JqpS+G+ zYVs1!op|(0P2S9P36K6eIP~tA%+1Rq7*k;hsdP2R_uGP!}*7sJFB-oqf( zAeCsUH}F~Gu;U0w2Uhb1Co2f*0DZ`ZVGqRTHIsAr!LGwJ4P?d!URS!jNCz~s%Z@wX> e%g&KC_rSmZapx~=R+T%>G1*_-Wb=DcHezNsp#YtyaJOCNJvgzz$Z8PwMejXQfWy^ex8z!LUBoANveXaLbXC!VooWD SrBqN_oRONMv^iOHEiV8R6&DEr delta 12 TcmccbKEZ86spw`GvDv%;BzSHjuZyz4iw=exrQ6xccWzo_)&*;3V;gg3+Z zCnm4wi`cwLyagn10VuhC^L^=h2q&Ajdh&i*x5@EZf}6Dz{%}lIQ*@ndrR4(v!|XJk diff --git a/drivers/SmartThings/zigbee-button/src/test/test_somfy_situo_1_button.lua b/drivers/SmartThings/zigbee-button/src/test/test_somfy_situo_1_button.lua index a2e50a9bab..03d26ba1b3 100644 --- a/drivers/SmartThings/zigbee-button/src/test/test_somfy_situo_1_button.lua +++ b/drivers/SmartThings/zigbee-button/src/test/test_somfy_situo_1_button.lua @@ -54,14 +54,23 @@ test.register_coroutine_test( test.socket.capability:__expect_send( mock_device:generate_test_message("button1", (button_attr.pushed({ state_change = true }))) ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) test.socket.zigbee:__queue_receive({ mock_device.id, WindowCovering.server.commands.DownOrClose.build_test_rx(mock_device) }) test.socket.capability:__expect_send( mock_device:generate_test_message("button3", (button_attr.pushed({ state_change = true }))) ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) test.socket.zigbee:__queue_receive({ mock_device.id, WindowCovering.server.commands.Stop.build_test_rx(mock_device) }) test.socket.capability:__expect_send( mock_device:generate_test_message("button2", (button_attr.pushed({ state_change = true }))) ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) end ) @@ -116,7 +125,7 @@ test.register_coroutine_test( test.register_coroutine_test( "ZDO Message handler and adding hub to group", function() - local binding_table = mgmt_bind_response.BindingTableListRecord("j����^��", 0x01, 0x0006, 0x01, 0xB9F2) + local binding_table = mgmt_bind_response.BindingTableListRecord("\x6A\x9D\xC0\xFE\xFF\x5E\xCF\xD0", 0x01, 0x0006, 0x01, 0xB9F2) local response = mgmt_bind_response.MgmtBindResponse({ status = 0x00, total_binding_table_entry_count = 0x01, @@ -170,6 +179,13 @@ test.register_coroutine_test( }) end end + test.socket.capability:__expect_send({ + mock_device.id, + { + capability_id = "button", component_id = "main", + attribute_id = "button", state = { value = "pushed" } + } + }) test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) test.wait_for_events() diff --git a/drivers/SmartThings/zigbee-button/src/test/test_somfy_situo_4_button.lua b/drivers/SmartThings/zigbee-button/src/test/test_somfy_situo_4_button.lua index 93a95800bfe77a4f2796d79ec54359f887f50d6d..74cc9967068c59ed1456b3f82f252917c3e65490 100644 GIT binary patch delta 110 zcmcZ|a42X4v!X&wg_&bag{4bOg|k6Sg_|o7yTw$P0%>O;?P9Q*TX7%TWC1bF$rqFh zO_EAWO7ioRbQFq95=&AQY!#{%$`W%*K`f<$(&CKN6eWdPE(I`v(6ySAPpD4@01>Gp AOaK4? delta 25 hcmX>UbUR=Jvm!^<+ynpq$DO~hSy^!(+vE)zlK`b}43z)? diff --git a/drivers/SmartThings/zigbee-button/src/test/test_zigbee_button.lua b/drivers/SmartThings/zigbee-button/src/test/test_zigbee_button.lua index d595abf6e9..7e10be306e 100644 --- a/drivers/SmartThings/zigbee-button/src/test/test_zigbee_button.lua +++ b/drivers/SmartThings/zigbee-button/src/test/test_zigbee_button.lua @@ -183,11 +183,11 @@ test.register_coroutine_test( } ) test.socket.capability:__expect_send({ - mock_device.id, - { - capability_id = "button", component_id = "main", - attribute_id = "button", state = { value = "pushed"} - } + mock_device.id, + { + capability_id = "button", component_id = "main", + attribute_id = "button", state = { value = "pushed" } + } }) test.wait_for_events() diff --git a/drivers/SmartThings/zigbee-button/src/test/test_zigbee_ecosmart_button.lua b/drivers/SmartThings/zigbee-button/src/test/test_zigbee_ecosmart_button.lua index 438dcc5b2e..eeec8a341d 100644 --- a/drivers/SmartThings/zigbee-button/src/test/test_zigbee_ecosmart_button.lua +++ b/drivers/SmartThings/zigbee-button/src/test/test_zigbee_ecosmart_button.lua @@ -4,7 +4,7 @@ -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- --- http://www.apache.org/licenses/LICENSE-2.0 +-- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, @@ -26,18 +26,18 @@ local PowerConfiguration = clusters.PowerConfiguration local button_attr = capabilities.button.button local mock_device = test.mock_device.build_test_zigbee_device( - { - profile = t_utils.get_profile_definition("four-buttons-battery.yml"), - zigbee_endpoints = { - [1] = { - id = 1, - manufacturer = "LDS", - model = "ZBT-CCTSwitch-D0001", - server_clusters = {0x0001}, - client_clusters = {0x0006, 0x0008, 0x0300} - } - } + { + profile = t_utils.get_profile_definition("four-buttons-battery.yml"), + zigbee_endpoints = { + [1] = { + id = 1, + manufacturer = "LDS", + model = "ZBT-CCTSwitch-D0001", + server_clusters = {0x0001}, + client_clusters = {0x0006, 0x0008, 0x0300} } + } + } ) zigbee_test_utils.prepare_zigbee_env_info() @@ -49,189 +49,222 @@ end test.set_test_init_function(test_init) test.register_message_test( - "Battery percentage report should be handled", + "Battery percentage report should be handled", + { { - { - channel = "zigbee", - direction = "receive", - message = { mock_device.id, PowerConfiguration.attributes.BatteryPercentageRemaining:build_test_attr_report(mock_device, 55) } - }, - { - channel = "capability", - direction = "send", - message = mock_device:generate_test_message("main", capabilities.battery.battery(28)) - } + channel = "zigbee", + direction = "receive", + message = { mock_device.id, PowerConfiguration.attributes.BatteryPercentageRemaining:build_test_attr_report(mock_device, 55) } + }, + { + channel = "capability", + direction = "send", + message = mock_device:generate_test_message("main", capabilities.battery.battery(28)) } + } ) test.register_coroutine_test( - "added lifecycle event", - function() - test.socket.capability:__set_channel_ordering("relaxed") - test.socket.capability:__expect_send( - { - mock_device.id, - { - capability_id = "button", component_id = "main", - attribute_id = "supportedButtonValues", state = { value = { "pushed" } } - } - } - ) - test.socket.capability:__expect_send( - { - mock_device.id, - { - capability_id = "button", component_id = "main", - attribute_id = "numberOfButtons", state = { value = 4 } - } - } - ) - for button_number = 1, 4 do - test.socket.capability:__expect_send( - { - mock_device.id, - { - capability_id = "button", component_id = "button" .. button_number, - attribute_id = "supportedButtonValues", state = { value = { "pushed" } } - } - } - ) - test.socket.capability:__expect_send( - { - mock_device.id, - { - capability_id = "button", component_id = "button" .. button_number, - attribute_id = "numberOfButtons", state = { value = 1 } - } - } - ) - end - - test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) - test.wait_for_events() + "added lifecycle event", + function() + test.socket.capability:__set_channel_ordering("relaxed") + test.socket.capability:__expect_send( + { + mock_device.id, + { + capability_id = "button", component_id = "main", + attribute_id = "supportedButtonValues", state = { value = { "pushed" } } + } + } + ) + test.socket.capability:__expect_send( + { + mock_device.id, + { + capability_id = "button", component_id = "main", + attribute_id = "numberOfButtons", state = { value = 4 } + } + } + ) + for button_number = 1, 4 do + test.socket.capability:__expect_send( + { + mock_device.id, + { + capability_id = "button", component_id = "button" .. button_number, + attribute_id = "supportedButtonValues", state = { value = { "pushed" } } + } + } + ) + test.socket.capability:__expect_send( + { + mock_device.id, + { + capability_id = "button", component_id = "button" .. button_number, + attribute_id = "numberOfButtons", state = { value = 1 } + } + } + ) end + test.socket.capability:__expect_send({ + mock_device.id, + { + capability_id = "button", component_id = "main", + attribute_id = "button", state = { value = "pushed" } + } + }) + + test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) + test.wait_for_events() + end ) test.register_coroutine_test( - "button 1 handler", - function() - test.wait_for_events() - - test.socket.zigbee:__queue_receive({ mock_device.id, OnOff.server.commands.Off.build_test_rx(mock_device) }) - test.socket.capability:__expect_send( - mock_device:generate_test_message("button1", button_attr.pushed({ state_change = true })) - ) - test.socket.zigbee:__queue_receive({ mock_device.id, OnOff.server.commands.On.build_test_rx(mock_device) }) - test.socket.capability:__expect_send( - mock_device:generate_test_message("button1", button_attr.pushed({ state_change = true })) - ) - end + "button 1 handler", + function() + test.wait_for_events() + + test.socket.zigbee:__queue_receive({ mock_device.id, OnOff.server.commands.Off.build_test_rx(mock_device) }) + test.socket.capability:__expect_send( + mock_device:generate_test_message("button1", button_attr.pushed({ state_change = true })) + ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) + test.socket.zigbee:__queue_receive({ mock_device.id, OnOff.server.commands.On.build_test_rx(mock_device) }) + test.socket.capability:__expect_send( + mock_device:generate_test_message("button1", button_attr.pushed({ state_change = true })) + ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) + end ) test.register_coroutine_test( - "button 2 handler", - function() - test.wait_for_events() - + "button 2 handler", + function() + test.wait_for_events() - test.socket.zigbee:__queue_receive({ mock_device.id, Level.server.commands.Move.build_test_rx(mock_device, 0x00, 0x00) }) - test.socket.capability:__expect_send( - mock_device:generate_test_message("button2", button_attr.pushed({ state_change = true })) - ) - end + test.socket.zigbee:__queue_receive({ mock_device.id, Level.server.commands.Move.build_test_rx(mock_device, 0x00, 0x00) }) + test.socket.capability:__expect_send( + mock_device:generate_test_message("button2", button_attr.pushed({ state_change = true })) + ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) + end ) test.register_coroutine_test( - "button 3 handler", - function() - test.wait_for_events() - - test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveToColorTemperature.build_test_rx(mock_device, 0x00, 0x00) }) - test.socket.capability:__expect_send( - mock_device:generate_test_message("button3", button_attr.pushed({ state_change = true })) - ) - - test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveColorTemperature.build_test_rx(mock_device, 0x01, 0x0055, 0x0099, 0x0172, 0x00, 0x00) }) - test.socket.capability:__expect_send( - mock_device:generate_test_message("button3", button_attr.pushed({ state_change = true })) - ) - end + "button 3 handler", + function() + test.wait_for_events() + + test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveToColorTemperature.build_test_rx(mock_device, 0x00, 0x00) }) + test.socket.capability:__expect_send( + mock_device:generate_test_message("button3", button_attr.pushed({ state_change = true })) + ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) + + test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveColorTemperature.build_test_rx(mock_device, 0x01, 0x0055, 0x0099, 0x0172, 0x00, 0x00) }) + test.socket.capability:__expect_send( + mock_device:generate_test_message("button3", button_attr.pushed({ state_change = true })) + ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) + end ) test.register_coroutine_test( - "button 4 handler", - function() - test.wait_for_events() - - test.socket.zigbee:__queue_receive({ mock_device.id, Level.server.commands.MoveToLevelWithOnOff.build_test_rx(mock_device, 0x00, 0x00) }) - test.socket.capability:__expect_send( - mock_device:generate_test_message("button4", button_attr.pushed({ state_change = true })) - ) - -- Ignore this event - test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveToColorTemperature.build_test_rx(mock_device, 0x00, 0x00) }) - -- Should handle - test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveToColorTemperature.build_test_rx(mock_device, 0x00, 0x00) }) - test.socket.capability:__expect_send( - mock_device:generate_test_message("button3", button_attr.pushed({ state_change = true })) - ) - test.socket.zigbee:__queue_receive({ mock_device.id, Level.server.commands.MoveToLevelWithOnOff.build_test_rx(mock_device, 0x00, 0x00) }) - test.socket.capability:__expect_send( - mock_device:generate_test_message("button4", button_attr.pushed({ state_change = true })) - ) - -- Ignore this event - test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveToColorTemperature.build_test_rx(mock_device, 0x00, 0x00) }) - -- Should handle - test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveColorTemperature.build_test_rx(mock_device, 0x00, 0x01) }) - test.socket.capability:__expect_send( - mock_device:generate_test_message("button3", button_attr.pushed({ state_change = true })) - ) - end + "button 4 handler", + function() + test.wait_for_events() + + test.socket.zigbee:__queue_receive({ mock_device.id, Level.server.commands.MoveToLevelWithOnOff.build_test_rx(mock_device, 0x00, 0x00) }) + test.socket.capability:__expect_send( + mock_device:generate_test_message("button4", button_attr.pushed({ state_change = true })) + ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) + -- Ignore this event + test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveToColorTemperature.build_test_rx(mock_device, 0x00, 0x00) }) + -- Should handle + test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveToColorTemperature.build_test_rx(mock_device, 0x00, 0x00) }) + test.socket.capability:__expect_send( + mock_device:generate_test_message("button3", button_attr.pushed({ state_change = true })) + ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) + test.socket.zigbee:__queue_receive({ mock_device.id, Level.server.commands.MoveToLevelWithOnOff.build_test_rx(mock_device, 0x00, 0x00) }) + test.socket.capability:__expect_send( + mock_device:generate_test_message("button4", button_attr.pushed({ state_change = true })) + ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) + -- Ignore this event + test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveToColorTemperature.build_test_rx(mock_device, 0x00, 0x00) }) + -- Should handle + test.socket.zigbee:__queue_receive({ mock_device.id, ColorControl.server.commands.MoveColorTemperature.build_test_rx(mock_device, 0x00, 0x01) }) + test.socket.capability:__expect_send( + mock_device:generate_test_message("button3", button_attr.pushed({ state_change = true })) + ) + test.socket.capability:__expect_send( + mock_device:generate_test_message("main", button_attr.pushed({ state_change = true })) + ) + end ) test.register_coroutine_test( - "Configure should configure all necessary attributes", - function() - test.wait_for_events() - - test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" }) - test.socket.zigbee:__set_channel_ordering("relaxed") - - test.socket.zigbee:__expect_send( - { - mock_device.id, - PowerConfiguration.attributes.BatteryPercentageRemaining:read(mock_device) - } - ) - - test.socket.zigbee:__expect_send( - { - mock_device.id, - zigbee_test_utils.build_bind_request(mock_device, - zigbee_test_utils.mock_hub_eui, - PowerConfiguration.ID) - } - ) - test.socket.zigbee:__expect_send( - { - mock_device.id, - PowerConfiguration.attributes.BatteryPercentageRemaining:configure_reporting(mock_device, - 30, - 21600, - 1) - } - ) - test.socket.zigbee:__expect_send( - { - mock_device.id, - zigbee_test_utils.build_bind_request(mock_device, - zigbee_test_utils.mock_hub_eui, - OnOff.ID) - } - ) - test.socket.zigbee:__expect_add_hub_to_group(0x4003) - - mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" }) - end + "Configure should configure all necessary attributes", + function() + test.wait_for_events() + + test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" }) + test.socket.zigbee:__set_channel_ordering("relaxed") + + test.socket.zigbee:__expect_send( + { + mock_device.id, + PowerConfiguration.attributes.BatteryPercentageRemaining:read(mock_device) + } + ) + + test.socket.zigbee:__expect_send( + { + mock_device.id, + zigbee_test_utils.build_bind_request(mock_device, + zigbee_test_utils.mock_hub_eui, + PowerConfiguration.ID) + } + ) + test.socket.zigbee:__expect_send( + { + mock_device.id, + PowerConfiguration.attributes.BatteryPercentageRemaining:configure_reporting(mock_device, + 30, + 21600, + 1) + } + ) + test.socket.zigbee:__expect_send( + { + mock_device.id, + zigbee_test_utils.build_bind_request(mock_device, + zigbee_test_utils.mock_hub_eui, + OnOff.ID) + } + ) + test.socket.zigbee:__expect_add_hub_to_group(0x4003) + + mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + end ) test.run_registered_tests() diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/adurosmart/init.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/adurosmart/init.lua index 3598cecd90..5f06250c13 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/adurosmart/init.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/adurosmart/init.lua @@ -16,6 +16,7 @@ local capabilities = require "st.capabilities" local clusters = require "st.zigbee.zcl.clusters" local device_management = require "st.zigbee.device_management" local log = require "log" +local button_utils = require "button_utils" local OnOff = clusters.OnOff local Level = clusters.Level @@ -34,9 +35,9 @@ local ADURO_BUTTON_FINGERPRINTS = { local is_aduro_button = function(opts, driver, device) for _, fingerprint in ipairs(ADURO_BUTTON_FINGERPRINTS) do - if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then - return true - end + if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then + return true + end end return false end @@ -50,21 +51,6 @@ local do_configuration = function(self, device) device:send(OnOff.attributes.OnOff:configure_reporting(device, 0, 600, 1)) end -local function aduro_on_off_attr_handler(button_name, pressed_type) - return function(driver, device, zb_rx) - local additional_fields = { - state_change = true - } - local event = pressed_type(additional_fields) - local comp = device.profile.components[button_name] - if comp ~= nil then - device:emit_component_event(comp, event) - else - log.warn("Attempted to emit button event for unknown button: " .. button_name) - end - end -end - local aduro_mfg_cluster_handler = function(driver, device, zb_rx) local additional_fields = { state_change = true @@ -76,6 +62,7 @@ local aduro_mfg_cluster_handler = function(driver, device, zb_rx) local comp = device.profile.components[button_name] if comp ~= nil then device:emit_component_event(comp, event) + device:emit_event(event) else log.warn("Attempted to emit button event for unknown button: " .. button_name) end @@ -89,8 +76,8 @@ local aduro_device_handler = { zigbee_handlers = { cluster = { [OnOff.ID] = { - [OnOff.server.commands.Off.ID] = aduro_on_off_attr_handler("button4", capabilities.button.button.pushed), - [OnOff.server.commands.On.ID] = aduro_on_off_attr_handler("button1", capabilities.button.button.pushed) + [OnOff.server.commands.Off.ID] = button_utils.build_button_handler("button4", capabilities.button.button.pushed), + [OnOff.server.commands.On.ID] = button_utils.build_button_handler("button1", capabilities.button.button.pushed) }, [ADURO_MANUFACTURER_SPECIFIC_CLUSTER] = { [ADURO_MANUFACTURER_SPECIFIC_CMD] = aduro_mfg_cluster_handler diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/centralite/init.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/centralite/init.lua index 42b47c875e..273670314a 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/centralite/init.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/centralite/init.lua @@ -42,9 +42,9 @@ local CENTRALITE_BUTTON_FINGERPRINTS = { local is_centralite_button = function(opts, driver, device) for _, fingerprint in ipairs(CENTRALITE_BUTTON_FINGERPRINTS) do - if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then - return true - end + if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then + return true + end end return false end diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ecosmart/init.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ecosmart/init.lua index 74a3a7ef78..8f7d4ec6d8 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ecosmart/init.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ecosmart/init.lua @@ -62,6 +62,7 @@ local emit_pushed_event = function(button_name, device) local comp = device.profile.components[button_name] if comp ~= nil then device:emit_component_event(comp, event) + device:emit_event(event) else log.warn("Attempted to emit button event for unknown button: " .. button_name) end diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/heiman/init.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/heiman/init.lua index 5f1ebd4079..14e1322c5e 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/heiman/init.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/heiman/init.lua @@ -67,6 +67,7 @@ local function scenes_cluster_handler(driver, device, zb_rx) local comp = device.profile.components[button_name] if comp ~= nil then device:emit_component_event(comp, event) + device:emit_event(event) else log.warn("Attempted to emit button event for unknown button: " .. button_name) end diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_on_off_switch.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_on_off_switch.lua index 7bf8531174..3a4ee4b54d 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_on_off_switch.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_on_off_switch.lua @@ -15,37 +15,23 @@ local capabilities = require "st.capabilities" local clusters = require "st.zigbee.zcl.clusters" local log = require "log" +local button_utils = require "button_utils" local Level = clusters.Level local OnOff = clusters.OnOff local PowerConfiguration = clusters.PowerConfiguration -local function build_button_handler(button_name, pressed_type) - return function(driver, device, zb_rx) - local additional_fields = { - state_change = true - } - local event = pressed_type(additional_fields) - local comp = device.profile.components[button_name] - if comp ~= nil then - device:emit_component_event(comp, event) - else - log.warn("Attempted to emit button event for unknown button: " .. button_name) - end - end -end - local on_off_switch = { NAME = "On/Off Switch", zigbee_handlers = { cluster = { [OnOff.ID] = { - [OnOff.server.commands.Off.ID] = build_button_handler("button1", capabilities.button.button.pushed), - [OnOff.server.commands.On.ID] = build_button_handler("button2", capabilities.button.button.pushed) + [OnOff.server.commands.Off.ID] = button_utils.build_button_handler("button1", capabilities.button.button.pushed), + [OnOff.server.commands.On.ID] = button_utils.build_button_handler("button2", capabilities.button.button.pushed) }, [Level.ID] = { - [Level.server.commands.Move.ID] = build_button_handler("button1", capabilities.button.button.held), - [Level.server.commands.MoveWithOnOff.ID] = build_button_handler("button2", capabilities.button.button.held) + [Level.server.commands.Move.ID] = button_utils.build_button_handler("button1", capabilities.button.button.held), + [Level.server.commands.MoveWithOnOff.ID] = button_utils.build_button_handler("button2", capabilities.button.button.held) }, } }, diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_open_close_remote.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_open_close_remote.lua index 0057467c7c..a816a5390f 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_open_close_remote.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_open_close_remote.lua @@ -15,31 +15,17 @@ local capabilities = require "st.capabilities" local clusters = require "st.zigbee.zcl.clusters" local log = require "log" +local button_utils = require "button_utils" local WindowCovering = clusters.WindowCovering -local function build_button_handler(button_name, pressed_type) - return function(driver, device, zb_rx) - local additional_fields = { - state_change = true - } - local event = pressed_type(additional_fields) - local comp = device.profile.components[button_name] - if comp ~= nil then - device:emit_component_event(comp, event) - else - log.warn("Attempted to emit button event for unknown button: " .. button_name) - end - end -end - local open_close_remote = { NAME = "Open/Close Remote", zigbee_handlers = { cluster = { [WindowCovering.ID] = { - [WindowCovering.server.commands.UpOrOpen.ID] = build_button_handler("button1", capabilities.button.button.pushed), - [WindowCovering.server.commands.DownOrClose.ID] = build_button_handler("button2", capabilities.button.button.pushed) + [WindowCovering.server.commands.UpOrOpen.ID] = button_utils.build_button_handler("button1", capabilities.button.button.pushed), + [WindowCovering.server.commands.DownOrClose.ID] = button_utils.build_button_handler("button2", capabilities.button.button.pushed) } } }, diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_remote_control.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_remote_control.lua index 2c4086343f..68dd7a68f1 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_remote_control.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_remote_control.lua @@ -15,27 +15,13 @@ local capabilities = require "st.capabilities" local clusters = require "st.zigbee.zcl.clusters" local log = require "log" +local button_utils = require "button_utils" local Level = clusters.Level local OnOff = clusters.OnOff local Scenes = clusters.Scenes local PowerConfiguration = clusters.PowerConfiguration -local function build_button_handler(button_name, pressed_type) - return function(driver, device, zb_rx) - local additional_fields = { - state_change = true - } - local event = pressed_type(additional_fields) - local comp = device.profile.components[button_name] - if comp ~= nil then - device:emit_component_event(comp, event) - else - log.warn("Attempted to emit button event for unknown button: " .. button_name) - end - end -end - local function build_button_payload_handler(pressed_type) return function(driver, device, zb_rx) local additional_fields = { @@ -49,6 +35,9 @@ local function build_button_payload_handler(pressed_type) local comp = device.profile.components[button_name] if comp ~= nil then device:emit_component_event(comp, event) + if button_name ~= "main" then + device:emit_event(event) + end else log.warn("Attempted to emit button event for unknown button: " .. button_name) end @@ -69,6 +58,7 @@ local function added_handler(self, device) end end device:send(PowerConfiguration.attributes.BatteryVoltage:read(device)) + device:emit_event(capabilities.button.button.pushed({state_change = false})) end local remote_control = { @@ -76,13 +66,13 @@ local remote_control = { zigbee_handlers = { cluster = { [OnOff.ID] = { - [OnOff.server.commands.Toggle.ID] = build_button_handler("button5", capabilities.button.button.pushed) + [OnOff.server.commands.Toggle.ID] = button_utils.build_button_handler("button5", capabilities.button.button.pushed) }, [Level.ID] = { - [Level.server.commands.Move.ID] = build_button_handler("button3", capabilities.button.button.held), - [Level.server.commands.Step.ID] = build_button_handler("button3", capabilities.button.button.pushed), - [Level.server.commands.MoveWithOnOff.ID] = build_button_handler("button1", capabilities.button.button.held), - [Level.server.commands.StepWithOnOff.ID] = build_button_handler("button1", capabilities.button.button.pushed) + [Level.server.commands.Move.ID] = button_utils.build_button_handler("button3", capabilities.button.button.held), + [Level.server.commands.Step.ID] = button_utils.build_button_handler("button3", capabilities.button.button.pushed), + [Level.server.commands.MoveWithOnOff.ID] = button_utils.build_button_handler("button1", capabilities.button.button.held), + [Level.server.commands.StepWithOnOff.ID] = button_utils.build_button_handler("button1", capabilities.button.button.pushed) }, -- Manufacturer command id used in ikea [Scenes.ID] = { diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/init.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/init.lua index d18aa7485c..50c1c8a93b 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/init.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/init.lua @@ -62,6 +62,7 @@ local function added_handler(self, device) device:emit_component_event(component, capabilities.button.numberOfButtons({value = number_of_buttons})) end device:send(PowerConfiguration.attributes.BatteryPercentageRemaining:read(device)) + device:emit_event(capabilities.button.button.pushed({state_change = false})) end local function zdo_binding_table_handler(driver, device, zb_rx) diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/init.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/init.lua index c22198afc3..db68472d04 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/init.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/init.lua @@ -57,6 +57,7 @@ local function added_handler(self, device) end device:emit_component_event(component, capabilities.button.numberOfButtons({value = number_of_buttons})) end + device:emit_event(capabilities.button.button.pushed({state_change = false})) end local zigbee_multi_button = { diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/shinasystems/init.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/shinasystems/init.lua index 8752f73e8c..37511e5521 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/shinasystems/init.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/shinasystems/init.lua @@ -56,6 +56,9 @@ local function build_button_handler(pressed_type) button_comp = "main" end device:emit_component_event(device.profile.components[button_comp], event) + if button_comp ~= "main" then + device:emit_event(event) + end end end diff --git a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/somfy/somfy_situo_1.lua b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/somfy/somfy_situo_1.lua index 6150a77219..840e0f92a9 100644 --- a/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/somfy/somfy_situo_1.lua +++ b/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/somfy/somfy_situo_1.lua @@ -21,25 +21,10 @@ local mgmt_bind_resp = require "st.zigbee.zdo.mgmt_bind_response" local mgmt_bind_req = require "st.zigbee.zdo.mgmt_bind_request" local log = require "log" local zdo_messages = require "st.zigbee.zdo" +local button_utils = require "button_utils" local PowerConfiguration = clusters.PowerConfiguration local WindowCovering = clusters.WindowCovering - -local function build_button_handler(button_name, pressed_type) - return function(driver, device, zb_rx) - local additional_fields = { - state_change = true - } - local event = pressed_type(additional_fields) - local comp = device.profile.components[button_name] - if comp ~= nil then - device:emit_component_event(comp, event) - else - log.warn("Attempted to emit button event for unknown button: " .. button_name) - end - end -end - local do_configure = function(self, device) device:send(device_management.build_bind_request(device, PowerConfiguration.ID, self.environment_info.hub_zigbee_eui)) device:send(device_management.build_bind_request(device, WindowCovering.ID, self.environment_info.hub_zigbee_eui)) @@ -73,9 +58,9 @@ local somfy_handler = { zigbee_handlers = { cluster = { [WindowCovering.ID] = { - [WindowCovering.server.commands.UpOrOpen.ID] = build_button_handler("button1", capabilities.button.button.pushed), - [WindowCovering.server.commands.DownOrClose.ID] = build_button_handler("button3", capabilities.button.button.pushed), - [WindowCovering.server.commands.Stop.ID] = build_button_handler("button2", capabilities.button.button.pushed) + [WindowCovering.server.commands.UpOrOpen.ID] = button_utils.build_button_handler("button1", capabilities.button.button.pushed), + [WindowCovering.server.commands.DownOrClose.ID] = button_utils.build_button_handler("button3", capabilities.button.button.pushed), + [WindowCovering.server.commands.Stop.ID] = button_utils.build_button_handler("button2", capabilities.button.button.pushed) } } },