Skip to content

Commit 086647a

Browse files
committed
Init quirk
1 parent f0a7498 commit 086647a

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
@@ -10,6 +10,8 @@
1010

1111
from zhaquirks.const import BatterySize
1212
from zhaquirks.tuya import (
13+
TUYA_MCU_VERSION_REQ,
14+
TUYA_QUERY_DATA,
1315
TUYA_SET_TIME,
1416
TuyaPowerConfigurationCluster2AAA,
1517
TuyaTimePayload,
@@ -33,6 +35,53 @@ class TuyaNousTempHumiAlarm(t.enum8):
3335
Canceled = 0x02
3436

3537

38+
class NoManufTimeTuyaMCUCluster(TuyaMCUCluster):
39+
"""Tuya Manufacturer Cluster with set_time mod."""
40+
41+
set_time_offset = 1970
42+
set_time_local_offset = 1970
43+
44+
# Deepcopy required to override 'set_time', without, it will revert
45+
server_commands = copy.deepcopy(TuyaMCUCluster.server_commands)
46+
server_commands.update(
47+
{
48+
TUYA_SET_TIME: foundation.ZCLCommandDef(
49+
"set_time",
50+
{"time": TuyaTimePayload},
51+
False,
52+
is_manufacturer_specific=False,
53+
),
54+
}
55+
)
56+
57+
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+
3685
(
3786
TuyaQuirkBuilder("_TZE200_bjawzodf", "TS0601")
3887
.applies_to("_TZE200_zl1kmjqx", "TS0601")
@@ -89,26 +138,6 @@ class TuyaNousTempHumiAlarm(t.enum8):
89138
)
90139

91140

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

0 commit comments

Comments
 (0)