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