Skip to content

Commit 48c6150

Browse files
committed
Just use enchantment with data spell
1 parent 13c969d commit 48c6150

File tree

2 files changed

+4
-65
lines changed

2 files changed

+4
-65
lines changed

tests/test_tuya_sensor.py

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
"""Tests for Tuya Sensor quirks."""
22

3-
from unittest import mock
4-
53
import pytest
64
from zigpy.zcl import foundation
75
from zigpy.zcl.clusters.general import Basic, PowerConfiguration
86
from zigpy.zcl.clusters.measurement import RelativeHumidity, TemperatureMeasurement
97

10-
from tests.common import wait_for_zigpy_tasks
118
import zhaquirks
12-
from zhaquirks.tuya import TUYA_MCU_VERSION_RSP, TuyaLocalCluster
9+
from zhaquirks.tuya import TuyaLocalCluster
1310
from zhaquirks.tuya.mcu import TuyaMCUCluster
14-
from zhaquirks.tuya.tuya_sensor import RespondingTuyaMCUCluster
1511

1612
# Temp DP 1, Humidity DP 2, Battery DP 3
1713
TUYA_TEMP01_HUM02_BAT03 = b"\x09\xe0\x02\x0b\x33\x01\x02\x00\x04\x00\x00\x00\xfd\x02\x02\x00\x04\x00\x00\x00\x47\x03\x02\x00\x04\x00\x00\x00\x01"
@@ -49,7 +45,6 @@
4945
("_TZE200_ydrdfkim", "TS0601", 100, 10, False),
5046
("_TZE284_locansqn", "TS0601", 100, 10, False),
5147
("_TZE200_vvmbj46n", "TS0601", 100, 10, True),
52-
("_TZE204_upagmta9", "TS0601", 100, 10, False),
5348
],
5449
)
5550
async def test_handle_get_data(
@@ -113,6 +108,7 @@ async def test_handle_get_data(
113108
("_TZE204_yjjdcqsq", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT04),
114109
("_TZE204_ksz749x8", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT04),
115110
("_TZE204_upagmta9", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT03),
111+
("_TZE204_upagmta9", "TS0601", 100, 10, TUYA_TEMP01_HUM02_BAT03),
116112
],
117113
)
118114
async def test_handle_get_data_enum_batt(
@@ -174,32 +170,3 @@ def test_valid_attributes(zigpy_device_from_v2_quirk):
174170
assert {temperature_attr_id} == temperature_cluster._VALID_ATTRIBUTES
175171
assert {humidity_attr_id} == humidity_cluster._VALID_ATTRIBUTES
176172
assert {power_attr_id} == power_config_cluster._VALID_ATTRIBUTES
177-
178-
179-
async def test_tuya_version(zigpy_device_from_v2_quirk):
180-
"""Test TUYA_MCU_VERSION_RSP messages, ensure response."""
181-
182-
quirked = zigpy_device_from_v2_quirk("_TZE204_upagmta9", "TS0601")
183-
ep = quirked.endpoints[1]
184-
185-
tuya_cluster = ep.tuya_manufacturer
186-
187-
assert ep.tuya_manufacturer is not None
188-
assert isinstance(ep.tuya_manufacturer, TuyaMCUCluster)
189-
assert isinstance(ep.tuya_manufacturer, RespondingTuyaMCUCluster)
190-
191-
# simulate a TUYA_MCU_VERSION_RSP message
192-
hdr, args = tuya_cluster.deserialize(ZCL_TUYA_VERSION_RSP)
193-
assert hdr.command_id == TUYA_MCU_VERSION_RSP
194-
195-
with mock.patch.object(
196-
ep.tuya_manufacturer._endpoint,
197-
"request",
198-
return_value=foundation.Status.SUCCESS,
199-
) as m1:
200-
ep.tuya_manufacturer.handle_message(hdr, args)
201-
await wait_for_zigpy_tasks()
202-
203-
res_hdr = foundation.ZCLHeader.deserialize(m1.await_args[1]["data"])
204-
assert not res_hdr[0].manufacturer
205-
assert not res_hdr[0].frame_control.is_manufacturer_specific

zhaquirks/tuya/tuya_sensor.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
from zhaquirks.const import BatterySize
1212
from zhaquirks.tuya import (
13-
TUYA_MCU_VERSION_REQ,
14-
TUYA_QUERY_DATA,
1513
TUYA_SET_TIME,
1614
TuyaPowerConfigurationCluster2AAA,
1715
TuyaTimePayload,
@@ -55,33 +53,6 @@ class NoManufTimeTuyaMCUCluster(TuyaMCUCluster):
5553
)
5654

5755

58-
class RespondingTuyaMCUCluster(TuyaMCUCluster):
59-
"""Tuya Manufacturer Cluster with mcu version response."""
60-
61-
def handle_mcu_version_response(
62-
self, payload: TuyaMCUCluster.MCUVersion
63-
) -> foundation.Status:
64-
"""Handle MCU version response."""
65-
66-
self.create_catching_task(
67-
super().command(TUYA_MCU_VERSION_REQ, 2, expect_reply=False)
68-
)
69-
self.create_catching_task(super().command(TUYA_QUERY_DATA, expect_reply=False))
70-
super().handle_mcu_version_response(payload)
71-
72-
server_commands = copy.deepcopy(TuyaMCUCluster.server_commands)
73-
server_commands.update(
74-
{
75-
TUYA_MCU_VERSION_REQ: foundation.ZCLCommandDef(
76-
"mcu_version_req",
77-
{"data": t.uint16_t},
78-
True,
79-
is_manufacturer_specific=False,
80-
),
81-
}
82-
)
83-
84-
8556
(
8657
TuyaQuirkBuilder("_TZE200_bjawzodf", "TS0601")
8758
.applies_to("_TZE200_zl1kmjqx", "TS0601")
@@ -353,6 +324,7 @@ def handle_mcu_version_response(
353324
converter=lambda x: {0: 50, 1: 100, 2: 200}[x],
354325
)
355326
.adds(TuyaPowerConfigurationCluster2AAA)
327+
.tuya_enchantment(data_query_spell=True)
356328
.skip_configuration()
357-
.add_to_registry(replacement_cluster=RespondingTuyaMCUCluster)
329+
.add_to_registry()
358330
)

0 commit comments

Comments
 (0)