Skip to content

Commit 22cccb1

Browse files
committed
Add test for TY0201 quirk handling bad ZCL direction
Introduces a test to verify that the TY0201 quirk correctly handles devices sending ZCL commands with an incorrect direction. The test ensures no direction-related warnings are logged and that the custom TY0201Device class is used.
1 parent be4e97f commit 22cccb1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_tuya.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,3 +2023,38 @@ async def test_ts601_door_sensor(
20232023
attrs = await cluster.read_attributes(attributes=[attribute])
20242024

20252025
assert attrs[0].get(attribute) == expected_value
2026+
2027+
2028+
async def test_ty0201_bad_direction(zigpy_device_from_v2_quirk, caplog):
2029+
"""Test TY0201 quirk dealing with bad ZCL command direction."""
2030+
import logging
2031+
2032+
import zhaquirks.tuya.ty0201
2033+
2034+
# Use one of the TY0201 device signatures from our quirk
2035+
device = zigpy_device_from_v2_quirk("_TZ3000_zl1kmjqx", "TY0201")
2036+
2037+
# The device has a bad ZCL header and reports the incorrect direction for commands
2038+
with caplog.at_level(logging.WARNING):
2039+
device.packet_received(
2040+
t.ZigbeePacket(
2041+
profile_id=260,
2042+
cluster_id=0, # Basic cluster
2043+
src_ep=1,
2044+
dst_ep=1,
2045+
data=t.SerializableBytes(bytes.fromhex("18930A00001001")),
2046+
)
2047+
)
2048+
2049+
# No direction-related warning gets logged because our direction fix handles it
2050+
direction_warnings = [
2051+
record
2052+
for record in caplog.records
2053+
if record.levelno >= logging.WARNING
2054+
and "direction" in record.getMessage().lower()
2055+
]
2056+
assert not direction_warnings
2057+
2058+
# Our matching logic should be forgiving and handle the direction fix
2059+
# The device should use our custom TY0201Device class with direction fix
2060+
assert isinstance(device, zhaquirks.tuya.ty0201.TY0201Device)

0 commit comments

Comments
 (0)