-
Notifications
You must be signed in to change notification settings - Fork 659
/
ts0201.py
219 lines (195 loc) · 6.81 KB
/
ts0201.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
"""Tuya TS201 temperature, humidity and optional illumination sensors."""
from zigpy.profiles import zha
from zigpy.profiles.zha import DeviceType
from zigpy.quirks import CustomCluster, CustomDevice
import zigpy.types as t
from zigpy.zcl.clusters.general import Basic, Identify, Ota, PowerConfiguration, Time
from zigpy.zcl.clusters.measurement import (
IlluminanceMeasurement,
RelativeHumidity,
TemperatureMeasurement,
)
from zigpy.zdo.types import NodeDescriptor
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
NODE_DESCRIPTOR,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
class ValueAlarm(t.enum8):
"""Temperature and humidity alarm values."""
ALARM_OFF = 0x02
MAX_ALARM_ON = 0x01
MIN_ALARM_ON = 0x00
class TuyaTemperatureHumidityAlarmCluster(CustomCluster):
"""Tuya temperature and humidity alarm cluster (0xE002)."""
name = "Tuya Temperature and Humidity Alarm Cluster"
cluster_id = 0xE002
attributes = {
# Alarm settings
0xD00A: ("alarm_temperature_max", t.uint16_t, True),
0xD00B: ("alarm_temperature_min", t.uint16_t, True),
0xD00C: ("alarm_humidity_max", t.uint16_t, True),
0xD00E: ("alarm_humidity_min", t.uint16_t, True),
# Alarm information
0xD00F: ("alarm_humidity", ValueAlarm, True),
0xD006: ("temperature_humidity", ValueAlarm, True),
# Unknown
0xD010: ("unknown", t.uint8_t, True),
}
class NeoTemperatureHumidtyIlluminanceSensor(CustomDevice):
"""Neo temperature, humidity and illumination sensor."""
signature = {
# <SimpleDescriptor endpoint=1, profile=260, device_type=262
# device_version=1
# input_clusters=[0, 1, 1024, 57346]
# output_clusters=[25, 10]>
MODELS_INFO: [("_TZ3000_qaaysllp", "TS0201")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: DeviceType.LIGHT_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
IlluminanceMeasurement.cluster_id,
TuyaTemperatureHumidityAlarmCluster.cluster_id,
],
OUTPUT_CLUSTERS: [
Time.cluster_id,
Ota.cluster_id,
],
},
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
IlluminanceMeasurement.cluster_id,
TuyaTemperatureHumidityAlarmCluster,
],
OUTPUT_CLUSTERS: [
Time.cluster_id,
Ota.cluster_id,
],
},
2: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
],
},
},
}
class ZemismartTemperatureHumidtySensor(CustomDevice):
"""Zemismart temperature and humidity sensor."""
signature = {
# <SimpleDescriptor endpoint=1 profile=260 device_type=770
# device_version=1
# input_clusters=[0, 1, 3, 1029, 1026, 61183]
# output_clusters=[3, 25]>
MODELS_INFO: [("_TZ3000_lfa05ajd", "TS0201")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
RelativeHumidity.cluster_id,
TemperatureMeasurement.cluster_id,
0xEEFF, # Unknown
],
OUTPUT_CLUSTERS: [Identify.cluster_id, Ota.cluster_id],
}
},
}
replacement = {
NODE_DESCRIPTOR: NodeDescriptor(
0x02,
0x40,
0x80,
0x1037,
0x7F,
0x0064,
0x2C00,
0x0064,
0x00, # Forcing capability 0x80 instead of 0x84 so AC Power = false
),
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
RelativeHumidity.cluster_id,
TemperatureMeasurement.cluster_id,
],
OUTPUT_CLUSTERS: [Identify.cluster_id, Ota.cluster_id],
}
},
}
class RelativeHumidityX10(CustomCluster, RelativeHumidity):
"""Handles invalid humidity values."""
def _update_attribute(self, attrid, value):
# x10 factor in measured_value`(attrid=0)
if attrid == 0:
value = value * 10
super()._update_attribute(attrid, value)
class MoesTemperatureHumidtySensorWithScreen(CustomDevice):
"""Moes temperature and humidity sensor with screen."""
signature = {
# <SimpleDescriptor endpoint=1, profile=260, device_type="0x0302"
# input_clusters=["0x0000", "0x0001", "0x0003", "0x0402", "0x0405", "0xe002"]
# output_clusters=["0x0003", "0x000a", "0x0019"]>
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
TuyaTemperatureHumidityAlarmCluster.cluster_id,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Time.cluster_id,
Ota.cluster_id,
],
},
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidityX10,
TuyaTemperatureHumidityAlarmCluster,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Time.cluster_id,
Ota.cluster_id,
],
},
},
}