-
Notifications
You must be signed in to change notification settings - Fork 557
[WWSTCERT-13550] Sonoff - Add the pressure display function to SNZB-02M #3194
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
laity-w-sudo
wants to merge
7
commits into
SmartThingsCommunity:main
Choose a base branch
from
laity-w-sudo: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
7 commits
Select commit
Hold shift + click to select a range
1f3d8bb
Add the pressure display function to SNZB-02M
laity-w-sudo b5e3665
Wire SNZB-02M sub-driver and add pressure tests
yanggx24 46e746d
Fix SNZB-02M lazy-load and pressure test
laity-w-sudo 0909220
Load-SNZB-02M-handlers-during-lazy-load
laity-w-sudo 1ca26b1
Limit-parallel-driver-tests-to-changed-drivers
laity-w-sudo 7780cd9
Merge branch 'SmartThingsCommunity:main' into main
laity-w-sudo b7123f5
Modify the relevant contents of SNZB-02M according to the suggestions
laity-w-sudo 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
18 changes: 18 additions & 0 deletions
18
drivers/SmartThings/zigbee-humidity-sensor/profiles/sonoff-humidity-temp-press-battery.yml
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,18 @@ | ||
| name: sonoff-humidity-temp-press-battery | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: temperatureMeasurement | ||
| version: 1 | ||
| - id: relativeHumidityMeasurement | ||
| version: 1 | ||
| - id: atmosphericPressureMeasurement | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: MultiFunctionalSensor | ||
12 changes: 12 additions & 0 deletions
12
drivers/SmartThings/zigbee-humidity-sensor/src/sonoff/SNZB-02M/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,12 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local function can_handle(opts, driver, device, ...) | ||
| if device:get_model() == "SNZB-02M" then | ||
| return true, require("sonoff.SNZB-02M") | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
| return can_handle |
51 changes: 51 additions & 0 deletions
51
drivers/SmartThings/zigbee-humidity-sensor/src/sonoff/SNZB-02M/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,51 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local capabilities = require "st.capabilities" | ||
| local clusters = require "st.zigbee.zcl.clusters" | ||
| local log = require "log" | ||
|
|
||
| local function convert_pressure_value(raw_value) | ||
| if raw_value == nil then | ||
| return nil | ||
| end | ||
|
|
||
| return raw_value / 10.0 | ||
| end | ||
|
|
||
| local function pressure_report_handler(driver, device, value, zb_rx) | ||
| local pressure_value = convert_pressure_value(value.value) | ||
| if pressure_value == nil then | ||
| log.warn(string.format("SNZB-02M pressure report has no value: %s", tostring(value))) | ||
| return | ||
| end | ||
|
|
||
| log.debug(string.format("SNZB-02M pressure raw: %s, converted: %s kPa", tostring(value.value), tostring(pressure_value))) | ||
| device:emit_event(capabilities.atmosphericPressureMeasurement.atmosphericPressure({value = pressure_value, unit = "kPa"})) | ||
| end | ||
|
|
||
| local function refresh_handler(driver, device, command) | ||
| device:send(clusters.TemperatureMeasurement.attributes.MeasuredValue:read(device)) | ||
| device:send(clusters.RelativeHumidity.attributes.MeasuredValue:read(device)) | ||
| device:send(clusters.PressureMeasurement.attributes.MeasuredValue:read(device)) | ||
| device:send(clusters.PowerConfiguration.attributes.BatteryPercentageRemaining:read(device)) | ||
| end | ||
|
|
||
| local can_handle = require "sonoff.SNZB-02M.can_handle" | ||
|
|
||
| return { | ||
| NAME = "Sonoff SNZB-02M Sensor", | ||
| zigbee_handlers = { | ||
| attr = { | ||
| [clusters.PressureMeasurement.ID] = { | ||
| [clusters.PressureMeasurement.attributes.MeasuredValue.ID] = pressure_report_handler | ||
| } | ||
| } | ||
| }, | ||
| capability_handlers = { | ||
| [capabilities.refresh.ID] = { | ||
| [capabilities.refresh.commands.refresh.NAME] = refresh_handler | ||
| } | ||
| }, | ||
| can_handle = can_handle | ||
| } |
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 |
|---|---|---|
|
|
@@ -9,5 +9,6 @@ local sub_drivers = { | |
| lazy_load_if_possible("centralite-sensor"), | ||
| lazy_load_if_possible("heiman-sensor"), | ||
| lazy_load_if_possible("frient-sensor"), | ||
| lazy_load_if_possible("sonoff.SNZB-02M"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the comma at the end of line |
||
| } | ||
| return sub_drivers | ||
117 changes: 117 additions & 0 deletions
117
drivers/SmartThings/zigbee-humidity-sensor/src/test/test_sonoff_snzb02m.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,117 @@ | ||||||
| -- Copyright 2025 SmartThings, Inc. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| -- Licensed under the Apache License, Version 2.0 | ||||||
|
|
||||||
| local test = require "integration_test" | ||||||
| local t_utils = require "integration_test.utils" | ||||||
| local zigbee_test_utils = require "integration_test.zigbee_test_utils" | ||||||
| local clusters = require "st.zigbee.zcl.clusters" | ||||||
| local capabilities = require "st.capabilities" | ||||||
|
|
||||||
| local PowerConfiguration = clusters.PowerConfiguration | ||||||
| local TemperatureMeasurement = clusters.TemperatureMeasurement | ||||||
| local RelativeHumidity = clusters.RelativeHumidity | ||||||
| local PressureMeasurement = clusters.PressureMeasurement | ||||||
|
|
||||||
| local mock_device = test.mock_device.build_test_zigbee_device( | ||||||
| { | ||||||
| profile = t_utils.get_profile_definition("sonoff-humidity-temp-press-battery.yml"), | ||||||
| zigbee_endpoints = { | ||||||
| [1] = { | ||||||
| id = 1, | ||||||
| manufacturer = "SONOFF", | ||||||
| model = "SNZB-02M", | ||||||
| server_clusters = { 0x0001, 0x0402, 0x0405, 0x0403 } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| zigbee_test_utils.prepare_zigbee_env_info() | ||||||
| local function test_init() | ||||||
| test.mock_device.add_test_device(mock_device) | ||||||
| end | ||||||
|
|
||||||
| test.set_test_init_function(test_init) | ||||||
|
|
||||||
| test.register_message_test( | ||||||
| "Pressure report above 2000 should be divided by 1000", | ||||||
| { | ||||||
| { | ||||||
| channel = "zigbee", | ||||||
| direction = "receive", | ||||||
| message = { | ||||||
| mock_device.id, | ||||||
| PressureMeasurement.attributes.MeasuredValue:build_test_attr_report(mock_device, 10000) | ||||||
| } | ||||||
| }, | ||||||
| { | ||||||
| channel = "capability", | ||||||
| direction = "send", | ||||||
| message = mock_device:generate_test_message("main", | ||||||
| capabilities.atmosphericPressureMeasurement.atmosphericPressure({ value = 10.0, unit = "kPa" })) | ||||||
| } | ||||||
| }, | ||||||
| { | ||||||
| min_api_version = 14 | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| test.register_message_test( | ||||||
| "Pressure report at or below 2000 should be divided by 10", | ||||||
| { | ||||||
| { | ||||||
| channel = "zigbee", | ||||||
| direction = "receive", | ||||||
| message = { | ||||||
| mock_device.id, | ||||||
| PressureMeasurement.attributes.MeasuredValue:build_test_attr_report(mock_device, 960) | ||||||
| } | ||||||
| }, | ||||||
| { | ||||||
| channel = "capability", | ||||||
| direction = "send", | ||||||
| message = mock_device:generate_test_message("main", | ||||||
| capabilities.atmosphericPressureMeasurement.atmosphericPressure({ value = 96.0, unit = "kPa" })) | ||||||
| } | ||||||
| }, | ||||||
| { | ||||||
| min_api_version = 14 | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| test.register_message_test( | ||||||
| "Refresh should read temperature, humidity, pressure and battery", | ||||||
| { | ||||||
| { | ||||||
| channel = "capability", | ||||||
| direction = "receive", | ||||||
| message = { mock_device.id, { capability = "refresh", component = "main", command = "refresh", args = {} } } | ||||||
| }, | ||||||
| { | ||||||
| channel = "zigbee", | ||||||
| direction = "send", | ||||||
| message = { mock_device.id, TemperatureMeasurement.attributes.MeasuredValue:read(mock_device) } | ||||||
| }, | ||||||
| { | ||||||
| channel = "zigbee", | ||||||
| direction = "send", | ||||||
| message = { mock_device.id, RelativeHumidity.attributes.MeasuredValue:read(mock_device) } | ||||||
| }, | ||||||
| { | ||||||
| channel = "zigbee", | ||||||
| direction = "send", | ||||||
| message = { mock_device.id, PressureMeasurement.attributes.MeasuredValue:read(mock_device) } | ||||||
| }, | ||||||
| { | ||||||
| channel = "zigbee", | ||||||
| direction = "send", | ||||||
| message = { mock_device.id, PowerConfiguration.attributes.BatteryPercentageRemaining:read(mock_device) } | ||||||
| } | ||||||
| }, | ||||||
| { | ||||||
| inner_block_ordering = "relaxed", | ||||||
| min_api_version = 14 | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| test.run_registered_tests() | ||||||
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.
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.
@laity-w-sudo this requested change is mandatory