Fix Tuya Saswell TRVs causing ZHA to generate new climate entity #3846
+21
−4
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 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-reportedSMART_PLUG
toTHERMOSTAT
. As thisDEVICE_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
toTHERMOSTAT
. E.g. this one: https://github.com/jacekk015/zha_quirks/blob/dcfc3beb98008bbb40780dbcf4f38af82c117e5d/ts0601_trv_me167.py#L466-L493So, 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
[BUG] Tuya TS0601 TRV temperature offset not exposed after 2025.2.0 #3837
Checklist
pre-commit
checks pass / the code has been formatted using Black