Skip to content

Commit

Permalink
Merge branch 'dev' into add-_TZE204_upagmta9
Browse files Browse the repository at this point in the history
  • Loading branch information
prairiesnpr authored Jan 20, 2025
2 parents fa6e3c1 + b7f2bc7 commit 01e9e7e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 4 deletions.
40 changes: 38 additions & 2 deletions tests/test_tuya_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@
[
("_TZE200_dq1mfjug", "TS0601", []),
("_TZE200_m9skfctm", "TS0601", []),
("_TZE200_ntcy3xu1", "TS0601", []),
("_TZE200_rccxox8p", "TS0601", []),
("_TZE284_rccxox8p", "TS0601", []),
("_TZE200_vzekyi4c", "TS0601", []),
("_TZE204_vawy74yh", "TS0601", []),
(
"_TZE200_ntcy3xu1",
"TS0601",
(
(b"\x09\x3a\x02\x00\x12\x0e\x04\x00\x01\x02", 200),
(b"\x09\x3a\x02\x00\x12\x0e\x04\x00\x01\x01", 80),
(b"\x09\x3a\x02\x00\x12\x0e\x04\x00\x01\x00", 10),
),
),
(
"_TZE204_ntcy3xu1",
"TS0601",
Expand All @@ -31,7 +39,6 @@
),
),
("_TZE284_0zaf1cr8", "TS0601", []),
("_TZ3210_up3pngle", "TS0205", []),
],
)
async def test_handle_get_data(zigpy_device_from_v2_quirk, model, manuf, battery_test):
Expand Down Expand Up @@ -80,3 +87,32 @@ async def test_handle_get_data(zigpy_device_from_v2_quirk, model, manuf, battery

assert len(power_listener.attribute_updates) == 1
assert power_listener.attribute_updates[0][1] == state


async def test_tuya_smoke_sensor_attribute_update(zigpy_device_from_v2_quirk):
"""Test update_attribute on Tuya smoke sensor."""

device = zigpy_device_from_v2_quirk("_TZ3210_up3pngle", "TS0205")

tuya_cluster = device.endpoints[1].tuya_manufacturer
tuya_listener = ClusterListener(tuya_cluster)

ias_cluster = device.endpoints[1].ias_zone
ias_listener = ClusterListener(ias_cluster)

zone_status_id = IasZone.AttributeDefs.zone_status.id

# check that updating smoke attribute also updates zone status on the Ias Zone cluster

# turn on smoke alarm
tuya_cluster.update_attribute(0x0401, 1)
assert len(tuya_listener.attribute_updates) == 1
assert len(ias_listener.attribute_updates) == 1
assert ias_listener.attribute_updates[0][0] == zone_status_id
assert ias_listener.attribute_updates[0][1] == 0
# turn off smoke alarm
tuya_cluster.update_attribute(0x0401, 0)
assert len(tuya_listener.attribute_updates) == 2
assert len(ias_listener.attribute_updates) == 2
assert ias_listener.attribute_updates[1][0] == zone_status_id
assert ias_listener.attribute_updates[1][1] == IasZone.ZoneStatus.Alarm_1
60 changes: 58 additions & 2 deletions zhaquirks/tuya/tuya_smoke.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,82 @@
"""Smoke Sensor."""

from zigpy.quirks.v2 import EntityType, QuirkBuilder
from zigpy.quirks.v2.homeassistant.binary_sensor import BinarySensorDeviceClass
import zigpy.types as t
from zigpy.zcl.clusters.general import OnOff, Time
from zigpy.zcl.clusters.lightlink import LightLink
from zigpy.zcl.clusters.security import IasZone
from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef

from zhaquirks import LocalDataCluster
from zhaquirks.tuya import TuyaManufClusterAttributes
from zhaquirks.tuya.builder import TuyaPowerConfigurationCluster2AAA, TuyaQuirkBuilder


class TuyaIasZone(LocalDataCluster, IasZone):
"""IAS Zone."""

_CONSTANT_ATTRIBUTES = {
IasZone.AttributeDefs.zone_type.id: IasZone.ZoneType.Fire_Sensor
}


class TuyaSmokeDetectorCluster(TuyaManufClusterAttributes):
"""Manufacturer Specific Cluster of the TS0205 smoke detector."""

class AttributeDefs(BaseAttributeDefs):
"""Attribute definitions."""

smoke_detected = ZCLAttributeDef(
id=0x0401, # [0]/[1] [Detected]/[Clear]
type=t.uint8_t,
is_manufacturer_specific=True,
)

def _update_attribute(self, attrid, value):
super()._update_attribute(attrid, value)
if attrid == self.AttributeDefs.smoke_detected.id:
self.endpoint.ias_zone.update_attribute(
IasZone.AttributeDefs.zone_status.id,
IasZone.ZoneStatus.Alarm_1 if value == 0 else 0,
)


(
QuirkBuilder("_TZ3210_up3pngle", "TS0205")
.removes(LightLink.cluster_id)
.removes(OnOff.cluster_id)
.removes(Time.cluster_id)
.replaces(TuyaIasZone)
.replaces(TuyaSmokeDetectorCluster)
.add_to_registry()
)

(
TuyaQuirkBuilder("_TZE200_aycxwiau", "TS0601")
.applies_to("_TZE200_dq1mfjug", "TS0601")
.applies_to("_TZE200_m9skfctm", "TS0601")
.applies_to("_TZE200_ntcy3xu1", "TS0601")
.applies_to("_TZE200_rccxox8p", "TS0601")
.applies_to("_TZE284_rccxox8p", "TS0601")
.applies_to("_TZE200_vzekyi4c", "TS0601")
.applies_to("_TZE204_vawy74yh", "TS0601")
.applies_to("_TZE284_0zaf1cr8", "TS0601")
.applies_to("_TZ3210_up3pngle", "TS0205")
.tuya_smoke(dp_id=1)
.skip_configuration()
.add_to_registry()
)

(
TuyaQuirkBuilder("_TZE204_ntcy3xu1", "TS0601")
.applies_to("_TZE200_ntcy3xu1", "TS0601")
.tuya_smoke(dp_id=1)
.tuya_binary_sensor(
dp_id=4,
attribute_name="tamper",
device_class=BinarySensorDeviceClass.TAMPER,
entity_type=EntityType.DIAGNOSTIC,
fallback_name="Tamper",
)
.tuya_dp(
dp_id=14,
ep_attribute=TuyaPowerConfigurationCluster2AAA.ep_attribute,
Expand Down

0 comments on commit 01e9e7e

Please sign in to comment.