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.junit.jupiter.api.Assertions.assertEquals;
16 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_COMMAND_STRING;
17 import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.commandChannelUID;
18 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.LIGHTING5;
19 import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.Commands.*;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.rfxcom.internal.RFXComTestHelper;
24 import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
25 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
26 import org.openhab.core.library.types.OnOffType;
27 import org.openhab.core.library.types.StringType;
28 import org.openhab.core.util.HexUtils;
31 * Test for RFXCom-binding
33 * @author Martin van Wingerden - Initial contribution
36 public class RFXComLighting5MessageTest {
37 private final MockDeviceState deviceState = new MockDeviceState();
38 private static final RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
40 config.deviceId = "2061.1";
41 config.subType = RFXComLighting5Message.SubType.IT.toString();
45 public void convertFromStateItMessage() throws RFXComException {
46 RFXComMessage itMessageObject = RFXComMessageFactoryImpl.INSTANCE.createMessage(LIGHTING5, config,
47 commandChannelUID, OnOffType.ON);
48 byte[] message = itMessageObject.decodeMessage();
49 String hexMessage = HexUtils.bytesToHex(message);
50 assertEquals("0A140F0000080D01010000", hexMessage, "Message is not as expected");
51 RFXComLighting5Message msg = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE.createMessage(message);
52 assertEquals(RFXComLighting5Message.SubType.IT, msg.subType, "SubType");
53 assertEquals("2061.1", msg.getDeviceId(), "Sensor Id");
54 assertEquals(ON, msg.command, "Command");
58 public void basicBoundaryCheck() throws RFXComException {
59 RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
60 config.deviceId = "206.1";
61 config.subType = RFXComLighting5Message.SubType.LIGHTWAVERF.toString();
63 RFXComLighting5Message message = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE
64 .createMessage(LIGHTING5, config, commandChannelUID, OnOffType.ON);
66 RFXComTestHelper.basicBoundaryCheck(LIGHTING5, message);
69 // TODO please add more tests for different messages
72 public void testStringCommandOpenRelay() throws RFXComException {
73 RFXComLighting5Message msg = new RFXComLighting5Message();
75 msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OPEN_RELAY"));
76 assertEquals(StringType.valueOf("OPEN_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
77 assertEquals(OPEN_RELAY, msg.command);
81 public void testStringCommandCloseRelay() throws RFXComException {
82 RFXComLighting5Message msg = new RFXComLighting5Message();
84 msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("CLOSE_RELAY"));
85 assertEquals(StringType.valueOf("CLOSE_RELAY"),
86 msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
87 assertEquals(CLOSE_RELAY, msg.command);
91 public void testStringCommandStopRelay() throws RFXComException {
92 RFXComLighting5Message msg = new RFXComLighting5Message();
94 msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("STOP_RELAY"));
95 assertEquals(StringType.valueOf("STOP_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
96 assertEquals(STOP_RELAY, msg.command);