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.rfxcom.internal.messages;
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;
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;
30 * Test for RFXCom-binding
32 * @author Martin van Wingerden - Initial contribution
35 public class RFXComFanLucciAirDc2MessageTest {
38 public void testCommandOn() throws RFXComException {
39 testCommand(CHANNEL_COMMAND, OnOffType.ON, OnOffType.ON, UnDefType.UNDEF, new DecimalType(3),
40 StringType.valueOf("SPEED_3"));
44 public void testCommandOff() throws RFXComException {
45 testCommand(CHANNEL_COMMAND, OnOffType.OFF, OnOffType.OFF, UnDefType.UNDEF, new DecimalType(0),
46 StringType.valueOf("POWER_OFF"));
50 public void testFanLightOn() throws RFXComException {
51 testCommand(CHANNEL_FAN_LIGHT, OnOffType.ON, null, OnOffType.ON, null, StringType.valueOf("LIGHT"));
55 public void testFanSpeed0() throws RFXComException {
56 testFanSpeed(0, OnOffType.OFF);
60 public void testFanSpeed1() throws RFXComException {
61 testFanSpeed(1, OnOffType.ON);
65 public void testFanSpeed2() throws RFXComException {
66 testFanSpeed(2, OnOffType.ON);
70 public void testFanSpeed3() throws RFXComException {
71 testFanSpeed(3, OnOffType.ON);
75 public void testFanSpeed4() throws RFXComException {
76 testFanSpeed(4, OnOffType.ON);
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"));
101 private void testFanSpeed(int value, OnOffType expectedCommand) throws RFXComException {
102 StringType expectedCommandString;
104 expectedCommandString = StringType.valueOf("POWER_OFF");
106 expectedCommandString = StringType.valueOf("SPEED_" + value);
108 testCommand(CHANNEL_FAN_SPEED, new DecimalType(value), expectedCommand, UnDefType.UNDEF, new DecimalType(value),
109 expectedCommandString);
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);