2 * Copyright (c) 2010-2022 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 static org.junit.jupiter.api.Assertions.*;
17 import java.time.LocalDateTime;
18 import java.time.ZoneId;
19 import java.time.ZonedDateTime;
20 import java.util.HashMap;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.core.library.types.DateTimeType;
26 import org.openhab.core.library.types.DecimalType;
27 import org.openhab.core.library.types.OnOffType;
28 import org.openhab.core.library.types.StringType;
29 import org.openhab.core.types.State;
30 import org.openhab.core.types.UnDefType;
33 * Test class for (@link LxControlAlarm} - version for alarm without presence sensors
35 * @author Pawel Pieczul - initial contribution
38 public class LxControlAlarmNoPresenceTest extends LxControlTest {
39 static final String ARM_DELAYED_CHANNEL = " / Arm Delayed";
40 static final String NEXT_LEVEL_CHANNEL = " / Next Level";
41 static final String NEXT_LEVEL_DELAY_CHANNEL = " / Next Level Delay";
42 static final String NEXT_LEVEL_DELAY_TOTAL_CHANNEL = " / Next Level Delay Total";
43 static final String LEVEL_CHANNEL = " / Level";
44 static final String START_TIME_CHANNEL = " / Start Time";
45 static final String ARMED_DELAY_CHANNEL = " / Armed Delay";
46 static final String ARMED_TOTAL_DELAY_CHANNEL = " / Armed Total Delay";
47 static final String SENSORS_CHANNEL = " / Sensors";
48 static final String QUIT_CHANNEL = " / Acknowledge";
50 private static final String NUMBER_CHANNELS[] = { NEXT_LEVEL_CHANNEL, NEXT_LEVEL_DELAY_CHANNEL,
51 NEXT_LEVEL_DELAY_TOTAL_CHANNEL, LEVEL_CHANNEL, ARMED_DELAY_CHANNEL, ARMED_TOTAL_DELAY_CHANNEL };
55 setupControl("233d5db0-0333-5865-ffff403fb0c34b9e", "0b734138-037d-034e-ffff403fb0c34b9e",
56 "0fe650c2-0004-d446-ffff504f9410790f", "Burglar Alarm No Presence");
60 public void testControlCreation() {
61 testControlCreation(LxControlAlarm.class, 2, 1, 11, 12, 10);
65 public void testChannels() {
66 // read-write channels
67 testChannel("Switch");
68 testChannel("Switch", ARM_DELAYED_CHANNEL);
69 testChannel("Switch", QUIT_CHANNEL, null, null, null, null, true, null);
71 testChannel("Number", NEXT_LEVEL_CHANNEL);
72 testChannel("Number", NEXT_LEVEL_DELAY_CHANNEL);
73 testChannel("Number", NEXT_LEVEL_DELAY_TOTAL_CHANNEL);
74 testChannel("Number", LEVEL_CHANNEL);
75 testChannel("Number", ARMED_DELAY_CHANNEL);
76 testChannel("Number", ARMED_TOTAL_DELAY_CHANNEL);
77 testChannel("String", SENSORS_CHANNEL);
78 testChannel("DateTime", START_TIME_CHANNEL);
82 public void testCommandsDefaultChannel() {
84 for (int i = 0; i < 20; i++) {
85 changeLoxoneState("disabledmove", 0.0);
86 executeCommand(OnOffType.ON);
88 executeCommand(OnOffType.OFF);
90 changeLoxoneState("disabledmove", 1.0);
91 executeCommand(OnOffType.ON);
93 executeCommand(OnOffType.OFF);
99 public void testCommandsArmWithDelayChannel() {
101 for (int i = 0; i < 20; i++) {
102 changeLoxoneState("disabledmove", 0.0);
103 executeCommand(ARM_DELAYED_CHANNEL, OnOffType.ON);
104 testAction("delayedon");
105 executeCommand(ARM_DELAYED_CHANNEL, OnOffType.OFF);
107 changeLoxoneState("disabledmove", 1.0);
108 executeCommand(ARM_DELAYED_CHANNEL, OnOffType.ON);
109 testAction("delayedon");
110 executeCommand(ARM_DELAYED_CHANNEL, OnOffType.OFF);
116 public void testCommandsQuitChannel() {
118 for (int i = 0; i < 20; i++) {
119 executeCommand(QUIT_CHANNEL, OnOffType.ON);
121 executeCommand(QUIT_CHANNEL, OnOffType.OFF);
127 public void testNumberChannels() {
128 testNumberChannel(NEXT_LEVEL_CHANNEL, "nextlevel");
129 testNumberChannel(NEXT_LEVEL_DELAY_CHANNEL, "nextleveldelay");
130 testNumberChannel(NEXT_LEVEL_DELAY_TOTAL_CHANNEL, "nextleveldelaytotal");
131 testNumberChannel(LEVEL_CHANNEL, "level");
132 testNumberChannel(ARMED_DELAY_CHANNEL, "armeddelay");
133 testNumberChannel(ARMED_TOTAL_DELAY_CHANNEL, "armeddelaytotal");
137 public void testStartedTimeChannel() {
138 changeLoxoneState("starttime", "2019-11-18 14:54:21");
139 LocalDateTime ldt = LocalDateTime.of(2019, 11, 18, 14, 54, 21);
140 ZonedDateTime dt = ldt.atZone(ZoneId.systemDefault());
141 testChannelState(START_TIME_CHANNEL, new DateTimeType(dt));
143 changeLoxoneState("starttime", "something else");
144 testChannelState(START_TIME_CHANNEL, null);
146 changeLoxoneState("starttime", "1981-01-02 03:04:05");
147 ldt = LocalDateTime.of(1981, 1, 2, 3, 4, 5);
148 dt = ldt.atZone(ZoneId.systemDefault());
149 testChannelState(START_TIME_CHANNEL, new DateTimeType(dt));
151 changeLoxoneState("starttime", "1981-13-02 03:04:05");
152 testChannelState(START_TIME_CHANNEL, null);
156 public void testSensorsChannel() {
157 testChannelState(SENSORS_CHANNEL, null);
158 for (int i = 0; i < 20; i++) {
159 changeLoxoneState("sensors", "test sensors channel string " + i);
160 testChannelState(SENSORS_CHANNEL, new StringType("test sensors channel string " + i));
165 public void testLevelAndAcknowledge() {
166 changeLoxoneState("level", 0.0);
167 testChannel("Switch", QUIT_CHANNEL, null, null, null, null, true, null);
168 for (Double i = 1.0; i <= 6.0; i++) {
169 changeLoxoneState("level", i);
170 testChannel("Switch", QUIT_CHANNEL, null, null, null, null, false, null);
171 changeLoxoneState("level", 0.0);
172 testChannel("Switch", QUIT_CHANNEL, null, null, null, null, true, null);
176 private void testNumberChannel(String channel, String state) {
177 Map<String, State> states = new HashMap<>();
178 for (String s : NUMBER_CHANNELS) {
179 states.put(s, getChannelState(s));
181 for (Double i = -100.0; i <= 100.0; i += 2.341) {
182 changeLoxoneState(state, i);
183 testChannelState(channel, new DecimalType(i));
184 states.entrySet().stream().filter(v -> !v.getKey().equals(channel)).forEach(v -> {
185 String key = v.getKey();
186 assertEquals(states.get(key), getChannelState(key));
189 changeLoxoneState(state, Double.NaN);
190 testChannelState(channel, UnDefType.UNDEF);