forked from zigpy/zha-device-handlers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_saswell_tuya_trv.py
784 lines (704 loc) · 27.8 KB
/
test_saswell_tuya_trv.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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
"""Tests for Saswell Tuya TRV quirks."""
from datetime import UTC, datetime
import pytest
from zigpy.zcl.clusters.general import AnalogOutput, OnOff
from zigpy.zcl.clusters.hvac import KeypadLockout, SystemMode, Thermostat, UserInterface
from tests.common import ClusterListener
import zhaquirks.tuya.ts0601_trv
from zhaquirks.tuya.ts0601_trv import (
SASWELL_ANTI_FREEZE_ATTR,
SASWELL_AWAY_MODE_ATTR,
SASWELL_CHILD_LOCK_ATTR,
SASWELL_LIMESCALE_PROTECT_ATTR,
SASWELL_ONOFF_ATTR,
SASWELL_ROOM_TEMP_ATTR,
SASWELL_SCHEDULE_MODE_ATTR,
SASWELL_TARGET_TEMP_ATTR,
SASWELL_TEMP_CORRECTION_ATTR,
SASWELL_WINDOW_DETECT_ATTR,
Saswell_TYST11,
Saswell_TZE200,
)
@pytest.mark.parametrize(
"manufacturer,model",
[
("_TZE200_c88teujp", "TS0601"),
("_TZE200_azqp6ssj", "TS0601"),
("_TZE200_yw7cahqs", "TS0601"),
("_TZE200_9gvruqf5", "TS0601"),
("_TZE200_zuhszj9s", "TS0601"),
("_TZE200_zr9c0day", "TS0601"),
("_TZE200_0dvm9mva", "TS0601"),
("_TZE200_h4cgnbzg", "TS0601"),
("_TZE200_exfrnlow", "TS0601"),
("_TZE200_9m4kmbfu", "TS0601"),
("_TZE200_3yp57tby", "TS0601"),
("_TZE200_mz5y07w2", "TS0601"),
],
)
def test_tze200_signature(assert_signature_matches_quirk, manufacturer, model):
"""Test Tuya devices signatures are matched to their quirks."""
# <SimpleDescriptor endpoint=1 profile=260 device_type=81
# device_version=1
# input_clusters=[0, 4, 5, 61184]
# output_clusters=[10, 25]>
signature = {
"endpoints": {
"1": {
"profile_id": 0x0104,
"device_type": "0x0051",
"in_clusters": ["0x0000", "0x0004", "0x0005", "0xef00"],
"out_clusters": ["0x000a", "0x0019"],
}
},
"manufacturer": manufacturer,
"model": model,
"class": "Saswell_TZE200",
}
assert_signature_matches_quirk(Saswell_TZE200, signature)
@pytest.mark.parametrize(
"manufacturer,model",
[
("_TYST11_KGbxAXL2", "GbxAXL2"),
("_TYST11_c88teujp", "88teujp"),
("_TYST11_azqp6ssj", "zqp6ssj"),
("_TYST11_yw7cahqs", "w7cahqs"),
("_TYST11_9gvruqf5", "gvruqf5"),
("_TYST11_zuhszj9s", "uhszj9s"),
("_TYST11_caj4jz0i", "aj4jz0i"),
],
)
def test_tyst11_signature(assert_signature_matches_quirk, manufacturer, model):
"""Test Tuya devices signatures are matched to their quirks."""
# <SimpleDescriptor endpoint=1 profile=260 device_type=0
# device_version=0
# input_clusters=[0, 3]
# output_clusters=[3, 25]>
signature = {
"endpoints": {
"1": {
"profile_id": 0x0104,
"device_type": "0",
"in_clusters": [
"0x0000",
"0x0003",
],
"out_clusters": ["0x0003", "0x0019"],
}
},
"manufacturer": manufacturer,
"model": model,
"class": "Saswell_TYST11",
}
assert_signature_matches_quirk(Saswell_TYST11, signature)
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_map_attributes(zigpy_device_from_quirk, quirk):
"""Test map attributes."""
device = zigpy_device_from_quirk(quirk)
thermostat_cluster = device.endpoints[1].thermostat
input_params = [
("local_temperature_calibration", 60),
("occupied_heating_setpoint", 200),
("system_mode", SystemMode.Off),
("system_mode", SystemMode.Heat),
]
return_values = [
(SASWELL_TEMP_CORRECTION_ATTR, 6),
(SASWELL_TARGET_TEMP_ATTR, 20),
(SASWELL_ONOFF_ATTR, 0),
(SASWELL_ONOFF_ATTR, 1),
]
for (attr_desc, value), (attr_id, ret_value) in zip(input_params, return_values):
assert thermostat_cluster.map_attribute(attr_desc, value) == {
attr_id: ret_value
}
str_on_off = "on_off"
open_window_detection_cluster = device.endpoints[1].on_off
assert open_window_detection_cluster.map_attribute(str_on_off, 1) == {
SASWELL_WINDOW_DETECT_ATTR: 1
}
child_lock_cluster = device.endpoints[2].on_off
assert child_lock_cluster.map_attribute(str_on_off, 1) == {
SASWELL_CHILD_LOCK_ATTR: 1
}
anti_freeze_cluster = device.endpoints[3].on_off
assert anti_freeze_cluster.map_attribute(str_on_off, 1) == {
SASWELL_ANTI_FREEZE_ATTR: 1
}
limescale_protection_cluster = device.endpoints[4].on_off
assert limescale_protection_cluster.map_attribute(str_on_off, 1) == {
SASWELL_LIMESCALE_PROTECT_ATTR: 1
}
schedule_mode_cluster = device.endpoints[5].on_off
assert schedule_mode_cluster.map_attribute(str_on_off, 1) == {
SASWELL_SCHEDULE_MODE_ATTR: 1
}
away_mode_cluster = device.endpoints[6].on_off
assert away_mode_cluster.map_attribute(str_on_off, 1) == {SASWELL_AWAY_MODE_ATTR: 1}
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_trv_target_and_room_temperature(zigpy_device_from_quirk, quirk):
"""Test target and room temperature changes when system is off or in heat mode."""
device = zigpy_device_from_quirk(quirk)
manuf_cluster = device.endpoints[1].tuya_manufacturer
thermostat_cluster = device.endpoints[1].thermostat
thermostat_cluster_listener = ClusterListener(thermostat_cluster)
# system mode is set to off, so after setting values the running mode/state are set to off/idle
thermostat_cluster._attr_cache[
Thermostat.AttributeDefs.system_mode.id
] = Thermostat.SystemMode.Off
thermostat_cluster._attr_last_updated[
Thermostat.AttributeDefs.system_mode.id
] = datetime.now(UTC)
temp_target_attr_id = SASWELL_TARGET_TEMP_ATTR # maps to occupied heating setpoint
room_temp_attr_id = SASWELL_ROOM_TEMP_ATTR # maps to local temperature
# target temp change leaves running mode/state at off/idle
manuf_cluster.update_attribute(temp_target_attr_id, 15)
assert len(thermostat_cluster_listener.attribute_updates) == 3
assert (
thermostat_cluster_listener.attribute_updates[0][0]
== Thermostat.AttributeDefs.occupied_heating_setpoint.id
)
assert (
thermostat_cluster_listener.attribute_updates[0][1] == 150
) # value is multiplied by 10
assert (
thermostat_cluster_listener.attribute_updates[1][0]
== Thermostat.AttributeDefs.running_mode.id
)
assert (
thermostat_cluster_listener.attribute_updates[1][1]
== Thermostat.RunningMode.Off
)
assert (
thermostat_cluster_listener.attribute_updates[2][0]
== Thermostat.AttributeDefs.running_state.id
)
assert (
thermostat_cluster_listener.attribute_updates[2][1]
== Thermostat.RunningState.Idle
)
# room temp change leaves running mode/state at off/idle
manuf_cluster.update_attribute(room_temp_attr_id, 20)
assert len(thermostat_cluster_listener.attribute_updates) == 6
assert (
thermostat_cluster_listener.attribute_updates[3][0]
== Thermostat.AttributeDefs.local_temperature.id
)
assert (
thermostat_cluster_listener.attribute_updates[3][1] == 200
) # value is multiplied by 10
assert (
thermostat_cluster_listener.attribute_updates[4][0]
== Thermostat.AttributeDefs.running_mode.id
)
assert (
thermostat_cluster_listener.attribute_updates[4][1]
== Thermostat.RunningMode.Off
)
assert (
thermostat_cluster_listener.attribute_updates[5][0]
== Thermostat.AttributeDefs.running_state.id
)
assert (
thermostat_cluster_listener.attribute_updates[5][1]
== Thermostat.RunningState.Idle
)
# system mode is set to heat, so target and room temperature influence the running mode/state
thermostat_cluster._attr_cache[
Thermostat.AttributeDefs.system_mode.id
] = Thermostat.SystemMode.Heat
thermostat_cluster._attr_last_updated[
Thermostat.AttributeDefs.system_mode.id
] = datetime.now(UTC)
# target temp > room temp -> heating
manuf_cluster.update_attribute(temp_target_attr_id, 25)
assert len(thermostat_cluster_listener.attribute_updates) == 9
assert (
thermostat_cluster_listener.attribute_updates[6][0]
== Thermostat.AttributeDefs.occupied_heating_setpoint.id
)
assert (
thermostat_cluster_listener.attribute_updates[6][1] == 250
) # value is multiplied by 10
assert (
thermostat_cluster_listener.attribute_updates[7][0]
== Thermostat.AttributeDefs.running_mode.id
)
assert (
thermostat_cluster_listener.attribute_updates[7][1]
== Thermostat.RunningMode.Heat
)
assert (
thermostat_cluster_listener.attribute_updates[8][0]
== Thermostat.AttributeDefs.running_state.id
)
assert (
thermostat_cluster_listener.attribute_updates[8][1]
== Thermostat.RunningState.Heat_State_On
)
# set target temp < room temp -> no heating
manuf_cluster.update_attribute(room_temp_attr_id, 30)
assert len(thermostat_cluster_listener.attribute_updates) == 12
assert (
thermostat_cluster_listener.attribute_updates[9][0]
== Thermostat.AttributeDefs.local_temperature.id
)
assert (
thermostat_cluster_listener.attribute_updates[9][1] == 300
) # value is multiplied by 10
assert (
thermostat_cluster_listener.attribute_updates[10][0]
== Thermostat.AttributeDefs.running_mode.id
)
assert (
thermostat_cluster_listener.attribute_updates[10][1]
== Thermostat.RunningMode.Off
)
assert (
thermostat_cluster_listener.attribute_updates[11][0]
== Thermostat.AttributeDefs.running_state.id
)
assert (
thermostat_cluster_listener.attribute_updates[11][1]
== Thermostat.RunningState.Idle
)
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_trv_thermostat_check_min_max_heat_setpoint_limits_initialization(
zigpy_device_from_quirk, quirk
):
"""Test that the min/max heat setpoint limits are set. Devices display min/max heat setpoints of 5°C/30°C."""
device = zigpy_device_from_quirk(quirk)
thermostat_cluster = device.endpoints[1].thermostat
assert (
thermostat_cluster._attr_cache[
Thermostat.AttributeDefs.min_heat_setpoint_limit.id
]
== 500
)
assert (
thermostat_cluster._attr_cache[
Thermostat.AttributeDefs.max_heat_setpoint_limit.id
]
== 3000
)
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_trv_temperature_calibration(zigpy_device_from_quirk, quirk):
"""Test temperature calibration."""
device = zigpy_device_from_quirk(quirk)
manuf_cluster = device.endpoints[1].tuya_manufacturer
thermostat_cluster = device.endpoints[1].thermostat
thermostat_cluster_listener = ClusterListener(thermostat_cluster)
temp_calibration_cluster = device.endpoints[7].analog_output
temp_calibration_cluster_listener = ClusterListener(temp_calibration_cluster)
temp_corr_attr_id = SASWELL_TEMP_CORRECTION_ATTR
# values assigned to attributes at initialization
assert (
temp_calibration_cluster._attr_cache[AnalogOutput.AttributeDefs.description.id]
== "Temperature Offset"
)
assert (
temp_calibration_cluster._attr_cache[
AnalogOutput.AttributeDefs.max_present_value.id
]
== 6
)
assert (
temp_calibration_cluster._attr_cache[
AnalogOutput.AttributeDefs.min_present_value.id
]
== -6
)
assert (
temp_calibration_cluster._attr_cache[AnalogOutput.AttributeDefs.resolution.id]
== 1
)
assert (
temp_calibration_cluster._attr_cache[
AnalogOutput.AttributeDefs.application_type.id
]
== 13 << 16
)
assert (
temp_calibration_cluster._attr_cache[
AnalogOutput.AttributeDefs.engineering_units.id
]
== 62
)
# saswell temp correction attr -> local temperature calibration
manuf_cluster.update_attribute(temp_corr_attr_id, 2)
assert len(thermostat_cluster_listener.attribute_updates) == 1
assert (
thermostat_cluster_listener.attribute_updates[0][0]
== Thermostat.AttributeDefs.local_temperature_calibration.id
)
assert (
thermostat_cluster_listener.attribute_updates[0][1] == 20
) # value is multiplied by 10 and rounded
assert len(temp_calibration_cluster_listener.attribute_updates) == 1
assert (
temp_calibration_cluster_listener.attribute_updates[0][0]
== AnalogOutput.AttributeDefs.present_value.id
)
assert (
temp_calibration_cluster_listener.attribute_updates[0][1]
== temp_calibration_cluster.get_value()
)
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_on_off_event(zigpy_device_from_quirk, quirk):
"""Test on/off event (system mode/running mode/running state)."""
device = zigpy_device_from_quirk(quirk)
manuf_cluster = device.endpoints[1].tuya_manufacturer
thermostat_cluster = device.endpoints[1].thermostat
thermostat_cluster_listener = ClusterListener(thermostat_cluster)
on_off_attr_id = SASWELL_ONOFF_ATTR
# saswell device on -> system mode/running mode/running state are "heating"
manuf_cluster.update_attribute(on_off_attr_id, 1)
assert len(thermostat_cluster_listener.attribute_updates) == 3
assert (
thermostat_cluster_listener.attribute_updates[0][0]
== Thermostat.AttributeDefs.system_mode.id
)
assert (
thermostat_cluster_listener.attribute_updates[0][1]
== Thermostat.SystemMode.Heat
)
assert (
thermostat_cluster_listener.attribute_updates[1][0]
== Thermostat.AttributeDefs.running_mode.id
)
assert (
thermostat_cluster_listener.attribute_updates[1][1]
== Thermostat.RunningMode.Heat
)
assert (
thermostat_cluster_listener.attribute_updates[2][0]
== Thermostat.AttributeDefs.running_state.id
)
assert (
thermostat_cluster_listener.attribute_updates[2][1]
== Thermostat.RunningState.Heat_State_On
)
# saswell off -> system mode/running mode/running state are off/idle
manuf_cluster.update_attribute(on_off_attr_id, 0)
assert len(thermostat_cluster_listener.attribute_updates) == 6
assert (
thermostat_cluster_listener.attribute_updates[3][0]
== Thermostat.AttributeDefs.system_mode.id
)
assert (
thermostat_cluster_listener.attribute_updates[3][1] == Thermostat.SystemMode.Off
)
assert (
thermostat_cluster_listener.attribute_updates[4][0]
== Thermostat.AttributeDefs.running_mode.id
)
assert (
thermostat_cluster_listener.attribute_updates[4][1]
== Thermostat.RunningMode.Off
)
assert (
thermostat_cluster_listener.attribute_updates[5][0]
== Thermostat.AttributeDefs.running_state.id
)
assert (
thermostat_cluster_listener.attribute_updates[5][1]
== Thermostat.RunningState.Idle
)
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_schedule_mode(zigpy_device_from_quirk, quirk):
"""Test schedule mode."""
device = zigpy_device_from_quirk(quirk)
manuf_cluster = device.endpoints[1].tuya_manufacturer
schedule_mode_cluster = device.endpoints[5].on_off
schedule_mode_cluster_listener = ClusterListener(schedule_mode_cluster)
schedule_mode_attr_id = SASWELL_SCHEDULE_MODE_ATTR
# schedule mode activated
manuf_cluster.update_attribute(schedule_mode_attr_id, True)
assert len(schedule_mode_cluster_listener.attribute_updates) == 1
assert (
schedule_mode_cluster_listener.attribute_updates[0][0]
== OnOff.AttributeDefs.on_off.id
)
assert schedule_mode_cluster_listener.attribute_updates[0][1] is True
# schedule mode deactivated
manuf_cluster.update_attribute(schedule_mode_attr_id, False)
assert len(schedule_mode_cluster_listener.attribute_updates) == 2
assert (
schedule_mode_cluster_listener.attribute_updates[1][0]
== OnOff.AttributeDefs.on_off.id
)
assert schedule_mode_cluster_listener.attribute_updates[1][1] is False
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_away_mode(zigpy_device_from_quirk, quirk):
"""Test away mode."""
device = zigpy_device_from_quirk(quirk)
manuf_cluster = device.endpoints[1].tuya_manufacturer
away_mode_cluster = device.endpoints[6].on_off
away_mode_cluster_listener = ClusterListener(away_mode_cluster)
away_mode_attr_id = SASWELL_AWAY_MODE_ATTR
# away mode activated
manuf_cluster.update_attribute(away_mode_attr_id, True)
assert len(away_mode_cluster_listener.attribute_updates) == 1
assert (
away_mode_cluster_listener.attribute_updates[0][0]
== OnOff.AttributeDefs.on_off.id
)
assert away_mode_cluster_listener.attribute_updates[0][1] is True
# away mode deactivated
manuf_cluster.update_attribute(away_mode_attr_id, False)
assert len(away_mode_cluster_listener.attribute_updates) == 2
assert (
away_mode_cluster_listener.attribute_updates[1][0]
== OnOff.AttributeDefs.on_off.id
)
assert away_mode_cluster_listener.attribute_updates[1][1] is False
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_child_lock(zigpy_device_from_quirk, quirk):
"""Test child lock enabled/disabled."""
device = zigpy_device_from_quirk(quirk)
manuf_cluster = device.endpoints[1].tuya_manufacturer
child_lock_cluster = device.endpoints[2].on_off
child_lock_cluster_listener = ClusterListener(child_lock_cluster)
ui_interface_cluster = device.endpoints[1].thermostat_ui
ui_interface_cluster_listener = ClusterListener(ui_interface_cluster)
child_lock_attr_id = SASWELL_CHILD_LOCK_ATTR
# child lock enabled
manuf_cluster.update_attribute(child_lock_attr_id, True)
assert len(child_lock_cluster_listener.attribute_updates) == 1
assert (
child_lock_cluster_listener.attribute_updates[0][0]
== OnOff.AttributeDefs.on_off.id
)
assert child_lock_cluster_listener.attribute_updates[0][1] is True
assert len(ui_interface_cluster_listener.attribute_updates) == 1
assert (
ui_interface_cluster_listener.attribute_updates[0][0]
== UserInterface.AttributeDefs.keypad_lockout.id
)
assert (
ui_interface_cluster_listener.attribute_updates[0][1]
== KeypadLockout.Level_1_lockout
)
# child lock disabled
manuf_cluster.update_attribute(child_lock_attr_id, False)
assert len(child_lock_cluster_listener.attribute_updates) == 2
assert (
child_lock_cluster_listener.attribute_updates[1][0]
== OnOff.AttributeDefs.on_off.id
)
assert child_lock_cluster_listener.attribute_updates[1][1] is False
assert len(ui_interface_cluster_listener.attribute_updates) == 2
assert (
ui_interface_cluster_listener.attribute_updates[1][0]
== UserInterface.AttributeDefs.keypad_lockout.id
)
assert (
ui_interface_cluster_listener.attribute_updates[1][1]
== KeypadLockout.No_lockout
)
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_open_window_detection(zigpy_device_from_quirk, quirk):
"""Test open window detection."""
device = zigpy_device_from_quirk(quirk)
manuf_cluster = device.endpoints[1].tuya_manufacturer
window_open_detect_cluster = device.endpoints[1].on_off
window_open_detect_cluster_listener = ClusterListener(window_open_detect_cluster)
window_open_detect_attr_id = SASWELL_WINDOW_DETECT_ATTR
# open window detection activated
manuf_cluster.update_attribute(window_open_detect_attr_id, True)
assert len(window_open_detect_cluster_listener.attribute_updates) == 1
assert (
window_open_detect_cluster_listener.attribute_updates[0][0]
== OnOff.AttributeDefs.on_off.id
)
assert window_open_detect_cluster_listener.attribute_updates[0][1] is True
# open window detection deactivated
manuf_cluster.update_attribute(window_open_detect_attr_id, False)
assert len(window_open_detect_cluster_listener.attribute_updates) == 2
assert (
window_open_detect_cluster_listener.attribute_updates[1][0]
== OnOff.AttributeDefs.on_off.id
)
assert window_open_detect_cluster_listener.attribute_updates[1][1] is False
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_anti_freeze(zigpy_device_from_quirk, quirk):
"""Test anti freeze."""
device = zigpy_device_from_quirk(quirk)
manuf_cluster = device.endpoints[1].tuya_manufacturer
anti_freeze_cluster = device.endpoints[3].on_off
cluster_listener = ClusterListener(anti_freeze_cluster)
anti_freeze_attr_id = SASWELL_ANTI_FREEZE_ATTR
# anti freeze activated
manuf_cluster.update_attribute(anti_freeze_attr_id, True)
assert len(cluster_listener.attribute_updates) == 1
assert cluster_listener.attribute_updates[0][0] == OnOff.AttributeDefs.on_off.id
assert cluster_listener.attribute_updates[0][1] is True
# anti freeze deactivated
manuf_cluster.update_attribute(anti_freeze_attr_id, False)
assert len(cluster_listener.attribute_updates) == 2
assert cluster_listener.attribute_updates[1][0] == OnOff.AttributeDefs.on_off.id
assert cluster_listener.attribute_updates[1][1] is False
@pytest.mark.parametrize(
"quirk",
(
Saswell_TYST11,
Saswell_TZE200,
),
)
async def test_saswell_limescale_protection(zigpy_device_from_quirk, quirk):
"""Test limescale protection."""
device = zigpy_device_from_quirk(quirk)
manuf_cluster = device.endpoints[1].tuya_manufacturer
limescale_protection_cluster = device.endpoints[4].on_off
limescale_protection_cluster_listener = ClusterListener(
limescale_protection_cluster
)
limescale_protection_attr_id = SASWELL_LIMESCALE_PROTECT_ATTR
# anti freeze activated
manuf_cluster.update_attribute(limescale_protection_attr_id, True)
assert len(limescale_protection_cluster_listener.attribute_updates) == 1
assert (
limescale_protection_cluster_listener.attribute_updates[0][0]
== OnOff.AttributeDefs.on_off.id
)
assert limescale_protection_cluster_listener.attribute_updates[0][1] is True
# anti freeze deactivated
manuf_cluster.update_attribute(limescale_protection_attr_id, False)
assert len(limescale_protection_cluster_listener.attribute_updates) == 2
assert (
limescale_protection_cluster_listener.attribute_updates[1][0]
== OnOff.AttributeDefs.on_off.id
)
assert limescale_protection_cluster_listener.attribute_updates[1][1] is False
# SASWELL_ROOM_TEMP_ATTR = 0x0266 # uint32 - current room temp 614
ZCL_SASWELL_TUYA_ROOM_TEMP = b"\tp\x02\x00\x02\x03\x02\x00\x04\x00\x00\x00\xb3"
# SASWELL_TARGET_TEMP_ATTR = 0x0267 # uint32 - target temp 615
ZCL_SASWELL_TUYA_TARGET_TEMP = b"\t3\x01\x03\x05\x02\x02\x00\x04\x00\x00\x002"
# SASWELL_ONOFF_ATTR = 0x0165 # [0/1] on/off 357
ZCL_SASWELL_TUYA_ONOFF = b"\t2\x01\x03\x04\x04\x04\x00\x01\x00"
# SASWELL_SCHEDULE_MODE_ATTR = 0x016C # [0/1] on/off 364
ZCL_SASWELL_TUYA_SCHEDULE_MODE = b"\t2\x01\x03\x04\x04\x04\x00\x01\x01"
# SASWELL_CHILD_LOCK_ATTR = 0x0128 # [0/1] on/off 296
ZCL_SASWELL_TUYA_CHILD_LOCK = b""
# SASWELL_ANTI_FREEZE_ATTR = 0x010A # [0/1] on/off 266
ZCL_SASWELL_TUYA_ANTI_FREEZE = b""
# SASWELL_WINDOW_DETECT_ATTR = 0x0108 # [0/1] on/off 264
ZCL_SASWELL_TUYA_DETECT_ATTR = b""
# SASWELL_LIMESCALE_PROTECT_ATTR = 0x0182 # [0/1] on/off 386
ZCL_SASWELL_TUYA_LIMESCALE_PROTECT = b""
# SASWELL_TEMP_CORRECTION_ATTR = 0x021B # uint32 - temp correction 539
ZCL_SASWELL_TUYA_TEMP_CORRECTION_ATTR = b""
# SASWELL_AWAY_MODE_ATTR = 0x016A # [0/1] on/off 362
ZCL_SASWELL_TUYA_AWAY_MODE_ATTR = b""
# SASWELL_BATTERY_ALARM_ATTR = 0x569 # [0/1] on/off - battery low 1385
ZCL_SASWELL_TUYA_BATTERY_ALARM_ATTR = b""
@pytest.mark.parametrize("quirk", (zhaquirks.tuya.ts0601_trv.Saswell_TZE200,))
async def test_valve_state_report(zigpy_device_from_quirk, quirk):
"""Test thermostatic valves standard reporting from incoming commands."""
valve_dev = zigpy_device_from_quirk(quirk)
tuya_cluster = valve_dev.endpoints[1].tuya_manufacturer
thermostat_listener = ClusterListener(valve_dev.endpoints[1].thermostat)
frames = (
ZCL_SASWELL_TUYA_ROOM_TEMP,
# ZCL_SASWELL_TUYA_TARGET_TEMP,
# ZCL_SASWELL_TUYA_ONOFF,
# ZCL_SASWELL_TUYA_SCHEDULE_MODE,
# ZCL_SASWELL_TUYA_CHILD_LOCK,
# ZCL_SASWELL_TUYA_ANTI_FREEZE,
# ZCL_SASWELL_TUYA_DETECT_ATTR,
# ZCL_SASWELL_TUYA_LIMESCALE_PROTECT,
# ZCL_SASWELL_TUYA_TEMP_CORRECTION_ATTR,
# ZCL_SASWELL_TUYA_AWAY_MODE_ATTR,
# ZCL_SASWELL_TUYA_BATTERY_ALARM_ATTR,
)
for frame in frames:
hdr, args = tuya_cluster.deserialize(frame)
tuya_cluster.handle_message(hdr, args)
assert len(thermostat_listener.cluster_commands) == 0
assert len(thermostat_listener.attribute_updates) == 13
assert thermostat_listener.attribute_updates[0][0] == 0x0000 # TEMP
assert thermostat_listener.attribute_updates[0][1] == 1790
assert thermostat_listener.attribute_updates[1][0] == 0x0012 # TARGET
assert thermostat_listener.attribute_updates[1][1] == 500
assert thermostat_listener.attribute_updates[2][0] == 0x001C # OFF
assert thermostat_listener.attribute_updates[2][1] == 0x00
assert thermostat_listener.attribute_updates[3][0] == 0x001E
assert thermostat_listener.attribute_updates[3][1] == 0x00
assert thermostat_listener.attribute_updates[4][0] == 0x0029
assert thermostat_listener.attribute_updates[4][1] == 0x00
assert thermostat_listener.attribute_updates[5][0] == 0x001C # SCHEDULE
assert thermostat_listener.attribute_updates[5][1] == 0x04
assert thermostat_listener.attribute_updates[6][0] == 0x0025
assert thermostat_listener.attribute_updates[6][1] == 0x01
assert thermostat_listener.attribute_updates[7][0] == 0x001E
assert thermostat_listener.attribute_updates[7][1] == 0x04
assert thermostat_listener.attribute_updates[8][0] == 0x0029
assert thermostat_listener.attribute_updates[8][1] == 0x01
assert thermostat_listener.attribute_updates[9][0] == 0x001C # MANUAL
assert thermostat_listener.attribute_updates[9][1] == 0x04
assert thermostat_listener.attribute_updates[10][0] == 0x0025
assert thermostat_listener.attribute_updates[10][1] == 0x00
assert thermostat_listener.attribute_updates[11][0] == 0x001E
assert thermostat_listener.attribute_updates[11][1] == 0x04
assert thermostat_listener.attribute_updates[12][0] == 0x0029
assert thermostat_listener.attribute_updates[12][1] == 0x01