diff --git a/zhaquirks/philips/__init__.py b/zhaquirks/philips/__init__.py index 7011d78ea6..b611d3875f 100644 --- a/zhaquirks/philips/__init__.py +++ b/zhaquirks/philips/__init__.py @@ -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.""" @@ -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() @@ -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 diff --git a/zhaquirks/philips/rdm001.py b/zhaquirks/philips/rdm001.py index 764e317487..da3e6523a6 100644 --- a/zhaquirks/philips/rdm001.py +++ b/zhaquirks/philips/rdm001.py @@ -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__) @@ -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): @@ -163,7 +100,7 @@ class PhilipsROM001(CustomDevice): PhilipsBasicCluster, PowerConfiguration.cluster_id, Identify.cluster_id, - PhilipsRemoteCluster, + PhilipsRdm001RemoteCluster, ], OUTPUT_CLUSTERS: [ Ota.cluster_id, @@ -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() + ) diff --git a/zhaquirks/philips/rdm002.py b/zhaquirks/philips/rdm002.py index 9f550695f7..d7dc0d0e4c 100644 --- a/zhaquirks/philips/rdm002.py +++ b/zhaquirks/philips/rdm002.py @@ -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, @@ -43,8 +33,8 @@ ) -class PhilipsRdmRemoteCluster(PhilipsRemoteCluster): - """Philips remote cluster for RDM devices.""" +class PhilipsRdm002RemoteCluster(PhilipsRemoteCluster): + """Philips remote cluster for RDM002.""" BUTTONS = { 1: BUTTON_1, @@ -52,12 +42,6 @@ class PhilipsRdmRemoteCluster(PhilipsRemoteCluster): 3: BUTTON_3, 4: BUTTON_4, } - PRESS_TYPES = { - 0: COMMAND_PRESS, - 1: COMMAND_HOLD, - 2: SHORT_RELEASE, - 3: LONG_RELEASE, - } class PhilipsRDM002(CustomDevice): @@ -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: [ @@ -103,7 +87,7 @@ class PhilipsRDM002(CustomDevice): PhilipsBasicCluster, PowerConfiguration.cluster_id, Identify.cluster_id, - PhilipsRdmRemoteCluster, + PhilipsRdm002RemoteCluster, LightLink.cluster_id, ], OUTPUT_CLUSTERS: [ @@ -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() + ) diff --git a/zhaquirks/philips/rom001.py b/zhaquirks/philips/rom001.py index 93fb66ad04..b8017ff6bc 100644 --- a/zhaquirks/philips/rom001.py +++ b/zhaquirks/philips/rom001.py @@ -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 ( @@ -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.""" @@ -84,7 +83,7 @@ class PhilipsROM001(CustomDevice): PhilipsBasicCluster, PowerConfiguration.cluster_id, Identify.cluster_id, - PhilipsRemoteCluster, + PhilipsRom001RemoteCluster, LightLink.cluster_id, ], OUTPUT_CLUSTERS: [ @@ -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() + ) diff --git a/zhaquirks/philips/rwl022.py b/zhaquirks/philips/rwl022.py index 6d093d679e..262705ab2a 100644 --- a/zhaquirks/philips/rwl022.py +++ b/zhaquirks/philips/rwl022.py @@ -22,7 +22,6 @@ PROFILE_ID, ) from zhaquirks.philips import ( - HUE_REMOTE_DEVICE_TRIGGERS, SIGNIFY, PhilipsBasicCluster, PhilipsRemoteCluster, @@ -91,4 +90,6 @@ class PhilipsRWL022(CustomDevice): } } - device_automation_triggers = HUE_REMOTE_DEVICE_TRIGGERS + device_automation_triggers = ( + PhilipsRemoteCluster.generate_device_automation_triggers() + ) diff --git a/zhaquirks/philips/rwlfirstgen.py b/zhaquirks/philips/rwlfirstgen.py index c0ef399162..68f3139a70 100644 --- a/zhaquirks/philips/rwlfirstgen.py +++ b/zhaquirks/philips/rwlfirstgen.py @@ -23,7 +23,6 @@ PROFILE_ID, ) from zhaquirks.philips import ( - HUE_REMOTE_DEVICE_TRIGGERS, PHILIPS, SIGNIFY, PhilipsBasicCluster, @@ -106,7 +105,9 @@ class PhilipsRWLFirstGen(CustomDevice): } } - device_automation_triggers = HUE_REMOTE_DEVICE_TRIGGERS + device_automation_triggers = ( + PhilipsRemoteCluster.generate_device_automation_triggers() + ) class PhilipsRWLFirstGen2(CustomDevice): @@ -180,4 +181,6 @@ class PhilipsRWLFirstGen2(CustomDevice): } } - device_automation_triggers = HUE_REMOTE_DEVICE_TRIGGERS + device_automation_triggers = ( + PhilipsRemoteCluster.generate_device_automation_triggers() + )