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 java.math.BigDecimal;
16 import java.util.Collections;
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;
24 * Test class for (@link LxControlTimedSwitch}
26 * @author Pawel Pieczul - initial contribution
29 public class LxControlTimedSwitchTest extends LxControlTest {
30 private static final String DELAY_CHANNEL = " / Deactivation Delay";
34 setupControl("1326771c-030e-3a7c-ffff403fb0c34b9e", "0b734138-037d-034e-ffff403fb0c34b9e",
35 "0fe650c2-0004-d446-ffff504f9410790f", "Stairwell Light Switch");
39 public void testControlCreation() {
40 testControlCreation(LxControlTimedSwitch.class, 1, 0, 2, 2, 2);
44 public void testChannels() {
45 testChannel("Switch", Collections.singleton("Switchable"));
46 testChannel("Number", DELAY_CHANNEL, new BigDecimal(-1), null, null, null, true, null);
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);
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));
67 changeLoxoneState("deactivationdelay", 0.0);
68 testChannelState(OnOffType.OFF);
69 testChannelState(DELAY_CHANNEL, DecimalType.ZERO);
73 public void testCommands() {
74 for (int i = 0; i < 100; i++) {
75 executeCommand(OnOffType.ON);
77 executeCommand(OnOffType.OFF);