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 org.junit.jupiter.api.BeforeEach;
16 import org.junit.jupiter.api.Test;
17 import org.openhab.core.library.types.IncreaseDecreaseType;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.library.types.PercentType;
20 import org.openhab.core.library.types.StopMoveType;
23 * Test class for (@link LxControlDimmer}
25 * @author Pawel Pieczul - initial contribution
28 public class LxControlDimmerTest extends LxControlTest {
31 setupControl("131b19cd-03c0-640f-ffff403fb0c34b9e", "0b734138-037d-034e-ffff403fb0c34b9e",
32 "0fe650c2-0004-d446-ffff504f9410790f", "Dimmer Control");
36 public void testControlCreation() {
37 testControlCreation(LxControlDimmer.class, 1, 0, 1, 1, 4);
41 public void testChannels() {
42 testChannel("Dimmer");
46 public void testLoxonePositionMinMaxChanges() {
47 // filling in missing state values
48 testChannelState(null);
49 changeLoxoneState("step", 1.0);
50 testChannelState(null);
51 changeLoxoneState("position", 50.0);
52 testChannelState(null);
53 changeLoxoneState("min", 0.0);
54 testChannelState(null);
55 changeLoxoneState("max", 100.0);
56 testChannelState(new PercentType(50));
58 // potential division by zero
59 changeLoxoneState("min", 55.0);
60 changeLoxoneState("max", 55.0);
61 testChannelState(null);
63 changeLoxoneState("min", 200.0);
64 changeLoxoneState("max", 400.0);
66 changeLoxoneState("position", 199.9);
67 testChannelState(null);
68 changeLoxoneState("position", 400.1);
69 testChannelState(null);
70 // scaling within range
71 changeLoxoneState("position", 200.0);
72 testChannelState(PercentType.ZERO);
73 changeLoxoneState("position", 400.0);
74 testChannelState(PercentType.HUNDRED);
75 changeLoxoneState("position", 300.0);
76 testChannelState(new PercentType(50));
77 // special value meaning switched off
78 changeLoxoneState("position", 0.0);
79 testChannelState(PercentType.ZERO);
81 // reversed range boundaries
82 changeLoxoneState("min", 50.0);
83 changeLoxoneState("max", 20.0);
84 // here dimmer still turned off
85 testChannelState(PercentType.ZERO);
86 // here within wrong range
87 changeLoxoneState("position", 30.0);
88 testChannelState(null);
92 public void testOnOffPercentCommands() {
93 executeCommand(OnOffType.ON);
95 executeCommand(OnOffType.OFF);
98 changeLoxoneState("min", 1000.0);
99 changeLoxoneState("max", 3000.0);
100 changeLoxoneState("step", 100.0);
101 executeCommand(PercentType.HUNDRED);
102 testAction("3000.0");
103 executeCommand(new PercentType(50));
104 testAction("2000.0");
105 executeCommand(new PercentType(1));
106 testAction("1020.0");
107 executeCommand(PercentType.ZERO);
110 executeCommand(StopMoveType.MOVE);
115 public void testIncreaseDecreaseCommands() {
116 changeLoxoneState("min", 123.0);
117 changeLoxoneState("max", 456.0);
118 changeLoxoneState("step", 23.0);
119 changeLoxoneState("position", 400.0);
120 testChannelState(new PercentType(83));
121 executeCommand(IncreaseDecreaseType.INCREASE);
123 changeLoxoneState("position", 423.0);
124 testChannelState(new PercentType(90));
125 executeCommand(IncreaseDecreaseType.INCREASE);
127 changeLoxoneState("position", 446.0);
128 testChannelState(new PercentType(96));
129 executeCommand(IncreaseDecreaseType.INCREASE);
130 testAction("456.0"); // trim to max
131 changeLoxoneState("position", 456.0);
132 testChannelState(PercentType.HUNDRED);
133 changeLoxoneState("step", 100.0);
134 executeCommand(IncreaseDecreaseType.DECREASE);
136 changeLoxoneState("position", 356.0);
137 testChannelState(new PercentType(69));
138 executeCommand(IncreaseDecreaseType.DECREASE);
140 changeLoxoneState("position", 256.0);
141 testChannelState(new PercentType(39));
142 executeCommand(IncreaseDecreaseType.DECREASE);
144 changeLoxoneState("position", 156.0);
145 testChannelState(new PercentType(9));
146 executeCommand(IncreaseDecreaseType.DECREASE);
147 testAction("123.0"); // trim to min
148 changeLoxoneState("position", 123.0);
149 testChannelState(PercentType.ZERO);