Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tuya PowerConfiguration clusters on quirks without battery_bus #3554

Merged

Conversation

TheJulianJES
Copy link
Collaborator

@TheJulianJES TheJulianJES commented Nov 27, 2024

Proposed change

This fixes an issue where you were unable to use TuyaPowerConfigurationCluster2AA and TuyaPowerConfigurationCluster3AA in modern quirks that do not create a battery_bus in CustomDevice.

TuyaPowerConfigurationCluster2AAA and TuyaPowerConfigurationCluster4AA are already able to be used without a battery_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 and AnalogInput 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

  • 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

@TheJulianJES TheJulianJES added Tuya Request/PR regarding a Tuya device bugfix This PR fixes a bug labels Nov 27, 2024
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.75%. Comparing base (8c68870) to head (ff08a83).
Report is 1 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #3554   +/-   ##
=======================================
  Coverage   89.74%   89.75%           
=======================================
  Files         320      320           
  Lines       10370    10371    +1     
=======================================
+ Hits         9307     9308    +1     
  Misses       1063     1063           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheJulianJES TheJulianJES merged commit 7995008 into zigpy:dev Nov 27, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR fixes a bug Tuya Request/PR regarding a Tuya device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant