]> git.basschouten.com Git - openhab-addons.git/blob
81483a776c618757377b152181fd93e05c526cd8
[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 LxControlDimmerTest extends LxControlTest {
29     @BeforeEach
30     public void setup() {
31         setupControl("131b19cd-03c0-640f-ffff403fb0c34b9e", "0b734138-037d-034e-ffff403fb0c34b9e",
32                 "0fe650c2-0004-d446-ffff504f9410790f", "Dimmer Control");
33     }
34
35     @Test
36     public void testControlCreation() {
37         testControlCreation(LxControlDimmer.class, 1, 0, 1, 1, 4);
38     }
39
40     @Test
41     public void testChannels() {
42         testChannel("Dimmer");
43     }
44
45     @Test
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));
57
58         // potential division by zero
59         changeLoxoneState("min", 55.0);
60         changeLoxoneState("max", 55.0);
61         testChannelState(null);
62
63         changeLoxoneState("min", 200.0);
64         changeLoxoneState("max", 400.0);
65         // out of range
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);
80
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);
89     }
90
91     @Test
92     public void testOnOffPercentCommands() {
93         executeCommand(OnOffType.ON);
94         testAction("On");
95         executeCommand(OnOffType.OFF);
96         testAction("Off");
97
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);
108         testAction("0.0");
109
110         executeCommand(StopMoveType.MOVE);
111         testAction(null);
112     }
113
114     @Test
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);
122         testAction("423.0");
123         changeLoxoneState("position", 423.0);
124         testChannelState(new PercentType(90));
125         executeCommand(IncreaseDecreaseType.INCREASE);
126         testAction("446.0");
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);
135         testAction("356.0");
136         changeLoxoneState("position", 356.0);
137         testChannelState(new PercentType(69));
138         executeCommand(IncreaseDecreaseType.DECREASE);
139         testAction("256.0");
140         changeLoxoneState("position", 256.0);
141         testChannelState(new PercentType(39));
142         executeCommand(IncreaseDecreaseType.DECREASE);
143         testAction("156.0");
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);
150     }
151 }