]> git.basschouten.com Git - openhab-addons.git/blob
88f23f1283b58d549a487b94c95c17416608b2e9
[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_FALMEC;
17 import static org.openhab.binding.rfxcom.internal.messages.RFXComFanMessage.SubType.FALMEC;
18 import static org.openhab.binding.rfxcom.internal.messages.RFXComFanMessageTest.testCommand;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
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.UnDefType;
27
28 /**
29  * Test for RFXCom-binding
30  *
31  * @author Martin van Wingerden - Initial contribution
32  */
33 @NonNullByDefault
34 public class RFXComFanFalmecMessageTest {
35
36     @Test
37     public void testFalmecCommandOn() throws RFXComException {
38         testCommand(FALMEC, CHANNEL_COMMAND, OnOffType.ON, OnOffType.ON, UnDefType.UNDEF, new DecimalType(2),
39                 StringType.valueOf("SPEED_2"), FAN_FALMEC);
40     }
41
42     @Test
43     public void testFalmecCommandOff() throws RFXComException {
44         testCommand(FALMEC, CHANNEL_COMMAND, OnOffType.OFF, OnOffType.OFF, UnDefType.UNDEF, new DecimalType(0),
45                 StringType.valueOf("POWER_OFF"), FAN_FALMEC);
46     }
47
48     @Test
49     public void testFanSpeed0() throws RFXComException {
50         testFalmecFanSpeed(0, OnOffType.OFF);
51     }
52
53     @Test
54     public void testFanSpeed1() throws RFXComException {
55         testFalmecFanSpeed(1, OnOffType.ON);
56     }
57
58     @Test
59     public void testFanSpeed2() throws RFXComException {
60         testFalmecFanSpeed(2, OnOffType.ON);
61     }
62
63     @Test
64     public void testFanSpeed3() throws RFXComException {
65         testFalmecFanSpeed(3, OnOffType.ON);
66     }
67
68     @Test
69     public void testFanSpeed4() throws RFXComException {
70         testFalmecFanSpeed(4, OnOffType.ON);
71     }
72
73     @Test
74     public void testFalmecFanLightOn() throws RFXComException {
75         testCommand(FALMEC, CHANNEL_FAN_LIGHT, OnOffType.ON, null, OnOffType.ON, null, StringType.valueOf("LIGHT_ON"),
76                 FAN_FALMEC);
77     }
78
79     @Test
80     public void testFalmecFanLightOff() throws RFXComException {
81         testCommand(FALMEC, CHANNEL_FAN_LIGHT, OnOffType.OFF, null, OnOffType.OFF, null,
82                 StringType.valueOf("LIGHT_OFF"), FAN_FALMEC);
83     }
84
85     private void testFalmecFanSpeed(int value, OnOffType expectedCommand) throws RFXComException {
86         StringType expectedCommandString;
87         if (value == 0) {
88             expectedCommandString = StringType.valueOf("POWER_OFF");
89         } else {
90             expectedCommandString = StringType.valueOf("SPEED_" + value);
91         }
92         testCommand(FALMEC, CHANNEL_FAN_SPEED, new DecimalType(value), expectedCommand, UnDefType.UNDEF,
93                 new DecimalType(value), expectedCommandString, FAN_FALMEC);
94     }
95 }