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 Niko Connected single/double switch #3701

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

RubenVerborgh
Copy link

Proposed change

Add support for the Niko Connected single switch (552-721X1) and Connected double switch (552-721X2).

Additional information

Request and previous work

Functionality

  • These Niko switches actually consist of three kinds of entities, which are coupled in the default configuration but can be decoupled:
    • 1 or 2 switches
    • 2 or 4 buttons (each on-device button can have its external extension button)
    • 1 of 2 status LEDs
  • This PR exposes each of those entities separately, such that they can be controlled individually:

Events

  • The buttons additionally generate events (short and long presses):

Configuration

  • Several configuration options are exposed as entities:

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 Jan 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.08%. Comparing base (b7f2bc7) to head (84cc4d8).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #3701      +/-   ##
==========================================
+ Coverage   89.89%   90.08%   +0.19%     
==========================================
  Files         320      322       +2     
  Lines       10400    10601     +201     
==========================================
+ Hits         9349     9550     +201     
  Misses       1051     1051              

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

@RubenVerborgh RubenVerborgh changed the title Feature/niko switch Add Niko Connected single/double switch Jan 11, 2025
@RubenVerborgh RubenVerborgh mentioned this pull request Jan 12, 2025
3 tasks
@TheJulianJES TheJulianJES added 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. labels Jan 16, 2025
@RubenVerborgh
Copy link
Author

Feel free to already test and provide feedback; perhaps some points before this PR is merged.

Improvements

Functionality

  • Currently, I'm exposing the option to have different colored lights (white / red / blue / purple) as an alert functionality, which seems to be the original intention. However, I could also expose this as a choice for indicator light color, such that, for instance, an outside toilet/bathroom switch could light up in red rather than white to indicate occupation. This is trivial for the one-LED version, and feasible for the two-LED version. But I'm not sure to what extent it is desirable to encode such more advanced behavior in quirks, as opposed to directly translating the manufacturer's intentions.

Any feedback on the above would be helpful!

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'll need to go through this properly when I find some free time, but one thing:
Bus shouldn't really be needed anymore. The docs/README really have to be updated, but I just haven't found the time yet.

You can access update_attribute and other methods on a different cluster directly (from your current cluster) using something like this:

self.endpoint.ias_zone.update_attribute(
IasZone.AttributeDefs.zone_status.id,
IasZone.ZoneStatus.Alarm_1 if value == AqaraMotion.Moving else 0,
)

You can also call methods on a different endpoint with self.endpoint.device.endpoints[2].ias_zone.do_something() for example (IIRC).

ias_zone is the ep_attribute of a cluster. You can also access it with self.endpoint.in_clusters[IasZone.cluster_id] e.g.

Doing this might avoid needing some of the tasks? Again, I have to look at this properly some time soon, but it seems a bit weird looking at it now.

Same goes for the inheritance with NikoCluster/the other Niko clusters.
And the NikoQuirkBuilder also is a bit out of the usual pattern that we wanted to have with "quirks v2", though I see why you're doing it.

Again, this isn't a review. Just some thoughts whilst having a very quick look at this.
Not sure why apply_custom_configuration wouldn't be working.. Your HA version is somewhat up-do-date?
You could also try overriding it in the CustomDeviceV2 class: https://github.com/zigpy/zigpy/blob/08f8f99df3d235aa0c0154331cb7c5b3dffde3e1/zigpy/quirks/__init__.py#L119-L137

@ccantill
Copy link

The same quirk also appears to work fine with the NIKO zigbee dimmer:

class NikoDimmer(NikoSwitch):
    """Niko Connected Dimmer 552-722X1."""

    model = "Connectable dimmer,3-200W,2-wire"
    model_friendly = "Connected dimmer"
    button_count = 2

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.

3 participants