]> git.basschouten.com Git - openhab-addons.git/blob
c90db3e8fda8524939512fafb968a50e503f6f22
[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.math.BigDecimal;
16
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.types.UnDefType;
21
22 /**
23  * Test class for (@link LxControlUpDownAnalog}
24  *
25  * @author Pawel Pieczul - initial contribution
26  *
27  */
28 public class LxControlUpDownAnalogTest extends LxControlTest {
29     Double min;
30     Double max;
31     Double step;
32     String format;
33
34     @BeforeEach
35     public void setup() {
36         min = 50.0;
37         max = 150.0;
38         step = 10.0;
39         format = "%.1f";
40         setupControl("131b1a96-02b9-f6e9-eeff403fb0c34b9e", "0b734138-037d-034e-ffff403fb0c34b9e",
41                 "0fe650c2-0004-d446-ffff504f9410790f", "Up Down Analog Input");
42     }
43
44     @Test
45     public void testControlCreation() {
46         testControlCreation(LxControlUpDownAnalog.class, 1, 0, 1, 1, 2);
47     }
48
49     @Test
50     public void testChannels() {
51         testChannel("Number", null, new BigDecimal(min), new BigDecimal(max), new BigDecimal(step), format, false,
52                 null);
53     }
54
55     @Test
56     public void testLoxoneStateChanges() {
57         testChannelState(null);
58         for (int j = 0; j < 2; j++) {
59             changeLoxoneState("error", 0.0);
60             for (Double i = min - 50.0; i < min; i += 0.5) {
61                 changeLoxoneState("value", i);
62                 testChannelState(null);
63             }
64             for (Double i = min; i <= max; i += 0.5) {
65                 changeLoxoneState("value", i);
66                 testChannelState(new DecimalType(i));
67             }
68             for (Double i = max + 0.5; i < max + 50.0; i += 0.5) {
69                 changeLoxoneState("value", i);
70                 testChannelState(null);
71             }
72             changeLoxoneState("error", 1.0);
73             for (Double i = min - 50.0; i < max + 50.0; i += 0.5) {
74                 changeLoxoneState("value", i);
75                 testChannelState(UnDefType.UNDEF);
76             }
77         }
78     }
79
80     @Test
81     public void testCommands() {
82         for (Double i = min - 50.0; i < min; i += 0.5) {
83             executeCommand(new DecimalType(i));
84             testAction(null);
85         }
86         for (Double i = min; i <= max; i += 0.5) {
87             executeCommand(new DecimalType(i));
88             testAction(i.toString());
89         }
90         for (Double i = max + 0.5; i < max + 50.0; i += 0.5) {
91             executeCommand(new DecimalType(i));
92             testAction(null);
93         }
94     }
95 }