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

[BREAKING CHANGE] Phillips Hue remote manufacturer specific cluster handling #388

Merged
merged 6 commits into from
Jul 3, 2020
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
96 changes: 95 additions & 1 deletion zhaquirks/philips/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
"""Module for Philips quirks implementations."""
import logging

from zigpy.quirks import CustomCluster
from zigpy.zcl.clusters.general import OnOff
import zigpy.types as t
from zigpy.zcl.clusters.general import Basic, OnOff

from ..const import (
ARGS,
BUTTON,
COMMAND,
COMMAND_ID,
DIM_DOWN,
DIM_UP,
LONG_PRESS,
LONG_RELEASE,
PRESS_TYPE,
SHORT_PRESS,
SHORT_RELEASE,
TURN_OFF,
TURN_ON,
ZHA_SEND_EVENT,
)

DIAGNOSTICS_CLUSTER_ID = 0x0B05 # decimal = 2821
PHILIPS = "Philips"
_LOGGER = logging.getLogger(__name__)

HUE_REMOTE_DEVICE_TRIGGERS = {
(SHORT_PRESS, TURN_ON): {COMMAND: "on_press"},
(SHORT_PRESS, TURN_OFF): {COMMAND: "off_press"},
(SHORT_PRESS, DIM_UP): {COMMAND: "up_press"},
(SHORT_PRESS, DIM_DOWN): {COMMAND: "down_press"},
(LONG_PRESS, TURN_ON): {COMMAND: "on_hold"},
(LONG_PRESS, TURN_OFF): {COMMAND: "off_hold"},
(LONG_PRESS, DIM_UP): {COMMAND: "up_hold"},
(LONG_PRESS, DIM_DOWN): {COMMAND: "down_hold"},
(SHORT_RELEASE, TURN_ON): {COMMAND: "on_short_release"},
(SHORT_RELEASE, TURN_OFF): {COMMAND: "off_short_release"},
(SHORT_RELEASE, DIM_UP): {COMMAND: "up_short_release"},
(SHORT_RELEASE, DIM_DOWN): {COMMAND: "down_short_release"},
(LONG_RELEASE, TURN_ON): {COMMAND: "on_long_release"},
(LONG_RELEASE, TURN_OFF): {COMMAND: "off_long_release"},
(LONG_RELEASE, DIM_UP): {COMMAND: "up_long_release"},
(LONG_RELEASE, DIM_DOWN): {COMMAND: "down_long_release"},
}


class PowerOnState(t.enum8):
Expand All @@ -19,3 +59,57 @@ class PhilipsOnOffCluster(CustomCluster, OnOff):

attributes = OnOff.attributes.copy()
attributes.update({0x4003: ("power_on_state", PowerOnState)})


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

attributes = Basic.attributes.copy()
attributes.update({0x0031: ("philips", t.bitmap16)})
Adminiuga marked this conversation as resolved.
Show resolved Hide resolved

attr_config = {0x0031: 0x000B}

async def bind(self):
"""Bind cluster."""
result = await super().bind()
await self.write_attributes(self.attr_config, manufacturer=0x100B)
return result


class PhilipsRemoteCluster(CustomCluster):
"""Philips remote cluster."""

cluster_id = 64512
name = "PhilipsRemoteCluster"
ep_attribute = "philips_remote_cluster"
attributes = {}
server_commands = {}
client_commands = {
0x0000: (
"notification",
(t.uint8_t, t.uint24_t, t.uint8_t, t.uint8_t, t.uint8_t, t.uint8_t),
False,
)
}
BUTTONS = {1: "on", 2: "up", 3: "down", 4: "off"}
PRESS_TYPES = {0: "press", 1: "hold", 2: "short_release", 3: "long_release"}

def handle_cluster_request(self, tsn, command_id, args):
"""Handle the cluster command."""
_LOGGER.debug(
"PhilipsRemoteCluster - handle_cluster_request tsn: [%s] command id: %s - args: [%s]",
tsn,
command_id,
args,
)
button = self.BUTTONS.get(args[0], args[0])
press_type = self.PRESS_TYPES.get(args[2], args[2])

event_args = {
BUTTON: button,
PRESS_TYPE: press_type,
COMMAND_ID: command_id,
ARGS: args,
}
action = "{}_{}".format(button, press_type)
self.listener_event(ZHA_SEND_EVENT, action, event_args)
70 changes: 9 additions & 61 deletions zhaquirks/philips/rwl020.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Phillips RWL020 device."""
"""Philips RWL020 device."""

from zigpy.profiles import zha, zll
from zigpy.quirks import CustomCluster, CustomDevice
import zigpy.types as t
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import (
Basic,
BinaryInput,
Expand All @@ -13,39 +13,14 @@
PowerConfiguration,
)

from ..const import (
ARGS,
CLUSTER_ID,
COMMAND,
COMMAND_OFF_WITH_EFFECT,
COMMAND_ON,
COMMAND_STEP,
DEVICE_TYPE,
DIM_DOWN,
DIM_UP,
ENDPOINT_ID,
ENDPOINTS,
INPUT_CLUSTERS,
LONG_PRESS,
OUTPUT_CLUSTERS,
PROFILE_ID,
SHORT_PRESS,
TURN_OFF,
TURN_ON,
)
from . import HUE_REMOTE_DEVICE_TRIGGERS, PhilipsBasicCluster, PhilipsRemoteCluster
from ..const import DEVICE_TYPE, ENDPOINTS, INPUT_CLUSTERS, OUTPUT_CLUSTERS, PROFILE_ID

DIAGNOSTICS_CLUSTER_ID = 0x0B05 # decimal = 2821


class BasicCluster(CustomCluster, Basic):
"""Centralite acceleration cluster."""

attributes = Basic.attributes.copy()
attributes.update({0x0031: ("phillips", t.bitmap16)})


class PhilipsRWL020(CustomDevice):
"""Phillips RWL020 device."""
"""Philips RWL020 device."""

signature = {
# <SimpleDescriptor endpoint=1 profile=49246 device_type=2080
Expand Down Expand Up @@ -98,42 +73,15 @@ class PhilipsRWL020(CustomDevice):
},
2: {
INPUT_CLUSTERS: [
BasicCluster,
PhilipsBasicCluster,
PowerConfiguration.cluster_id,
Identify.cluster_id,
BinaryInput.cluster_id,
64512,
PhilipsRemoteCluster,
],
OUTPUT_CLUSTERS: [Ota.cluster_id],
},
}
}

device_automation_triggers = {
(SHORT_PRESS, TURN_ON): {COMMAND: COMMAND_ON},
(SHORT_PRESS, TURN_OFF): {COMMAND: COMMAND_OFF_WITH_EFFECT},
(SHORT_PRESS, DIM_UP): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [0, 30, 9],
},
(LONG_PRESS, DIM_UP): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [0, 56, 9],
},
(SHORT_PRESS, DIM_DOWN): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [1, 30, 9],
},
(LONG_PRESS, DIM_DOWN): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [1, 56, 9],
},
}
device_automation_triggers = HUE_REMOTE_DEVICE_TRIGGERS
70 changes: 9 additions & 61 deletions zhaquirks/philips/rwl021.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Phillips RWL021 device."""
"""Philips RWL021 device."""

from zigpy.profiles import zha, zll
from zigpy.quirks import CustomCluster, CustomDevice
import zigpy.types as t
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import (
Basic,
BinaryInput,
Expand All @@ -14,39 +14,14 @@
Scenes,
)

from ..const import (
ARGS,
CLUSTER_ID,
COMMAND,
COMMAND_OFF_WITH_EFFECT,
COMMAND_ON,
COMMAND_STEP,
DEVICE_TYPE,
DIM_DOWN,
DIM_UP,
ENDPOINT_ID,
ENDPOINTS,
INPUT_CLUSTERS,
LONG_PRESS,
OUTPUT_CLUSTERS,
PROFILE_ID,
SHORT_PRESS,
TURN_OFF,
TURN_ON,
)
from . import HUE_REMOTE_DEVICE_TRIGGERS, PhilipsBasicCluster, PhilipsRemoteCluster
from ..const import DEVICE_TYPE, ENDPOINTS, INPUT_CLUSTERS, OUTPUT_CLUSTERS, PROFILE_ID

DIAGNOSTICS_CLUSTER_ID = 0x0B05 # decimal = 2821


class BasicCluster(CustomCluster, Basic):
"""Centralite acceleration cluster."""

attributes = Basic.attributes.copy()
attributes.update({0x0031: ("phillips", t.bitmap16)})


class PhilipsRWL021(CustomDevice):
"""Phillips RWL021 device."""
"""Philips RWL021 device."""

signature = {
# <SimpleDescriptor endpoint=1 profile=49246 device_type=2096
Expand Down Expand Up @@ -101,42 +76,15 @@ class PhilipsRWL021(CustomDevice):
},
2: {
INPUT_CLUSTERS: [
BasicCluster,
PhilipsBasicCluster,
PowerConfiguration.cluster_id,
Identify.cluster_id,
BinaryInput.cluster_id,
64512,
PhilipsRemoteCluster,
],
OUTPUT_CLUSTERS: [Ota.cluster_id],
},
}
}

device_automation_triggers = {
(SHORT_PRESS, TURN_ON): {COMMAND: COMMAND_ON},
(SHORT_PRESS, TURN_OFF): {COMMAND: COMMAND_OFF_WITH_EFFECT},
(SHORT_PRESS, DIM_UP): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [0, 30, 9],
},
(LONG_PRESS, DIM_UP): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [0, 56, 9],
},
(SHORT_PRESS, DIM_DOWN): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [1, 30, 9],
},
(LONG_PRESS, DIM_DOWN): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [1, 56, 9],
},
}
device_automation_triggers = HUE_REMOTE_DEVICE_TRIGGERS