-
Notifications
You must be signed in to change notification settings - Fork 534
WWSTCERT-10701 Add Sonoff SNZB-01M Smart Scene Button into zigbee-button. #2510
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
Open
Oniums
wants to merge
15
commits into
SmartThingsCommunity:main
Choose a base branch
from
Oniums:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1329c3f
Add Sonoff SNZB-01M Smart Scene Button into zigbee-button.
Oniums f1e199d
modify Copyright Date
Oniums c0ae8b7
modify test_sonoff.py fix PR error
Oniums df3c547
Update copyright year from 2022 to 2026,remove remove whitespace-only…
Oniums bce843b
remove log.info
Oniums e929ca4
Use defaults for Sonoff battery and added lifecycle
Oniums 9aeec23
remove log
Oniums 61d1077
Fix Sonoff multi-button sub-driver registration and test execution
Oniums d487ce0
update copyright sections for sonoff multi-button
Oniums 21d7877
Merge branch 'SmartThingsCommunity:main' into main
Oniums f465c2f
fix: address review feedback for Sonoff SNZB-01M button support
Oniums 70dd9ec
fix: resolve Sonoff SNZB-01M unit test failures
Oniums 14c276c
Merge branch 'SmartThingsCommunity:main' into main
Oniums e025d91
Merge branch 'main' into main
Oniums 51656f3
Merge branch 'main' into main
Oniums File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
278 changes: 278 additions & 0 deletions
278
drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,278 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local test = require "integration_test" | ||
| local clusters = require "st.zigbee.zcl.clusters" | ||
| local capabilities = require "st.capabilities" | ||
| local t_utils = require "integration_test.utils" | ||
| local zigbee_test_utils = require "integration_test.zigbee_test_utils" | ||
| local zb_const = require "st.zigbee.constants" | ||
| local messages = require "st.zigbee.messages" | ||
| local data_types = require "st.zigbee.data_types" | ||
| local zcl_messages = require "st.zigbee.zcl" | ||
| local report_attr = require "st.zigbee.zcl.global_commands.report_attribute" | ||
|
|
||
| local SONOFF_PRIVATE_BUTTON_CLUSTER = 0xFC12 | ||
| local SONOFF_PRIVATE_ATTR = 0x0000 | ||
|
|
||
| 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 = "SONOFF", | ||
| model = "SNZB-01M", | ||
| server_clusters = { 0x0001, 0xFC12 } | ||
| }, | ||
| [2] = { | ||
| id = 2, | ||
| manufacturer = "SONOFF", | ||
| model = "SNZB-01M", | ||
| server_clusters = { 0x0001, 0xFC12 } | ||
| }, | ||
| [3] = { | ||
| id = 3, | ||
| manufacturer = "SONOFF", | ||
| model = "SNZB-01M", | ||
| server_clusters = { 0x0001, 0xFC12 } | ||
| }, | ||
| [4] = { | ||
| id = 4, | ||
| manufacturer = "SONOFF", | ||
| model = "SNZB-01M", | ||
| server_clusters = { 0x0001, 0xFC12 } | ||
| } | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| zigbee_test_utils.prepare_zigbee_env_info() | ||
|
|
||
| local function build_test_attr_report(device, endpoint, value) | ||
| local report_body = report_attr.ReportAttribute({ | ||
| report_attr.ReportAttributeAttributeRecord(SONOFF_PRIVATE_ATTR, data_types.Uint8.ID, value) | ||
| }) | ||
| local zclh = zcl_messages.ZclHeader({ | ||
| cmd = data_types.ZCLCommandId(report_body.ID) | ||
| }) | ||
| local addrh = messages.AddressHeader( | ||
| device:get_short_address(), | ||
| endpoint, | ||
| zb_const.HUB.ADDR, | ||
| zb_const.HUB.ENDPOINT, | ||
| zb_const.HA_PROFILE_ID, | ||
| SONOFF_PRIVATE_BUTTON_CLUSTER | ||
| ) | ||
| local message_body = zcl_messages.ZclMessageBody({ | ||
| zcl_header = zclh, | ||
| zcl_body = report_body | ||
| }) | ||
|
|
||
| return messages.ZigbeeMessageRx({ | ||
| address_header = addrh, | ||
| body = message_body | ||
| }) | ||
| end | ||
|
|
||
| local function test_init() | ||
| test.mock_device.add_test_device(mock_device) | ||
| end | ||
|
|
||
| test.set_test_init_function(test_init) | ||
|
|
||
| test.register_coroutine_test( | ||
| "added lifecycle event", | ||
| function() | ||
| test.socket.capability:__set_channel_ordering("relaxed") | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "main", | ||
| capabilities.button.supportedButtonValues({ "pushed", "double", "held", "pushed_3x" }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "main", | ||
| capabilities.button.numberOfButtons({ value = 4 }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
|
|
||
| -- Check initial events for button 1 | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "button1", | ||
| capabilities.button.supportedButtonValues({ "pushed", "double", "held", "pushed_3x" }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "button1", | ||
| capabilities.button.numberOfButtons({ value = 1 }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
|
|
||
| -- Check initial events for button 2 | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "button2", | ||
| capabilities.button.supportedButtonValues({ "pushed", "double", "held", "pushed_3x" }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "button2", | ||
| capabilities.button.numberOfButtons({ value = 1 }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
|
|
||
| -- Check initial events for button 3 | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "button3", | ||
| capabilities.button.supportedButtonValues({ "pushed", "double", "held", "pushed_3x" }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "button3", | ||
| capabilities.button.numberOfButtons({ value = 1 }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
|
|
||
| -- Check initial events for button 4 | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "button4", | ||
| capabilities.button.supportedButtonValues({ "pushed", "double", "held", "pushed_3x" }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "button4", | ||
| capabilities.button.numberOfButtons({ value = 1 }, { visibility = { displayed = false } }) | ||
| ) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("main", capabilities.button.button.pushed({ state_change = false })) | ||
| ) | ||
|
|
||
| test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) | ||
| test.wait_for_events() | ||
| end, | ||
| { | ||
| min_api_version = 17 | ||
| } | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Button pushed message should generate event", | ||
| function() | ||
| -- 0xFC12, 0x0000, 0x01 = pushed | ||
| local attr_report = build_test_attr_report(mock_device, 1, data_types.Uint8(0x01)) | ||
|
|
||
| test.socket.zigbee:__queue_receive({ mock_device.id, attr_report }) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("button1", capabilities.button.button.pushed({ state_change = true })) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("main", capabilities.button.button.pushed({ state_change = true })) | ||
| ) | ||
| end, | ||
| { | ||
| min_api_version = 17 | ||
| } | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Button double message should generate event", | ||
| function() | ||
| -- 0xFC12, 0x0000, 0x02 = double | ||
| local attr_report = build_test_attr_report(mock_device, 1, data_types.Uint8(0x02)) | ||
|
|
||
| test.socket.zigbee:__queue_receive({ mock_device.id, attr_report }) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("button1", capabilities.button.button.double({ state_change = true })) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("main", capabilities.button.button.double({ state_change = true })) | ||
| ) | ||
| end, | ||
| { | ||
| min_api_version = 17 | ||
| } | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Button held message should generate event", | ||
| function() | ||
| -- 0xFC12, 0x0000, 0x03 = held | ||
| local attr_report = build_test_attr_report(mock_device, 1, data_types.Uint8(0x03)) | ||
|
|
||
| test.socket.zigbee:__queue_receive({ mock_device.id, attr_report }) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("button1", capabilities.button.button.held({ state_change = true })) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("main", capabilities.button.button.held({ state_change = true })) | ||
| ) | ||
| end, | ||
| { | ||
| min_api_version = 17 | ||
| } | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Button pushed_3x message should generate event", | ||
| function() | ||
| -- 0xFC12, 0x0000, 0x04 = pushed_3x | ||
| local attr_report = build_test_attr_report(mock_device, 1, data_types.Uint8(0x04)) | ||
|
|
||
| test.socket.zigbee:__queue_receive({ mock_device.id, attr_report }) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("button1", capabilities.button.button.pushed_3x({ state_change = true })) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("main", capabilities.button.button.pushed_3x({ state_change = true })) | ||
| ) | ||
| end, | ||
| { | ||
| min_api_version = 17 | ||
| } | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Button 2 pushed message should generate event on button2 component", | ||
| function() | ||
| -- Endpoint 2 test | ||
| local attr_report = build_test_attr_report(mock_device, 2, data_types.Uint8(0x01)) | ||
|
|
||
| test.socket.zigbee:__queue_receive({ mock_device.id, attr_report }) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("button2", capabilities.button.button.pushed({ state_change = true })) | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("main", capabilities.button.button.pushed({ state_change = true })) | ||
| ) | ||
| end, | ||
| { | ||
| min_api_version = 17 | ||
| } | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Battery percentage report should generate event", | ||
| function() | ||
| local battery_report = clusters.PowerConfiguration.attributes.BatteryPercentageRemaining:build_test_attr_report(mock_device, 180) | ||
|
|
||
| test.socket.zigbee:__queue_receive({ mock_device.id, battery_report }) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message("main", capabilities.battery.battery(90)) | ||
| ) | ||
| end, | ||
| { | ||
| min_api_version = 17 | ||
| } | ||
| ) | ||
|
|
||
| test.run_registered_tests() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
drivers/SmartThings/zigbee-button/src/zigbee-multi-button/sonoff/can_handle.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local function sonoff_can_handle(opts, driver, device, ...) | ||
| local fingerprints = require("zigbee-multi-button.sonoff.fingerprints") | ||
|
|
||
| for _, fingerprint in ipairs(fingerprints) do | ||
| if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then | ||
| return true, require("zigbee-multi-button.sonoff") | ||
| end | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| return sonoff_can_handle | ||
8 changes: 8 additions & 0 deletions
8
drivers/SmartThings/zigbee-button/src/zigbee-multi-button/sonoff/fingerprints.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local SONOFF_FINGERPRINTS = { | ||
| { mfr = "SONOFF", model = "SNZB-01M" } | ||
| } | ||
|
|
||
| return SONOFF_FINGERPRINTS |
43 changes: 43 additions & 0 deletions
43
drivers/SmartThings/zigbee-button/src/zigbee-multi-button/sonoff/init.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local capabilities = require "st.capabilities" | ||
|
|
||
| local SONOFF_CLUSTER_ID = 0xFC12 | ||
| local SONOFF_ATTR_ID = 0x0000 | ||
|
|
||
| local EVENT_MAP = { | ||
| [0x01] = capabilities.button.button.pushed, | ||
| [0x02] = capabilities.button.button.double, | ||
| [0x03] = capabilities.button.button.held, | ||
| [0x04] = capabilities.button.button.pushed_3x | ||
| } | ||
|
|
||
| local function sonoff_attr_handler(driver, device, value, zb_rx) | ||
| local attr_val = value.value | ||
| local endpoint = zb_rx.address_header.src_endpoint.value | ||
| local button_name = "button" .. tostring(endpoint) | ||
| local event_func = EVENT_MAP[attr_val] | ||
| if event_func then | ||
| local comp = device.profile.components[button_name] | ||
| if comp then | ||
| local event = event_func({ state_change = true }) | ||
| device:emit_component_event(comp, event) | ||
| device:emit_event(event) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| local sonoff_handler = { | ||
| NAME = "SONOFF Multi-Button Handler", | ||
| zigbee_handlers = { | ||
| attr = { | ||
| [SONOFF_CLUSTER_ID] = { | ||
| [SONOFF_ATTR_ID] = sonoff_attr_handler | ||
| } | ||
| } | ||
| }, | ||
| can_handle = require("zigbee-multi-button.sonoff.can_handle") | ||
| } | ||
|
|
||
| return sonoff_handler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: newline in this file and all the other files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Oniums