Skip to content

Commit 57fff7a

Browse files
committed
Fix long release dim down for Ikea 2 button remote (Rodret)
1 parent 6ab11ea commit 57fff7a

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

zhaquirks/ikea/twobtnremote.py

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
"""Device handler for IKEA of Sweden TRADFRI remote control."""
22

3+
from typing import Any, Optional, Union
4+
35
from zigpy.profiles import zha, zll
4-
from zigpy.quirks import CustomDevice
6+
from zigpy.quirks import CustomCluster, CustomDevice
7+
import zigpy.types as t
8+
from zigpy.zcl import foundation
59
from zigpy.zcl.clusters.closures import WindowCovering
610
from zigpy.zcl.clusters.general import (
711
Alarms,
@@ -40,6 +44,7 @@
4044
SHORT_PRESS,
4145
TURN_OFF,
4246
TURN_ON,
47+
ZHA_SEND_EVENT,
4348
)
4449
from zhaquirks.ikea import (
4550
IKEA,
@@ -48,6 +53,45 @@
4853
PowerConfig1AAACluster,
4954
)
5055

56+
COMMAND_LONG_RELESE_DIM_UP = "long_release_dim_up"
57+
COMMAND_LONG_RELESE_DIM_DOWN = "long_release_dim_down"
58+
59+
60+
class IkeaRemoteLongReleaseControl(CustomCluster, LevelControl):
61+
"""Ikea Remote Long Release Control cluster."""
62+
63+
def __init__(self, *args, **kwargs):
64+
"""Initialize instance."""
65+
super().__init__(*args, **kwargs)
66+
self._dim_direction_down = None
67+
68+
def handle_cluster_request(
69+
self,
70+
hdr: foundation.ZCLHeader,
71+
args: list[Any],
72+
*,
73+
dst_addressing: Optional[
74+
Union[t.Addressing.Group, t.Addressing.IEEE, t.Addresszhing.NWK]
75+
] = None,
76+
) -> None:
77+
"""Handle cluster specific commands.
78+
79+
We just want to keep track of direction, to associate it with the stop command.
80+
"""
81+
82+
cmd_name = self.server_commands[hdr.command_id].name
83+
if cmd_name == COMMAND_MOVE_ON_OFF:
84+
self._dim_direction_down = False
85+
elif cmd_name == COMMAND_MOVE:
86+
self._dim_direction_down = True
87+
elif cmd_name in (COMMAND_STOP_ON_OFF, COMMAND_STOP):
88+
action = (
89+
COMMAND_LONG_RELESE_DIM_DOWN
90+
if self._dim_direction_down
91+
else COMMAND_LONG_RELESE_DIM_UP
92+
)
93+
self.listener_event(ZHA_SEND_EVENT, action, [])
94+
5195

5296
class IkeaTradfriRemote2Btn(CustomDevice):
5397
"""Custom device representing IKEA of Sweden TRADFRI remote control."""
@@ -102,7 +146,7 @@ class IkeaTradfriRemote2Btn(CustomDevice):
102146
Identify.cluster_id,
103147
Groups.cluster_id,
104148
OnOff.cluster_id,
105-
LevelControl.cluster_id,
149+
IkeaRemoteLongReleaseControl,
106150
Ota.cluster_id,
107151
WindowCovering.cluster_id,
108152
LightLink.cluster_id,
@@ -120,7 +164,7 @@ class IkeaTradfriRemote2Btn(CustomDevice):
120164
PARAMS: {"move_mode": 0},
121165
},
122166
(LONG_RELEASE, DIM_UP): {
123-
COMMAND: COMMAND_STOP_ON_OFF,
167+
COMMAND: COMMAND_LONG_RELESE_DIM_UP,
124168
CLUSTER_ID: 8,
125169
ENDPOINT_ID: 1,
126170
},
@@ -132,7 +176,7 @@ class IkeaTradfriRemote2Btn(CustomDevice):
132176
PARAMS: {"move_mode": 1},
133177
},
134178
(LONG_RELEASE, DIM_DOWN): {
135-
COMMAND: COMMAND_STOP,
179+
COMMAND: COMMAND_LONG_RELESE_DIM_DOWN,
136180
CLUSTER_ID: 8,
137181
ENDPOINT_ID: 1,
138182
},
@@ -191,7 +235,7 @@ class IkeaTradfriRemote2BtnZLL(CustomDevice):
191235
Identify.cluster_id,
192236
Groups.cluster_id,
193237
OnOff.cluster_id,
194-
LevelControl.cluster_id,
238+
IkeaRemoteLongReleaseControl,
195239
Ota.cluster_id,
196240
WindowCovering.cluster_id,
197241
LightLink.cluster_id,
@@ -253,7 +297,7 @@ class IkeaRodretRemote2Btn(CustomDevice):
253297
Identify.cluster_id,
254298
Groups.cluster_id,
255299
OnOff.cluster_id,
256-
LevelControl.cluster_id,
300+
IkeaRemoteLongReleaseControl,
257301
Ota.cluster_id,
258302
LightLink.cluster_id,
259303
],
@@ -315,7 +359,7 @@ class IkeaRodretRemote2BtnNew(CustomDevice):
315359
Identify.cluster_id,
316360
Groups.cluster_id,
317361
OnOff.cluster_id,
318-
LevelControl.cluster_id,
362+
IkeaRemoteLongReleaseControl,
319363
Ota.cluster_id,
320364
LightLink.cluster_id,
321365
],

0 commit comments

Comments
 (0)