]> git.basschouten.com Git - openhab-addons.git/blob
487cdf2f76aa4d54fd0548e60046e9ce2b9bdae7
[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.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;
21
22 /**
23  * Test class for (@link LxControlDimmer}
24  *
25  * @author Pawel Pieczul - initial contribution
26  *
27  */
28 public class LxControlEIBDimmerTest extends LxControlTest {
29     @BeforeEach
30     public void setup() {
31         setupControl("faa30f5c-4b4f-11e2-8928b8ba17ef51ee", "0b734138-037d-034e-ffff403fb0c34b9e",
32                 "0fe650c2-0004-d446-ffff504f9410790f", "Kitchen Dimmer");
33     }
34
35     @Test
36     public void testControlCreation() {
37         testControlCreation(LxControlDimmer.class, 1, 0, 1, 1, 1);
38     }
39
40     @Test
41     public void testChannels() {
42         testChannel("Dimmer");
43     }
44
45     @Test
46     public void testLoxonePositionChanges() {
47         // filling in missing state values
48         testChannelState(null);
49         for (Double i = 0.0; i <= 100.0; i += 1.0) {
50             changeLoxoneState("position", i);
51             testChannelState(new PercentType(i.intValue()));
52         }
53         // out of range
54         changeLoxoneState("position", 199.9);
55         testChannelState(null);
56         changeLoxoneState("position", 400.1);
57         testChannelState(null);
58     }
59
60     @Test
61     public void testOnOffPercentCommands() {
62         executeCommand(OnOffType.ON);
63         testAction("On");
64         executeCommand(OnOffType.OFF);
65         testAction("Off");
66         for (Double i = 0.0; i <= 100.0; i += 1.0) {
67             executeCommand(new PercentType(i.intValue()));
68             testAction(i.toString());
69         }
70         executeCommand(StopMoveType.MOVE);
71         testAction(null);
72     }
73
74     @Test
75     public void testIncreaseDecreaseCommands() {
76         for (Double i = 0.0; i <= 95.0; i += 1.0) {
77             changeLoxoneState("position", i);
78             testChannelState(new PercentType(i.intValue()));
79             testAction(null);
80             executeCommand(IncreaseDecreaseType.INCREASE);
81             Double j = i + 5.0;
82             testAction(j.toString());
83         }
84         for (Double i = 100.0; i >= 5.0; i -= 1.0) {
85             changeLoxoneState("position", i);
86             testChannelState(new PercentType(i.intValue()));
87             testAction(null);
88             executeCommand(IncreaseDecreaseType.DECREASE);
89             Double j = i - 5.0;
90             testAction(j.toString());
91         }
92         // test not exceeding range
93         changeLoxoneState("position", 100.0);
94         testChannelState(PercentType.HUNDRED);
95         testAction(null);
96         executeCommand(IncreaseDecreaseType.INCREASE);
97         testAction("100.0");
98
99         changeLoxoneState("position", 0.0);
100         testChannelState(PercentType.ZERO);
101         testAction(null);
102         executeCommand(IncreaseDecreaseType.DECREASE);
103         testAction("0.0");
104     }
105 }