]> git.basschouten.com Git - openhab-addons.git/blob
bc2a7af799a24eb6be0ce87e13016a6a4ef5273e
[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 import java.util.Set;
17
18 import org.junit.jupiter.api.BeforeEach;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.library.types.OnOffType;
22
23 /**
24  * Test class for (@link LxControlTimedSwitch}
25  *
26  * @author Pawel Pieczul - initial contribution
27  *
28  */
29 public class LxControlTimedSwitchTest extends LxControlTest {
30     private static final String DELAY_CHANNEL = " / Deactivation Delay";
31
32     @BeforeEach
33     public void setup() {
34         setupControl("1326771c-030e-3a7c-ffff403fb0c34b9e", "0b734138-037d-034e-ffff403fb0c34b9e",
35                 "0fe650c2-0004-d446-ffff504f9410790f", "Stairwell Light Switch");
36     }
37
38     @Test
39     public void testControlCreation() {
40         testControlCreation(LxControlTimedSwitch.class, 1, 0, 2, 2, 2);
41     }
42
43     @Test
44     public void testChannels() {
45         testChannel("Switch", Set.of("Switchable"));
46         testChannel("Number", DELAY_CHANNEL, new BigDecimal(-1), null, null, null, true, null);
47     }
48
49     @Test
50     public void testLoxoneStateChanges() {
51         testChannelState(null);
52         testChannelState(DELAY_CHANNEL, null);
53         changeLoxoneState("deactivationdelaytotal", 100.0);
54         for (int i = 0; i < 100; i++) {
55             changeLoxoneState("deactivationdelay", 0.0);
56             testChannelState(OnOffType.OFF);
57             testChannelState(DELAY_CHANNEL, DecimalType.ZERO);
58             changeLoxoneState("deactivationdelay", -1.0);
59             testChannelState(OnOffType.ON);
60             testChannelState(DELAY_CHANNEL, DecimalType.ZERO);
61         }
62         for (Double i = 100.0; i >= 1.0; i--) {
63             changeLoxoneState("deactivationdelay", i);
64             testChannelState(OnOffType.ON);
65             testChannelState(DELAY_CHANNEL, new DecimalType(i));
66         }
67         changeLoxoneState("deactivationdelay", 0.0);
68         testChannelState(OnOffType.OFF);
69         testChannelState(DELAY_CHANNEL, DecimalType.ZERO);
70     }
71
72     @Test
73     public void testCommands() {
74         for (int i = 0; i < 100; i++) {
75             executeCommand(OnOffType.ON);
76             testAction("Pulse");
77             executeCommand(OnOffType.OFF);
78             testAction("Off");
79         }
80     }
81 }