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

Use zigpy AttributeDefs for PhilipsBasicCluster #3434

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions zhaquirks/philips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import itertools
import logging
import time
from typing import Any, Optional, Union
from typing import Any, Final, Optional, Union

from zigpy.quirks import CustomCluster
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import Basic
from zigpy.zcl.clusters.measurement import OccupancySensing
from zigpy.zcl.foundation import ZCLAttributeDef

from zhaquirks.const import (
ARGS,
Expand Down Expand Up @@ -59,10 +60,14 @@ class PhilipsOccupancySensing(CustomCluster):
class PhilipsBasicCluster(CustomCluster, Basic):
"""Philips Basic cluster."""

attributes = Basic.attributes.copy()
attributes[0x0031] = ("philips", t.bitmap16, True)
class AttributeDefs(Basic.AttributeDefs):
"""Attribute definitions."""

attr_config = {0x0031: 0x000B}
philips: Final = ZCLAttributeDef(
id=0x0031, type=t.bitmap16, is_manufacturer_specific=True
)

attr_config = {AttributeDefs.philips.id: 0x000B}

async def bind(self):
"""Bind cluster."""
Expand Down
41 changes: 23 additions & 18 deletions zhaquirks/philips/wall_switch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Signify wall switch devices (RDM001 and RDM004)."""

from typing import Final

from zigpy.profiles import zha
from zigpy.quirks import CustomCluster, CustomDevice
from zigpy.quirks import CustomDevice
import zigpy.types as t
from zigpy.zcl.clusters.general import (
Basic,
Expand All @@ -12,6 +14,7 @@
Ota,
PowerConfiguration,
)
from zigpy.zcl.foundation import ZCLAttributeDef

from zhaquirks.const import (
DEVICE_TYPE,
Expand All @@ -28,29 +31,31 @@
SHORT_RELEASE,
TURN_ON,
)
from zhaquirks.philips import PHILIPS, SIGNIFY, Button, PhilipsRemoteCluster, PressType
from zhaquirks.philips import (
PHILIPS,
SIGNIFY,
Button,
PhilipsBasicCluster,
PhilipsRemoteCluster,
PressType,
)

DEVICE_SPECIFIC_UNKNOWN = 64512


class PhilipsBasicCluster(CustomCluster, Basic):
"""Philips Basic cluster."""
class PhilipsWallSwitchBasicCluster(PhilipsBasicCluster):
"""Philips wall switch Basic cluster."""

attributes = Basic.attributes.copy()
attributes.update(
{
0x0031: ("philips", t.bitmap16, True),
0x0034: ("mode", t.enum8, True),
}
)
class AttributeDefs(PhilipsBasicCluster.AttributeDefs):
"""Attribute definitions."""

attr_config = {0x0031: 0x000B, 0x0034: 0x02}
mode: Final = ZCLAttributeDef(
id=0x0034,
type=t.enum8,
is_manufacturer_specific=True,
)

async def bind(self):
"""Bind cluster."""
result = await super().bind()
await self.write_attributes(self.attr_config, manufacturer=0x100B)
return result
attr_config = {**PhilipsBasicCluster.attr_config, AttributeDefs.mode.id: 0x02}


class PhilipsWallSwitchRemoteCluster(PhilipsRemoteCluster):
Expand Down Expand Up @@ -113,7 +118,7 @@ class PhilipsWallSwitch(CustomDevice):
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.NON_COLOR_CONTROLLER,
INPUT_CLUSTERS: [
PhilipsBasicCluster,
PhilipsWallSwitchBasicCluster,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PhilipsWallSwitchRemoteCluster,
Expand Down