Skip to content

Commit b20b82b

Browse files
authored
Fix Tuya smoke detector _TZ3210_up3pngle (#3724)
1 parent e61ecbb commit b20b82b

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

tests/test_tuya_smoke.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
),
3232
),
3333
("_TZE284_0zaf1cr8", "TS0601", []),
34-
("_TZ3210_up3pngle", "TS0205", []),
3534
],
3635
)
3736
async def test_handle_get_data(zigpy_device_from_v2_quirk, model, manuf, battery_test):
@@ -80,3 +79,32 @@ async def test_handle_get_data(zigpy_device_from_v2_quirk, model, manuf, battery
8079

8180
assert len(power_listener.attribute_updates) == 1
8281
assert power_listener.attribute_updates[0][1] == state
82+
83+
84+
async def test_tuya_smoke_sensor_attribute_update(zigpy_device_from_v2_quirk):
85+
"""Test update_attribute on Tuya smoke sensor."""
86+
87+
device = zigpy_device_from_v2_quirk("_TZ3210_up3pngle", "TS0205")
88+
89+
tuya_cluster = device.endpoints[1].tuya_manufacturer
90+
tuya_listener = ClusterListener(tuya_cluster)
91+
92+
ias_cluster = device.endpoints[1].ias_zone
93+
ias_listener = ClusterListener(ias_cluster)
94+
95+
zone_status_id = IasZone.AttributeDefs.zone_status.id
96+
97+
# check that updating smoke attribute also updates zone status on the Ias Zone cluster
98+
99+
# turn on smoke alarm
100+
tuya_cluster.update_attribute(0x0401, 1)
101+
assert len(tuya_listener.attribute_updates) == 1
102+
assert len(ias_listener.attribute_updates) == 1
103+
assert ias_listener.attribute_updates[0][0] == zone_status_id
104+
assert ias_listener.attribute_updates[0][1] == 0
105+
# turn off smoke alarm
106+
tuya_cluster.update_attribute(0x0401, 0)
107+
assert len(tuya_listener.attribute_updates) == 2
108+
assert len(ias_listener.attribute_updates) == 2
109+
assert ias_listener.attribute_updates[1][0] == zone_status_id
110+
assert ias_listener.attribute_updates[1][1] == IasZone.ZoneStatus.Alarm_1

zhaquirks/tuya/tuya_smoke.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,56 @@
11
"""Smoke Sensor."""
22

3+
from zigpy.quirks.v2 import QuirkBuilder
4+
import zigpy.types as t
5+
from zigpy.zcl.clusters.general import OnOff, Time
6+
from zigpy.zcl.clusters.lightlink import LightLink
7+
from zigpy.zcl.clusters.security import IasZone
8+
from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef
9+
10+
from zhaquirks import LocalDataCluster
11+
from zhaquirks.tuya import TuyaManufClusterAttributes
312
from zhaquirks.tuya.builder import TuyaPowerConfigurationCluster2AAA, TuyaQuirkBuilder
413

14+
15+
class TuyaIasZone(LocalDataCluster, IasZone):
16+
"""IAS Zone."""
17+
18+
_CONSTANT_ATTRIBUTES = {
19+
IasZone.AttributeDefs.zone_type.id: IasZone.ZoneType.Fire_Sensor
20+
}
21+
22+
23+
class TuyaSmokeDetectorCluster(TuyaManufClusterAttributes):
24+
"""Manufacturer Specific Cluster of the TS0205 smoke detector."""
25+
26+
class AttributeDefs(BaseAttributeDefs):
27+
"""Attribute definitions."""
28+
29+
smoke_detected = ZCLAttributeDef(
30+
id=0x0401, # [0]/[1] [Detected]/[Clear]
31+
type=t.uint8_t,
32+
is_manufacturer_specific=True,
33+
)
34+
35+
def _update_attribute(self, attrid, value):
36+
super()._update_attribute(attrid, value)
37+
if attrid == self.AttributeDefs.smoke_detected.id:
38+
self.endpoint.ias_zone.update_attribute(
39+
IasZone.AttributeDefs.zone_status.id,
40+
IasZone.ZoneStatus.Alarm_1 if value == 0 else 0,
41+
)
42+
43+
44+
(
45+
QuirkBuilder("_TZ3210_up3pngle", "TS0205")
46+
.removes(LightLink.cluster_id)
47+
.removes(OnOff.cluster_id)
48+
.removes(Time.cluster_id)
49+
.replaces(TuyaIasZone)
50+
.replaces(TuyaSmokeDetectorCluster)
51+
.add_to_registry()
52+
)
53+
554
(
655
TuyaQuirkBuilder("_TZE200_aycxwiau", "TS0601")
756
.applies_to("_TZE200_dq1mfjug", "TS0601")
@@ -12,7 +61,6 @@
1261
.applies_to("_TZE200_vzekyi4c", "TS0601")
1362
.applies_to("_TZE204_vawy74yh", "TS0601")
1463
.applies_to("_TZE284_0zaf1cr8", "TS0601")
15-
.applies_to("_TZ3210_up3pngle", "TS0205")
1664
.tuya_smoke(dp_id=1)
1765
.skip_configuration()
1866
.add_to_registry()

0 commit comments

Comments
 (0)