Skip to content

Conversation

@Oniums
Copy link

@Oniums Oniums commented Oct 29, 2025

Proposed change

Additional information

Device diagnostics

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works
  • Device diagnostics data has been attached

@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.26%. Comparing base (aa7b32d) to head (495e7b9).
⚠️ Report is 4 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #4447      +/-   ##
==========================================
+ Coverage   92.24%   92.26%   +0.02%     
==========================================
  Files         369      370       +1     
  Lines       12088    12120      +32     
==========================================
+ Hits        11150    11182      +32     
  Misses        938      938              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TheJulianJES TheJulianJES added manufacturer This request was made by the device's manufacturer needs review This PR should be reviewed soon, as it generally looks good. needs reviewer answer An answer from a reviewer is needed (e.g. why a PR isn't acceptable in the current state). labels Nov 5, 2025
@TheJulianJES TheJulianJES changed the title Add Sonoff SNZB-01M Smart Scene Button. Add Sonoff SNZB-01M Smart Scene remote Nov 5, 2025
Copy link
Collaborator

@TheJulianJES TheJulianJES left a comment

Choose a reason for hiding this comment

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

This PR adds a v1 quirk that doesn't use any constants in the quirk signature and replacement. This is something that all other v1 quirks do. Like, you'd wanna do OnOff.cluster_id instead of 0x0006.
Some parts of the tests are also a bit unnecessary as well.

In general, we shouldn't add new v1 quirks anymore if v2 quirks also work.

I'll get back to you with more details soon, but for now, please take a look at some v2 quirks adding device automation triggers:

  1. https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/sonoff/button.py
    This one doesn't use a custom cluster though, but it's a nice simple example.
  2. https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/smarthjemmet/quadzigsw.py
    This one is a bit special, but does use a custom cluster, and works around a firmware issue with all the extra endpoints/clusters.
  3. Maybe also see: https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/candeo/rotary_dimmer_switches.py

You'll wanna use the QuirkBuilder, .replaces(SonoffButtonCluster, endpoint_id=x) for the custom cluster, and .device_automation_triggers(...).

For the test, something like https://github.com/zigpy/zha-device-handlers/blob/dev/tests/test_smarthjemmet.py would be enough. We don't need to test that the quirk definition and so on works properly, just added logic, like in the new custom cluster.

@Oniums
Copy link
Author

Oniums commented Nov 6, 2025

Thanks for the review and the example links — that helped a lot.
follow that i change in this PR

  • Migrated the quirk to the v2 API (QuirkBuilder) instead of adding a new v1 quirk. This avoids hard-coded cluster IDs in signatures/replacements and follows the v2 pattern you pointed to.
  • Implemented the device registration with QuirkBuilder and kept the custom cluster implementation (SonoffButtonCluster) intact.
  • Simplified tests to only cover the added cluster logic (the attribute → event conversion), following the style used in the smarthjemmet example you pointed at. Tests now:
  1. Use the zigpy_device_from_v2_quirk fixture.
  2. Create endpoints 1–4 so the v2 quirk can add the custom cluster to each endpoint.
  3. Avoid testing QuirkBuilder registration internals (device_automation_triggers/signature/replacement), per your guidance.
  • Fixed lint/pre-commit issues reported during CI (moved imports to module top, added concise test docstrings).
  • Fixed a duplicate metadata registration bug: I removed a redundant .applies_to(...) call that caused the same manufacturer/model to be registered twice (this was the root cause of the manufacturer-model uniqueness failure).
  • Kept the quirk file exporting a SNZB01M variable (the QuirkBuilder result) so other code/tests can access device_automation_triggers if needed, but the tests themselves no longer assert on that registry mapping.

Files changed

  • snzb01m.py
  1. QuirkBuilder registration (v2), removed redundant .applies_to().
  2. SonoffButtonCluster unchanged (still handles attribute updates → listener events).
  • test_sonoff.py
  1. Tests reduced to cluster behavior only (attribute handling and emitted events).
  2. Use zigpy_device_from_v2_quirk("SONOFF", "SNZB-01M", endpoint_ids=[1,2,3,4]).

@TheJulianJES When you have a moment,could you please review the latest changes in this PR? Thanks

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

Labels

manufacturer This request was made by the device's manufacturer needs review This PR should be reviewed soon, as it generally looks good. needs reviewer answer An answer from a reviewer is needed (e.g. why a PR isn't acceptable in the current state).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants