Add _DEFAULT_VALUES to CustomCluster#1777
Draft
TheJulianJES wants to merge 3 commits intozigpy:devfrom
Draft
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1777 +/- ##
==========================================
- Coverage 99.52% 99.49% -0.04%
==========================================
Files 63 63
Lines 12715 12727 +12
==========================================
+ Hits 12655 12663 +8
- Misses 60 64 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
4 tasks
4 tasks
Contributor
Author
|
For reference, I've merged the quirks-only The quirks are all migrated as well. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DRAFT: Tests not committed yet + questions below (sorry for the wall of text again)
Proposed change
This adds
_DEFAULT_VALUEStoCustomCluster, essentially implementing this zha-quirks PR directly in zigpy:LocalDataCluster._DEFAULT_VALUESand migrate quirks zha-device-handlers#4771This allows quirks to provide default values to be used by ZHA (i.e. using
Cluster.get) when the device hasn't filled the attribute cache with a real value yet.Additional information
read_attributes_rawoverrideThe implementation for
CustomCluster.getis fine, butread_attributes_rawis a bit more complicated, as we only want to use the defaults if the device doesn't support the attribute.Now, I'm not sure whether we actually need this. AFAIK, we don't really use
read_attributesoutput directly anywhere, but this implementation would be consistent with_CONSTANT_ATTRIBUTES.I wonder if we can only keep that implementation in
CustomClusterfor_CONSTANT_ATTRIBUTES, but essentially revert the changes toread_attributes_rawfor_DEFAULT_VALUESfrom this PR. Thoughts?Or, should
read_attributespopulate the attribute cache normally, but instead of directly returning the results from the device read, we return them from the attribute cache viaCluster.get, so we can simplify some of the read attributes logic?Attribute values leaking into zigpy DB
Also, when
read_attributesreads attributes that are either in_CONSTANT_ATTRIBUTESor_DEFAULT_VALUES, those quirks-defined values will also leak into the zigpy DB. Ideally, this would not be the case at all. With how we overrideread_attributes_raw, this really isn't possible to do though.But implementing support for this in
read_attributes(or overridingread_attributes) also doesn't sound that great?Maybe there could be a separate
read_update_attributemethod it calls per attribute, which we can override inCustomClusterto ignore updating attribute cache for reads from constant attributes (or possibly even for default values)?Future PRs
In a future PR, I likely also want to implement
_UNSUPPORTED_ATTRIBUTES, as we have some quirks that currently callself.add_unsupported_attribute(attr.id)inCluster.__init__.In another PR, we should allow
_CONSTANT_ATTRIBUTESand_DEFAULT_VALUESto also acceptZCLAttributeDef(and attribute names?) directly. For now, this isn't really needed and is consistent with the implementation for_CONSTANT_ATTRIBUTES, which also only accepts attribute IDs.Side note:
LocalDataClusterThe
LocalDataClusteris also a bit weird in general, but maybe not for the reasons you think. It's crucial for complicated quirks and actually works really nicely. Obviously, it would be nice to have a better API that's separate from ZCL, but it does allow us to point quirks v2 entities at such aLocalDataCluster. When we have a better API – that could actually be really similar toCluster/LocalDataCluster– we can just swap out the cluster logic then and keep the same quirks v2 entities.Now, it's a bit weird in the regard that the
LocalDataClusterstill allows attribute reports from the device to come through if you use acluster_idthat's already present on the device. Unfortunately, I believe some quirks rely on this behavior now...?The
LocalDataClusteralso needs to re-implementread_attributes_rawsomewhat to fully prevent device reads and only use_CONSTANT_ATTRIBUTES(and_DEFAULT_VALUES). I almost wonder if it makes sense to add constants toCustomClusterin a similar style, like_PREVENT_READS(and possibly prevent write, ...)?I'm not sure though, but we'd have to repeat less of the logic in
LocalDataCluster. For now, I don't think it's a big deal, since that logic is only in two places and we can easily rework it in the future.Unintended (breaking) zigpy change?
Also, zigpy was recently changed to drop
_update_attributecalls inwrite_attributes(previous, now). Luckily, we've not noticed any quirks breaking, so far(?)However, the
LocalDataClusterstill calls_update_attributein itswrite_attributeshere. I guess also removing that could break actually break some quirks? I'm not sure if any quirks really rely on that behavior though, or if they use/overridewrite_attributes. At least Tuya quirks seem to usewrite_attributesfor the (fake) ZCL -> Tuya DP conversion.We should look at this in the future.