/
__init__.py
209 lines (172 loc) · 5.88 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
"""Ikea module."""
import logging
from zigpy.quirks import CustomCluster
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import PowerConfiguration, Scenes
from zhaquirks import DoublingPowerConfigurationCluster, EventableCluster
_LOGGER = logging.getLogger(__name__)
IKEA = "IKEA of Sweden"
IKEA_CLUSTER_ID = 0xFC7C # decimal = 64636
WWAH_CLUSTER_ID = 0xFC57 # decimal = 64599 ('Works with all Hubs' cluster)
IKEA_SHORTCUT_CLUSTER_V1_ID = 0xFC7F # decimal = 64639 Shortcut V1 commands
IKEA_MATTER_SWITCH_CLUSTER_ID = 0xFC80 # decimal = 64640 Shortcut V2 commands
COMMAND_SHORTCUT_V1 = "shortcut_v1_events"
# PowerConfiguration cluster attributes
BATTERY_VOLTAGE = PowerConfiguration.attributes_by_name["battery_voltage"].id
BATTERY_SIZE = PowerConfiguration.attributes_by_name["battery_size"].id
BATTERY_QUANTITY = PowerConfiguration.attributes_by_name["battery_quantity"].id
BATTERY_RATED_VOLTAGE = PowerConfiguration.attributes_by_name[
"battery_rated_voltage"
].id
class ScenesCluster(CustomCluster, Scenes):
"""Ikea Scenes cluster."""
server_commands = Scenes.server_commands.copy()
server_commands.update(
{
0x0007: foundation.ZCLCommandDef(
"press",
{"param1": t.int16s, "param2": t.int8s, "param3": t.int8s},
False,
is_manufacturer_specific=True,
),
0x0008: foundation.ZCLCommandDef(
"hold",
{"param1": t.int16s, "param2": t.int8s},
False,
is_manufacturer_specific=True,
),
0x0009: foundation.ZCLCommandDef(
"release",
{
"param1": t.int16s,
},
False,
is_manufacturer_specific=True,
),
}
)
class ShortcutV1Cluster(EventableCluster):
"""Ikea Shortcut Button Cluster Variant 1."""
cluster_id = IKEA_SHORTCUT_CLUSTER_V1_ID
server_commands = {
0x01: foundation.ZCLCommandDef(
COMMAND_SHORTCUT_V1,
{
"shortcut_button": t.int8s,
"shortcut_event": t.int8s,
},
False,
is_manufacturer_specific=True,
),
}
class ShortcutV2Cluster(EventableCluster):
"""Ikea Shortcut Button Cluster Variant 2."""
cluster_id = IKEA_MATTER_SWITCH_CLUSTER_ID
server_commands = {
0x00: foundation.ZCLCommandDef(
"switch_latched",
{
"new_position": t.int8s,
},
False,
is_manufacturer_specific=True,
),
0x01: foundation.ZCLCommandDef(
"initial_press",
{
"new_position": t.int8s,
},
False,
is_manufacturer_specific=True,
),
0x02: foundation.ZCLCommandDef(
"long_press",
{
"previous_position": t.int8s,
},
False,
is_manufacturer_specific=True,
),
0x03: foundation.ZCLCommandDef(
"short_release",
{
"previous_position": t.int8s,
},
False,
is_manufacturer_specific=True,
),
0x04: foundation.ZCLCommandDef(
"long_release",
{
"previous_position": t.int8s,
},
False,
is_manufacturer_specific=True,
),
0x05: foundation.ZCLCommandDef(
"multi_press_ongoing",
{
"new_position": t.int8s,
# "current_number_of_presses_counted": t.int8s, # not implemented
},
False,
is_manufacturer_specific=True,
),
0x06: foundation.ZCLCommandDef(
"multi_press_complete",
{
"previous_position": t.int8s,
"total_number_of_presses_counted": t.int8s,
},
False,
is_manufacturer_specific=True,
),
}
# ZCL compliant IKEA power configuration clusters:
class PowerConfig2AAACluster(CustomCluster, PowerConfiguration):
"""Updating power attributes: 2 AAA."""
_CONSTANT_ATTRIBUTES = {
BATTERY_SIZE: 4,
BATTERY_QUANTITY: 2,
BATTERY_RATED_VOLTAGE: 15,
}
class PowerConfig2CRCluster(CustomCluster, PowerConfiguration):
"""Updating power attributes: 2 CR2032."""
_CONSTANT_ATTRIBUTES = {
BATTERY_SIZE: 10,
BATTERY_QUANTITY: 2,
BATTERY_RATED_VOLTAGE: 30,
}
class PowerConfig1CRCluster(CustomCluster, PowerConfiguration):
"""Updating power attributes: 1 CR2032."""
_CONSTANT_ATTRIBUTES = {
BATTERY_SIZE: 10,
BATTERY_QUANTITY: 1,
BATTERY_RATED_VOLTAGE: 30,
}
class PowerConfig1CRXCluster(CustomCluster, PowerConfiguration):
"""Updating power attributes: 1 CR2032 and zero voltage."""
_CONSTANT_ATTRIBUTES = {
BATTERY_VOLTAGE: 0,
BATTERY_SIZE: 10,
BATTERY_QUANTITY: 1,
BATTERY_RATED_VOLTAGE: 30,
}
# doubling IKEA power configuration clusters:
class DoublingPowerConfig2AAACluster(
DoublingPowerConfigurationCluster, PowerConfig2AAACluster
):
"""Doubling power configuration cluster. Updating power attributes: 2 AAA."""
class DoublingPowerConfig2CRCluster(
DoublingPowerConfigurationCluster, PowerConfig2CRCluster
):
"""Doubling power configuration cluster. Updating power attributes: 2 CR2032."""
class DoublingPowerConfig1CRCluster(
DoublingPowerConfigurationCluster, PowerConfig1CRCluster
):
"""Doubling power configuration cluster. Updating power attributes: 1 CR2032."""
class DoublingPowerConfig1CRXCluster(
DoublingPowerConfigurationCluster, PowerConfig1CRXCluster
):
"""Doubling power configuration cluster. Updating power attributes: 1 CR2032 and zero voltage."""