|
2 | 2 |
|
3 | 3 | import base64
|
4 | 4 | import datetime
|
| 5 | +import logging |
5 | 6 | import struct
|
6 | 7 | from typing import Final
|
7 | 8 | from unittest import mock
|
|
14 | 15 | from zigpy.quirks import CustomDevice, get_device
|
15 | 16 | import zigpy.types as t
|
16 | 17 | from zigpy.zcl import foundation
|
17 |
| -from zigpy.zcl.clusters.general import PowerConfiguration |
| 18 | +from zigpy.zcl.clusters.general import Basic, PowerConfiguration |
18 | 19 | from zigpy.zcl.clusters.security import IasZone, ZoneStatus
|
19 | 20 | from zigpy.zcl.foundation import ZCLAttributeDef
|
20 | 21 |
|
@@ -2023,3 +2024,31 @@ async def test_ts601_door_sensor(
|
2023 | 2024 | attrs = await cluster.read_attributes(attributes=[attribute])
|
2024 | 2025 |
|
2025 | 2026 | 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