File: cover_test.py

package info (click to toggle)
python-xknx 3.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,044 kB
  • sloc: python: 40,087; javascript: 8,556; makefile: 32; sh: 12
file content (1088 lines) | stat: -rw-r--r-- 39,062 bytes parent folder | download | duplicates (2)
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
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
"""Unit test for Cover objects."""

from unittest.mock import AsyncMock, Mock, patch

from xknx import XKNX
from xknx.devices import Cover
from xknx.dpt import DPTArray, DPTBinary
from xknx.telegram import GroupAddress, Telegram
from xknx.telegram.apci import GroupValueRead, GroupValueWrite

from ..conftest import EventLoopClockAdvancer


class TestCover:
    """Test class for Cover objects."""

    #
    # SUPPORTS STOP/POSITION/ANGLE
    #
    def test_supports_stop_true(self) -> None:
        """Test support_position_true."""
        xknx = XKNX()
        cover_short_stop = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_short="1/4/15",
        )
        assert cover_short_stop.supports_stop

        cover_manual_stop = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_stop="1/4/15",
        )
        assert cover_manual_stop.supports_stop

    async def test_supports_stop_false(self) -> None:
        """Test support_position_true."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_position="1/4/16",
            group_address_angle="1/4/18",
        )
        assert not cover.supports_stop
        with patch("logging.Logger.warning") as mock_warn:
            await cover.stop()
            assert xknx.telegrams.qsize() == 0
            mock_warn.assert_called_with(
                "Stop not supported for device %s", "Children.Venetian"
            )

    def test_supports_position_true(self) -> None:
        """Test support_position_true."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_short="1/4/15",
            group_address_position="1/4/16",
        )
        assert cover.supports_position

    def test_supports_position_false(self) -> None:
        """Test support_position_true."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_short="1/4/15",
        )
        assert not cover.supports_position

    def test_supports_angle_true(self) -> None:
        """Test support_position_true."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_short="1/4/15",
            group_address_angle="1/4/18",
        )
        assert cover.supports_angle

    def test_support_angle_false(self) -> None:
        """Test support_position_true."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_short="1/4/15",
        )
        assert not cover.supports_angle

    #
    # SUPPORTS LOCKED
    #
    def test_support_locked(self) -> None:
        """Test support_position_true."""
        xknx = XKNX()
        cover_locked = Cover(
            xknx,
            "Children.Venetian",
            group_address_locked_state="1/4/14",
        )
        assert cover_locked.supports_locked
        cover_manual_stop = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_stop="1/4/15",
        )
        assert cover_manual_stop.supports_locked is False

    #
    # SYNC
    #
    async def test_sync(self) -> None:
        """Test sync function / sending group reads to KNX bus."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverSync",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position_state="1/2/3",
        )
        await cover.sync()
        assert xknx.telegrams.qsize() == 1
        telegram1 = xknx.telegrams.get_nowait()
        assert telegram1 == Telegram(
            destination_address=GroupAddress("1/2/3"), payload=GroupValueRead()
        )

    async def test_sync_state(self) -> None:
        """Test sync function with explicit state address."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverSyncState",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
        )
        await cover.sync()
        assert xknx.telegrams.qsize() == 1
        telegram1 = xknx.telegrams.get_nowait()
        assert telegram1 == Telegram(
            destination_address=GroupAddress("1/2/4"), payload=GroupValueRead()
        )

    async def test_sync_angle(self) -> None:
        """Test sync function for cover with angle."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverSyncAngle",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position_state="1/2/3",
            group_address_angle_state="1/2/4",
        )
        await cover.sync()
        assert xknx.telegrams.qsize() == 2
        telegram1 = xknx.telegrams.get_nowait()
        assert telegram1 == Telegram(
            destination_address=GroupAddress("1/2/3"), payload=GroupValueRead()
        )
        telegram2 = xknx.telegrams.get_nowait()
        assert telegram2 == Telegram(
            destination_address=GroupAddress("1/2/4"), payload=GroupValueRead()
        )

    async def test_sync_angle_state(self) -> None:
        """Test sync function with angle/explicit state."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverSyncAngleState",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_angle="1/2/3",
            group_address_angle_state="1/2/4",
        )
        await cover.sync()
        assert xknx.telegrams.qsize() == 1
        telegram1 = xknx.telegrams.get_nowait()
        assert telegram1 == Telegram(
            destination_address=GroupAddress("1/2/4"), payload=GroupValueRead()
        )

    #
    # TEST SET UP
    #
    async def test_set_up(self) -> None:
        """Test moving cover to 'up' position."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverSetUp",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
        )
        await cover.set_up()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        # DPT 1.008 - 0:up 1:down
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/1"),
            payload=GroupValueWrite(DPTBinary(0)),
        )

    #
    # TEST SET DOWN
    #
    async def test_set_short_down(self) -> None:
        """Test moving cover to 'down' position."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverShortDown",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
        )
        await cover.set_down()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/1"),
            payload=GroupValueWrite(DPTBinary(1)),
        )

    #
    # TEST SET DOWN INVERTED
    #
    async def test_set_down_inverted(self) -> None:
        """Test moving cover to 'down' position."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverSetDownInverted",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
            invert_updown=True,
        )
        await cover.set_down()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/1"),
            payload=GroupValueWrite(DPTBinary(0)),
        )

    #
    # TEST SET SHORT UP
    #
    async def test_set_short_up(self) -> None:
        """Test moving cover 'short up'."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverSetShortUp",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
        )
        await cover.set_short_up()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        # DPT 1.008 - 0:up 1:down
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/2"),
            payload=GroupValueWrite(DPTBinary(0)),
        )

    #
    # TEST SET UP INVERTED
    #
    async def test_set_up_inverted(self) -> None:
        """Test moving cover 'short up'."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverSetUpInverted",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
            invert_updown=True,
        )
        await cover.set_short_up()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        # DPT 1.008 - 0:up 1:down
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/2"),
            payload=GroupValueWrite(DPTBinary(1)),
        )

    #
    # TEST SET SHORT DOWN
    #
    async def test_set_down(self) -> None:
        """Test moving cover 'short down'."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverSetDown",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
        )
        await cover.set_short_down()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        # DPT 1.008 - 0:up 1:down
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/2"),
            payload=GroupValueWrite(DPTBinary(1)),
        )

    #
    # TEST STOP
    #
    async def test_stop(self) -> None:
        """Test stopping cover."""
        xknx = XKNX()
        cover_short_stop = Cover(
            xknx,
            "TestCoverStop",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
        )
        # Attempt stopping while not actually moving
        await cover_short_stop.stop()
        assert xknx.telegrams.qsize() == 0

        # Attempt stopping while moving down
        cover_short_stop.travelcalculator.set_position(0)
        await cover_short_stop.set_down()
        await cover_short_stop.stop()
        assert xknx.telegrams.qsize() == 2
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/1"),
            payload=GroupValueWrite(DPTBinary(1)),
        )
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/2"),
            payload=GroupValueWrite(DPTBinary(1)),
        )

        # Attempt stopping while moving up
        cover_short_stop.travelcalculator.set_position(100)
        await cover_short_stop.set_up()
        await cover_short_stop.stop()
        assert xknx.telegrams.qsize() == 2
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/1"),
            payload=GroupValueWrite(DPTBinary(0)),
        )
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/2"),
            payload=GroupValueWrite(DPTBinary(0)),
        )

        cover_manual_stop = Cover(
            xknx,
            "TestCoverManualStop",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_stop="1/2/0",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
        )
        await cover_manual_stop.stop()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/0"),
            payload=GroupValueWrite(DPTBinary(1)),
        )

    async def test_stop_angle(self) -> None:
        """Test stopping cover during angle move / tilting."""
        xknx = XKNX()
        cover_short_stop = Cover(
            xknx,
            "TestCoverStopAngle",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_angle="1/2/5",
            group_address_angle_state="1/2/6",
        )
        # Attempt stopping while not actually tilting
        await cover_short_stop.stop()
        assert xknx.telegrams.qsize() == 0

        # Set cover tilt to a dummy start value, since otherwise we cannot
        # determine later on a tilt direction and without it, stopping the
        # til process has no effect.
        cover_short_stop.angle.process(
            Telegram(
                destination_address=GroupAddress("1/2/5"),
                payload=GroupValueWrite(DPTArray(0xAA)),
            )
        )

        # Attempt stopping while tilting down
        await cover_short_stop.set_angle(100)
        await cover_short_stop.stop()
        assert xknx.telegrams.qsize() == 2
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/5"),
            payload=GroupValueWrite(DPTArray(0xFF)),
        )
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/2"),
            payload=GroupValueWrite(DPTBinary(1)),
        )

        # Attempt stopping while tilting up
        await cover_short_stop.set_angle(0)
        await cover_short_stop.stop()
        assert xknx.telegrams.qsize() == 2
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/5"),
            payload=GroupValueWrite(DPTArray(0x00)),
        )
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/2"),
            payload=GroupValueWrite(DPTBinary(0)),
        )

    #
    # TEST POSITION
    #
    async def test_position(self) -> None:
        """Test moving cover to absolute position."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverPosition",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
        )
        await cover.set_position(50)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0x80)),
        )
        await cover.stop()  # clean up tasks

    async def test_position_without_binary(self) -> None:
        """Test moving cover - with no binary positioning supported."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverPositionWithoutBinary",
            group_address_position="1/2/3",
        )
        await cover.set_down()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0xFF)),
        )
        await cover.set_position(50)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0x80)),
        )
        await cover.set_up()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0x00)),
        )

    async def test_position_without_position_address_up(self) -> None:
        """Test moving cover to absolute position - with no absolute positioning supported."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverPWPAD",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position_state="1/2/4",
        )
        cover.travelcalculator.set_position(60)
        await cover.set_position(50)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        # DPT 1.008 - 0:up 1:down
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/1"),
            payload=GroupValueWrite(DPTBinary(0)),
        )
        assert cover.travelcalculator._travel_to_position == 50
        assert cover.is_opening()
        # process the outgoing telegram to make sure it doesn't overwrite the target position
        cover.process(telegram)
        assert cover.travelcalculator._travel_to_position == 50
        assert xknx.telegrams.qsize() == 0

        await cover.stop()  # clean up tasks

    async def test_position_without_position_address_down(self) -> None:
        """Test moving cover down - with no absolute positioning supported."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverPWPAD",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position_state="1/2/4",
        )
        cover.travelcalculator.set_position(70)
        await cover.set_position(80)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/1"),
            payload=GroupValueWrite(DPTBinary(1)),
        )
        assert cover.travelcalculator._travel_to_position == 80
        assert cover.is_closing()
        # process the outgoing telegram to make sure it doesn't overwrite the target position
        cover.process(telegram)
        assert cover.travelcalculator._travel_to_position == 80

        await cover.stop()  # clean up tasks

    async def test_position_without_position_address_uninitialized_up(self) -> None:
        """Test moving uninitialized cover to absolute position - with no absolute positioning supported."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverPWPAUU",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position_state="1/2/4",
        )

        with patch("logging.Logger.warning") as mock_warn:
            await cover.set_position(50)
            assert xknx.telegrams.qsize() == 0
            mock_warn.assert_called_with(
                "Current position unknown. Initialize cover by moving to end position."
            )

        await cover.set_position(0)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/1"),
            payload=GroupValueWrite(DPTBinary(0)),
        )
        await cover.stop()  # clean up tasks

    async def test_position_without_position_address_uninitialized_down(self) -> None:
        """Test moving uninitialized cover to absolute position - with no absolute positioning supported."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverPWPAUD",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position_state="1/2/4",
        )

        with patch("logging.Logger.warning") as mock_warn:
            await cover.set_position(50)
            assert xknx.telegrams.qsize() == 0
            mock_warn.assert_called_with(
                "Current position unknown. Initialize cover by moving to end position."
            )

        await cover.set_position(100)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/1"),
            payload=GroupValueWrite(DPTBinary(1)),
        )
        await cover.stop()  # clean up tasks

    async def test_angle(self) -> None:
        """Test changing angle."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_short="1/4/15",
            group_address_position_state="1/4/17",
            group_address_position="1/4/16",
            group_address_angle="1/4/18",
            group_address_angle_state="1/4/19",
        )
        await cover.set_angle(50)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/4/18"),
            payload=GroupValueWrite(DPTArray(0x80)),
        )

    async def test_angle_not_supported(self) -> None:
        """Test changing angle on cover which does not support angle."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "Children.Venetian",
            group_address_long="1/4/14",
            group_address_short="1/4/15",
        )
        with patch("logging.Logger.warning") as mock_warn:
            await cover.set_angle(50)
            assert xknx.telegrams.qsize() == 0
            mock_warn.assert_called_with(
                "Angle not supported for device %s", "Children.Venetian"
            )

    #
    # TEST PROCESS
    #
    async def test_process_position(self) -> None:
        """Test process / reading telegrams from telegram queue. Test if position is processed correctly."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessPosition",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
        )
        # initial position process - position is unknown so this is the new state - not moving
        telegram = Telegram(
            GroupAddress("1/2/3"), payload=GroupValueWrite(DPTArray(213))
        )
        cover.process(telegram)
        assert cover.current_position() == 84
        assert not cover.is_traveling()
        # state telegram updates current position - we are not moving so this is new state - not moving
        telegram = Telegram(
            GroupAddress("1/2/4"), payload=GroupValueWrite(DPTArray(42))
        )
        cover.process(telegram)
        assert cover.current_position() == 16
        assert not cover.is_traveling()
        assert cover.travelcalculator._travel_to_position == 16
        # new position - movement starts
        telegram = Telegram(
            GroupAddress("1/2/3"), payload=GroupValueWrite(DPTArray(255))
        )
        cover.process(telegram)
        assert cover.current_position() == 16
        assert cover.is_closing()
        assert cover.travelcalculator._travel_to_position == 100
        # new state while moving - movement goes on; travelcalculator updated
        telegram = Telegram(
            GroupAddress("1/2/4"), payload=GroupValueWrite(DPTArray(213))
        )
        cover.process(telegram)
        assert cover.current_position() == 84
        assert cover.is_closing()
        assert cover.travelcalculator._travel_to_position == 100

        await cover.stop()  # clean up tasks

    async def test_process_angle(self) -> None:
        """Test process / reading telegrams from telegram queue. Test if position is processed correctly."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessAngle",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_angle="1/2/3",
            group_address_angle_state="1/2/4",
        )
        telegram = Telegram(
            GroupAddress("1/2/4"), payload=GroupValueWrite(DPTArray(42))
        )
        cover.process(telegram)
        assert cover.current_angle() == 16

    async def test_process_locked(self) -> None:
        """Test process / reading telegrams from telegram queue. Test if position is processed correctly."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessLocked",
            group_address_long="1/2/1",
            group_address_locked_state="1/2/4",
        )
        telegram = Telegram(
            GroupAddress("1/2/4"), payload=GroupValueWrite(DPTBinary(1))
        )
        cover.process(telegram)
        assert cover.is_locked() is True

    async def test_process_up(self) -> None:
        """Test process / reading telegrams from telegram queue. Test if up/down is processed correctly."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessUp",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
        )
        cover.travelcalculator.set_position(50)
        assert not cover.is_traveling()
        telegram = Telegram(
            GroupAddress("1/2/1"), payload=GroupValueWrite(DPTBinary(0))
        )
        cover.process(telegram)
        assert cover.is_opening()

        await cover.stop()  # clean up tasks

    async def test_process_down(self) -> None:
        """Test process / reading telegrams from telegram queue. Test if up/down is processed correctly."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessDown",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
        )
        cover.travelcalculator.set_position(50)
        assert not cover.is_traveling()
        telegram = Telegram(
            GroupAddress("1/2/1"), payload=GroupValueWrite(DPTBinary(1))
        )
        cover.process(telegram)
        assert cover.is_closing()

        await cover.stop()  # clean up tasks

    async def test_process_stop(self) -> None:
        """Test process / reading telegrams from telegram queue. Test if stop is processed correctly."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessStop",
            group_address_long="1/2/1",
            group_address_stop="1/2/2",
        )
        cover.travelcalculator.set_position(50)
        await cover.set_down()
        assert cover.is_traveling()
        telegram = Telegram(
            GroupAddress("1/2/2"), payload=GroupValueWrite(DPTBinary(1))
        )
        cover.process(telegram)
        assert not cover.is_traveling()

    async def test_process_short_stop(self) -> None:
        """Test process / reading telegrams from telegram queue. Test if stop is processed correctly."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessShortStop",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
        )
        cover.travelcalculator.set_position(50)
        await cover.set_down()
        assert cover.is_traveling()
        telegram = Telegram(
            GroupAddress("1/2/2"), payload=GroupValueWrite(DPTBinary(1))
        )
        cover.process(telegram)
        assert not cover.is_traveling()

    async def test_process_callback(self) -> None:
        """Test process / reading telegrams from telegram queue. Test if callback is executed."""

        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessCallback",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_stop="1/2/3",
            group_address_position="1/2/4",
            group_address_position_state="1/2/5",
            group_address_angle="1/2/6",
            group_address_angle_state="1/2/7",
        )

        after_update_callback = Mock()

        cover.register_device_updated_cb(after_update_callback)
        for address, payload, _feature in [
            ("1/2/1", DPTBinary(1), "long"),
            ("1/2/2", DPTBinary(1), "short"),
            ("1/2/4", DPTArray(42), "position"),
            ("1/2/3", DPTBinary(1), "stop"),
            # call position with same value again to make sure `always_callback` is set for target position
            ("1/2/4", DPTArray(42), "position"),
            ("1/2/5", DPTArray(42), "position state"),
            ("1/2/6", DPTArray(42), "angle"),
            ("1/2/7", DPTArray(51), "angle state"),
        ]:
            telegram = Telegram(
                destination_address=GroupAddress(address),
                payload=GroupValueWrite(payload),
            )
            cover.process(telegram)
            after_update_callback.assert_called_with(cover)
            after_update_callback.reset_mock()
        # Stop only when cover is travelling
        telegram = Telegram(
            GroupAddress("1/2/3"), payload=GroupValueWrite(DPTBinary(1))
        )
        cover.process(telegram)
        after_update_callback.assert_not_called()
        await cover.set_down()
        cover.process(telegram)
        after_update_callback.assert_called_with(cover)

        await cover.stop()  # clean up tasks

    #
    # IS TRAVELING / IS UP / IS DOWN
    #
    async def test_is_traveling(self) -> None:
        """Test moving cover to absolute position."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverIsTraveling",
            group_address_long="1/2/1",
            group_address_stop="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
            travel_time_down=10,
            travel_time_up=10,
        )
        with patch("time.time") as mock_time:
            mock_time.return_value = 1517000000.0
            assert not cover.is_traveling()
            assert not cover.is_opening()
            assert not cover.is_closing()
            assert cover.position_reached()
            # we start with state open covers (up)
            cover.travelcalculator.set_position(0)
            await cover.set_down()
            assert cover.is_traveling()
            assert cover.is_open()
            assert not cover.is_closed()
            assert not cover.is_opening()
            assert cover.is_closing()

            mock_time.return_value = 1517000005.0  # 5 Seconds, half way
            assert not cover.position_reached()
            assert cover.is_traveling()
            assert not cover.is_open()
            assert not cover.is_closed()
            assert not cover.is_opening()
            assert cover.is_closing()

            mock_time.return_value = 1517000010.0  # 10 Seconds, fully closed
            assert cover.position_reached()
            assert not cover.is_traveling()
            assert not cover.is_open()
            assert cover.is_closed()
            assert not cover.is_opening()
            assert not cover.is_closing()
            # up again
            await cover.set_up()
            assert not cover.position_reached()
            assert cover.is_traveling()
            assert not cover.is_open()
            assert cover.is_closed()
            assert cover.is_opening()
            assert not cover.is_closing()

            mock_time.return_value = 1517000015.0  # 15 Seconds, half way
            assert not cover.position_reached()
            assert cover.is_traveling()
            assert not cover.is_open()
            assert not cover.is_closed()
            assert cover.is_opening()
            assert not cover.is_closing()

            mock_time.return_value = 1517000016.0  # 16 Seconds, manual stop
            await cover.stop()
            assert cover.position_reached()
            assert not cover.is_traveling()
            assert not cover.is_open()
            assert not cover.is_closed()
            assert not cover.is_opening()
            assert not cover.is_closing()

    #
    # TEST TASKS
    #
    async def test_auto_stop(self, time_travel: EventLoopClockAdvancer) -> None:
        """Test auto stop functionality."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverAutoStop",
            group_address_long="1/2/1",
            group_address_stop="1/2/2",
            travel_time_down=10,
            travel_time_up=10,
        )
        with patch("time.time") as mock_time:
            mock_time.return_value = 1517000000.0
            # we start with state 0 - open covers (up) this is assumed immediately
            await cover.set_position(0)
            assert xknx.telegrams.qsize() == 1
            _ = xknx.telegrams.get_nowait()

            await cover.set_position(50)

            await time_travel(1)
            mock_time.return_value = 1517000001.0
            assert xknx.telegrams.qsize() == 1
            telegram1 = xknx.telegrams.get_nowait()
            assert telegram1 == Telegram(
                destination_address=GroupAddress("1/2/1"),
                payload=GroupValueWrite(DPTBinary(True)),
            )

            await time_travel(4)
            mock_time.return_value = 1517000005.0
            assert xknx.telegrams.qsize() == 1
            telegram1 = xknx.telegrams.get_nowait()
            assert telegram1 == Telegram(
                destination_address=GroupAddress("1/2/2"),
                payload=GroupValueWrite(DPTBinary(True)),
            )

    async def test_periodic_update(self, time_travel: EventLoopClockAdvancer) -> None:
        """Test periodic update functionality."""
        xknx = XKNX()
        callback_mock = Mock()
        cover = Cover(
            xknx,
            "TestCoverPeriodicUpdate",
            group_address_long="1/2/1",
            group_address_stop="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
            travel_time_down=10,
            travel_time_up=10,
            device_updated_cb=callback_mock,
        )
        with patch("time.time") as mock_time:
            mock_time.return_value = 1517000000.0
            # state telegram updates current position - we are not moving so this is new state - not moving
            telegram = Telegram(
                GroupAddress("1/2/4"), payload=GroupValueWrite(DPTArray(0))
            )
            cover.process(telegram)
            await time_travel(0)
            assert callback_mock.call_count == 1
            callback_mock.reset_mock()
            # move to 50%
            telegram = Telegram(
                GroupAddress("1/2/3"), payload=GroupValueWrite(DPTArray(125))
            )
            cover.process(telegram)
            await time_travel(0)
            assert callback_mock.call_count == 1

            mock_time.return_value = 1517000001.0
            await time_travel(1)
            assert callback_mock.call_count == 2

            # state telegram from bus too early
            mock_time.return_value = 1517000001.6
            await time_travel(0.6)
            assert callback_mock.call_count == 2
            telegram = Telegram(
                GroupAddress("1/2/4"), payload=GroupValueWrite(DPTArray(42))
            )
            cover.process(telegram)
            assert callback_mock.call_count == 3
            # next update 1 second after last received state telegram
            mock_time.return_value = 1517000002.0
            await time_travel(0.4)
            assert callback_mock.call_count == 3
            mock_time.return_value = 1517000002.6
            await time_travel(0.6)
            assert callback_mock.call_count == 4
            # last callback - auto updater is removed
            mock_time.return_value = 1517000005.0
            await time_travel(2.4)
            assert callback_mock.call_count == 5
            assert cover.position_reached()
            assert cover._periodic_update_task is None

    @patch("xknx.core.TelegramQueue.process_telegram_outgoing", new_callable=AsyncMock)
    async def test_remove_task_cancel(
        self, _outgoing: AsyncMock, xknx_no_interface: XKNX
    ) -> None:
        """Test if tasks are removed correctly when device is removed."""
        xknx = xknx_no_interface
        cover = Cover(
            xknx,
            "TestCoverRemoveTaskCancel",
            group_address_long="1/2/1",
            group_address_stop="1/2/2",
            group_address_position_state="1/2/4",
            travel_time_down=10,
            travel_time_up=10,
        )
        xknx.devices.async_add(cover)
        async with xknx:
            # state telegram updates current position - we are not moving so this is new state - not moving
            telegram = Telegram(
                GroupAddress("1/2/4"), payload=GroupValueWrite(DPTArray(0))
            )
            cover.process(telegram)
            assert cover.current_position() == 0
            await cover.set_position(50)
            assert cover._periodic_update_task is not None
            assert cover._auto_stop_task is not None
            xknx.devices.async_remove(cover)
            assert cover._periodic_update_task is None
            assert cover._auto_stop_task is None

    #
    # HAS GROUP ADDRESS
    #
    def test_has_group_address(self) -> None:
        """Test sensor has group address."""
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverHasGroupAddress",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_position="1/2/3",
            group_address_position_state="1/2/4",
            group_address_angle="1/2/5",
            group_address_angle_state="1/2/6",
        )

        assert cover.has_group_address(GroupAddress("1/2/1"))
        assert cover.has_group_address(GroupAddress("1/2/2"))
        assert cover.has_group_address(GroupAddress("1/2/3"))
        assert cover.has_group_address(GroupAddress("1/2/4"))
        assert cover.has_group_address(GroupAddress("1/2/5"))
        assert cover.has_group_address(GroupAddress("1/2/6"))
        assert not cover.has_group_address(GroupAddress("1/2/7"))