Skip to content

Commit 947a8ae

Browse files
authored
Improve Tuya local temp calibration, remove setpoint min/max (#3877)
1 parent 2a96ada commit 947a8ae

File tree

4 files changed

+128
-17
lines changed

4 files changed

+128
-17
lines changed

tests/test_tuya_thermostat.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
Thermostat.AttributeDefs.occupied_heating_setpoint,
3737
2500,
3838
), # Setpoint to 25, dp 16
39-
(
40-
"_TZE204_p3lqqy2r",
41-
b"\t\x17\x02\x00\n\x1c\x02\x00\x04\x00\x00\x00\x00",
42-
Thermostat.AttributeDefs.local_temperature_calibration,
43-
0,
44-
), # Local calibration to 0, dp 28
4539
(
4640
"_TZE204_p3lqqy2r",
4741
b"\t\x1c\x02\x00\x0fh\x01\x00\x01\x01",
@@ -121,3 +115,46 @@ async def test_tuya_no_mcu_version(zigpy_device_from_v2_quirk):
121115

122116
tuya_cluster.handle_message(hdr, args)
123117
assert len(cluster_listener.attribute_updates) == 0
118+
119+
120+
@pytest.mark.parametrize(
121+
"manuf,msg,dp_id,value",
122+
[
123+
(
124+
"_TZE204_p3lqqy2r",
125+
b"\t\x1d\x02\x00\x10\x1c\x02\x00\x04\xff\xff\xff\xf7",
126+
28,
127+
-9,
128+
), # Local temp calibration to -2, dp 28
129+
(
130+
"_TZE204_lzriup1j",
131+
b"\t\x1d\x02\x00\x10\x13\x02\x00\x04\xff\xff\xff\x9d",
132+
19,
133+
-99,
134+
), # Local temp calibration to -9.9, dp 19
135+
],
136+
)
137+
async def test_handle_get_data_tmcu(
138+
zigpy_device_from_v2_quirk, manuf, msg, dp_id, value
139+
):
140+
"""Test handle_get_data for multiple attributes."""
141+
142+
attr_id = (0xEF << 8) | dp_id
143+
144+
quirked = zigpy_device_from_v2_quirk(manuf, "TS0601")
145+
ep = quirked.endpoints[1]
146+
147+
assert ep.tuya_manufacturer is not None
148+
assert isinstance(ep.tuya_manufacturer, TuyaMCUCluster)
149+
150+
tmcu_listener = ClusterListener(ep.tuya_manufacturer)
151+
152+
hdr, data = ep.tuya_manufacturer.deserialize(msg)
153+
status = ep.tuya_manufacturer.handle_get_data(data.data)
154+
assert status == foundation.Status.SUCCESS
155+
156+
assert len(tmcu_listener.attribute_updates) == 1
157+
assert tmcu_listener.attribute_updates[0][0] == attr_id
158+
assert tmcu_listener.attribute_updates[0][1] == value
159+
160+
assert ep.tuya_manufacturer.get(attr_id) == value

tests/test_tuya_trv.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,52 @@ async def async_success(*args, **kwargs):
190190
assert status == [
191191
foundation.WriteAttributesStatusRecord(foundation.Status.SUCCESS)
192192
]
193+
194+
195+
@pytest.mark.parametrize(
196+
"manuf,msg,dp_id,value",
197+
[
198+
(
199+
"_TZE200_3yp57tby",
200+
b"\t\x1d\x02\x00\x10\x1b\x02\x00\x04\xff\xff\xff\xfa",
201+
27,
202+
-6,
203+
), # Local temp calibration to -6, dp 27
204+
(
205+
"_TZE204_rtrmfadk",
206+
b"\t\x1d\x02\x00\x10\x65\x02\x00\x04\xff\xff\xff\xfa",
207+
101,
208+
-6,
209+
), # Local temp calibration to -6, dp 101
210+
(
211+
"_TZE284_ogx8u5z6",
212+
b"\t\x1d\x02\x00\x10\x2f\x02\x00\x04\xff\xff\xff\xfa",
213+
47,
214+
-6,
215+
), # Local temp calibration to -6, dp 47
216+
],
217+
)
218+
async def test_handle_get_data_tmcu(
219+
zigpy_device_from_v2_quirk, manuf, msg, dp_id, value
220+
):
221+
"""Test handle_get_data for multiple attributes."""
222+
223+
attr_id = (0xEF << 8) | dp_id
224+
225+
quirked = zigpy_device_from_v2_quirk(manuf, "TS0601")
226+
ep = quirked.endpoints[1]
227+
228+
assert ep.tuya_manufacturer is not None
229+
assert isinstance(ep.tuya_manufacturer, TuyaMCUCluster)
230+
231+
tmcu_listener = ClusterListener(ep.tuya_manufacturer)
232+
233+
hdr, data = ep.tuya_manufacturer.deserialize(msg)
234+
status = ep.tuya_manufacturer.handle_get_data(data.data)
235+
assert status == foundation.Status.SUCCESS
236+
237+
assert len(tmcu_listener.attribute_updates) == 1
238+
assert tmcu_listener.attribute_updates[0][0] == attr_id
239+
assert tmcu_listener.attribute_updates[0][1] == value
240+
241+
assert ep.tuya_manufacturer.get(attr_id) == value

zhaquirks/tuya/tuya_thermostat.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ def __init__(self, *args, **kwargs):
114114
)
115115
self.add_unsupported_attribute(Thermostat.AttributeDefs.pi_heating_demand.id)
116116

117+
# Previously mapped, marking as explicitly unsupported.
118+
self.add_unsupported_attribute(
119+
Thermostat.AttributeDefs.local_temperature_calibration.id
120+
)
121+
117122

118123
class NoManufTimeNoVersionRespTuyaMCUCluster(TuyaMCUCluster):
119124
"""Tuya Manufacturer Cluster with set_time mod."""
@@ -173,12 +178,16 @@ def handle_mcu_version_response(
173178
attribute_name=TuyaThermostat.AttributeDefs.local_temperature.name,
174179
converter=lambda x: x * 100,
175180
)
176-
.tuya_dp(
181+
.tuya_number(
177182
dp_id=28,
178-
ep_attribute=TuyaThermostat.ep_attribute,
179-
attribute_name=Thermostat.AttributeDefs.local_temperature_calibration.name,
180-
converter=lambda x: x * 100,
181-
dp_converter=lambda x: x // 100,
183+
attribute_name=TuyaThermostat.AttributeDefs.local_temperature_calibration.name,
184+
type=t.int32s,
185+
min_value=-9,
186+
max_value=9,
187+
unit=UnitOfTemperature.CELSIUS,
188+
step=1,
189+
translation_key="local_temperature_calibration",
190+
fallback_name="Local temperature calibration",
182191
)
183192
.tuya_switch(
184193
dp_id=30,
@@ -341,12 +350,17 @@ def handle_mcu_version_response(
341350
converter=lambda x: x * 10,
342351
dp_converter=lambda x: x // 10,
343352
)
344-
.tuya_dp(
353+
.tuya_number(
345354
dp_id=19,
346-
ep_attribute=TuyaThermostat.ep_attribute,
347355
attribute_name=TuyaThermostat.AttributeDefs.local_temperature_calibration.name,
348-
converter=lambda x: x * 10,
349-
dp_converter=lambda x: x // 10,
356+
type=t.int32s,
357+
min_value=-9.9,
358+
max_value=9.9,
359+
unit=UnitOfTemperature.CELSIUS,
360+
step=0.1,
361+
multiplier=0.1,
362+
translation_key="local_temperature_calibration",
363+
fallback_name="Local temperature calibration",
350364
)
351365
.tuya_dp(
352366
dp_id=101,

zhaquirks/tuya/tuya_trv.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class TuyaThermostatV2(Thermostat, TuyaAttributesCluster):
5151
"""Tuya local thermostat cluster."""
5252

5353
_CONSTANT_ATTRIBUTES = {
54-
Thermostat.AttributeDefs.min_heat_setpoint_limit.id: 500,
55-
Thermostat.AttributeDefs.max_heat_setpoint_limit.id: 3000,
54+
Thermostat.AttributeDefs.abs_min_heat_setpoint_limit.id: 500,
55+
Thermostat.AttributeDefs.abs_max_heat_setpoint_limit.id: 3000,
5656
Thermostat.AttributeDefs.ctrl_sequence_of_oper.id: Thermostat.ControlSequenceOfOperation.Heating_Only,
5757
}
5858

@@ -67,6 +67,17 @@ def __init__(self, *args, **kwargs):
6767
)
6868
self.add_unsupported_attribute(Thermostat.AttributeDefs.pi_heating_demand.id)
6969

70+
# Previously mapped, marking as explicitly unsupported.
71+
self.add_unsupported_attribute(
72+
Thermostat.AttributeDefs.local_temperature_calibration.id
73+
)
74+
self.add_unsupported_attribute(
75+
Thermostat.AttributeDefs.min_heat_setpoint_limit.id
76+
)
77+
self.add_unsupported_attribute(
78+
Thermostat.AttributeDefs.max_heat_setpoint_limit.id
79+
)
80+
7081

7182
(
7283
TuyaQuirkBuilder("_TYST11_KGbxAXL2", "GbxAXL2")

0 commit comments

Comments
 (0)