2 * Copyright (c) 2010-2021 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.*;
17 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.LIGHTING5;
18 import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.Commands.*;
19 import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.SubType.IT;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
24 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
25 import org.openhab.core.library.types.OnOffType;
26 import org.openhab.core.library.types.StringType;
27 import org.openhab.core.util.HexUtils;
30 * Test for RFXCom-binding
32 * @author Martin van Wingerden - Initial contribution
35 public class RFXComLighting5MessageTest {
36 private final MockDeviceState deviceState = new MockDeviceState();
39 public void convertFromStateItMessage() throws RFXComException {
40 RFXComDeviceMessage itMessageObject = (RFXComDeviceMessage) RFXComMessageFactory.createMessage(LIGHTING5);
41 itMessageObject.setDeviceId("2061.1");
42 itMessageObject.setSubType(IT);
43 itMessageObject.convertFromState(CHANNEL_COMMAND, OnOffType.ON);
44 byte[] message = itMessageObject.decodeMessage();
45 String hexMessage = HexUtils.bytesToHex(message);
46 assertEquals("0A140F0000080D01010000", hexMessage, "Message is not as expected");
47 RFXComLighting5Message msg = (RFXComLighting5Message) RFXComMessageFactory.createMessage(message);
48 assertEquals(IT, msg.subType, "SubType");
49 assertEquals("2061.1", msg.getDeviceId(), "Sensor Id");
50 assertEquals(ON, msg.command, "Command");
54 public void basicBoundaryCheck() throws RFXComException {
55 RFXComLighting5Message message = (RFXComLighting5Message) RFXComMessageFactory.createMessage(LIGHTING5);
57 message.subType = RFXComLighting5Message.SubType.LIGHTWAVERF;
60 RFXComTestHelper.basicBoundaryCheck(LIGHTING5, message);
63 // TODO please add more tests for different messages
66 public void testStringCommandOpenRelay() throws RFXComUnsupportedChannelException {
67 RFXComLighting5Message msg = new RFXComLighting5Message();
69 msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OPEN_RELAY"));
70 assertEquals(StringType.valueOf("OPEN_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
71 assertEquals(OPEN_RELAY, msg.command);
75 public void testStringCommandCloseRelay() throws RFXComUnsupportedChannelException {
76 RFXComLighting5Message msg = new RFXComLighting5Message();
78 msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("CLOSE_RELAY"));
79 assertEquals(StringType.valueOf("CLOSE_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
80 assertEquals(CLOSE_RELAY, msg.command);
84 public void testStringCommandStopRelay() throws RFXComUnsupportedChannelException {
85 RFXComLighting5Message msg = new RFXComLighting5Message();
87 msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("STOP_RELAY"));
88 assertEquals(StringType.valueOf("STOP_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
89 assertEquals(STOP_RELAY, msg.command);