-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tuya TRV
_TZE204_ogx8u5z6
(#3682)
- Loading branch information
1 parent
f1b8f5c
commit 567660d
Showing
2 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
"""Test for Tuya TRV.""" | ||
|
||
from unittest import mock | ||
|
||
import pytest | ||
import zigpy.types as t | ||
from zigpy.zcl import foundation | ||
from zigpy.zcl.clusters.hvac import Thermostat | ||
|
||
from tests.common import ClusterListener, wait_for_zigpy_tasks | ||
import zhaquirks | ||
from zhaquirks.tuya.mcu import TuyaMCUCluster | ||
|
||
zhaquirks.setup() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"msg,attr,value", | ||
[ | ||
( | ||
b"\t\xc2\x02\x00q\x02\x04\x00\x01\x00", | ||
Thermostat.AttributeDefs.system_mode, | ||
Thermostat.SystemMode.Auto, | ||
), # Set to Auto (0x00), dp 2 | ||
( | ||
b"\t\xc3\x02\x00r\x02\x04\x00\x01\x01", | ||
Thermostat.AttributeDefs.system_mode, | ||
Thermostat.SystemMode.Heat, | ||
), # Set to Heat (0x01), dp 2 | ||
( | ||
b"\t\xc2\x02\x00q\x02\x04\x00\x01\x02", | ||
Thermostat.AttributeDefs.system_mode, | ||
Thermostat.SystemMode.Off, | ||
), # Set to Off (0x02), dp 2 | ||
], | ||
) | ||
async def test_handle_get_data(zigpy_device_from_v2_quirk, msg, attr, value): | ||
"""Test handle_get_data for multiple attributes.""" | ||
|
||
quirked = zigpy_device_from_v2_quirk("_TZE204_ogx8u5z6", "TS0601") | ||
ep = quirked.endpoints[1] | ||
|
||
assert ep.tuya_manufacturer is not None | ||
assert isinstance(ep.tuya_manufacturer, TuyaMCUCluster) | ||
|
||
assert ep.thermostat is not None | ||
assert isinstance(ep.thermostat, Thermostat) | ||
|
||
thermostat_listener = ClusterListener(ep.thermostat) | ||
|
||
hdr, data = ep.tuya_manufacturer.deserialize(msg) | ||
status = ep.tuya_manufacturer.handle_get_data(data.data) | ||
assert status == foundation.Status.SUCCESS | ||
|
||
assert len(thermostat_listener.attribute_updates) == 1 | ||
assert thermostat_listener.attribute_updates[0][0] == attr.id | ||
assert thermostat_listener.attribute_updates[0][1] == value | ||
|
||
assert ep.thermostat.get(attr.id) == value | ||
|
||
async def async_success(*args, **kwargs): | ||
return foundation.Status.SUCCESS | ||
|
||
with mock.patch.object( | ||
ep.tuya_manufacturer.endpoint, "request", side_effect=async_success | ||
) as m1: | ||
(status,) = await ep.thermostat.write_attributes( | ||
{ | ||
"occupied_heating_setpoint": 2500, | ||
} | ||
) | ||
await wait_for_zigpy_tasks() | ||
m1.assert_called_with( | ||
cluster=0xEF00, | ||
sequence=1, | ||
data=b"\x01\x01\x00\x00\x01\x04\x02\x00\x04\x00\x00\x00\xfa", | ||
command_id=0, | ||
timeout=5, | ||
expect_reply=False, | ||
use_ieee=False, | ||
ask_for_ack=None, | ||
priority=t.PacketPriority.NORMAL, | ||
) | ||
assert status == [ | ||
foundation.WriteAttributesStatusRecord(foundation.Status.SUCCESS) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters