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

Convert Sinope light to new style AttributeDefs, add ZHA events #3313

Merged
merged 16 commits into from
Sep 24, 2024

Conversation

ckm2k1
Copy link
Contributor

@ckm2k1 ckm2k1 commented Aug 23, 2024

Proposed change

Add ability for Sinope light switches to handle routing attribute reports on the manufacturer cluster attribute action_report as ZHA events.

Additional information

Related PR zigpy/zha/pull/153 made it so that action_report doesn't need to be manually configured for reporting (as shown by @claudegel here: https://github.com/claudegel/sinope-zha?tab=readme-ov-file#a-create-the-reporting-).

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 Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.72%. Comparing base (acecf70) to head (c8993f4).
Report is 13 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #3313      +/-   ##
==========================================
+ Coverage   88.49%   88.72%   +0.23%     
==========================================
  Files         305      306       +1     
  Lines        9621     9811     +190     
==========================================
+ Hits         8514     8705     +191     
+ Misses       1107     1106       -1     

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

tests/test_sinope.py Outdated Show resolved Hide resolved
@claudegel
Copy link
Contributor

So we will need to do the same in sinope thermostat.py, sensor.py and switch.py
Can I help to reformat some of them ?

@claudegel
Copy link
Contributor

Ok I'm almost finish with the changes for thermostat.py, switch.py and sensor.py.
This is clear for the manufacturer cluster but in those files there are attribute addition in other cluster like Thermostat cluster

    attributes = Thermostat.attributes.copy()
    attributes.update(
        {
            0x0400: ("set_occupancy", Occupancy, True),
            0x0401: ("main_cycle_output", CycleOutput, True),
            ...

How do you change the AttributeDefs

    class AttributeDefs(foundation.BaseAttributeDefs):
        """Sinope Thermostat Custom Cluster Attributes."""

        set_occupancy: Final = foundation.ZCLAttributeDef(
            id=0x0400, type=Occupancy, access="rw", is_manufacturer_specific=True
        )
        ...
        )

        attributes = Thermostat.attributes.copy()
        attributes.update(
        {
        set_occupancy
        ...
        }

@ckm2k1
Copy link
Contributor Author

ckm2k1 commented Sep 1, 2024

@claudegel I don't know for sure, but my guess would be that you can probably inherit from the ZHA thermostat cluster attribute defs, something like this:

class AttributeDefs(Thermostat.AttributeDefs):
 ...

Btw, thank you for all the work you've done on supporting Sinope devices in ZHA!

@claudegel
Copy link
Contributor

Thanks I'll push a PR tomorrow for thermostat, switch and sensor

@claudegel
Copy link
Contributor

I've tried this but the attribute is not added to IasZone cluster:

class SinopeTechnologiesIasZoneCluster(CustomCluster, IasZone):
    """SinopeTechnologiesIasZoneCluster custom cluster."""

    LeakStatus: Final = LeakStatus

    class AttributeDefs(IasZone.AttributeDefs):
        """Sinope Manufacturer IasZone Cluster Attributes."""

    leak_status: Final = foundation.ZCLAttributeDef(
        id=0x0030, type=LeakStatus, access="rw", is_manufacturer_specific=True
    )

Any idea ?

@claudegel
Copy link
Contributor

Was able to fix like this:
Attribute is added to IasZone cluster but I still have an error

    leak_status: Final = foundation.BaseAttributeDefs(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BaseAttributeDefs() takes no arguments
    class AttributeDefs(IasZone.AttributeDefs):
        """Sinope Manufacturer IasZone Cluster Attributes."""

    leak_status: Final = foundation.BaseAttributeDefs(
        id=0x0030, type=LeakStatus, access="rw", is_manufacturer_specific=True
    )

If I replace foundation.BaseAttributeDefs by foundation.ZCLAttributeDef it is not working and atribute leak_status is not added
I've another strange thing. In the SinopeManufacturerCluster I have some Unknown_attr_1... attributes that I'm still working on . I need them to appear in the cluster but with this new style AttributeDefs they are just skipped. All other named attributes are there but the unknown one are missing. Is it because there is a number in them ?

@claudegel
Copy link
Contributor

I got it ... a stupid indentation that was not noticed in the log
ready for a PR

@ckm2k1
Copy link
Contributor Author

ckm2k1 commented Sep 3, 2024

@TheJulianJES - Anything missing in this PR to merge up?

@claudegel
Copy link
Contributor

claudegel commented Sep 3, 2024

Maybe change line

cluster_revision: Final = foundation.ZCLAttributeDef(
            id=0xFFFD, type=t.uint16_t, access="r", is_manufacturer_specific=True
        )

by
cluster_revision: Final = foundation.ZCL_CLUSTER_REVISION_ATTR

@ckm2k1
Copy link
Contributor Author

ckm2k1 commented Sep 3, 2024

Maybe change line

cluster_revision: Final = foundation.ZCLAttributeDef(
            id=0xFFFD, type=t.uint16_t, access="r", is_manufacturer_specific=True
        )

by cluster_revision: Final = foundation.ZCL_CLUSTER_REVISION_ATTR

Good point, changed it.

@ckm2k1
Copy link
Contributor Author

ckm2k1 commented Sep 4, 2024

@TheJulianJES - another bump, anything else needed to merge this?
Review feedback is addressed, all tests are passing.

@TheJulianJES
Copy link
Collaborator

There's no need to ping me. It'll be looked at when I (or someone else) has time.
The next zha-quirks release will only be at the end of the month anyway, as they're always made a couple of days before the next major HA beta is released.

@claudegel
Copy link
Contributor

Look good. Thank you

@TheJulianJES TheJulianJES added the needs review This PR should be reviewed soon label Sep 16, 2024
@TheJulianJES TheJulianJES changed the title Sinope light switches action report Convert Sinope light to new style AttributeDefs, add ZHA events Sep 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.

AttributeDefs changes look good. The action_report stuff seems fine as well, I think.

tests/test_sinope.py Outdated Show resolved Hide resolved


@pytest.mark.parametrize("quirk", (SinopeTechnologieslight,))
async def test_sinope_light_switch_reporting(zigpy_device_from_quirk, quirk):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tbh, I'm not sure we really need this test in zha quirks? We're not really testing any quirk specific code here, right?
(maybe except that the attribute exists)

We can leave this in for now though.

] = None,
):
"""Handle the cluster command."""
self.debug(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can leave it like this for now, but this causes a zigpy log. We might want to use our own logger here, since that'll clearly be zhaquirks.sinope. Other quirks aren't consistent about this though.
The string does include "Sinope" at least, so that's good.

tests/test_sinope.py Outdated Show resolved Hide resolved
@@ -23,7 +23,7 @@

SINOPE = "Sinope Technologies"
SINOPE_MANUFACTURER_CLUSTER_ID = 0xFF01
ATTRIBUTE_ACTION = "actionReport"
ATTRIBUTE_ACTION = "action_report"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Changing this might cause issues with current automations that do not use device triggers, right?

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.

Thanks, let's try this.

@TheJulianJES TheJulianJES merged commit 2bdd076 into zigpy:dev Sep 24, 2024
5 checks passed
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants