]> git.basschouten.com Git - openhab-addons.git/blob
d62a5c7598d74ea0cf51c561e952e77eb1175553
[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 org.junit.jupiter.api.BeforeEach;
16 import org.junit.jupiter.api.Test;
17 import org.openhab.core.library.types.DecimalType;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.library.types.PercentType;
20 import org.openhab.core.library.types.StringType;
21 import org.openhab.core.types.UnDefType;
22
23 /**
24  * Test class for (@link LxControlSauna} - version with no door sensor and no vaporizer
25  *
26  * @author Pawel Pieczul - initial contribution
27  *
28  */
29 public class LxControlSaunaTest extends LxControlTest {
30     private static final String ACTIVE_CHANNEL = " / Active";
31     private static final String POWER_CHANNEL = " / Power";
32     private static final String TEMP_ACTUAL_CHANNEL = " / Temperature / Actual";
33     private static final String TEMP_BENCH_CHANNEL = " / Temperature / Bench";
34     private static final String TEMP_TARGET_CHANNEL = " / Temperature / Target";
35     private static final String FAN_CHANNEL = " / Fan";
36     private static final String DRYING_CHANNEL = " / Drying";
37     static final String DOOR_CLOSED_CHANNEL = " / Door Closed";
38     private static final String ERROR_CODE_CHANNEL = " / Error Code";
39     static final String VAPOR_POWER_CHANNEL = " / Evaporator / Power";
40     private static final String TIMER_CURRENT_CHANNEL = " / Timer / Current";
41     private static final String TIMER_TRIGGER_CHANNEL = " / Timer / Trigger";
42     private static final String TIMER_TOTAL_CHANNEL = " / Timer / Total";
43     static final String OUT_OF_WATER_CHANNEL = " / Evaporator / Out Of Water";
44     static final String ACTUAL_HUMIDITY_CHANNEL = " / Evaporator / Humidity / Actual";
45     static final String TARGET_HUMIDITY_CHANNEL = " / Evaporator / Humidity / Target";
46     static final String EVAPORATOR_MODE_CHANNEL = " / Evaporator / Mode";
47     private static final String NEXT_STATE_CHANNEL = " / Next State";
48
49     @BeforeEach
50     public void setup() {
51         setupControl("17452951-02ae-1b6e-ffff266cf17271db", "0b734138-037d-034e-ffff403fb0c34b9e",
52                 "0fe650c2-0004-d446-ffff504f9410790f", "Sauna Controller No Vaporizer No Door Sensor");
53     }
54
55     @Test
56     public void testControlCreation() {
57         testControlCreation(LxControlSauna.class, 3, 0, 12, 12, 14);
58     }
59
60     @Test
61     public void testChannels() {
62         testChannel("Switch", ACTIVE_CHANNEL);
63         testChannel("Number", POWER_CHANNEL);
64         testChannel("Number", TEMP_ACTUAL_CHANNEL);
65         testChannel("Number", TEMP_BENCH_CHANNEL);
66         testChannel("Number", TEMP_TARGET_CHANNEL);
67         testChannel("Switch", FAN_CHANNEL);
68         testChannel("Switch", DRYING_CHANNEL);
69         testChannel("Number", ERROR_CODE_CHANNEL);
70         testChannel("Number", TIMER_CURRENT_CHANNEL);
71         testChannel("Switch", TIMER_TRIGGER_CHANNEL);
72         testChannel("Number", TIMER_TOTAL_CHANNEL);
73         testChannel("Switch", NEXT_STATE_CHANNEL);
74     }
75
76     @Test
77     public void testActiveChannel() {
78         for (int i = 0; i < 5; i++) {
79             changeLoxoneState("active", 0.0);
80             testChannelState(ACTIVE_CHANNEL, OnOffType.OFF);
81             changeLoxoneState("active", 1.0);
82             testChannelState(ACTIVE_CHANNEL, OnOffType.ON);
83         }
84         for (int i = 0; i < 5; i++) {
85             executeCommand(ACTIVE_CHANNEL, OnOffType.ON);
86             testAction("on");
87             executeCommand(ACTIVE_CHANNEL, DecimalType.ZERO);
88             testAction(null);
89             executeCommand(ACTIVE_CHANNEL, OnOffType.OFF);
90             testAction("off");
91             executeCommand(ACTIVE_CHANNEL, StringType.EMPTY);
92             testAction(null);
93         }
94     }
95
96     @Test
97     public void testPowerChannel() {
98         for (Double i = 0.0; i <= 100.0; i += 1.0) {
99             changeLoxoneState("power", i);
100             testChannelState(POWER_CHANNEL, new PercentType(i.intValue()));
101         }
102         changeLoxoneState("power", -1.0);
103         testChannelState(POWER_CHANNEL, UnDefType.UNDEF);
104         changeLoxoneState("power", 100.1);
105         testChannelState(POWER_CHANNEL, UnDefType.UNDEF);
106     }
107
108     @Test
109     public void testTempActualBenchChannels() {
110         for (Double i = -20.0; i <= 150.0; i += 0.37) {
111             changeLoxoneState("tempactual", i);
112             testChannelState(TEMP_ACTUAL_CHANNEL, new DecimalType(i));
113             changeLoxoneState("tempbench", i * 1.1);
114             testChannelState(TEMP_BENCH_CHANNEL, new DecimalType(i * 1.1));
115             changeLoxoneState("temptarget", i * 1.2);
116             testChannelState(TEMP_TARGET_CHANNEL, new DecimalType(i * 1.2));
117         }
118     }
119
120     @Test
121     public void testTempTargetSetCommand() {
122         for (Double i = 0.0; i <= 150.0; i += 0.37) {
123             executeCommand(TEMP_TARGET_CHANNEL, new DecimalType(i));
124             testAction("temp/" + i.toString());
125         }
126     }
127
128     @Test
129     public void testFanChannel() {
130         for (int i = 0; i < 5; i++) {
131             changeLoxoneState("fan", 0.0);
132             testChannelState(FAN_CHANNEL, OnOffType.OFF);
133             changeLoxoneState("fan", 1.0);
134             testChannelState(FAN_CHANNEL, OnOffType.ON);
135         }
136         for (int i = 0; i < 5; i++) {
137             executeCommand(FAN_CHANNEL, OnOffType.ON);
138             testAction("fanon");
139             executeCommand(FAN_CHANNEL, DecimalType.ZERO);
140             testAction(null);
141             executeCommand(FAN_CHANNEL, OnOffType.OFF);
142             testAction("fanoff");
143             executeCommand(FAN_CHANNEL, StringType.EMPTY);
144             testAction(null);
145         }
146     }
147
148     @Test
149     public void testDryingChannel() {
150         for (int i = 0; i < 5; i++) {
151             changeLoxoneState("drying", 0.0);
152             testChannelState(DRYING_CHANNEL, OnOffType.OFF);
153             changeLoxoneState("drying", 1.0);
154             testChannelState(DRYING_CHANNEL, OnOffType.ON);
155         }
156     }
157
158     @Test
159     public void testDoorClosedChannel() {
160         testNoChannel(DOOR_CLOSED_CHANNEL);
161     }
162
163     @Test
164     public void testErrorCodeChannel() {
165         for (Double i = 0.0; i < 10.0; i += 1.0) {
166             changeLoxoneState("saunaerror", i);
167             changeLoxoneState("error", 0.0);
168             testChannelState(ERROR_CODE_CHANNEL, DecimalType.ZERO);
169             changeLoxoneState("error", 1.0);
170             testChannelState(ERROR_CODE_CHANNEL, new DecimalType(i));
171         }
172     }
173
174     @Test
175     public void testTimerCurrentTotalChannels() {
176         for (Double i = 0.0; i <= 150.0; i += 0.21) {
177             changeLoxoneState("timer", i);
178             testChannelState(TIMER_CURRENT_CHANNEL, new DecimalType(i));
179             changeLoxoneState("timertotal", i * 1.3);
180             testChannelState(TIMER_TOTAL_CHANNEL, new DecimalType(i * 1.3));
181         }
182     }
183
184     @Test
185     public void testTimerTriggerChannel() {
186         for (int i = 0; i <= 10; i++) {
187             executeCommand(TIMER_TRIGGER_CHANNEL, DecimalType.ZERO);
188             testAction(null);
189             testChannelState(TIMER_TRIGGER_CHANNEL, OnOffType.OFF);
190             executeCommand(TIMER_TRIGGER_CHANNEL, OnOffType.ON);
191             testAction("starttimer");
192             testChannelState(TIMER_TRIGGER_CHANNEL, OnOffType.OFF);
193             executeCommand(TIMER_TRIGGER_CHANNEL, OnOffType.OFF);
194             testAction(null);
195             testChannelState(TIMER_TRIGGER_CHANNEL, OnOffType.OFF);
196         }
197     }
198
199     @Test
200     public void vaporPowerChannel() {
201         testNoChannel(VAPOR_POWER_CHANNEL);
202     }
203
204     @Test
205     public void testOutOfWaterChannel() {
206         testNoChannel(OUT_OF_WATER_CHANNEL);
207     }
208
209     @Test
210     public void testActualHumidityChannel() {
211         testNoChannel(ACTUAL_HUMIDITY_CHANNEL);
212     }
213
214     @Test
215     public void testTargetHumidityChannel() {
216         testNoChannel(TARGET_HUMIDITY_CHANNEL);
217     }
218
219     @Test
220     public void testEvaporatorModelChannel() {
221         testNoChannel(EVAPORATOR_MODE_CHANNEL);
222     }
223
224     @Test
225     public void testNextStateTriggerChannel() {
226         for (int i = 0; i <= 10; i++) {
227             executeCommand(NEXT_STATE_CHANNEL, DecimalType.ZERO);
228             testAction(null);
229             testChannelState(NEXT_STATE_CHANNEL, OnOffType.OFF);
230             executeCommand(NEXT_STATE_CHANNEL, OnOffType.ON);
231             testAction("pulse");
232             testChannelState(NEXT_STATE_CHANNEL, OnOffType.OFF);
233             executeCommand(NEXT_STATE_CHANNEL, OnOffType.OFF);
234             testAction(null);
235             testChannelState(NEXT_STATE_CHANNEL, OnOffType.OFF);
236         }
237     }
238 }