2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.loxone.internal.controls;
15 import java.math.BigDecimal;
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.IncreaseDecreaseType;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.library.types.PercentType;
23 import org.openhab.core.library.types.StopMoveType;
26 * Test class for (@link LxControlValueSelector}
28 * @author Pawel Pieczul - initial contribution
31 public class LxControlValueSelectorTest extends LxControlTest {
32 private static final String NUMBER_CHANNEL = " / Number";
36 setupControl("432a7b7e-0022-3aac-ffff403fb0c34b9e", "0b734138-037d-034e-ffff403fb0c34b9e",
37 "0fe650c2-0004-d446-ffff504f9410790f", "Selection Switch");
41 public void testControlCreation() {
42 testControlCreation(LxControlValueSelector.class, 2, 0, 2, 2, 4);
46 public void testChannels() {
47 testChannel("Dimmer");
48 testChannel("Number", NUMBER_CHANNEL);
52 public void testLoxoneValueMinMaxChanges() {
53 // filling in missing state values
54 testChannelState(null);
55 changeLoxoneState("step", 1.0);
56 testChannelState(null);
57 changeLoxoneState("value", 50.0);
58 testChannelState(null);
59 changeLoxoneState("min", 0.0);
60 testChannelState(null);
61 changeLoxoneState("max", 100.0);
62 testChannelState(new PercentType(50));
63 testChannel("Dimmer", null, BigDecimal.ZERO, new BigDecimal(100), BigDecimal.ONE, "%.0f", false, null);
64 testChannel("Number", NUMBER_CHANNEL, BigDecimal.ZERO, new BigDecimal(100), BigDecimal.ONE, "%.0f", false,
67 // potential division by zero
68 changeLoxoneState("min", 55.0);
69 changeLoxoneState("max", 55.0);
70 testChannelState(null);
72 changeLoxoneState("min", 200.0);
73 changeLoxoneState("max", 400.0);
74 testChannel("Dimmer", null, new BigDecimal(200), new BigDecimal(400), BigDecimal.ONE, "%.0f", false, null);
75 testChannel("Number", NUMBER_CHANNEL, new BigDecimal(200), new BigDecimal(400), BigDecimal.ONE, "%.0f", false,
79 changeLoxoneState("value", 199.9);
80 testChannelState(null);
81 changeLoxoneState("value", 400.1);
82 testChannelState(null);
83 changeLoxoneState("value", 0.0);
84 testChannelState(null);
85 // scaling within range
86 changeLoxoneState("value", 200.0);
87 testChannelState(PercentType.ZERO);
88 changeLoxoneState("value", 400.0);
89 testChannelState(PercentType.HUNDRED);
90 changeLoxoneState("value", 300.0);
91 testChannelState(new PercentType(50));
92 // reversed range boundaries
93 changeLoxoneState("min", 50.0);
94 changeLoxoneState("max", 20.0);
95 changeLoxoneState("value", 30.0);
96 testChannelState(null);
100 public void testOnOffPercentCommands() {
101 changeLoxoneState("min", 1000.0);
102 changeLoxoneState("max", 3000.0);
103 changeLoxoneState("step", 100.0);
105 executeCommand(OnOffType.ON);
106 testAction("3000.0");
107 executeCommand(OnOffType.OFF);
108 testAction("1000.0");
110 executeCommand(PercentType.HUNDRED);
111 testAction("3000.0");
112 executeCommand(new PercentType(50));
113 testAction("2000.0");
114 executeCommand(new PercentType(1));
115 testAction("1020.0");
116 executeCommand(PercentType.ZERO);
117 testAction("1000.0");
119 executeCommand(StopMoveType.MOVE);
124 public void testIncreaseDecreaseCommands() {
125 changeLoxoneState("min", 123.0);
126 changeLoxoneState("max", 456.0);
127 changeLoxoneState("step", 23.0);
128 changeLoxoneState("value", 400.0);
129 testChannelState(new PercentType(83));
130 executeCommand(IncreaseDecreaseType.INCREASE);
132 changeLoxoneState("value", 423.0);
133 testChannelState(new PercentType(90));
134 executeCommand(IncreaseDecreaseType.INCREASE);
136 changeLoxoneState("value", 446.0);
137 testChannelState(new PercentType(96));
138 executeCommand(IncreaseDecreaseType.INCREASE);
139 testAction("456.0"); // trim to max
140 changeLoxoneState("value", 456.0);
141 testChannelState(PercentType.HUNDRED);
142 changeLoxoneState("step", 100.0);
143 executeCommand(IncreaseDecreaseType.DECREASE);
145 changeLoxoneState("value", 356.0);
146 testChannelState(new PercentType(69));
147 executeCommand(IncreaseDecreaseType.DECREASE);
149 changeLoxoneState("value", 256.0);
150 testChannelState(new PercentType(39));
151 executeCommand(IncreaseDecreaseType.DECREASE);
153 changeLoxoneState("value", 156.0);
154 testChannelState(new PercentType(9));
155 executeCommand(IncreaseDecreaseType.DECREASE);
156 testAction("123.0"); // trim to min
157 changeLoxoneState("value", 123.0);
158 testChannelState(PercentType.ZERO);
162 public void testNumberCommands() {
163 changeLoxoneState("min", 100.0);
164 changeLoxoneState("max", 300.0);
165 changeLoxoneState("step", 10.0);
166 for (Double i = 0.0; i < 100.0; i += 0.35) {
167 executeCommand(NUMBER_CHANNEL, new DecimalType(i));
170 for (Double i = 100.0; i <= 300.0; i += 0.47) {
171 executeCommand(NUMBER_CHANNEL, new DecimalType(i));
172 testAction(i.toString());
174 for (Double i = 300.01; i < 400.0; i += 0.59) {
175 executeCommand(NUMBER_CHANNEL, new DecimalType(i));
181 public void testLoxoneNumberChanges() {
182 testChannelState(null);
183 changeLoxoneState("min", 100.0);
184 changeLoxoneState("max", 300.0);
185 changeLoxoneState("step", 10.0);
186 for (Double i = 0.0; i < 100.0; i += 0.35) {
187 changeLoxoneState("value", i);
188 testChannelState(NUMBER_CHANNEL, null);
190 for (Double i = 100.0; i <= 300.0; i += 0.47) {
191 changeLoxoneState("value", i);
192 testChannelState(NUMBER_CHANNEL, new DecimalType(i));
194 for (Double i = 300.01; i < 400.0; i += 0.59) {
195 changeLoxoneState("value", i);
196 testChannelState(NUMBER_CHANNEL, null);