Skip to content

Fix configuring attribute reporting#648

Merged
puddly merged 12 commits intozigpy:devfrom
TheJulianJES:tjj/fix_attr_reporting
Feb 13, 2026
Merged

Fix configuring attribute reporting#648
puddly merged 12 commits intozigpy:devfrom
TheJulianJES:tjj/fix_attr_reporting

Conversation

@TheJulianJES
Copy link
Copy Markdown
Contributor

@TheJulianJES TheJulianJES commented Feb 7, 2026

Proposed change

This fixes configuration of attribute reporting after the recent zigpy manufacturer code changes.

  • configure_reporting_multiple is now called with ZCLAttributeDef and ReportingConfig, instead of the attribute name (str) and a tuple containing min/max/reportable change int values.
  • _configure_reporting_status was updated to get the attribute name from ZCLAttributeDef.
  • The cluster_id >= 0xFC00 check for using the manufacturer code is removed, as zigpy now does this better and automatically, grouping respective attributes properly.
  • The tests were updated to expect the new configure_reporting_multiple calls.
  • The condition res[0].status == Status.SUCCESS and len(res) == 1 was updated to len(res) == 1 and res[0].status == Status.SUCCESS. This should now properly work with empty lists.
    • EDIT: Zigpy should never send us an empty list though. I think it's still fine to not catastrophically break in the case zigpy sends something unexpected though, as that's just for the reporting status. We'll just mark the reports as failed then.
  • A test was added for 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 PowerConfiguration cluster again. This is also represented in the HA frontend.

Additional information

Related PRs:

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.41%. Comparing base (7754950) to head (182a8bc).
⚠️ Report is 2 commits behind head on dev.

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.
📢 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
Copy link
Copy Markdown
Contributor Author

We can add a test for configure_reporting_status in this PR or another PR. For example: TheJulianJES:tjj/fix_attr_reporting...TheJulianJES:tjj/fix_attr_reporting_status_tests

@TheJulianJES
Copy link
Copy Markdown
Contributor Author

@puddly Want me to just add the above test to this PR or make another one? (test for reporting status used by frontend)

@puddly
Copy link
Copy Markdown
Contributor

puddly commented Feb 11, 2026

Let's roll it into this one

@TheJulianJES TheJulianJES marked this pull request as ready for review February 11, 2026 20:08
@TheJulianJES TheJulianJES requested a review from Copilot February 11, 2026 20:10
@TheJulianJES
Copy link
Copy Markdown
Contributor Author

Do note the updated tests in this PR still would not really catch an issue where the method signature of zigpy's cluster.configure_reporting_multiple changes. I guess we'd have to properly test the configure_reporting_multiple method in ZHA then and check the final zigpy requests..

I'd keep this PR as is now.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_multiple calls 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)):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +438 to 447
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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@puddly
Copy link
Copy Markdown
Contributor

puddly commented Feb 13, 2026

I've tested this PR as well (along with all of the other zigpy + ZHA changes) and it works as expected.

@puddly puddly merged commit b5e3a92 into zigpy:dev Feb 13, 2026
9 checks passed
@jclsn
Copy link
Copy Markdown

jclsn commented Feb 14, 2026

The fixes haven't landed in 26.2.2, have they?

@puddly
Copy link
Copy Markdown
Contributor

puddly commented Feb 14, 2026

They have.

@jclsn
Copy link
Copy Markdown

jclsn commented Feb 14, 2026

Ah found it home-assistant/core#162894

@jclsn
Copy link
Copy Markdown

jclsn commented Feb 14, 2026

Yeah works again. Firmware versions are still unknown, but I guess this is related to something else?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants