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 Saswell TRVs causing ZHA to generate new climate entity #3846

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

TheJulianJES
Copy link
Collaborator

@TheJulianJES TheJulianJES commented Feb 9, 2025

Proposed change

This works around an issue in ZHA where the updated v2 quirk for the Tuya Saswell TRV caused ZHA to generate a new climate entity.

Cause

The v2 quirk replaced an old v1 quirk in #3772. The v1 quirk changed the DEVICE_TYPE for endpoint 1 from the Tuya-reported SMART_PLUG to THERMOSTAT. As this DEVICE_TYPE is generally not used anymore, we do not change them in v2 quirks.
However, there's some old legacy code in ZHA that changes unique IDs depending on if ZHA and HA platform match. This is rarely the case (the code is somewhat bad), but for thermostats, it unfortunately applied before: https://github.com/zigpy/zha/blob/d6bb4a89ff857137e96b2932f711f1bdb2fbe80b/zha/application/discovery.py#L564-L573

So, we need to change back the profile type to THERMOSTAT for Tuya Saswell TRVs again, like the v1 quirk did.
In the future, we should really remove that code in ZHA and migrate existing UIDs to new ones.

Other v2 TRV quirks

Some other v2 TRV quirks were added in 0.0.131 too, but I think this was the only TRV quirk that replaced an existing v1 quirk. If we were to change this for all v2 quirks, we'd break the entity used by everyone in 2025.2.0 and 2025.1.

But if they were using custom quirks before, they would have already changed the DEVICE_TYPE to THERMOSTAT. E.g. this one: https://github.com/jacekk015/zha_quirks/blob/dcfc3beb98008bbb40780dbcf4f38af82c117e5d/ts0601_trv_me167.py#L466-L493
So, for those people, it already broke in 2025.2.x and adding this to all v2 TRV quirks would restore functionality.

Now, we don't support custom quirks, of course. But it's an unfortunate reality that they're used a lot in production instances, without being contributed upstream. Maybe we do want to add this to all Tuya v2 TRV (+ thermostat?) quirks for now, so they cause ZHA to use the same unique ID?

(cc @prairiesnpr for thoughts on this when you're back 😄)

Additional information

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 Feb 9, 2025
Copy link

codecov bot commented Feb 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.93%. Comparing base (8b92f69) to head (f2e5e24).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #3846   +/-   ##
=======================================
  Coverage   90.93%   90.93%           
=======================================
  Files         326      326           
  Lines       10591    10592    +1     
=======================================
+ Hits         9631     9632    +1     
  Misses        960      960           

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

@TheJulianJES TheJulianJES added this to the 2025.2 milestone Feb 9, 2025
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