Fix configuring attribute reporting#648
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #648 +/- ##
==========================================
+ Coverage 97.29% 97.41% +0.12%
==========================================
Files 62 62
Lines 10712 10719 +7
==========================================
+ Hits 10422 10442 +20
+ Misses 290 277 -13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
We can add a test for |
|
@puddly Want me to just add the above test to this PR or make another one? (test for reporting status used by frontend) |
|
Let's roll it into this one |
|
Do note the updated tests in this PR still would not really catch an issue where the method signature of zigpy's I'd keep this PR as is now. |
There was a problem hiding this comment.
Pull request overview
Updates ZHA cluster handler attribute reporting configuration to match recent zigpy manufacturer-code/attribute-definition API changes, and adjusts tests accordingly.
Changes:
- Switch
configure_reporting_multiplecalls to pass{ZCLAttributeDef: ReportingConfig}instead of{str: (min,max,change)}. - Remove manual manufacturer-code selection logic for manufacturer-specific clusters and rely on zigpy’s handling.
- Update reporting-status parsing and test expectations, adding coverage for reporting-status emission.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
zha/zigbee/cluster_handlers/__init__.py |
Updates reporting configuration payload format, removes manufacturer kwarg logic, and adjusts reporting-status parsing. |
tests/test_device.py |
Updates join/bind/reporting test assertions to expect ZCLAttributeDef + ReportingConfig mappings. |
tests/test_cluster_handlers.py |
Updates reporting-related test assertions and adds a parametrized test for reporting-status parsing/emission. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """Parse configure reporting result.""" | ||
| if isinstance(res, (Exception, ConfigureReportingResponseRecord)): | ||
| attr_names = {attr_def.name for attr_def in attrs} | ||
| if not res or isinstance(res, (Exception, ConfigureReportingResponseRecord)): |
There was a problem hiding this comment.
We should not be able to hit the isinstance(res, (Exception, ConfigureReportingResponseRecord)) check ever now? Like, returning an exception or just a single ConfigureReportingResponseRecord? Should I just remove this?
If so, should I at least keep the guard against zigpy returning an empty list? Even though that should not happen after zigpy/zigpy#1764 anymore. We'd just mark the attributes as failed to configure if zigpy (or some test mocks elsewhere) somehow return an empty list. Or should we just ignore that and fail however that would fail? (causing SUCCESS)
There was a problem hiding this comment.
I've removed it with 182a8bc (this PR). Having zigpy return an exception or a single status report can't happen at all from what I see. It's always a list at least.
There was a problem hiding this comment.
Yeah, returning exception objects (instead of raising them) is a legacy artifact and something that we've slowly been trying to get rid of. There are more instances within the ZHA library that still account for this possibility. I believe we do still have a few asyncio.gather(..., return_exceptions=True) invocations that were the cause of this pattern.
…eReportingResponseRecord`
| if not res: | ||
| self.debug( | ||
| "attr reporting for '%s' on '%s': %s", | ||
| attrs, | ||
| attr_names, | ||
| self.name, | ||
| res, | ||
| ) | ||
| for attr in attrs: | ||
| event_data[attr]["status"] = Status.FAILURE.name | ||
| for attr_name in attr_names: | ||
| event_data[attr_name]["status"] = Status.FAILURE.name | ||
| return |
There was a problem hiding this comment.
Technically, zigpy should also never return an empty list. Do we want to keep this failure case in case zigpy breaks again, so we report all attributes as failed to configure then?
If we remove this, they'd report as being successfully configured otherwise, which also isn't great. But this should never happen (again), soo..
There was a problem hiding this comment.
I think we can keep it in. In the near future I'd like to persist the attribute configuration state in the database so this code likely will be reworked anyways.
|
I've tested this PR as well (along with all of the other zigpy + ZHA changes) and it works as expected. |
|
The fixes haven't landed in 26.2.2, have they? |
|
They have. |
|
Ah found it home-assistant/core#162894 |
|
Yeah works again. Firmware versions are still unknown, but I guess this is related to something else? |
Proposed change
This fixes configuration of attribute reporting after the recent zigpy manufacturer code changes.
configure_reporting_multipleis now called withZCLAttributeDefandReportingConfig, instead of the attribute name (str) and a tuple containing min/max/reportable change int values._configure_reporting_statuswas updated to get the attribute name fromZCLAttributeDef.cluster_id >= 0xFC00check for using the manufacturer code is removed, as zigpy now does this better and automatically, grouping respective attributes properly.configure_reporting_multiplecalls.res[0].status == Status.SUCCESS and len(res) == 1was updated tolen(res) == 1 and res[0].status == Status.SUCCESS. This should now properly work with empty lists.configure_reporting_status, which sends reports on attribute reports used by HA frontend.This change was tested with an IKEA motion sensor, where attribute reporting is now correctly configured for the
PowerConfigurationcluster again. This is also represented in the HA frontend.Additional information
Related PRs: