]> git.basschouten.com Git - openhab-addons.git/blob
5af5575e1ef9a169985ba4b7e13cea3550f304b9
[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.rfxcom.internal.messages;
14
15 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
16 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.FAN_LUCCI_DC_II;
17 import static org.openhab.binding.rfxcom.internal.messages.RFXComFanMessage.SubType.LUCCI_AIR_DC_II;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
23 import org.openhab.core.library.types.DecimalType;
24 import org.openhab.core.library.types.OnOffType;
25 import org.openhab.core.library.types.StringType;
26 import org.openhab.core.types.State;
27 import org.openhab.core.types.UnDefType;
28
29 /**
30  * Test for RFXCom-binding
31  *
32  * @author Martin van Wingerden - Initial contribution
33  */
34 @NonNullByDefault
35 public class RFXComFanLucciAirDc2MessageTest {
36
37     @Test
38     public void testCommandOn() throws RFXComException {
39         testCommand(CHANNEL_COMMAND, OnOffType.ON, OnOffType.ON, UnDefType.UNDEF, new DecimalType(3),
40                 StringType.valueOf("SPEED_3"));
41     }
42
43     @Test
44     public void testCommandOff() throws RFXComException {
45         testCommand(CHANNEL_COMMAND, OnOffType.OFF, OnOffType.OFF, UnDefType.UNDEF, new DecimalType(0),
46                 StringType.valueOf("POWER_OFF"));
47     }
48
49     @Test
50     public void testFanLightOn() throws RFXComException {
51         testCommand(CHANNEL_FAN_LIGHT, OnOffType.ON, null, OnOffType.ON, null, StringType.valueOf("LIGHT"));
52     }
53
54     @Test
55     public void testFanSpeed0() throws RFXComException {
56         testFanSpeed(0, OnOffType.OFF);
57     }
58
59     @Test
60     public void testFanSpeed1() throws RFXComException {
61         testFanSpeed(1, OnOffType.ON);
62     }
63
64     @Test
65     public void testFanSpeed2() throws RFXComException {
66         testFanSpeed(2, OnOffType.ON);
67     }
68
69     @Test
70     public void testFanSpeed3() throws RFXComException {
71         testFanSpeed(3, OnOffType.ON);
72     }
73
74     @Test
75     public void testFanSpeed4() throws RFXComException {
76         testFanSpeed(4, OnOffType.ON);
77     }
78
79     @Test
80     public void testCommandString() throws RFXComException {
81         testCommand(CHANNEL_COMMAND_STRING, StringType.valueOf("POWER_OFF"), OnOffType.OFF, UnDefType.UNDEF,
82                 new DecimalType(0), StringType.valueOf("POWER_OFF"));
83         testCommand(CHANNEL_COMMAND_STRING, StringType.valueOf("LIGHT"), null, OnOffType.ON, null,
84                 StringType.valueOf("LIGHT"));
85         testCommand(CHANNEL_COMMAND_STRING, StringType.valueOf("REVERSE"), null, UnDefType.UNDEF, null,
86                 StringType.valueOf("REVERSE"));
87         testCommand(CHANNEL_COMMAND_STRING, StringType.valueOf("SPEED_1"), OnOffType.ON, UnDefType.UNDEF,
88                 new DecimalType(1), StringType.valueOf("SPEED_1"));
89         testCommand(CHANNEL_COMMAND_STRING, StringType.valueOf("SPEED_2"), OnOffType.ON, UnDefType.UNDEF,
90                 new DecimalType(2), StringType.valueOf("SPEED_2"));
91         testCommand(CHANNEL_COMMAND_STRING, StringType.valueOf("SPEED_3"), OnOffType.ON, UnDefType.UNDEF,
92                 new DecimalType(3), StringType.valueOf("SPEED_3"));
93         testCommand(CHANNEL_COMMAND_STRING, StringType.valueOf("SPEED_4"), OnOffType.ON, UnDefType.UNDEF,
94                 new DecimalType(4), StringType.valueOf("SPEED_4"));
95         testCommand(CHANNEL_COMMAND_STRING, StringType.valueOf("SPEED_5"), OnOffType.ON, UnDefType.UNDEF,
96                 new DecimalType(5), StringType.valueOf("SPEED_5"));
97         testCommand(CHANNEL_COMMAND_STRING, StringType.valueOf("SPEED_6"), OnOffType.ON, UnDefType.UNDEF,
98                 new DecimalType(6), StringType.valueOf("SPEED_6"));
99     }
100
101     private void testFanSpeed(int value, OnOffType expectedCommand) throws RFXComException {
102         StringType expectedCommandString;
103         if (value == 0) {
104             expectedCommandString = StringType.valueOf("POWER_OFF");
105         } else {
106             expectedCommandString = StringType.valueOf("SPEED_" + value);
107         }
108         testCommand(CHANNEL_FAN_SPEED, new DecimalType(value), expectedCommand, UnDefType.UNDEF, new DecimalType(value),
109                 expectedCommandString);
110     }
111
112     private void testCommand(String channel, State inputValue, @Nullable OnOffType expectedCommand,
113             State expectedLightCommand, @Nullable State expectedFanSpeed, State expectedCommandString)
114             throws RFXComException {
115         RFXComFanMessageTest.testCommand(LUCCI_AIR_DC_II, channel, inputValue, expectedCommand, expectedLightCommand,
116                 expectedFanSpeed, expectedCommandString, FAN_LUCCI_DC_II);
117     }
118 }