Skip to content

Add LocalDataCluster._DEFAULT_VALUES#4771

Draft
TheJulianJES wants to merge 2 commits intozigpy:devfrom
TheJulianJES:tjj/localdatacluster_default_values
Draft

Add LocalDataCluster._DEFAULT_VALUES#4771
TheJulianJES wants to merge 2 commits intozigpy:devfrom
TheJulianJES:tjj/localdatacluster_default_values

Conversation

@TheJulianJES
Copy link
Collaborator

@TheJulianJES TheJulianJES commented Feb 19, 2026

Proposed change

This adds a _DEFAULT_VALUES dict to LocalDataCluster, similar to _CONSTANT_ATTRIBUTES.
This allows quirks using LocalDataCluster to set default values that can be overridden, unlike _CONSTANT_ATTRIBUTES.

TODO: Tests

Additional information

There are multiple issues with the current pattern of checking attrid not in self._attr_cache and then using update_attribute:

There's an issue though: The Aqara feeder implementation also uses default values, but it's not a LocalDataCluster. That should be converted and/or we should consider moving this into zigpy's CustomCluster, where the _CONSTANT_ATTRIBUTES also (partly) live already.

In the future, we can also look at making _CONSTANT_ATTRIBUTES, _VALID_ATTRIBUTES, and _DEFAULT_VALUES (only) compatible with ZCLAttributeDef and/or name, instead of just IDs.
I'd do that in a separate PR though and keep the implementations consistent for now.

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
  • Device diagnostics data has been attached

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.29%. Comparing base (40b41de) to head (69cd7f0).

Files with missing lines Patch % Lines
zhaquirks/__init__.py 76.92% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #4771      +/-   ##
==========================================
- Coverage   92.32%   92.29%   -0.03%     
==========================================
  Files         371      371              
  Lines       12190    12191       +1     
==========================================
- Hits        11254    11252       -2     
- Misses        936      939       +3     

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

Comment on lines 702 to 708
# Previously, this cluster was wrongly setting the total_active_power attribute,
# which was not added to HA.
# Since it is now added to HA and the incorrect value could be set, we need to
# reset it.
self._update_attribute(
ElectricalMeasurement.AttributeDefs.total_active_power.id, None
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll need to look into this as well (to clear an attribute). Or maybe have an _UNSUPPORTED_ATTRIBUTES constant in LocalDataCluster and/or CustomCluster as well? It would also help for some Tuya quirks...

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.

1 participant

Comments