]> git.basschouten.com Git - openhab-addons.git/blob
477c3a05d8286f4acf579afd45207977e2ec825c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.rfxcom.internal.messages;
14
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;
20
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;
27
28 /**
29  * Test for RFXCom-binding
30  *
31  * @author Martin van Wingerden - Initial contribution
32  */
33 @NonNullByDefault
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");
42
43         return msg;
44     }
45
46     @Test
47     public void testWelcomeCopyRightMessage() throws RFXComException {
48         RFXComInterfaceMessage msg = testMessage("1401070307436F7079726967687420524658434F4D", START_RECEIVER, 3,
49                 Commands.START_RECEIVER);
50
51         assertEquals("Copyright RFXCOM", msg.text, "text");
52     }
53
54     @Test
55     public void testRespondOnUnknownMessage() throws RFXComException {
56         testMessage("0D01FF190053E2000C2701020000", UNKNOWN_COMMAND, 25, UNSUPPORTED_COMMAND);
57     }
58
59     @Test
60     public void testStatusMessage() throws RFXComException {
61         RFXComInterfaceMessage msg = testMessage("1401000102530C0800270001031C04524658434F4D", RESPONSE, 1, GET_STATUS);
62
63         assertEquals(_433_92MHZ_TRANSCEIVER, msg.transceiverType, "Command");
64
65         // TODO this is not correct, improvements for this have been made in the OH1 repo
66         assertEquals(12, msg.firmwareVersion, "firmwareVersion");
67     }
68 }