10
10
11
11
from zhaquirks .const import BatterySize
12
12
from zhaquirks .tuya import (
13
+ TUYA_MCU_VERSION_REQ ,
14
+ TUYA_QUERY_DATA ,
13
15
TUYA_SET_TIME ,
14
16
TuyaPowerConfigurationCluster2AAA ,
15
17
TuyaTimePayload ,
@@ -33,6 +35,53 @@ class TuyaNousTempHumiAlarm(t.enum8):
33
35
Canceled = 0x02
34
36
35
37
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
+
36
85
(
37
86
TuyaQuirkBuilder ("_TZE200_bjawzodf" , "TS0601" )
38
87
.applies_to ("_TZE200_zl1kmjqx" , "TS0601" )
@@ -89,26 +138,6 @@ class TuyaNousTempHumiAlarm(t.enum8):
89
138
)
90
139
91
140
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
-
112
141
# TH01Z - Temperature and humidity sensor with clock
113
142
(
114
143
TuyaQuirkBuilder ("_TZE200_lve3dvpy" , "TS0601" )
@@ -311,3 +340,19 @@ class NoManufTimeTuyaMCUCluster(TuyaMCUCluster):
311
340
.skip_configuration ()
312
341
.add_to_registry ()
313
342
)
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