Fix Tuya PowerConfiguration clusters on quirks without battery_bus
#3554
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.
Proposed change
This fixes an issue where you were unable to use
TuyaPowerConfigurationCluster2AA
andTuyaPowerConfigurationCluster3AA
in modern quirks that do not create abattery_bus
inCustomDevice
.TuyaPowerConfigurationCluster2AAA
andTuyaPowerConfigurationCluster4AA
are already able to be used without abattery_bus
though.This inconsistency is fixed by this PR, whilst keeping the legacy behavior for the Tuya TRV quirks.
This is done by checking if the
battery_bus
attribute exists before we start listening to it.Additional information
This change is required by #3505
TODO
We need to fix two(?) Tuya TRV quirks (that are immensely broken in other ways too) in our repo to no longer emit events to the
battery_bus
. That's easy, but we cannot fix custom quirks:Custom quirks
The Tuya TRV quirks in this repo are incomplete and broken, so everyone uses custom quirks, e.g. from here: https://github.com/jacekk015/zha_quirks
Those quirks still depend on the
battery_bus
for these clusters, so we would break a lot of people's setups. The repo alone already has 145 stars at the moment. A lot of people that use custom quirks do not even have a GitHub account, so the real usage number is much higher.As we can easily avoid breaking these custom quirks here, we do it.
Generally though, custom quirks remain completely unsupported.
Future
We'll need to redo all Tuya TRV quirks. Remove all global variables (that break when you have more than one device using the same quirk), remove virtual
OnOff
andAnalogInput
clusters for user configuration, convert those quirks to expose quirks v2 entities, and more..Hopefully, #1961 can be picked up again at some point. It was really close and would have at least supported some Tuya TRVs with a good basis.
However, we should use quirks v2 entities for that and not define them in ZHA. This is especially important for Tuya devices, as there are many variations and we want contributors to easily add support for slight variations, without needing to dig in multiple codebases.
If we have fixed our Tuya TRV quirks, we can also get rid of this workaround (and remove
Bus
entirely?).cc @prairiesnpr (per #3550 and discussion)
Checklist
pre-commit
checks pass / the code has been formatted using Black