Skip to content

Commit 374375f

Browse files
authored
Add support of Tuya Moes temperature and humidity sensor with screen. (#1672)
* Add support of Tuya Moes temperature and humidity sensor with screen Support of Tuya Moes temperature and humidity sensor with screen is added. Files ts0201_neo.py and ts0201_zemismart.py are merged into one ts0201.py and new classes added there * Formatting of source code changed * Minor change in comments
1 parent 57a68a2 commit 374375f

File tree

3 files changed

+219
-175
lines changed

3 files changed

+219
-175
lines changed

zhaquirks/tuya/ts0201.py

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

zhaquirks/tuya/ts0201_neo.py

Lines changed: 0 additions & 103 deletions
This file was deleted.

zhaquirks/tuya/ts0201_zemismart.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)