Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Philips Hue contact sensor quirk #3432

Merged
merged 14 commits into from
Oct 20, 2024
Merged
93 changes: 93 additions & 0 deletions zhaquirks/philips/soc001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""Signify SOC001 device."""

from zigpy import types
from zigpy.quirks import CustomCluster
from zigpy.quirks.v2 import (
BinarySensorDeviceClass,
ClusterType,
EntityType,
QuirkBuilder,
)
from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef


class OnOff(CustomCluster):
"""Custom On/Off cluster to still allow binding."""

cluster_id = 6 # 0x0006
name = "On/Off cluster"
ep_attribute = "on_off_cluster"

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

on_off = ZCLAttributeDef(
id=0x0000,
type=types.Bool,
is_manufacturer_specific=False,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should/can do this. We're replacing a ZCL cluster and are also changing the ep_attribute here.
IIRC there are places where ZHA expects the ep_attribute to be unchanged for a standard ZCL cluster.
Not subclassing OnOff (and its AttributeDefs) is also not good.



class PhilipsContactCluster(CustomCluster):
"""Philips manufacturer specific cluster for contact sensor."""

cluster_id = 64518 # 0xfc06
name = "Philips contact cluster"
ep_attribute = "philips_contact_cluster"

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

contact = ZCLAttributeDef(
id=0x0100,
type=types.enum8,
is_manufacturer_specific=True,
)
last_contact_change = ZCLAttributeDef(
id=0x0101,
type=types.uint32_t,
is_manufacturer_specific=True,
)
tamper = ZCLAttributeDef(
id=0x0102,
type=types.enum8,
is_manufacturer_specific=True,
)
last_tamper_change = ZCLAttributeDef(
id=0x0103,
type=types.uint32_t,
is_manufacturer_specific=True,
)


(
# <SimpleDescriptor endpoint=2 profile=260 device_type=1026
# device_version=0
# input_clusters=[0, 1, 3, 64518]
# output_clusters=[0, 3, 6, 25]>
QuirkBuilder("Signify Netherlands B.V.", "SOC001")
.replaces(
replacement_cluster_class=OnOff,
cluster_id=6, # 0x0006
cluster_type=ClusterType.Client,
endpoint_id=2,
)
.replaces(PhilipsContactCluster, endpoint_id=2)
.binary_sensor(
"contact",
PhilipsContactCluster.cluster_id,
endpoint_id=2,
device_class=BinarySensorDeviceClass.OPENING,
fallback_name="Contact",
entity_type=EntityType.STANDARD,
)
.binary_sensor(
"tamper",
PhilipsContactCluster.cluster_id,
endpoint_id=2,
device_class=BinarySensorDeviceClass.TAMPER,
fallback_name="Tamper",
entity_type=EntityType.DIAGNOSTIC,
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
)
.add_to_registry()
)