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

Add quirk for Sonoff ZBMINIR2 #3428

Merged
merged 9 commits into from
Nov 24, 2024
Merged

Add quirk for Sonoff ZBMINIR2 #3428

merged 9 commits into from
Nov 24, 2024

Conversation

lcheng33775823
Copy link
Contributor

@lcheng33775823 lcheng33775823 commented Oct 15, 2024

Proposed change

Add quirk for Sonoff ZBMINIR2

Additional information

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

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.44%. Comparing base (4d53f30) to head (82b7d05).
Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
zhaquirks/sonoff/zbminir2.py 91.30% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #3428   +/-   ##
=======================================
  Coverage   89.44%   89.44%           
=======================================
  Files         311      312    +1     
  Lines       10031    10054   +23     
=======================================
+ Hits         8972     8993   +21     
- Misses       1059     1061    +2     

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


🚨 Try these New Features:

@lcheng33775823
Copy link
Contributor Author

Hi @TheJulianJES, I've created a PR. Is there anything I need to do before merging it?

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.

I've added some suggestions. I'll go ahead and commit some of them to your PR/branch.
I'll still need to check up on some other things.

zhaquirks/sonoff/zbminir2.py Outdated Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Outdated Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Outdated Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Outdated Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Outdated Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Outdated Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Outdated Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Outdated Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Outdated Show resolved Hide resolved
Comment on lines +33 to +50
async def _read_attributes(
self,
attribute_ids: list[t.uint16_t],
*args,
manufacturer: int | t.uint16_t | None = None,
**kwargs,
):
"""Read attributes ZCL foundation command."""
return await super()._read_attributes(
attribute_ids,
*args,
manufacturer=foundation.ZCLHeader.NO_MANUFACTURER_ID,
**kwargs,
)

@property
def _is_manuf_specific(self):
return False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, in the future, we should have a better solution for this, so we don't need to duplicate it across all quirks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's possible that zigpy/zigpy#1505 can clean this up?

Comment on lines 55 to 58
edge_trigger = 0x00
pulse_trigger = 0x01
normally_off_follow_trigger = 0x02
normally_on_follow_trigger = 0x82
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll have to check which naming convention we want to use here.
Other possibilities include: EdgeTrigger, Edge_Trigger, and Edge_trigger.

zhaquirks/sonoff/zbminir2.py Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Show resolved Hide resolved
zhaquirks/sonoff/zbminir2.py Show resolved Hide resolved
@TheJulianJES TheJulianJES added the needs review This PR should be reviewed soon, as it generally looks good. label Oct 31, 2024
@lcheng33775823
Copy link
Contributor Author

Thank you very much for your assistance.

@pngunit
Copy link

pngunit commented Nov 18, 2024

@TheJulianJES Can this be merged? Z2M has had proper support for this device for a while, and it would be a shame to block it over variable naming.

@tomasgatial
Copy link

I have tested the Quirk, few insights:

  • external trigger mode config works great
  • the detached mode config doesn't work right for me with switch in edge trigger mode:
    switch position updates HA entity state, and HA ends up confused
  • I miss inching configuration (as ewelink cluster command)

@marcohamersma
Copy link

I just got this device today, tried this quirk and can confirm it's still a bit weird when using detached mode like tomas said.

So I'm new to these types of devices, but is it normal that when using the external trigger mode of a pulse trigger, the relay switch shows up as on for a second, then reverts to false? This seems like it would make it basically impossible to distinguish between double-tapping the switch or holding the switch for a while. Wouldn't this be what the sensor is for?

@TheJulianJES TheJulianJES added the v2 quirk Quirks using v2 API. Might add custom entities that need translation keys in HA. label Nov 24, 2024
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.

The lines regarding the "no manufacturer id" modification are not covered.

I'm merging this to get initial support for the device, but we should try and use manufacturer_id_override = foundation.ZCLHeader.NO_MANUFACTURER_ID in the future (when zigpy/zigpy#1505 is merged) and hopefully be able to remove those uncovered lines.
Otherwise, we should add (trivial) tests for this and/or move the _read_attributes and _is_manuf_specific overrides, as they're also required for other Sonoff devices.

Regarding the device implementation of the "detached mode", that's not affected by us. Not sure we can do anything about it with a quirk.

@TheJulianJES TheJulianJES merged commit 68e37ae into zigpy:dev Nov 24, 2024
9 checks passed
@arnekaiser
Copy link

I can confirm the strange behavior in detached mode. It looks like the state of the relay and also the state of the external switch are mapped to the switch entity.

I tried the detached mode with the same device (firmware 0x00001002) with Z2M without any issues. The state of the relay is mapped to the switch entity and on external switch use, the HA device receives toggle actions.

@TheJulianJES
Copy link
Collaborator

Since the behavior differs from Z2M, please create an issue in this repo and link it here.

@marcohamersma
Copy link

I've just created a new issue for this in #3579

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review This PR should be reviewed soon, as it generally looks good. v2 quirk Quirks using v2 API. Might add custom entities that need translation keys in HA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants