forked from claudegel/sinope-zha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.py
679 lines (611 loc) · 21.1 KB
/
switch.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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
"""Module to handle quirks of the Sinopé Technologies switches.
Supported devices, SP2600ZB, SP2610ZB, RM3250ZB, RM3500ZB,
VA4200WZ, VA4201WZ, VA4200ZB, VA4201ZB, VA4220ZB, VA4221ZB and MC3100ZB,
2nd gen VA4220ZB, VA4221ZB with flow meeter FS4220, FS4221.
"""
import zigpy.profiles.zha as zha_p
from zigpy.quirks import CustomCluster, CustomDevice
import zigpy.types as t
from zigpy.zcl.clusters.general import (
Basic,
BinaryInput,
DeviceTemperature,
Groups,
Identify,
LevelControl,
OnOff,
Ota,
PowerConfiguration,
Scenes,
Time,
)
from zigpy.zcl.clusters.homeautomation import Diagnostic, ElectricalMeasurement
from zigpy.zcl.clusters.lightlink import LightLink
from zigpy.zcl.clusters.measurement import (
FlowMeasurement,
RelativeHumidity,
TemperatureMeasurement,
)
from zigpy.zcl.clusters.security import IasZone
from zigpy.zcl.clusters.smartenergy import Metering
from zigpy.zcl.foundation import Array
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.sinope import (
SINOPE,
SINOPE_MANUFACTURER_CLUSTER_ID,
CustomDeviceTemperatureCluster,
)
class SinopeManufacturerCluster(CustomCluster):
"""SinopeManufacturerCluster manufacturer cluster."""
class KeypadLock(t.enum8):
"""Keypad_lockout values."""
Unlocked = 0x00
Locked = 0x01
Partial_lock = 0x02
class FlowAlarm(t.enum8):
"""Abnormal flow alarm."""
Off = 0x00
On = 0x01
class AlarmAction(t.enum8):
"""Flow alarm action."""
Nothing = 0x00
Notify = 0x01
Close = 0x02
Close_notify = 0x03
class PowerSource(t.uint32_t):
"""Valve power source types."""
Battery = 0x00000000
ACUPS_01 = 0x00000001
DC_power = 0x0001D4C0
class EmergencyPower(t.uint32_t):
"""Valve emergency power source types."""
Battery = 0x00000000
ACUPS_01 = 0x00000001
Battery_ACUPS_01 = 0x0000003C
class AbnormalAction(t.bitmap16):
"""Action in case of abnormal flow detected."""
Nothing = 0x0000
Close_valve = 0x0001
Close_notify = 0x0003
class ColdStatus(t.enum8):
"""Cold_load_pickup_status values."""
Active = 0x00
Off = 0x01
class FlowDuration(t.uint32_t):
"""Abnormal flow duration."""
M_15 = 0x00000384
M_30 = 0x00000708
M_45 = 0x00000A8C
M_60 = 0x00000E10
M_75 = 0x00001194
M_90 = 0x00001518
H_3 = 0x00002A30
H_6 = 0x00005460
H_12 = 0x0000A8C0
H_24 = 0x00015180
class InputDelay(t.uint16_t):
"""Delay for on/off input."""
Off = 0x0000
M_1 = 0x003C
M_2 = 0x0078
M_5 = 0x012C
M_10 = 0x0258
M_15 = 0x0384
M_30 = 0x0708
H_1 = 0x0E10
H_2 = 0x1C20
H_3 = 0x2A30
cluster_id = SINOPE_MANUFACTURER_CLUSTER_ID
name = "Sinopé Manufacturer specific"
ep_attribute = "sinope_manufacturer_specific"
attributes = {
0x0001: ("unknown_attr_1", t.Bool, True),
0x0002: ("keypad_lockout", KeypadLock, True),
0x0003: ("firmware_number", t.uint16_t, True),
0x0004: ("firmware_version", t.CharacterString, True),
0x0010: ("outdoor_temp", t.int16s, True),
0x0013: ("unknown_attr_0", t.enum8, True),
0x0030: ("unknown_attr_2", t.uint8_t, True),
0x0035: ("unknown_attr_8", t.uint16_t, True),
0x0037: ("unknown_attr_9", t.uint16_t, True),
0x0038: ("unknown_attr_10", t.enum8, True),
0x0060: ("connected_load", t.uint16_t, True),
0x0070: ("current_load", t.bitmap8, True),
0x0074: ("unknown_attr_11", t.enum8, True),
0x0076: ("dr_config_water_temp_min", t.uint8_t, True),
0x0077: ("dr_config_water_temp_time", t.uint8_t, True),
0x0078: ("dr_wt_time_on", t.uint16_t, True),
0x0079: ("unknown_attr_6", t.bitmap8, True),
0x007A: ("unknown_attr_20", t.uint16_t, True),
0x007B: ("unknown_attr_21", t.uint16_t, True),
0x007C: ("min_measured_temp", t.int16s, True),
0x007D: ("max_measured_temp", t.int16s, True),
0x0080: ("unknown_attr_5", t.uint32_t, True),
0x0090: ("current_summation_delivered", t.uint32_t, True),
0x00A0: ("timer", t.uint32_t, True),
0x00A1: ("timer_countdown", t.uint32_t, True),
0x00B0: ("unknown_attr_12", t.Bool, True),
0x0101: ("unknown_attr_7", Array, True),
0x012A: ("unknown_attr_13", t.enum8, True),
0x012C: ("unknown_attr_14", Array, True),
0x0200: ("status", t.bitmap32, True),
0x0202: ("unknown_attr_15", t.enum8, True),
0x0203: ("unknown_attr_16", t.enum8, True),
0x0220: ("unknown_attr_3", t.bitmap16, True),
0x0221: ("unknown_attr_4", t.bitmap16, True),
0x0230: ("alarm_flow_threshold", FlowAlarm, True),
0x0231: ("alarm_options", AlarmAction, True),
0x0240: ("flow_meter_config", Array, True),
0x0241: ("valve_countdown", t.uint32_t, True),
0x0250: ("power_source", PowerSource, True),
0x0251: ("emergency_power_source", EmergencyPower, True),
0x0252: ("abnormal_flow_duration", FlowDuration, True),
0x0253: ("abnormal_flow_action", AbnormalAction, True),
0x0280: ("max_measured_value", t.int16s, True),
0x0281: ("unknown_attr_18", t.uint16_t, True),
0x0282: ("unknown_attr_19", t.uint16_t, True),
0x0283: ("cold_load_pickup_status", ColdStatus, True),
0x0284: ("cold_load_pickup_remaining_time", t.uint16_t, True),
0x02A0: ("input_on_delay", InputDelay, True),
0x02A1: ("input_off_delay", InputDelay, True),
0xFFFD: ("cluster_revision", t.uint16_t, True),
}
class CustomBasicCluster(CustomCluster, Basic):
"""Custom Basic Cluster."""
class PowerSource(t.enum8):
"""Power source."""
Unknown = 0x0000
DC_mains = 0x0001
Battery = 0x0003
DC_source = 0x0004
ACUPS_01 = 0x0081
ACUPS01 = 0x0082
attributes = Basic.attributes.copy()
attributes.update(
{
0x0007: ("power_source", PowerSource, True),
}
)
class CustomMeteringCluster(CustomCluster, Metering):
"""Custom Metering Cluster."""
class ValveStatus(t.bitmap8):
"""Valve_status."""
Off = 0x00
Off_armed = 0x01
On = 0x02
class UnitOfMeasure(t.enum8):
"""Unit_of_measure."""
KWh = 0x00
Lh = 0x07
DIVISOR = 0x0302
_CONSTANT_ATTRIBUTES = {DIVISOR: 1000}
attributes = Metering.attributes.copy()
attributes.update(
{
0x0200: ("status", ValveStatus, True),
0x0300: ("unit_of_measure", UnitOfMeasure, True),
}
)
class CustomFlowMeasurementCluster(CustomCluster, FlowMeasurement):
"""Custom flow measurement cluster that divides value by 10."""
def _update_attribute(self, attrid, value):
if attrid == self.AttributeDefs.measured_value.id:
value = value / 10
super()._update_attribute(attrid, value)
class SinopeTechnologiesSwitch(CustomDevice):
"""SinopeTechnologiesSwitch custom device."""
signature = {
# <SimpleDescriptor(endpoint=1, profile=260,
# device_type=81, device_version=0,
# input_clusters=[0, 3, 6, 1794, 2820, 65281]
# output_clusters=[25]>
MODELS_INFO: [
(SINOPE, "SP2600ZB"),
(SINOPE, "SP2610ZB"),
],
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.SMART_PLUG,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
OnOff.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [Ota.cluster_id],
}
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
OnOff.cluster_id,
CustomMeteringCluster,
ElectricalMeasurement.cluster_id,
SinopeManufacturerCluster,
],
OUTPUT_CLUSTERS: [Ota.cluster_id],
}
}
}
class SinopeTechnologiesLoadController(CustomDevice):
"""SinopeTechnologiesLoadController custom device."""
signature = {
# <SimpleDescriptor(endpoint=1, profile=260,
# device_type=2, device_version=0,
# input_clusters=[0, 3, 4, 5, 6, 1794, 2820, 2821, 65281]
# output_clusters=[3, 4, 25]>
MODELS_INFO: [
(SINOPE, "RM3250ZB"),
],
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.ON_OFF_OUTPUT,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
Diagnostic.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
Ota.cluster_id,
],
}
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
Diagnostic.cluster_id,
SinopeManufacturerCluster,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Groups.cluster_id,
Ota.cluster_id,
],
}
}
}
class SinopeTechnologiesValve(CustomDevice):
"""SinopeTechnologiesValve custom device."""
signature = {
# <SimpleDescriptor(endpoint=1, profile=260,
# device_type=3, device_version=0,
# input_clusters=[0, 1, 3, 4, 5, 6, 8, 2821, 65281]
# output_clusters=[3, 25]>
MODELS_INFO: [
(SINOPE, "VA4200WZ"),
(SINOPE, "VA4201WZ"),
(SINOPE, "VA4200ZB"),
(SINOPE, "VA4201ZB"),
(SINOPE, "VA4220ZB"),
(SINOPE, "VA4221ZB"),
],
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.LEVEL_CONTROLLABLE_OUTPUT,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
Diagnostic.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Ota.cluster_id,
],
}
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
CustomBasicCluster,
PowerConfiguration.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
Diagnostic.cluster_id,
SinopeManufacturerCluster,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Ota.cluster_id,
],
}
}
}
class SinopeTechnologiesValveG2(CustomDevice):
"""SinopeTechnologiesValveG2 custom device."""
signature = {
# <SimpleDescriptor(endpoint=1, profile=260,
# device_type=3, device_version=0,
# input_clusters=[0, 1, 3, 4, 5, 6, 8, 1026, 1280, 1794, 2821, 65281]
# output_clusters=[3, 6, 25]>
MODELS_INFO: [
(SINOPE, "VA4220ZB"),
(SINOPE, "VA4221ZB"),
],
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.LEVEL_CONTROLLABLE_OUTPUT,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
TemperatureMeasurement.cluster_id,
IasZone.cluster_id,
Metering.cluster_id,
Diagnostic.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
OnOff.cluster_id,
Ota.cluster_id,
],
}
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
CustomBasicCluster,
PowerConfiguration.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
LevelControl.cluster_id,
TemperatureMeasurement.cluster_id,
CustomFlowMeasurementCluster,
IasZone.cluster_id,
CustomMeteringCluster,
Diagnostic.cluster_id,
SinopeManufacturerCluster,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
OnOff.cluster_id,
Ota.cluster_id,
],
}
}
}
class SinopeTechnologiesMultiController(CustomDevice):
"""SinopeTechnologiesMultiController custom device."""
signature = {
# <SimpleDescriptor(endpoint=1, profile=260,
# device_type=2, device_version=0,
# input_clusters=[0, 1, 3, 4, 5, 6, 15, 1026, 1029, 2821, 65281]
# output_clusters=[25]>
MODELS_INFO: [(SINOPE, "MC3100ZB")],
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.ON_OFF_OUTPUT,
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
BinaryInput.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
Diagnostic.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [Ota.cluster_id],
},
2: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.ON_OFF_OUTPUT,
INPUT_CLUSTERS: [
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
BinaryInput.cluster_id,
TemperatureMeasurement.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [],
},
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
Basic.cluster_id,
PowerConfiguration.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
BinaryInput.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
Diagnostic.cluster_id,
SinopeManufacturerCluster,
],
OUTPUT_CLUSTERS: [Ota.cluster_id],
},
2: {
INPUT_CLUSTERS: [
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
BinaryInput.cluster_id,
TemperatureMeasurement.cluster_id,
SinopeManufacturerCluster,
],
OUTPUT_CLUSTERS: [],
},
},
}
class SinopeTechnologiesCalypso(CustomDevice):
"""SinopeTechnologiesCalypso custom device."""
signature = {
# <SimpleDescriptor(endpoint=1, profile=260,
# device_type=260, device_version=0,
# input_clusters=[0, 2, 3, 4, 5, 6, 1026, 1280, 1794, 2820, 2821, 65281]
# output_clusters=[10, 25]>
MODELS_INFO: [
(SINOPE, "RM3500ZB"),
],
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,
TemperatureMeasurement.cluster_id,
IasZone.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
Diagnostic.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Time.cluster_id,
Ota.cluster_id,
],
},
2: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.DIMMER_SWITCH,
INPUT_CLUSTERS: [
TemperatureMeasurement.cluster_id,
],
OUTPUT_CLUSTERS: [],
},
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.ON_OFF_OUTPUT,
INPUT_CLUSTERS: [
Basic.cluster_id,
CustomDeviceTemperatureCluster,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
TemperatureMeasurement.cluster_id,
IasZone.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
Diagnostic.cluster_id,
SinopeManufacturerCluster,
],
OUTPUT_CLUSTERS: [
Time.cluster_id,
Ota.cluster_id,
],
}
}
}
class SinopeTechnologiesNewSwitch(CustomDevice):
"""SinopeTechnologiesNewSwitch custom device."""
signature = {
# <SimpleDescriptor(endpoint=1, profile=260,
# device_type=81, device_version=0,
# input_clusters=[0, 3, 6, 1794, 2820, 4096, 65281]
# output_clusters=[25, 4096]>
MODELS_INFO: [
(SINOPE, "SP2600ZB"),
(SINOPE, "SP2610ZB"),
],
ENDPOINTS: {
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.SMART_PLUG,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
OnOff.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
LightLink.cluster_id,
SINOPE_MANUFACTURER_CLUSTER_ID,
],
OUTPUT_CLUSTERS: [
Ota.cluster_id,
LightLink.cluster_id,
],
}
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
OnOff.cluster_id,
CustomMeteringCluster,
ElectricalMeasurement.cluster_id,
LightLink.cluster_id,
SinopeManufacturerCluster,
],
OUTPUT_CLUSTERS: [
Ota.cluster_id,
LightLink.cluster_id,
],
}
}
}