Skip to content

Commit

Permalink
Streamline Philips implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fholzer committed Sep 1, 2023
1 parent 01ca727 commit 7b67a4e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 192 deletions.
56 changes: 19 additions & 37 deletions zhaquirks/philips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,6 @@
SIGNIFY = "Signify Netherlands B.V."
_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"},
(DOUBLE_PRESS, TURN_ON): {COMMAND: "on_double_press"},
(DOUBLE_PRESS, TURN_OFF): {COMMAND: "off_double_press"},
(DOUBLE_PRESS, DIM_UP): {COMMAND: "up_double_press"},
(DOUBLE_PRESS, DIM_DOWN): {COMMAND: "down_double_press"},
(TRIPLE_PRESS, TURN_ON): {COMMAND: "on_triple_press"},
(TRIPLE_PRESS, TURN_OFF): {COMMAND: "off_triple_press"},
(TRIPLE_PRESS, DIM_UP): {COMMAND: "up_triple_press"},
(TRIPLE_PRESS, DIM_DOWN): {COMMAND: "down_triple_press"},
(QUADRUPLE_PRESS, TURN_ON): {COMMAND: "on_quadruple_press"},
(QUADRUPLE_PRESS, TURN_OFF): {COMMAND: "off_quadruple_press"},
(QUADRUPLE_PRESS, DIM_UP): {COMMAND: "up_quadruple_press"},
(QUADRUPLE_PRESS, DIM_DOWN): {COMMAND: "down_quadruple_press"},
(QUINTUPLE_PRESS, TURN_ON): {COMMAND: "on_quintuple_press"},
(QUINTUPLE_PRESS, TURN_OFF): {COMMAND: "off_quintuple_press"},
(QUINTUPLE_PRESS, DIM_UP): {COMMAND: "up_quintuple_press"},
(QUINTUPLE_PRESS, DIM_DOWN): {COMMAND: "down_quintuple_press"},
(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 PhilipsOccupancySensing(CustomCluster):
"""Philips occupancy cluster."""
Expand Down Expand Up @@ -157,8 +122,17 @@ class PhilipsRemoteCluster(CustomCluster):
is_manufacturer_specific=True,
)
}
BUTTONS = {1: "on", 2: "up", 3: "down", 4: "off"}
PRESS_TYPES = {0: "press", 1: "hold", 2: "short_release", 3: "long_release"}
BUTTONS = {1: TURN_ON, 2: DIM_UP, 3: DIM_DOWN, 4: TURN_OFF}
PRESS_TYPES = {
0: SHORT_PRESS,
1: LONG_PRESS,
2: SHORT_RELEASE,
3: LONG_RELEASE,
4: DOUBLE_PRESS,
5: TRIPLE_PRESS,
6: QUADRUPLE_PRESS,
7: QUINTUPLE_PRESS,
}

button_press_queue = ButtonPressQueue()

Expand Down Expand Up @@ -222,3 +196,11 @@ def send_press_event(click_count):
else:
action = f"{button}_{press_type}"
self.listener_event(ZHA_SEND_EVENT, action, event_args)

@classmethod
def generate_device_automation_triggers(cls):
triggers = {}
for button in cls.BUTTONS.values():
for press_type in cls.PRESS_TYPES.values():
triggers[(press_type, button)] = {COMMAND: f"{button}_{press_type}"}
return triggers
98 changes: 10 additions & 88 deletions zhaquirks/philips/rdm001.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,16 @@
)

from zhaquirks.const import (
ARGS,
BUTTON,
COMMAND,
COMMAND_ID,
DEVICE_TYPE,
DOUBLE_PRESS,
ENDPOINTS,
INPUT_CLUSTERS,
LONG_PRESS,
LONG_RELEASE,
MODELS_INFO,
OUTPUT_CLUSTERS,
PRESS_TYPE,
PROFILE_ID,
QUADRUPLE_PRESS,
QUINTUPLE_PRESS,
RIGHT,
SHORT_PRESS,
SHORT_RELEASE,
TRIPLE_PRESS,
TURN_ON,
ZHA_SEND_EVENT,
)
from zhaquirks.philips import PHILIPS, SIGNIFY
from zhaquirks.philips import PHILIPS, SIGNIFY, PhilipsRemoteCluster

DEVICE_SPECIFIC_UNKNOWN = 64512
_LOGGER = logging.getLogger(__name__)
Expand All @@ -66,62 +52,13 @@ async def bind(self):
return result


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

cluster_id = 64512
name = "PhilipsRemoteCluster"
ep_attribute = "philips_remote_cluster"
client_commands = {
0x00: foundation.ZCLCommandDef(
"notification",
{
"param1": t.uint8_t,
"param2": t.uint24_t,
"param3": t.uint8_t,
"param4": t.uint8_t,
"param5": t.uint8_t,
"param6": t.uint8_t,
},
is_manufacturer_specific=True,
direction=foundation.Direction.Server_to_Client,
)
}
class PhilipsRdm001RemoteCluster(PhilipsRemoteCluster):
"""Philips remote cluster for RDM001."""

BUTTONS = {
1: "left",
2: "right",
1: TURN_ON,
2: RIGHT,
}
PRESS_TYPES = {0: "press", 1: "hold", 2: "press_release", 3: "hold_release"}

def handle_cluster_request(
self,
hdr: foundation.ZCLHeader,
args: List[Any],
*,
dst_addressing: Optional[
Union[t.Addressing.Group, t.Addressing.IEEE, t.Addressing.NWK]
] = None,
):
"""Handle the cluster command."""
_LOGGER.debug(
"PhilipsRemoteCluster - handle_cluster_request tsn: [%s] command id: %s - args: [%s]",
hdr.tsn,
hdr.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: hdr.command_id,
ARGS: args,
}

action = f"{button}_{press_type}"
self.listener_event(ZHA_SEND_EVENT, action, event_args)


class PhilipsROM001(CustomDevice):
Expand Down Expand Up @@ -163,7 +100,7 @@ class PhilipsROM001(CustomDevice):
PhilipsBasicCluster,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PhilipsRemoteCluster,
PhilipsRdm001RemoteCluster,
],
OUTPUT_CLUSTERS: [
Ota.cluster_id,
Expand All @@ -176,21 +113,6 @@ class PhilipsROM001(CustomDevice):
}
}

device_automation_triggers = {
(SHORT_PRESS, TURN_ON): {COMMAND: "left_press"},
(LONG_PRESS, TURN_ON): {COMMAND: "left_hold"},
(DOUBLE_PRESS, TURN_ON): {COMMAND: "left_double_press"},
(TRIPLE_PRESS, TURN_ON): {COMMAND: "left_triple_press"},
(QUADRUPLE_PRESS, TURN_ON): {COMMAND: "left_quadruple_press"},
(QUINTUPLE_PRESS, TURN_ON): {COMMAND: "left_quintuple_press"},
(SHORT_RELEASE, TURN_ON): {COMMAND: "left_short_release"},
(LONG_RELEASE, TURN_ON): {COMMAND: "left_long_release"},
(SHORT_PRESS, RIGHT): {COMMAND: "right_press"},
(LONG_PRESS, RIGHT): {COMMAND: "right_hold"},
(DOUBLE_PRESS, RIGHT): {COMMAND: "right_double_press"},
(TRIPLE_PRESS, RIGHT): {COMMAND: "right_triple_press"},
(QUADRUPLE_PRESS, RIGHT): {COMMAND: "right_quadruple_press"},
(QUINTUPLE_PRESS, RIGHT): {COMMAND: "right_quintuple_press"},
(SHORT_RELEASE, RIGHT): {COMMAND: "right_short_release"},
(LONG_RELEASE, RIGHT): {COMMAND: "right_long_release"},
}
device_automation_triggers = (
PhilipsRdm001RemoteCluster.generate_device_automation_triggers()
)
49 changes: 7 additions & 42 deletions zhaquirks/philips/rdm002.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,12 @@
BUTTON_2,
BUTTON_3,
BUTTON_4,
COMMAND,
COMMAND_HOLD,
COMMAND_PRESS,
DEVICE_TYPE,
DOUBLE_PRESS,
ENDPOINTS,
INPUT_CLUSTERS,
LONG_RELEASE,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
QUADRUPLE_PRESS,
QUINTUPLE_PRESS,
SHORT_PRESS,
SHORT_RELEASE,
TRIPLE_PRESS,
)
from zhaquirks.philips import (
PHILIPS,
Expand All @@ -43,21 +33,15 @@
)


class PhilipsRdmRemoteCluster(PhilipsRemoteCluster):
"""Philips remote cluster for RDM devices."""
class PhilipsRdm002RemoteCluster(PhilipsRemoteCluster):
"""Philips remote cluster for RDM002."""

BUTTONS = {
1: BUTTON_1,
2: BUTTON_2,
3: BUTTON_3,
4: BUTTON_4,
}
PRESS_TYPES = {
0: COMMAND_PRESS,
1: COMMAND_HOLD,
2: SHORT_RELEASE,
3: LONG_RELEASE,
}


class PhilipsRDM002(CustomDevice):
Expand All @@ -77,7 +61,7 @@ class PhilipsRDM002(CustomDevice):
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PhilipsRdmRemoteCluster.cluster_id,
PhilipsRdm002RemoteCluster.cluster_id,
LightLink.cluster_id,
],
OUTPUT_CLUSTERS: [
Expand All @@ -103,7 +87,7 @@ class PhilipsRDM002(CustomDevice):
PhilipsBasicCluster,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PhilipsRdmRemoteCluster,
PhilipsRdm002RemoteCluster,
LightLink.cluster_id,
],
OUTPUT_CLUSTERS: [
Expand All @@ -120,25 +104,6 @@ class PhilipsRDM002(CustomDevice):
}
}

device_automation_triggers = {
(SHORT_PRESS, BUTTON_1): {COMMAND: f"{BUTTON_1}_press"},
(SHORT_PRESS, BUTTON_2): {COMMAND: f"{BUTTON_2}_press"},
(SHORT_PRESS, BUTTON_3): {COMMAND: f"{BUTTON_3}_press"},
(SHORT_PRESS, BUTTON_4): {COMMAND: f"{BUTTON_4}_press"},
(DOUBLE_PRESS, BUTTON_1): {COMMAND: f"{BUTTON_1}_double_press"},
(DOUBLE_PRESS, BUTTON_2): {COMMAND: f"{BUTTON_2}_double_press"},
(DOUBLE_PRESS, BUTTON_3): {COMMAND: f"{BUTTON_3}_double_press"},
(DOUBLE_PRESS, BUTTON_4): {COMMAND: f"{BUTTON_4}_double_press"},
(TRIPLE_PRESS, BUTTON_1): {COMMAND: f"{BUTTON_1}_triple_press"},
(TRIPLE_PRESS, BUTTON_2): {COMMAND: f"{BUTTON_2}_triple_press"},
(TRIPLE_PRESS, BUTTON_3): {COMMAND: f"{BUTTON_3}_triple_press"},
(TRIPLE_PRESS, BUTTON_4): {COMMAND: f"{BUTTON_4}_triple_press"},
(QUADRUPLE_PRESS, BUTTON_1): {COMMAND: f"{BUTTON_1}_quadruple_press"},
(QUADRUPLE_PRESS, BUTTON_2): {COMMAND: f"{BUTTON_2}_quadruple_press"},
(QUADRUPLE_PRESS, BUTTON_3): {COMMAND: f"{BUTTON_3}_quadruple_press"},
(QUADRUPLE_PRESS, BUTTON_4): {COMMAND: f"{BUTTON_4}_quadruple_press"},
(QUINTUPLE_PRESS, BUTTON_1): {COMMAND: f"{BUTTON_1}_quintuple_press"},
(QUINTUPLE_PRESS, BUTTON_2): {COMMAND: f"{BUTTON_2}_quintuple_press"},
(QUINTUPLE_PRESS, BUTTON_3): {COMMAND: f"{BUTTON_3}_quintuple_press"},
(QUINTUPLE_PRESS, BUTTON_4): {COMMAND: f"{BUTTON_4}_quintuple_press"},
}
device_automation_triggers = (
PhilipsRdm002RemoteCluster.generate_device_automation_triggers()
)
32 changes: 12 additions & 20 deletions zhaquirks/philips/rom001.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,12 @@
from zigpy.zcl.clusters.lightlink import LightLink

from zhaquirks.const import (
COMMAND,
DEVICE_TYPE,
DOUBLE_PRESS,
ENDPOINTS,
INPUT_CLUSTERS,
LONG_PRESS,
LONG_RELEASE,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
QUADRUPLE_PRESS,
QUINTUPLE_PRESS,
SHORT_PRESS,
SHORT_RELEASE,
TRIPLE_PRESS,
TURN_ON,
)
from zhaquirks.philips import (
Expand All @@ -41,6 +32,14 @@
DEVICE_SPECIFIC_UNKNOWN = 64512


class PhilipsRom001RemoteCluster(PhilipsRemoteCluster):
"""Philips remote cluster for ROM001."""

BUTTONS = {
1: TURN_ON,
}


class PhilipsROM001(CustomDevice):
"""Philips ROM001 device."""

Expand Down Expand Up @@ -84,7 +83,7 @@ class PhilipsROM001(CustomDevice):
PhilipsBasicCluster,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PhilipsRemoteCluster,
PhilipsRom001RemoteCluster,
LightLink.cluster_id,
],
OUTPUT_CLUSTERS: [
Expand All @@ -101,13 +100,6 @@ class PhilipsROM001(CustomDevice):
}
}

device_automation_triggers = {
(SHORT_PRESS, TURN_ON): {COMMAND: "on_press"},
(LONG_PRESS, TURN_ON): {COMMAND: "on_hold"},
(DOUBLE_PRESS, TURN_ON): {COMMAND: "on_double_press"},
(TRIPLE_PRESS, TURN_ON): {COMMAND: "on_triple_press"},
(QUADRUPLE_PRESS, TURN_ON): {COMMAND: "on_quadruple_press"},
(QUINTUPLE_PRESS, TURN_ON): {COMMAND: "on_quintuple_press"},
(SHORT_RELEASE, TURN_ON): {COMMAND: "on_short_release"},
(LONG_RELEASE, TURN_ON): {COMMAND: "on_long_release"},
}
device_automation_triggers = (
PhilipsRom001RemoteCluster.generate_device_automation_triggers()
)
5 changes: 3 additions & 2 deletions zhaquirks/philips/rwl022.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
PROFILE_ID,
)
from zhaquirks.philips import (
HUE_REMOTE_DEVICE_TRIGGERS,
SIGNIFY,
PhilipsBasicCluster,
PhilipsRemoteCluster,
Expand Down Expand Up @@ -91,4 +90,6 @@ class PhilipsRWL022(CustomDevice):
}
}

device_automation_triggers = HUE_REMOTE_DEVICE_TRIGGERS
device_automation_triggers = (
PhilipsRemoteCluster.generate_device_automation_triggers()
)
Loading

0 comments on commit 7b67a4e

Please sign in to comment.