-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlight.py
447 lines (399 loc) · 14.7 KB
/
light.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
"""Module to handle quirks of the Sinopé Technologies light.
Supported devices SW2500ZB, SW2500ZB-G2 dimmer DM2500ZB, DM2500ZB-G2, DM2550ZB,
DM2550ZB-G2.
"""
import logging
from typing import Any, Final, Optional, Union
import zigpy.profiles.zha as zha_p
from zigpy.quirks import CustomCluster, CustomDevice
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import (
Basic,
DeviceTemperature,
Groups,
Identify,
LevelControl,
OnOff,
Ota,
Scenes,
Time,
)
from zigpy.zcl.clusters.homeautomation import Diagnostic, ElectricalMeasurement
from zigpy.zcl.clusters.smartenergy import Metering
from zhaquirks import EventableCluster
from zhaquirks.const import (
ATTRIBUTE_ID,
ATTRIBUTE_NAME,
BUTTON,
COMMAND_M_INITIAL_PRESS,
COMMAND_M_LONG_RELEASE,
COMMAND_M_MULTI_PRESS_COMPLETE,
COMMAND_M_SHORT_RELEASE,
DESCRIPTION,
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
TURN_OFF,
TURN_ON,
VALUE,
ZHA_SEND_EVENT,
)
from zhaquirks.sinope import (
ATTRIBUTE_ACTION,
LIGHT_DEVICE_TRIGGERS,
SINOPE,
SINOPE_MANUFACTURER_CLUSTER_ID,
ButtonAction,
CustomDeviceTemperatureCluster,
)
_LOGGER = logging.getLogger(__name__)
class KeypadLock(t.enum8):
"""Keypad_lockout values."""
Unlocked = 0x00
Locked = 0x01
Partial_lock = 0x02
class PhaseControl(t.enum8):
"""Phase control value, reverse / forward."""
Forward = 0x00
Reverse = 0x01
class DoubleFull(t.enum8):
"""Double click up set full intensity."""
Off = 0x00
On = 0x01
class SinopeTechnologiesManufacturerCluster(CustomCluster):
"""SinopeTechnologiesManufacturerCluster manufacturer cluster."""
KeypadLock: Final = KeypadLock
PhaseControl: Final = PhaseControl
DoubleFull: Final = DoubleFull
Action: Final = ButtonAction
cluster_id: Final[t.uint16_t] = SINOPE_MANUFACTURER_CLUSTER_ID
name: Final = "SinopeTechnologiesManufacturerCluster"
ep_attribute: Final = "sinope_manufacturer_specific"
class AttributeDefs(foundation.BaseAttributeDefs):
"""Sinope Manufacturer Cluster Attributes."""
unknown_attr_1: Final = foundation.ZCLAttributeDef(
id=0x0001, type=t.Bool, access="rw", is_manufacturer_specific=True
)
keypad_lockout: Final = foundation.ZCLAttributeDef(
id=0x0002, type=KeypadLock, access="rw", is_manufacturer_specific=True
)
firmware_number: Final = foundation.ZCLAttributeDef(
id=0x0003, type=t.uint16_t, access="r", is_manufacturer_specific=True
)
firmware_version: Final = foundation.ZCLAttributeDef(
id=0x0004, type=t.CharacterString, access="r", is_manufacturer_specific=True
)
on_intensity: Final = foundation.ZCLAttributeDef(
id=0x0010, type=t.int16s, access="rw", is_manufacturer_specific=True
)
unknown_attr_2: Final = foundation.ZCLAttributeDef(
id=0x0012, type=t.enum8, access="rw", is_manufacturer_specific=True
)
unknown_attr_3: Final = foundation.ZCLAttributeDef(
id=0x0013, type=t.enum8, access="rw", is_manufacturer_specific=True
)
on_led_color: Final = foundation.ZCLAttributeDef(
id=0x0050, type=t.uint24_t, access="rw", is_manufacturer_specific=True
)
off_led_color: Final = foundation.ZCLAttributeDef(
id=0x0051, type=t.uint24_t, access="rw", is_manufacturer_specific=True
)
on_led_intensity: Final = foundation.ZCLAttributeDef(
id=0x0052, type=t.uint8_t, access="rw", is_manufacturer_specific=True
)
off_led_intensity: Final = foundation.ZCLAttributeDef(
id=0x0053, type=t.uint8_t, access="rw", is_manufacturer_specific=True
)
action_report: Final = foundation.ZCLAttributeDef(
id=0x0054, type=ButtonAction, access="rp", is_manufacturer_specific=True
)
min_intensity: Final = foundation.ZCLAttributeDef(
id=0x0055, type=t.uint16_t, access="rw", is_manufacturer_specific=True
)
phase_control: Final = foundation.ZCLAttributeDef(
id=0x0056, type=PhaseControl, access="rw", is_manufacturer_specific=True
)
double_up_full: Final = foundation.ZCLAttributeDef(
id=0x0058, type=DoubleFull, access="rw", is_manufacturer_specific=True
)
unknown_attr_4: Final = foundation.ZCLAttributeDef(
id=0x0080, type=t.uint32_t, access="r", is_manufacturer_specific=True
)
current_summation_delivered: Final = foundation.ZCLAttributeDef(
id=0x0090, type=t.uint32_t, access="rp", is_manufacturer_specific=True
)
timer: Final = foundation.ZCLAttributeDef(
id=0x00A0, type=t.uint32_t, access="rw", is_manufacturer_specific=True
)
timer_countdown: Final = foundation.ZCLAttributeDef(
id=0x00A1, type=t.uint32_t, access="r", is_manufacturer_specific=True
)
connected_load: Final = foundation.ZCLAttributeDef(
id=0x0119, type=t.uint16_t, access="rw", is_manufacturer_specific=True
)
status: Final = foundation.ZCLAttributeDef(
id=0x0200, type=t.bitmap32, access="rp", is_manufacturer_specific=True
)
cluster_revision: Final = foundation.ZCL_CLUSTER_REVISION_ATTR
server_commands = {
0x54: foundation.ZCLCommandDef(
"button_press",
{"command": t.uint8_t},
direction=foundation.Direction.Server_to_Client,
is_manufacturer_specific=True,
)
}
def handle_cluster_general_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."""
self.debug(
"SINOPE cluster general request: hdr: %s - args: [%s]",
hdr,
args,
)
if hdr.command_id != foundation.GeneralCommand.Report_Attributes:
return super().handle_cluster_general_request(
hdr, args, dst_addressing=dst_addressing
)
attr = args[0][0]
if attr.attrid != self.AttributeDefs.action_report.id:
return super().handle_cluster_general_request(
hdr, args, dst_addressing=dst_addressing
)
action = self.Action(attr.value.value)
command, button = self._get_command_from_action(action)
if not command or not button:
return
event_args = {
ATTRIBUTE_ID: 84,
ATTRIBUTE_NAME: ATTRIBUTE_ACTION,
BUTTON: button,
DESCRIPTION: action.name,
VALUE: action.value,
}
self.debug(
"SINOPE ZHA_SEND_EVENT command: '%s' event_args: %s",
command,
event_args,
)
self.listener_event(ZHA_SEND_EVENT, command, event_args)
def _get_command_from_action(
self, action: ButtonAction
) -> tuple[str | None, str | None]:
# const lookup = {1: 'up_single', 2: 'up_single_released', 3: 'up_hold', 4: 'up_double',
# 17: 'down_single, 18: 'down_single_released', 19: 'down_hold', 20: 'down_double'};
match action:
case self.Action.Pressed_off:
return COMMAND_M_INITIAL_PRESS, TURN_OFF
case self.Action.Pressed_on:
return COMMAND_M_INITIAL_PRESS, TURN_ON
case self.Action.Released_off:
return COMMAND_M_SHORT_RELEASE, TURN_OFF
case self.Action.Released_on:
return COMMAND_M_SHORT_RELEASE, TURN_ON
case self.Action.Double_off:
return COMMAND_M_MULTI_PRESS_COMPLETE, TURN_OFF
case self.Action.Double_on:
return COMMAND_M_MULTI_PRESS_COMPLETE, TURN_ON
case self.Action.Long_off:
return COMMAND_M_LONG_RELEASE, TURN_OFF
case self.Action.Long_on:
return COMMAND_M_LONG_RELEASE, TURN_ON
case _:
self.debug("SINOPE unhandled action: %s", action)
return None, None
class LightManufacturerCluster(EventableCluster, SinopeTechnologiesManufacturerCluster):
"""LightManufacturerCluster: fire events corresponding to press type."""
class SinopeTechnologieslight(CustomDevice):
"""SinopeTechnologiesLight custom device."""
signature = {
# <SimpleDescriptor endpoint=1 profile=260 device_type=259
# device_version=0 input_clusters=[0, 2, 3, 4, 5, 6, 1794, 2821, 65281]
# output_clusters=[3, 4, 25]>
MODELS_INFO: [
(SINOPE, "SW2500ZB"),
(SINOPE, "SW2500ZB-G2"),
],
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.ON_OFF_LIGHT_SWITCH,
INPUT_CLUSTERS: [
Basic.cluster_id,
DeviceTemperature.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
Metering.cluster_id,
Diagnostic.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
Ota.cluster_id,
],
}
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.ON_OFF_LIGHT,
INPUT_CLUSTERS: [
Basic.cluster_id,
CustomDeviceTemperatureCluster,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
Metering.cluster_id,
Diagnostic.cluster_id,
LightManufacturerCluster,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
Ota.cluster_id,
],
}
}
}
device_automation_triggers = LIGHT_DEVICE_TRIGGERS
class SinopeDM2500ZB(CustomDevice):
"""DM2500ZB, DM2500ZB-G2 Dimmers."""
signature = {
# <SimpleDescriptor endpoint=1 profile=260 device_type=260 device_version=1
# input_clusters=[0, 2, 3, 4, 5, 6, 8, 1794, 2821, 65281]
# output_clusters=[3, 4, 25]>
MODELS_INFO: [
(SINOPE, "DM2500ZB"),
(SINOPE, "DM2500ZB-G2"),
],
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.DIMMER_SWITCH,
INPUT_CLUSTERS: [
Basic.cluster_id,
DeviceTemperature.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
Metering.cluster_id,
Diagnostic.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
Ota.cluster_id,
],
}
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.DIMMABLE_LIGHT,
INPUT_CLUSTERS: [
Basic.cluster_id,
CustomDeviceTemperatureCluster,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
Metering.cluster_id,
Diagnostic.cluster_id,
LightManufacturerCluster,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
Ota.cluster_id,
],
}
}
}
device_automation_triggers = LIGHT_DEVICE_TRIGGERS
class SinopeDM2550ZB(CustomDevice):
"""DM2550ZB, DM2550ZB-G2 Dimmers."""
signature = {
# <SimpleDescriptor endpoint=1 profile=260 device_type=260 device_version=1
# input_clusters=[0, 2, 3, 4, 5, 6, 8, 1794, 2820, 2821, 65281]
# output_clusters=[3, 4, 10, 25]>
MODELS_INFO: [
(SINOPE, "DM2550ZB"),
(SINOPE, "DM2550ZB-G2"),
],
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.DIMMER_SWITCH,
INPUT_CLUSTERS: [
Basic.cluster_id,
DeviceTemperature.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
Diagnostic.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
Time.cluster_id,
Ota.cluster_id,
],
}
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.DIMMABLE_LIGHT,
INPUT_CLUSTERS: [
Basic.cluster_id,
CustomDeviceTemperatureCluster,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
Diagnostic.cluster_id,
LightManufacturerCluster,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
Time.cluster_id,
Ota.cluster_id,
],
}
}
}
device_automation_triggers = LIGHT_DEVICE_TRIGGERS