Skip to content

Commit 3b25f04

Browse files
committed
Init quirk
1 parent c99f86b commit 3b25f04

File tree

1 file changed

+65
-20
lines changed

1 file changed

+65
-20
lines changed

zhaquirks/tuya/tuya_sensor.py

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from zigpy.zcl import foundation
1010

1111
from zhaquirks.tuya import (
12+
TUYA_MCU_VERSION_REQ,
13+
TUYA_QUERY_DATA,
1214
TUYA_SET_TIME,
1315
TuyaPowerConfigurationCluster2AAA,
1416
TuyaTimePayload,
@@ -32,6 +34,53 @@ class TuyaNousTempHumiAlarm(t.enum8):
3234
Canceled = 0x02
3335

3436

37+
class NoManufTimeTuyaMCUCluster(TuyaMCUCluster):
38+
"""Tuya Manufacturer Cluster with set_time mod."""
39+
40+
set_time_offset = 1970
41+
set_time_local_offset = 1970
42+
43+
# Deepcopy required to override 'set_time', without, it will revert
44+
server_commands = copy.deepcopy(TuyaMCUCluster.server_commands)
45+
server_commands.update(
46+
{
47+
TUYA_SET_TIME: foundation.ZCLCommandDef(
48+
"set_time",
49+
{"time": TuyaTimePayload},
50+
False,
51+
is_manufacturer_specific=False,
52+
),
53+
}
54+
)
55+
56+
57+
class RespondingTuyaMCUCluster(TuyaMCUCluster):
58+
"""Tuya Manufacturer Cluster with mcu version response."""
59+
60+
def handle_mcu_version_response(
61+
self, payload: TuyaMCUCluster.MCUVersion
62+
) -> foundation.Status:
63+
"""Handle MCU version response."""
64+
65+
self.create_catching_task(
66+
super().command(TUYA_MCU_VERSION_REQ, 2, expect_reply=False)
67+
)
68+
self.create_catching_task(super().command(TUYA_QUERY_DATA, expect_reply=False))
69+
super().handle_mcu_version_response(payload)
70+
71+
server_commands = copy.deepcopy(TuyaMCUCluster.server_commands)
72+
server_commands.update(
73+
{
74+
TUYA_MCU_VERSION_REQ: foundation.ZCLCommandDef(
75+
"mcu_version_req",
76+
{"data": t.uint16_t},
77+
True,
78+
is_manufacturer_specific=False,
79+
),
80+
}
81+
)
82+
83+
3584
(
3685
TuyaQuirkBuilder("_TZE200_bjawzodf", "TS0601")
3786
.applies_to("_TZE200_zl1kmjqx", "TS0601")
@@ -87,26 +136,6 @@ class TuyaNousTempHumiAlarm(t.enum8):
87136
)
88137

89138

90-
class NoManufTimeTuyaMCUCluster(TuyaMCUCluster):
91-
"""Tuya Manufacturer Cluster with set_time mod."""
92-
93-
set_time_offset = 1970
94-
set_time_local_offset = 1970
95-
96-
# Deepcopy required to override 'set_time', without, it will revert
97-
server_commands = copy.deepcopy(TuyaMCUCluster.server_commands)
98-
server_commands.update(
99-
{
100-
TUYA_SET_TIME: foundation.ZCLCommandDef(
101-
"set_time",
102-
{"time": TuyaTimePayload},
103-
False,
104-
is_manufacturer_specific=False,
105-
),
106-
}
107-
)
108-
109-
110139
# TH01Z - Temperature and humidity sensor with clock
111140
(
112141
TuyaQuirkBuilder("_TZE200_lve3dvpy", "TS0601")
@@ -317,3 +346,19 @@ class NoManufTimeTuyaMCUCluster(TuyaMCUCluster):
317346
.skip_configuration()
318347
.add_to_registry()
319348
)
349+
350+
351+
(
352+
TuyaQuirkBuilder("_TZE204_upagmta9", "TS0601")
353+
.tuya_temperature(dp_id=1, scale=10)
354+
.tuya_humidity(dp_id=2)
355+
.tuya_dp(
356+
dp_id=3,
357+
ep_attribute=TuyaPowerConfigurationCluster2AAA.ep_attribute,
358+
attribute_name="battery_percentage_remaining",
359+
converter=lambda x: {0: 50, 1: 100, 2: 200}[x],
360+
)
361+
.adds(TuyaPowerConfigurationCluster2AAA)
362+
.skip_configuration()
363+
.add_to_registry(replacement_cluster=RespondingTuyaMCUCluster)
364+
)

0 commit comments

Comments
 (0)