Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prairiesnpr committed Feb 16, 2025
1 parent 6da00a2 commit d41b0e4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
62 changes: 35 additions & 27 deletions tests/test_tuya.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import zhaquirks.tuya.ts0043
import zhaquirks.tuya.ts011f_plug
import zhaquirks.tuya.ts0501_fan_switch
import zhaquirks.tuya.ts0601_electric_heating
import zhaquirks.tuya.ts0601_trv
import zhaquirks.tuya.ts1201
import zhaquirks.tuya.tuya_motion
Expand Down Expand Up @@ -1326,11 +1325,24 @@ async def async_success(*args, **kwargs):
datetime.datetime = origdatetime


@pytest.mark.parametrize("quirk", (zhaquirks.tuya.ts0601_electric_heating.MoesBHT,))
async def test_eheating_state_report(zigpy_device_from_quirk, quirk):
@pytest.mark.parametrize(
"model,manuf",
[
("_TZE200_aoclfnxz", "TS0601"),
("_TZE200_ztvwu4nk", "TS0601"),
("_TZE204_5toc8efa", "TS0601"),
("_TZE200_5toc8efa", "TS0601"),
("_TZE200_ye5jkfsb", "TS0601"),
("_TZE204_aoclfnxz", "TS0601"),
("_TZE200_u9bfwha0", "TS0601"),
("_TZE204_u9bfwha0", "TS0601"),
("_TZE204_xalsoe3m", "TS0601"),
],
)
async def test_eheating_state_report(zigpy_device_from_v2_quirk, model, manuf):
"""Test thermostatic valves standard reporting from incoming commands."""

electric_dev = zigpy_device_from_quirk(quirk)
electric_dev = zigpy_device_from_v2_quirk(model, manuf)
tuya_cluster = electric_dev.endpoints[1].tuya_manufacturer

thermostat_listener = ClusterListener(electric_dev.endpoints[1].thermostat)
Expand All @@ -1348,11 +1360,24 @@ async def test_eheating_state_report(zigpy_device_from_quirk, quirk):
assert thermostat_listener.attribute_updates[1][1] == 2100


@pytest.mark.parametrize("quirk", (zhaquirks.tuya.ts0601_electric_heating.MoesBHT,))
async def test_eheat_send_attribute(zigpy_device_from_quirk, quirk):
@pytest.mark.parametrize(
"model,manuf",
[
("_TZE200_aoclfnxz", "TS0601"),
("_TZE200_ztvwu4nk", "TS0601"),
("_TZE204_5toc8efa", "TS0601"),
("_TZE200_5toc8efa", "TS0601"),
("_TZE200_ye5jkfsb", "TS0601"),
("_TZE204_aoclfnxz", "TS0601"),
("_TZE200_u9bfwha0", "TS0601"),
("_TZE204_u9bfwha0", "TS0601"),
("_TZE204_xalsoe3m", "TS0601"),
],
)
async def test_eheat_send_attribute(zigpy_device_from_v2_quirk, model, manuf):
"""Test electric thermostat outgoing commands."""

eheat_dev = zigpy_device_from_quirk(quirk)
eheat_dev = zigpy_device_from_v2_quirk(model, manuf)
tuya_cluster = eheat_dev.endpoints[1].tuya_manufacturer
thermostat_cluster = eheat_dev.endpoints[1].thermostat

Expand All @@ -1367,6 +1392,7 @@ async def async_success(*args, **kwargs):
"occupied_heating_setpoint": 2500,
}
)
await wait_for_zigpy_tasks()
m1.assert_called_with(
cluster=0xEF00,
sequence=1,
Expand All @@ -1387,6 +1413,7 @@ async def async_success(*args, **kwargs):
"system_mode": 0x00,
}
)
await wait_for_zigpy_tasks()
m1.assert_called_with(
cluster=0xEF00,
sequence=2,
Expand All @@ -1407,6 +1434,7 @@ async def async_success(*args, **kwargs):
"system_mode": 0x04,
}
)
await wait_for_zigpy_tasks()
m1.assert_called_with(
cluster=0xEF00,
sequence=3,
Expand All @@ -1422,26 +1450,6 @@ async def async_success(*args, **kwargs):
foundation.WriteAttributesStatusRecord(foundation.Status.SUCCESS)
]

# simulate a target temp update so that relative changes can work
hdr, args = tuya_cluster.deserialize(ZCL_TUYA_EHEAT_TARGET_TEMP)
tuya_cluster.handle_message(hdr, args)
_, status = await thermostat_cluster.command(0x0000, 0x00, 20)
m1.assert_called_with(
cluster=0xEF00,
sequence=4,
data=b"\x01\x04\x00\x00\x04\x10\x02\x00\x04\x00\x00\x00\x17",
command_id=0,
timeout=5,
expect_reply=False,
use_ieee=False,
ask_for_ack=None,
priority=t.PacketPriority.NORMAL,
)
assert status == foundation.Status.SUCCESS

_, status = await thermostat_cluster.command(0x0002)
assert status == foundation.Status.UNSUP_CLUSTER_COMMAND


@pytest.mark.parametrize(
"quirk, manufacturer",
Expand Down
8 changes: 4 additions & 4 deletions zhaquirks/tuya/tuya_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ def handle_mcu_version_response(
ep_attribute=TuyaThermostat.ep_attribute,
attribute_name=TuyaThermostat.AttributeDefs.system_mode.name,
converter=lambda x: {
0x01: Thermostat.SystemMode.Heat,
0x00: Thermostat.SystemMode.Off,
True: Thermostat.SystemMode.Heat,
False: Thermostat.SystemMode.Off,
}[x],
dp_converter=lambda x: {
Thermostat.SystemMode.Heat: 0x01,
Thermostat.SystemMode.Off: 0x00,
Thermostat.SystemMode.Heat: True,
Thermostat.SystemMode.Off: False,
}[x],
)
.tuya_switch(
Expand Down

0 comments on commit d41b0e4

Please sign in to comment.