Skip to content

Instantly share code, notes, and snippets.

@mool
Last active April 23, 2024 15:48
Show Gist options
  • Save mool/d4fb96eaed3d04b9bdbf1d7c1517141c to your computer and use it in GitHub Desktop.
Save mool/d4fb96eaed3d04b9bdbf1d7c1517141c to your computer and use it in GitHub Desktop.
ZHA quirck for Tuya TS0225_LINPTECH 24Ghz human presence sensor
"""Device handler for Tuya TS0225_LINPTECH 24Ghz human presence sensor."""
import logging
from typing import Dict
import zigpy.types as t
from zhaquirks.const import (DEVICE_TYPE, ENDPOINTS, INPUT_CLUSTERS,
MODELS_INFO, OUTPUT_CLUSTERS, PROFILE_ID)
from zhaquirks.tuya import NoManufacturerCluster, TuyaNewManufCluster
from zhaquirks.tuya.mcu import DPToAttributeMapping, TuyaMCUCluster
from zigpy.profiles import zha
from zigpy.quirks import CustomCluster, CustomDevice
from zigpy.zcl.clusters.general import (Basic, Groups, Identify, Ota, Scenes,
Time)
from zigpy.zcl.clusters.security import IasZone
_LOGGER = logging.getLogger(__name__)
class MmwRadarCluster(NoManufacturerCluster, CustomCluster):
"""Tuya TS0225_LINPTECH 24Ghz human presence sensor cluster."""
name = "Tuya Mmw Radar Cluster"
cluster_id = 0xE002
attributes = {
0xE001: ("existance_time", t.uint16_t, True), # RO
0xE004: ("motion_detection_sensitivity", t.enum8, True), # RW, 1-5, default: 4
0xE005: ("static_detection_sensitivity", t.enum8, True), # RW, 1-5, default: 3
0xE00A: ("distance", t.uint16_t, True), # RO
0xE00B: (
"motion_detection_distance",
t.enum16,
True,
), # RW, 75-600, step: 75 centimeters
}
class FadingTimeCluster(TuyaMCUCluster):
"""Tuya TS0225_LINPTECH Fading Time cluster."""
name = "Tuya Fading Time Cluster"
attributes = TuyaMCUCluster.attributes.copy()
attributes.update(
{
# ramdom attribute IDs
0xEF65: ("fading_time", t.uint32_t, True),
}
)
dp_to_attribute: Dict[int, DPToAttributeMapping] = {
101: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
"fading_time",
),
}
data_point_handlers = {
101: "_dp_2_attr_update",
}
class TS0225Radar(CustomDevice):
"""Quirk for Tuya ZG-205Z-A Mini 24Ghz human presence sensor."""
signature = {
MODELS_INFO: [("_TZ3218_awarhusb", "TS0225")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
INPUT_CLUSTERS: [
Basic.cluster_id, # 0x0000
Identify.cluster_id, # 0x0003
Groups.cluster_id, # 0x0004
Scenes.cluster_id, # 0x0005
IasZone.cluster_id, # 0x0500
0x4000,
MmwRadarCluster.cluster_id, # 0xE002
TuyaNewManufCluster.cluster_id, # 0xef00
],
OUTPUT_CLUSTERS: [
Time.cluster_id, # 0x000a
Ota.cluster_id, # 0x0019
],
},
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
IasZone.cluster_id,
MmwRadarCluster,
FadingTimeCluster,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment