Add _VALID_ATTRIBUTES
to LocalDataCluster, fix Tuya datapoint mappings on LocalDataClusters
#3415
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.
UNTESTED
This should probably be tested with some actual devices. Unit tests pass already.
Proposed change
This adds
_VALID_ATTRIBUTES
toLocalDataCluster
.This allows entities in ZHA to be created*, as the initial attribute reads will return
None
with success status, instead of "unsupported attribute" for all attributes in the_VALID_ATTRIBUTES
list.The PR also automatically adds all mapped to attributes from Tuya datapoints on
LocalDataClusters
to_VALID_ATTRIBUTES
to ensure entities in ZHA can be created on pairing.A basic test checking that attribute reads work as expected on a
LocalDataCluster
is also added.*: Do note that some entities in ZHA will not be created for
None
as a value in the attribute cache. This is only the case for configuration switch, configuration select, and configuration number entities IIRC. This should not be an issue, as this PR is mainly intended to fix the "actual ZCL entities" like temperature sensors and so on. Those are also created withNone
values on pairing.I explicitly chose to not populate the attribute cache with "valid" numbers like
0
, as the data type can vary and that's somewhat unclean in general. If needed, we can add aninitial_value
toDPToAttributeMapping
in the future, but I do not think this will be an issue at all.For ZCL devices, the attribute cache will also contain
None
at first. We just follow that behavior for Tuya devices that use aLocalDataCluster
with an attribute being mapped to from a Tuya datapoint.Additional information
Other non-Tuya quirks should likely also utilize
_VALID_ATTRIBUTES
if they are currently using aLocalDataCluster
where some attributes are only updated later and not when a device is initially paired.I've also noticed that a bunch of Tuya mappings do not exist on some quirks. It's not really an issue though, but I needed to account for that.
If the PR approach is good, then I'll probably split the PR to only include the_VALID_ATTRIBUTES
part in this PR and have a second PR with the third commit for the Tuya mapped attributes being initialized as "valid".EDIT: It was both done in this PR now.
Checklist
pre-commit
checks pass / the code has been formatted using Black