]> git.basschouten.com Git - openhab-addons.git/blob
a08b4ab0b92e81ddabc5dd9e1ed3a5682eae777c
[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.HashSet;
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
23 /**
24  * Test class for {@link LxControlIRoomControllerV2}
25  *
26  * @author Pawel Pieczul - initial contribution
27  *
28  */
29 public class LxControlIRoomControllerV2Test extends LxControlTest {
30     private static final String ACTIVE_MODE_CHANNEL = "/ Active Mode";
31     private static final String OPERATING_MODE_CHANNEL = "/ Operating Mode";
32     private static final String PREPARE_STATE_CHANNEL = "/ Prepare State";
33     private static final String OPEN_WINDOW_CHANNEL = "/ Open Window";
34     private static final String TEMP_ACTUAL_CHANNEL = "/ Current Temperature";
35     private static final String TEMP_TARGET_CHANNEL = "/ Target Temperature";
36     private static final String COMFORT_TEMPERATURE_CHANNEL = "/ Comfort Temperature";
37     private static final String COMFORT_TEMPERATURE_OFFSET_CHANNEL = "/ Comfort Temperature Offset";
38     private static final String COMFORT_TOLERANCE_CHANNEL = "/ Comfort Tolerance";
39     private static final String ABSENT_MIN_OFFSET_CHANNEL = "/ Absent Min Offset";
40     private static final String ABSENT_MAX_OFFSET_CHANNEL = "/ Absent Max Offset";
41     private static final String FROST_PROTECT_TEMPERATURE_CHANNEL = "/ Frost Protect Temperature";
42     private static final String HEAT_PROTECT_TEMPERATURE_CHANNEL = "/ Heat Protect Temperature";
43
44     @BeforeEach
45     public void setup() {
46         setupControl("14328f8a-21c9-7c0d-ffff403fb0c34b9e", "0b734138-037d-034e-ffff403fb0c34b9e",
47                 "0fe650c2-0004-d446-ffff504f9410790f", "Intelligent Room Controller");
48     }
49
50     @Test
51     public void testControlCreation() {
52         testControlCreation(LxControlIRoomControllerV2.class, 1, 0, 13, 13, 17);
53     }
54
55     @Test
56     public void testChannels() {
57         Set<String> tempTags = new HashSet<>();
58         tempTags.add("CurrentTemperature");
59         testChannel("Number", ACTIVE_MODE_CHANNEL);
60         testChannel("Number", OPERATING_MODE_CHANNEL);
61         testChannel("Number", PREPARE_STATE_CHANNEL);
62         testChannel("Switch", OPEN_WINDOW_CHANNEL);
63         testChannel("Number", TEMP_ACTUAL_CHANNEL, null, null, null, "%.1f°", true, null, tempTags);
64         testChannel("Number", TEMP_TARGET_CHANNEL, null, null, null, "%.1f°", false, null, tempTags);
65         testChannel("Number", COMFORT_TEMPERATURE_CHANNEL, null, null, null, "%.1f°", false, null, tempTags);
66         testChannel("Number", COMFORT_TEMPERATURE_OFFSET_CHANNEL, null, null, null, "%.1f°", false, null, tempTags);
67         testChannel("Number", COMFORT_TOLERANCE_CHANNEL, null, null, null, "%.1f°", false, null, tempTags);
68         testChannel("Number", ABSENT_MIN_OFFSET_CHANNEL, null, null, null, "%.1f°", false, null, tempTags);
69         testChannel("Number", ABSENT_MAX_OFFSET_CHANNEL, null, null, null, "%.1f°", false, null, tempTags);
70         testChannel("Number", FROST_PROTECT_TEMPERATURE_CHANNEL, null, null, null, "%.1f°", true, null, tempTags);
71         testChannel("Number", HEAT_PROTECT_TEMPERATURE_CHANNEL, null, null, null, "%.1f°", true, null, tempTags);
72     }
73
74     @Test
75     public void testModeStateChanges() {
76         for (int i = 0; i <= 3; i++) {
77             changeLoxoneState("activemode", Double.valueOf(i));
78             testChannelState(ACTIVE_MODE_CHANNEL, new DecimalType(i));
79         }
80         for (int i = 0; i <= 5; i++) {
81             changeLoxoneState("operatingmode", Double.valueOf(i));
82             testChannelState(OPERATING_MODE_CHANNEL, new DecimalType(i));
83         }
84         for (int i = -1; i <= 1; i++) {
85             changeLoxoneState("preparestate", Double.valueOf(i));
86             testChannelState(PREPARE_STATE_CHANNEL, new DecimalType(i));
87         }
88     }
89
90     @Test
91     public void testWindowStateChanges() {
92         for (int i = 0; i < 100; i++) {
93             changeLoxoneState("openwindow", 0.0);
94             testChannelState(OPEN_WINDOW_CHANNEL, OnOffType.OFF);
95             changeLoxoneState("openwindow", 1.0);
96             testChannelState(OPEN_WINDOW_CHANNEL, OnOffType.ON);
97         }
98     }
99
100     @Test
101     public void testTemperatureStateChanges() {
102         for (Double i = -50.0; i < 50.0; i += 0.3) {
103             changeLoxoneState("tempactual", i);
104             changeLoxoneState("temptarget", i + 0.01);
105             changeLoxoneState("comforttemperature", i + 0.02);
106             changeLoxoneState("comforttemperatureoffset", i + 0.03);
107             changeLoxoneState("comforttolerance", i + 0.04);
108             changeLoxoneState("absentminoffset", i + 0.05);
109             changeLoxoneState("absentmaxoffset", i + 0.06);
110             changeLoxoneState("frostprotecttemperature", i + 0.07);
111             changeLoxoneState("heatprotecttemperature", i + 0.08);
112             testChannelState(TEMP_ACTUAL_CHANNEL, new DecimalType(i));
113             testChannelState(TEMP_TARGET_CHANNEL, new DecimalType(i + 0.01));
114             testChannelState(COMFORT_TEMPERATURE_CHANNEL, new DecimalType(i + 0.02));
115             testChannelState(COMFORT_TEMPERATURE_OFFSET_CHANNEL, new DecimalType(i + 0.03));
116             testChannelState(COMFORT_TOLERANCE_CHANNEL, new DecimalType(i + 0.04));
117             testChannelState(ABSENT_MIN_OFFSET_CHANNEL, new DecimalType(i + 0.05));
118             testChannelState(ABSENT_MAX_OFFSET_CHANNEL, new DecimalType(i + 0.06));
119             testChannelState(FROST_PROTECT_TEMPERATURE_CHANNEL, new DecimalType(i + 0.07));
120             testChannelState(HEAT_PROTECT_TEMPERATURE_CHANNEL, new DecimalType(i + 0.08));
121         }
122     }
123
124     @Test
125     public void testModeCommands() {
126         testAction(null);
127         for (int i = 0; i <= 5; i++) {
128             executeCommand(OPERATING_MODE_CHANNEL, new DecimalType(i));
129             testAction("setOperatingMode/" + i);
130         }
131         testAction(null);
132     }
133
134     @Test
135     public void testTemperatureCommands() {
136         testAction(null);
137         for (Double t = -50.0; t < 50.0; t += 0.03) {
138             DecimalType a = new DecimalType(t);
139             executeCommand(TEMP_TARGET_CHANNEL, a);
140             testAction("setManualTemperature/" + t.toString());
141             executeCommand(COMFORT_TEMPERATURE_CHANNEL, a);
142             testAction("setComfortTemperature/" + t.toString());
143             executeCommand(COMFORT_TEMPERATURE_OFFSET_CHANNEL, a);
144             testAction("setComfortModeTemp/" + t.toString());
145             executeCommand(COMFORT_TOLERANCE_CHANNEL, a);
146             testAction("setComfortTolerance/" + t.toString());
147             executeCommand(ABSENT_MAX_OFFSET_CHANNEL, a);
148             testAction("setAbsentMaxTemperature/" + t.toString());
149             executeCommand(ABSENT_MIN_OFFSET_CHANNEL, a);
150             testAction("setAbsentMinTemperature/" + t.toString());
151         }
152         testAction(null);
153     }
154 }