Skip to content

Commit fcf23ac

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 fcf23ac

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tests/test_tuya.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import base64
44
import datetime
5+
import logging
56
import struct
67
from typing import Final
78
from unittest import mock
@@ -14,7 +15,7 @@
1415
from zigpy.quirks import CustomDevice, get_device
1516
import zigpy.types as t
1617
from zigpy.zcl import foundation
17-
from zigpy.zcl.clusters.general import PowerConfiguration
18+
from zigpy.zcl.clusters.general import Basic, PowerConfiguration
1819
from zigpy.zcl.clusters.security import IasZone, ZoneStatus
1920
from zigpy.zcl.foundation import ZCLAttributeDef
2021

@@ -2023,3 +2024,31 @@ async def test_ts601_door_sensor(
20232024
attrs = await cluster.read_attributes(attributes=[attribute])
20242025

20252026
assert attrs[0].get(attribute) == expected_value
2027+
2028+
2029+
async def test_ty0201_bad_direction(zigpy_device_from_v2_quirk, caplog):
2030+
"""Test TY0201 quirk dealing with bad ZCL command direction."""
2031+
2032+
device = zigpy_device_from_v2_quirk("_TZ3000_zl1kmjqx", "TY0201")
2033+
listener = ClusterListener(device.endpoints[1].in_clusters[Basic.cluster_id])
2034+
2035+
# The device has a bad ZCL header and reports the incorrect direction for commands
2036+
with caplog.at_level(logging.WARNING):
2037+
device.packet_received(
2038+
t.ZigbeePacket(
2039+
profile_id=260,
2040+
cluster_id=0, # Basic cluster
2041+
src_ep=1,
2042+
dst_ep=1,
2043+
data=t.SerializableBytes(bytes.fromhex("00930A00001001")),
2044+
)
2045+
)
2046+
2047+
# No warning gets logged
2048+
warning_messages = [
2049+
record.message for record in caplog.records if record.levelname == "WARNING"
2050+
]
2051+
assert not warning_messages
2052+
2053+
# Our matching logic should be forgiving
2054+
assert listener.attribute_updates == [(0, t.Bool.true)]

0 commit comments

Comments
 (0)