2 * Copyright (c) 2010-2020 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.messages.RFXComInterfaceMessage.Commands.*;
17 import static org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage.SubType.*;
18 import static org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage.SubType.START_RECEIVER;
19 import static org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage.TransceiverType._433_92MHZ_TRANSCEIVER;
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.messages.RFXComInterfaceMessage.Commands;
25 import org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage.SubType;
26 import org.openhab.core.util.HexUtils;
29 * Test for RFXCom-binding
31 * @author Martin van Wingerden - Initial contribution
34 public class RFXComInterfaceMessageTest {
35 private RFXComInterfaceMessage testMessage(String hexMsg, SubType subType, int seqNbr, Commands command)
36 throws RFXComException {
37 RFXComInterfaceMessage msg = (RFXComInterfaceMessage) RFXComMessageFactory
38 .createMessage(HexUtils.hexToBytes(hexMsg));
39 assertEquals(subType, msg.subType, "SubType");
40 assertEquals(seqNbr, (short) (msg.seqNbr & 0xFF), "Seq Number");
41 assertEquals(command, msg.command, "Command");
47 public void testWelcomeCopyRightMessage() throws RFXComException {
48 RFXComInterfaceMessage msg = testMessage("1401070307436F7079726967687420524658434F4D", START_RECEIVER, 3,
49 Commands.START_RECEIVER);
51 assertEquals("Copyright RFXCOM", msg.text, "text");
55 public void testRespondOnUnknownMessage() throws RFXComException {
56 testMessage("0D01FF190053E2000C2701020000", UNKNOWN_COMMAND, 25, UNSUPPORTED_COMMAND);
60 public void testStatusMessage() throws RFXComException {
61 RFXComInterfaceMessage msg = testMessage("1401000102530C0800270001031C04524658434F4D", RESPONSE, 1, GET_STATUS);
63 assertEquals(_433_92MHZ_TRANSCEIVER, msg.transceiverType, "Command");
65 // TODO this is not correct, improvements for this have been made in the OH1 repo
66 assertEquals(12, msg.firmwareVersion, "firmwareVersion");