]> git.basschouten.com Git - openhab-addons.git/blob
1f6fe2255ff2f5047895ba7a9ea565e28cb934bf
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.loxone.internal.controls;
14
15 import java.util.Collections;
16 import java.util.Set;
17
18 import org.junit.jupiter.api.BeforeEach;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.library.types.PercentType;
23 import org.openhab.core.library.types.StopMoveType;
24 import org.openhab.core.library.types.UpDownType;
25
26 /**
27  * Test class for (@link LxControlJalousie}
28  *
29  * @author Pawel Pieczul - initial contribution
30  *
31  */
32 public class LxControlJalousieTest extends LxControlTest {
33
34     private static final String ROLLERSHUTTER_CHANNEL = null;
35     private static final String SHADE_CHANNEL = " / Shade";
36     private static final String AUTO_SHADE_CHANNEL = " / Auto Shade";
37
38     @BeforeEach
39     public void setup() {
40         setupControl("0e367c09-0161-e2c1-ffff403fb0c34b9e", "0e368d32-014f-4604-ffff403fb0c34b9e",
41                 "0b734138-033e-02d8-ffff403fb0c34b9e", "Window Blinds");
42     }
43
44     @Test
45     public void testControlCreation() {
46         testControlCreation(LxControlJalousie.class, 1, 0, 3, 3, 11);
47     }
48
49     @Test
50     public void testChannels() {
51         testChannel("Rollershutter", Collections.singleton("Blinds"));
52         Set<String> tags = Collections.singleton("Switchable");
53         testChannel("Switch", SHADE_CHANNEL, tags);
54         testChannel("Switch", AUTO_SHADE_CHANNEL, tags);
55     }
56
57     @Test
58     public void testLoxonePositionAutoShadeStates() {
59         boolean a = false;
60         testChannelState(ROLLERSHUTTER_CHANNEL, null);
61         testChannelState(SHADE_CHANNEL, OnOffType.OFF);
62         testChannelState(AUTO_SHADE_CHANNEL, null);
63         for (int i = 0; i <= 100; i++) {
64             changeLoxoneState("position", i / 100.0);
65             testChannelState(ROLLERSHUTTER_CHANNEL, new PercentType(i));
66             testChannelState(SHADE_CHANNEL, OnOffType.OFF);
67             changeLoxoneState("autoactive", a ? 1.0 : 0.0);
68             testChannelState(AUTO_SHADE_CHANNEL, a ? OnOffType.ON : OnOffType.OFF);
69             a = !a;
70         }
71         changeLoxoneState("position", 100.1);
72         testChannelState(ROLLERSHUTTER_CHANNEL, null);
73         changeLoxoneState("position", -0.1);
74         testChannelState(ROLLERSHUTTER_CHANNEL, null);
75     }
76
77     @Test
78     public void testCommands() {
79         for (int i = 0; i < 20; i++) {
80             executeCommand(SHADE_CHANNEL, OnOffType.ON);
81             testAction("shade");
82             executeCommand(SHADE_CHANNEL, OnOffType.OFF);
83             testAction(null);
84             executeCommand(SHADE_CHANNEL, DecimalType.ZERO);
85             testAction(null);
86             executeCommand(AUTO_SHADE_CHANNEL, OnOffType.ON);
87             testAction("auto");
88             executeCommand(AUTO_SHADE_CHANNEL, OnOffType.OFF);
89             testAction("NoAuto");
90             executeCommand(AUTO_SHADE_CHANNEL, DecimalType.ZERO);
91             testAction(null);
92             executeCommand(ROLLERSHUTTER_CHANNEL, UpDownType.UP);
93             testAction("FullUp");
94             executeCommand(ROLLERSHUTTER_CHANNEL, UpDownType.DOWN);
95             testAction("FullDown");
96             executeCommand(ROLLERSHUTTER_CHANNEL, StopMoveType.STOP);
97             testAction("Stop");
98             executeCommand(ROLLERSHUTTER_CHANNEL, StopMoveType.MOVE);
99             testAction(null);
100         }
101     }
102
103     @Test
104     public void testMovingToPosition() {
105         changeLoxoneState("position", 0.1);
106         testChannelState(ROLLERSHUTTER_CHANNEL, new PercentType(10));
107         executeCommand(ROLLERSHUTTER_CHANNEL, new PercentType(73));
108         testAction("FullDown");
109         changeLoxoneState("up", 0.0);
110         changeLoxoneState("down", 1.0);
111         for (int i = 10; i <= 72; i++) {
112             changeLoxoneState("position", i / 100.0);
113             testChannelState(ROLLERSHUTTER_CHANNEL, new PercentType(i));
114         }
115         changeLoxoneState("position", 0.73);
116         testAction("Stop");
117         changeLoxoneState("position", 0.74);
118         testAction(null);
119         changeLoxoneState("up", 0.0);
120         changeLoxoneState("down", 0.0);
121         executeCommand(ROLLERSHUTTER_CHANNEL, new PercentType(10));
122         testAction("FullUp");
123         changeLoxoneState("up", 1.0);
124         changeLoxoneState("down", 0.0);
125         for (int i = 74; i >= 11; i--) {
126             changeLoxoneState("position", i / 100.0);
127             testChannelState(ROLLERSHUTTER_CHANNEL, new PercentType(i));
128         }
129         changeLoxoneState("position", 0.10);
130         testAction("Stop");
131         changeLoxoneState("position", 0.09);
132         testAction(null);
133
134         executeCommand(ROLLERSHUTTER_CHANNEL, new PercentType(50));
135         testAction("FullDown");
136         changeLoxoneState("up", 0.0);
137         changeLoxoneState("down", 1.0);
138         changeLoxoneState("position", 0.80);
139         testAction("Stop");
140         changeLoxoneState("position", 0.50);
141         testAction(null);
142
143         executeCommand(ROLLERSHUTTER_CHANNEL, new PercentType(90));
144         testAction("FullDown");
145         changeLoxoneState("up", 0.0);
146         changeLoxoneState("down", 0.0);
147         changeLoxoneState("position", 0.95);
148         testAction(null);
149         changeLoxoneState("position", 0.85);
150         testAction(null);
151
152         changeLoxoneState("down", 1.0);
153         changeLoxoneState("position", 0.85);
154         testAction(null);
155         changeLoxoneState("position", 0.95);
156         testAction("Stop");
157         changeLoxoneState("position", 0.85);
158         testAction(null);
159         changeLoxoneState("position", 0.95);
160         testAction(null);
161         changeLoxoneState("down", 0.0);
162
163         executeCommand(ROLLERSHUTTER_CHANNEL, new PercentType(30));
164         testAction("FullUp");
165         changeLoxoneState("up", 1.0);
166         changeLoxoneState("down", 0.0);
167         changeLoxoneState("position", 0.40);
168         testAction(null);
169         changeLoxoneState("position", 0.20);
170         testAction("Stop");
171         changeLoxoneState("position", 0.40);
172         testAction(null);
173         changeLoxoneState("position", 0.20);
174         testAction(null);
175         changeLoxoneState("up", 0.0);
176
177         executeCommand(ROLLERSHUTTER_CHANNEL, PercentType.HUNDRED);
178         testAction("FullDown");
179         changeLoxoneState("up", 0.0);
180         changeLoxoneState("down", 1.0);
181         changeLoxoneState("position", 0.80);
182         testAction(null);
183         changeLoxoneState("position", 1.00);
184         testAction(null);
185         changeLoxoneState("down", 0.0);
186
187         executeCommand(ROLLERSHUTTER_CHANNEL, PercentType.ZERO);
188         testAction("FullUp");
189         changeLoxoneState("up", 1.0);
190         changeLoxoneState("down", 0.0);
191         changeLoxoneState("position", 0.20);
192         testAction(null);
193         changeLoxoneState("position", 0.00);
194         testAction(null);
195         changeLoxoneState("up", 0.0);
196     }
197 }