Skip to content

Commit

Permalink
Convert IKEA Styrbar quirks to v2 quirk (#3175)
Browse files Browse the repository at this point in the history
* Convert IKEA Styrbar quirks to v2 quirk

* Remove `fourbtnremote` from `test_quirk_device_automation_triggers_unique`

The test does not handle v2 quirks yet and we'll need to see how we want to implement this, as all v2 quirks share the same quirk class.
For now, this just removes the `fourbtnremote` from the test.
  • Loading branch information
TheJulianJES authored May 29, 2024
1 parent 31c51ce commit b2751a2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 211 deletions.
7 changes: 1 addition & 6 deletions tests/test_quirks.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,6 @@ def test_migrated_lighting_automation_triggers(quirk: CustomDevice) -> None:
(zhaquirks.aurora.aurora_dimmer.COLOR_DOWN, const.LEFT),
],
],
zhaquirks.ikea.fourbtnremote.IkeaTradfriRemoteV1: [
[
(const.LONG_RELEASE, const.DIM_UP),
(const.LONG_RELEASE, const.DIM_DOWN),
]
],
zhaquirks.paulmann.fourbtnremote.PaulmannRemote4Btn: [
[
(const.LONG_RELEASE, const.BUTTON_1),
Expand All @@ -666,6 +660,7 @@ def test_migrated_lighting_automation_triggers(quirk: CustomDevice) -> None:
}


# XXX: Test does not handle v2 quirks
@pytest.mark.parametrize(
"quirk",
[q for q in ALL_QUIRK_CLASSES if getattr(q, "device_automation_triggers", None)],
Expand Down
282 changes: 77 additions & 205 deletions zhaquirks/ikea/fourbtnremote.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
"""Device handler for IKEA of Sweden TRADFRI remote control."""
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import (
Basic,
Identify,
LevelControl,
OnOff,
Ota,
PollControl,
PowerConfiguration,
)
from zigpy.zcl.clusters.lightlink import LightLink
from zigpy.quirks.v2 import add_to_registry_v2
from zigpy.zcl import ClusterType

from zhaquirks.const import (
CLUSTER_ID,
Expand All @@ -23,214 +13,96 @@
COMMAND_PRESS,
COMMAND_STOP,
COMMAND_STOP_ON_OFF,
DEVICE_TYPE,
DIM_DOWN,
DIM_UP,
ENDPOINT_ID,
ENDPOINTS,
INPUT_CLUSTERS,
LEFT,
LONG_PRESS,
LONG_RELEASE,
MODELS_INFO,
OUTPUT_CLUSTERS,
PARAMS,
PROFILE_ID,
RIGHT,
SHORT_PRESS,
TURN_OFF,
TURN_ON,
)
from zhaquirks.ikea import (
IKEA,
IKEA_CLUSTER_ID,
WWAH_CLUSTER_ID,
DoublingPowerConfig2AAACluster,
ScenesCluster,
)


class IkeaTradfriRemoteV1(CustomDevice):
"""Custom device representing IKEA of Sweden TRADFRI remote control V1.0.024."""

signature = {
# <SimpleDescriptor endpoint=1 profile=260 device_type=820
# device_version=1
# input_clusters=[0, 1, 3, 32, 4096, 64599]
# output_clusters=[3, 6, 8, 25, 4096]>
MODELS_INFO: [(IKEA, "Remote Control N2")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.NON_COLOR_CONTROLLER,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PollControl.cluster_id,
LightLink.cluster_id,
WWAH_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
Ota.cluster_id,
LightLink.cluster_id,
],
}
},
}
from zhaquirks.ikea import IKEA, DoublingPowerConfig2AAACluster, ScenesCluster

replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.NON_COLOR_CONTROLLER,
INPUT_CLUSTERS: [
Basic.cluster_id,
DoublingPowerConfig2AAACluster,
Identify.cluster_id,
PollControl.cluster_id,
LightLink.cluster_id,
WWAH_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
ScenesCluster,
OnOff.cluster_id,
LevelControl.cluster_id,
Ota.cluster_id,
LightLink.cluster_id,
],
}
}
}

device_automation_triggers = {
(SHORT_PRESS, TURN_ON): {COMMAND: COMMAND_ON, CLUSTER_ID: 6, ENDPOINT_ID: 1},
(LONG_PRESS, DIM_UP): {
COMMAND: COMMAND_MOVE_ON_OFF,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
PARAMS: {"move_mode": 0},
},
(LONG_RELEASE, DIM_UP): {
COMMAND: COMMAND_STOP_ON_OFF,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
},
(SHORT_PRESS, TURN_OFF): {COMMAND: COMMAND_OFF, CLUSTER_ID: 6, ENDPOINT_ID: 1},
(LONG_PRESS, DIM_DOWN): {
COMMAND: COMMAND_MOVE,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
PARAMS: {"move_mode": 1},
},
(LONG_RELEASE, DIM_DOWN): {
COMMAND: COMMAND_STOP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
},
(SHORT_PRESS, LEFT): {
COMMAND: COMMAND_PRESS,
CLUSTER_ID: 5,
ENDPOINT_ID: 1,
PARAMS: {
"param1": 257,
"param2": 13,
"param3": 0,
(
add_to_registry_v2(IKEA, "Remote Control N2")
.replaces(DoublingPowerConfig2AAACluster) # will only double for old firmware
.replaces(ScenesCluster, cluster_type=ClusterType.Client)
.device_automation_triggers(
{
(SHORT_PRESS, TURN_ON): {
COMMAND: COMMAND_ON,
CLUSTER_ID: 6,
ENDPOINT_ID: 1,
},
},
(LONG_PRESS, LEFT): {
COMMAND: COMMAND_HOLD,
CLUSTER_ID: 5,
ENDPOINT_ID: 1,
PARAMS: {
"param1": 3329,
"param2": 0,
(LONG_PRESS, DIM_UP): {
COMMAND: COMMAND_MOVE_ON_OFF,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
PARAMS: {"move_mode": 0},
},
},
(SHORT_PRESS, RIGHT): {
COMMAND: COMMAND_PRESS,
CLUSTER_ID: 5,
ENDPOINT_ID: 1,
PARAMS: {
"param1": 256,
"param2": 13,
"param3": 0,
(LONG_RELEASE, DIM_UP): {
COMMAND: COMMAND_STOP_ON_OFF,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
},
},
(LONG_PRESS, RIGHT): {
COMMAND: COMMAND_HOLD,
CLUSTER_ID: 5,
ENDPOINT_ID: 1,
PARAMS: {
"param1": 3328,
"param2": 0,
(SHORT_PRESS, TURN_OFF): {
COMMAND: COMMAND_OFF,
CLUSTER_ID: 6,
ENDPOINT_ID: 1,
},
(LONG_PRESS, DIM_DOWN): {
COMMAND: COMMAND_MOVE,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
PARAMS: {"move_mode": 1},
},
(LONG_RELEASE, DIM_DOWN): {
COMMAND: COMMAND_STOP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
},
(SHORT_PRESS, LEFT): {
COMMAND: COMMAND_PRESS,
CLUSTER_ID: 5,
ENDPOINT_ID: 1,
PARAMS: {
"param1": 257,
"param2": 13,
"param3": 0,
},
},
(LONG_PRESS, LEFT): {
COMMAND: COMMAND_HOLD,
CLUSTER_ID: 5,
ENDPOINT_ID: 1,
PARAMS: {
"param1": 3329,
"param2": 0,
},
},
(SHORT_PRESS, RIGHT): {
COMMAND: COMMAND_PRESS,
CLUSTER_ID: 5,
ENDPOINT_ID: 1,
PARAMS: {
"param1": 256,
"param2": 13,
"param3": 0,
},
},
(LONG_PRESS, RIGHT): {
COMMAND: COMMAND_HOLD,
CLUSTER_ID: 5,
ENDPOINT_ID: 1,
PARAMS: {
"param1": 3328,
"param2": 0,
},
},
},
}


class IkeaTradfriRemoteV2(CustomDevice):
"""Custom device representing IKEA of Sweden TRADFRI remote control Version 2.4.5."""

signature = {
# <SimpleDescriptor endpoint=1 profile=260 device_type=820
# device_version=1
# input_clusters=[0, 1, 3, 32, 4096, 64599, 64636]
# output_clusters=[3, 5, 6, 8, 25, 4096]>
MODELS_INFO: [(IKEA, "Remote Control N2")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.NON_COLOR_CONTROLLER,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PollControl.cluster_id,
LightLink.cluster_id,
WWAH_CLUSTER_ID,
IKEA_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
ScenesCluster.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
Ota.cluster_id,
LightLink.cluster_id,
],
}
},
}

replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.NON_COLOR_CONTROLLER,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
PollControl.cluster_id,
LightLink.cluster_id,
WWAH_CLUSTER_ID,
IKEA_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
ScenesCluster,
OnOff.cluster_id,
LevelControl.cluster_id,
Ota.cluster_id,
LightLink.cluster_id,
],
}
}
}

device_automation_triggers = IkeaTradfriRemoteV1.device_automation_triggers.copy()
)
)

0 comments on commit b2751a2

Please sign in to comment.