Skip to content

[WWSTCERT-13550] Sonoff - Add the pressure display function to SNZB-02M - #3194

Open
laity-w-sudo wants to merge 14 commits into
SmartThingsCommunity:mainfrom
laity-w-sudo:main
Open

laity-w-sudo wants to merge 14 commits into
SmartThingsCommunity:mainfrom
laity-w-sudo:main

Conversation

@laity-w-sudo

@laity-w-sudo laity-w-sudo commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Check all that apply

Type of Change

  • WWST Certification Request
    • If this is your first time contributing code:
      • I have reviewed the README.md file
      • I have reviewed the CODE_OF_CONDUCT.md file
      • I have signed the CLA
    • I plan on entering a WWST Certification Request or have entered a request through the WWST Certification console at developer.smartthings.com
  • Bug fix
  • New feature
  • Refactor

Checklist

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have verified my changes by testing with a device or have communicated a plan for testing
  • I am adding new behavior, such as adding a sub-driver, and have added and run new unit tests to cover the new behavior

Description of Change

Adding the air pressure function to the SNZB-02M equipment

Summary of Completed Tests

@github-actions

Copy link
Copy Markdown

Duplicate profile check: Passed - no duplicate profiles detected.

@github-actions

Copy link
Copy Markdown

Profile category check: ✅ Passed - all profiles have a category defined.

@github-actions

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Test Results

   73 files    545 suites   0s ⏱️
3 306 tests 3 306 ✅ 0 💤 0 ❌
5 299 runs  5 299 ✅ 0 💤 0 ❌

Results for commit 0371b3b.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

zigbee-humidity-sensor_coverage.xml

File Coverage
All files 98% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-humidity-sensor/src/init.lua 93% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-humidity-sensor/src/lazy_load_subdriver.lua 57% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-humidity-sensor/src/frient-sensor/air-quality/init.lua 98% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-humidity-sensor/src/sonoff/init.lua 93% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-humidity-sensor/src/plant-link/init.lua 96% ✅

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 0371b3b

The SNZB-02M sub-driver was added but never registered, so the
pressure display feature was dead code on the device. Register it
via sub_drivers.lua, drop the unrelated SNZB-02LD/WD handler and
utils (not in this driver, and referencing a nonexistent sub-driver),
and add unit tests for pressure conversion and refresh.

Co-Authored-By: Claude <noreply@anthropic.com>
@laity-w-sudo
laity-w-sudo force-pushed the main branch 2 times, most recently from ae161d5 to b5e3665 Compare August 25, 2026 11:23
Comment thread drivers/SmartThings/zigbee-humidity-sensor/src/sonoff/SNZB-02M/can_handle.lua Outdated
Comment thread drivers/SmartThings/zigbee-humidity-sensor/src/sonoff/SNZB-02M/init.lua Outdated
Comment thread drivers/SmartThings/zigbee-humidity-sensor/src/sonoff/SNZB-02M/init.lua Outdated
Comment thread tools/run_driver_tests_p.py Outdated
@KKlimczukS
KKlimczukS requested a review from cbaumler August 31, 2026 09:20
@KKlimczukS KKlimczukS changed the title Add the pressure display function to SNZB-02M [WWSTCERT-13550] Sonoff - Add the pressure display function to SNZB-02M Aug 31, 2026
Comment thread tools/run_driver_tests_p.py
Comment thread drivers/SmartThings/zigbee-humidity-sensor/src/test/test_sonoff_snzb02m.lua Outdated
Comment thread drivers/SmartThings/zigbee-humidity-sensor/src/sub_drivers.lua Outdated

@cjswedes cjswedes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My biggest concern is the lack of configuration for reporting the PressureMeasurement MeasuredValue attribute; has this been tested manually?

Comment thread drivers/SmartThings/zigbee-humidity-sensor/src/sonoff/init.lua
Comment thread drivers/SmartThings/zigbee-humidity-sensor/src/sonoff/SNZB-02M/can_handle.lua Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason to have the nested directories? We should just add a sonoff subdriver rather than having sonoff/SNZB-02M. We want to avoid having single subdrivers for each model.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please change the directory structure so that it is not nested, and everything falls under the sonoff directory.

Comment thread drivers/SmartThings/zigbee-humidity-sensor/src/sonoff/init.lua Outdated
@KKlimczukS
KKlimczukS requested a review from cjswedes September 10, 2026 11:54

@KKlimczukS KKlimczukS left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@laity-w-sudo Please update Your branch.

@KKlimczukS
KKlimczukS self-requested a review September 23, 2026 15:50

@KKlimczukS KKlimczukS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

Comment thread drivers/SmartThings/zigbee-humidity-sensor/src/test/test_sonoff_snzb02m.lua Outdated
@cbaumler

Copy link
Copy Markdown
Contributor

It looks like temperature, humidity, and battery reporting are not configured specifically for this model. So the default configs are used. The defaults are coarser than what's configured for the SNZB-02DR2 here. Just want to confirm this is intentional.

minimum_interval = 5,
maximum_interval = 3600,
data_type = PressureMeasurement.attributes.MeasuredValue.base_type,
reportable_change = 50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The PressureMeasurement.MeasuredValue attribute is in units of 0.1 kPa. So 50 means 5 kPa. Normal barometric changes are roughly 0.1–0.5 kPa per hour. So the device would almost never report on change. Can you confirm if this was tested on a real device and if this setting is desired?

device:add_configured_attribute(PRESSURE_CONFIGURATION)
end

local function refresh_handler(driver, device, command)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This handler looks redundant. I removed it locally, and the default refresh (device:refresh()) sends the same four reads: temperature, humidity, pressure (configured via add_configured_attribute) and battery percentage. The existing refresh test still passes unchanged with relaxed ordering. Could you drop refresh_handler and its capability_handlers entry unless there’s a read the default misses?

device:emit_event(capabilities.atmosphericPressureMeasurement.atmosphericPressure({value = pressure_value, unit = "kPa"}))
end

local function device_init(driver, device)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: A subdriver’s lifecycle_handlers.init replaces the parent’s device_init for this model instead of running alongside it. That’s harmless today, because configurations.lua has no SNZB-02M entry. If one is added later, its attributes will silently stop being configured. A one-line comment here would save the next person some debugging.

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)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The nil branch (log and return) has no test. Either add a small test for a report with no value, or drop the nil handling, since the framework always passes a value for this attribute.

direction = "receive",
message = {
mock_device.id,
PressureMeasurement.attributes.MeasuredValue:build_test_attr_report(mock_device, 960)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The only pressure test uses 960. Could you add a second case with a non-round value, such as 1013, so the division by 10 is covered more than once?

}
)

test.run_registered_tests()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don’t see a test that covers the pressure reporting configuration, which was @cjswedes's main concern earlier in the review. Please add one that checks device_init adds the pressure configuration and that doConfigure sends the bind and configure-reporting messages for cluster 0x0403.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lets remove sonoff from this profile name (and file name), so that other devices can use it if there are any others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants