diff --git a/zhaquirks/sonoff/snzb04p.py b/zhaquirks/sonoff/snzb04p.py new file mode 100644 index 0000000000..dd13e18a2f --- /dev/null +++ b/zhaquirks/sonoff/snzb04p.py @@ -0,0 +1,64 @@ +"""Sonoff SNZB-04 device.""" + +from zigpy import types +from zigpy.quirks import CustomCluster +from zigpy.quirks.v2 import ( + BinarySensorDeviceClass, + ClusterType, + EntityType, + QuirkBuilder, +) +from zigpy.zcl.clusters.general import OnOff +from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef + + +class SonoffOnOffCluster(CustomCluster, OnOff): + """Sonoff OnOff cluster for contact sensor.""" + + """Prevents the creation of the on_off entity since it is not functional.""" + + cluster_id = 6 # 0x0006 + name = "Sonoff OnOff cluster" + ep_attribute = "sonoff_onoff_cluster" + SKIP_CONFIGURATION = True + + +class SonoffContactCluster(CustomCluster): + """Sonoff manufacturer specific cluster for contact sensor.""" + + cluster_id = 64529 # 0xfc11 + name = "Sonoff contact cluster" + ep_attribute = "sonoff_contact_cluster" + + class AttributeDefs(BaseAttributeDefs): + """Attribute definitions.""" + + tamper = ZCLAttributeDef( + id=0x2000, + type=types.Bool, + is_manufacturer_specific=True, + ) + + +( + # + QuirkBuilder("eWeLink", "SNZB-04P") + .replaces( + SonoffOnOffCluster, + cluster_type=ClusterType.Client, + endpoint_id=1, + ) + .replaces(SonoffContactCluster, endpoint_id=1) + .binary_sensor( + "tamper", + SonoffContactCluster.cluster_id, + endpoint_id=1, + device_class=BinarySensorDeviceClass.TAMPER, + entity_type=EntityType.DIAGNOSTIC, + fallback_name="Tamper", + ) + .add_to_registry() +)