]> git.basschouten.com Git - openhab-addons.git/blob
d1004a3a9a30b080281108d57cb06b705eaeae86
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.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) RFXComMessageFactoryImpl.INSTANCE
34                 .createMessage(HexUtils.hexToBytes(hexMsg));
35         assertEquals(subType, msg.subType, "SubType");
36         assertEquals(seqNbr, (short) (msg.seqNbr & 0xFF), "Seq Number");
37         assertEquals(deviceId, msg.getDeviceId(), "Sensor Id");
38         assertEquals(command, msg.command, "Command");
39         assertEquals(signalLevel, msg.signalLevel, "Signal Level");
40
41         byte[] decoded = msg.decodeMessage();
42
43         assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back");
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 }