Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to add a Zigbee button for SLED switch #1021

Merged
merged 18 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions drivers/SmartThings/zigbee-button/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ zigbeeManufacturer:
manufacturer: Third Reality, Inc
model: 3RSB22BZ
deviceProfileName: one-button-battery
- id: Samsung/SAMSUNG-ITM-Z-005
deviceLabel: ITM Switch
manufacturer: Samsung Electronics
model: SAMSUNG-ITM-Z-005
deviceProfileName: SLED-three-buttons
# # Wall Hero
- id: "WALL HERO/ACL-401SCA4"
deviceLabel: 语音场景(4寸)面板
Expand Down
28 changes: 28 additions & 0 deletions drivers/SmartThings/zigbee-button/profiles/SLED-three-buttons.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: SLED-three-buttons
components:
- id: main
capabilities:
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: RemoteController
- 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
-- Copyright 2023 SmartThings
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- 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
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

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 Level = clusters.Level
local OnOff = clusters.OnOff
local ColorControl = clusters.ColorControl

local emit_pushed_event = function(button_name, device)
local additional_fields = {
state_change = true
}
local event = capabilities.button.button.pushed(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


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is extra whitespace as well that needs to be removed, please review.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra line

local emit_held_event = function(button_name, device)
local additional_fields = {
state_change = true
}
local event = capabilities.button.button.held(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

local do_configure = function(self, device)
do_refresh(self, device)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as pointed out by the luacheck automation, do_refresh is not defined

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lua code has been changed.

device:send(device_management.build_bind_request(device, OnOff.ID, self.environment_info.hub_zigbee_eui))
-- The device reports button presses to this group but it can't be read from the binding table
end

local SLED_button = {
NAME = "SLED Button",
capability_handlers = {
[capabilities.refresh.ID] = {
[capabilities.refresh.commands.refresh.NAME] = do_refresh,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are also referencing do_refresh here

Checking drivers/SmartThings/zigbee-button/src/zigbee-multi-button/SLED/init.lua 3 warnings

    drivers/SmartThings/zigbee-button/src/zigbee-multi-button/SLED/init.lua:30:45: (W612) line contains trailing whitespace
    drivers/SmartThings/zigbee-button/src/zigbee-multi-button/SLED/init.lua:44:45: (W612) line contains trailing whitespace
    drivers/SmartThings/zigbee-button/src/zigbee-multi-button/SLED/init.lua:59:54: (W113) accessing undefined variable do_refresh

Please address these comments. Please write some tests for this behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code was modified and there were no errors through lua check.

}
},
zigbee_handlers = {
cluster = {
[OnOff.ID] = {
[OnOff.server.commands.Off.ID] = function(driver, device, zb_rx) emit_pushed_event("button2", device) end,
[OnOff.server.commands.On.ID] = function(driver, device, zb_rx) emit_pushed_event("button1", device) end,
[OnOff.server.commands.Toggle.ID] = function(driver, device, zb_rx) emit_pushed_event("button3", device) end
},
[Level.ID] = {
[Level.server.commands.Move.ID] = function(driver, device, zb_rx) emit_held_event("button2", device) end,
[Level.server.commands.MoveWithOnOff.ID] = function(driver, device, zb_rx) emit_held_event("button1", device) end
},
[ColorControl.ID] = {
[ColorControl.server.commands.MoveToColorTemperature.ID] = function(driver, device, zb_rx) emit_held_event("button3", device) end
}
}
},
lifecycle_handlers = {
doConfigure = do_configure
},
can_handle = function(opts, driver, device, ...)
return device:get_manufacturer() == "Samsung Electronics" and device:get_model() == "SAMSUNG-ITM-Z-005"
end
}

return SLED_button
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ local ZIGBEE_MULTI_BUTTON_FINGERPRINTS = {
{ mfr = "ShinaSystem", model = "SBM300ZB3" },
{ mfr = "ROBB smarrt", model = "ROB_200-007-0" },
{ mfr = "ROBB smarrt", model = "ROB_200-008-0" },
{ mfr = "WALL HERO", model = "ACL-401SCA4" }
{ mfr = "WALL HERO", model = "ACL-401SCA4" },
{ mfr = "Samsung Electronics", model = "SAMSUNG-ITM-Z-005" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ mfr = "Samsung Electronics", model = "SAMSUNG-ITM-Z-005" },
{ mfr = "Samsung Electronics", model = "SAMSUNG-ITM-Z-005" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you delete and change the comma in the code, it will not be saved and it will be shown to request a creat pull request patch.
Please check it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comma.

}

local function can_handle_zigbee_multi_button(opts, driver, device, ...)
Expand Down Expand Up @@ -86,6 +87,7 @@ local zigbee_multi_button = {
require("zigbee-multi-button.shinasystems"),
require("zigbee-multi-button.robb"),
require("zigbee-multi-button.wallhero"),
require("zigbee-multi-button.SLED")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ local devices = {
{ mfr = "CentraLite", model = "3450-L" },
{ mfr = "CentraLite", model = "3450-L2" },
{ mfr = "ROBB smarrt", model = "ROB_200-008-0" }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please remove this extra line that is empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra line.

},
SUPPORTED_BUTTON_VALUES = { "pushed", "held" },
NUMBER_OF_BUTTONS = 4
Expand Down Expand Up @@ -52,6 +53,13 @@ local devices = {
SUPPORTED_BUTTON_VALUES = { "pushed" },
NUMBER_OF_BUTTONS = 3
},
BUTTON_PUSH_HELD_3 = {
MATCHING_MATRIX = {
{ mfr = "Samsung Electronics", model = "SAMSUNG-ITM-Z-005" },
},
SUPPORTED_BUTTON_VALUES = { "pushed", "held" },
NUMBER_OF_BUTTONS = 3
},
BUTTON_PUSH_4 = {
MATCHING_MATRIX = {
{ mfr = "LDS", model = "ZBT-CCTSwitch-D0001" },
Expand Down