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.Assert.assertEquals;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.Test;
19 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
20 import org.openhab.binding.rfxcom.internal.messages.RFXComBlinds1Message.Commands;
21 import org.openhab.binding.rfxcom.internal.messages.RFXComBlinds1Message.SubType;
22 import org.openhab.core.util.HexUtils;
25 * Test for RFXCom-binding
27 * @author Martin van Wingerden - Initial contribution
30 public class RFXComBlinds1MessageTest {
31 private void testMessage(String hexMsg, SubType subType, int seqNbr, String deviceId, int signalLevel,
32 RFXComBlinds1Message.Commands command) throws RFXComException {
33 final RFXComBlinds1Message msg = (RFXComBlinds1Message) RFXComMessageFactory
34 .createMessage(HexUtils.hexToBytes(hexMsg));
35 assertEquals("SubType", subType, msg.subType);
36 assertEquals("Seq Number", seqNbr, (short) (msg.seqNbr & 0xFF));
37 assertEquals("Sensor Id", deviceId, msg.getDeviceId());
38 assertEquals("Command", command, msg.command);
39 assertEquals("Signal Level", signalLevel, msg.signalLevel);
41 byte[] decoded = msg.decodeMessage();
43 assertEquals("Message converted back", hexMsg, HexUtils.bytesToHex(decoded));
47 public void testSomeMessages() throws RFXComException {
48 testMessage("0919040600A21B010280", SubType.T4, 6, "41499.1", 8, Commands.STOP);
50 testMessage("091905021A6280010000", SubType.T5, 2, "1729152.1", 0, Commands.OPEN);