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) RFXComMessageFactoryImpl.INSTANCE
41 .createMessage(LIGHTING5);
42 itMessageObject.setDeviceId("2061.1");
43 itMessageObject.setSubType(IT);
44 itMessageObject.convertFromState(CHANNEL_COMMAND, OnOffType.ON);
45 byte[] message = itMessageObject.decodeMessage();
46 String hexMessage = HexUtils.bytesToHex(message);
47 assertEquals("0A140F0000080D01010000", hexMessage, "Message is not as expected");
48 RFXComLighting5Message msg = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE.createMessage(message);
49 assertEquals(IT, msg.subType, "SubType");
50 assertEquals("2061.1", msg.getDeviceId(), "Sensor Id");
51 assertEquals(ON, msg.command, "Command");
55 public void basicBoundaryCheck() throws RFXComException {
56 RFXComLighting5Message message = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE
57 .createMessage(LIGHTING5);
59 message.subType = RFXComLighting5Message.SubType.LIGHTWAVERF;
62 RFXComTestHelper.basicBoundaryCheck(LIGHTING5, message);
65 // TODO please add more tests for different messages
68 public void testStringCommandOpenRelay() throws RFXComUnsupportedChannelException {
69 RFXComLighting5Message msg = new RFXComLighting5Message();
71 msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OPEN_RELAY"));
72 assertEquals(StringType.valueOf("OPEN_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
73 assertEquals(OPEN_RELAY, msg.command);
77 public void testStringCommandCloseRelay() throws RFXComUnsupportedChannelException {
78 RFXComLighting5Message msg = new RFXComLighting5Message();
80 msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("CLOSE_RELAY"));
81 assertEquals(StringType.valueOf("CLOSE_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
82 assertEquals(CLOSE_RELAY, msg.command);
86 public void testStringCommandStopRelay() throws RFXComUnsupportedChannelException {
87 RFXComLighting5Message msg = new RFXComLighting5Message();
89 msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("STOP_RELAY"));
90 assertEquals(StringType.valueOf("STOP_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
91 assertEquals(STOP_RELAY, msg.command);