]> git.basschouten.com Git - openhab-addons.git/blob
697588297244b7ee03dc886df9236ad6eb2a0245
[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.Assert.assertEquals;
16
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;
23
24 /**
25  * Test for RFXCom-binding
26  *
27  * @author Martin van Wingerden - Initial contribution
28  */
29 @NonNullByDefault
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);
40
41         byte[] decoded = msg.decodeMessage();
42
43         assertEquals("Message converted back", hexMsg, HexUtils.bytesToHex(decoded));
44     }
45
46     @Test
47     public void testSomeMessages() throws RFXComException {
48         testMessage("0919040600A21B010280", SubType.T4, 6, "41499.1", 8, Commands.STOP);
49
50         testMessage("091905021A6280010000", SubType.T5, 2, "1729152.1", 0, Commands.OPEN);
51     }
52 }