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;
16 import static org.openhab.binding.rfxcom.internal.messages.RFXComSecurity1Message.SubType.*;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.junit.Test;
21 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
22 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
23 import org.openhab.binding.rfxcom.internal.messages.RFXComSecurity1Message.Contact;
24 import org.openhab.binding.rfxcom.internal.messages.RFXComSecurity1Message.Motion;
25 import org.openhab.binding.rfxcom.internal.messages.RFXComSecurity1Message.Status;
26 import org.openhab.binding.rfxcom.internal.messages.RFXComSecurity1Message.SubType;
27 import org.openhab.core.util.HexUtils;
30 * Test for RFXCom-binding
32 * @author Martin van Wingerden - Initial contribution
35 public class RFXComSecurity1MessageTest {
36 private void testSomeMessages(String hexMessage, @Nullable SubType subType, int sequenceNumber,
37 @Nullable String deviceId, int batteryLevel, @Nullable Contact contact, @Nullable Motion motion,
38 @Nullable Status status, int signalLevel) throws RFXComException {
39 byte[] message = HexUtils.hexToBytes(hexMessage);
40 RFXComSecurity1Message msg = (RFXComSecurity1Message) RFXComMessageFactory.createMessage(message);
41 assertEquals("SubType", subType, msg.subType);
42 assertEquals("Seq Number", sequenceNumber, (short) (msg.seqNbr & 0xFF));
43 assertEquals("Sensor Id", deviceId, msg.getDeviceId());
44 assertEquals("Battery level", batteryLevel, msg.batteryLevel);
45 assertEquals("Contact", contact, msg.contact);
46 assertEquals("Motion", motion, msg.motion);
47 assertEquals("Status", status, msg.status);
48 assertEquals("Signal Level", signalLevel, msg.signalLevel);
50 byte[] decoded = msg.decodeMessage();
52 assertEquals("Message converted back", hexMessage, HexUtils.bytesToHex(decoded));
56 public void testX10SecurityMessage() throws RFXComException {
57 testSomeMessages("0820004DD3DC540089", X10_SECURITY, 77, "13884500", 8, Contact.NORMAL, Motion.UNKNOWN,
62 public void testRM174RFSecurityMessage() throws RFXComException {
63 testSomeMessages("08200A0E8000200650", RM174RF, 14, "8388640", 5, Contact.UNKNOWN, Motion.UNKNOWN, Status.PANIC,
65 testSomeMessages("08200A081450450650", RM174RF, 8, "1331269", 5, Contact.UNKNOWN, Motion.UNKNOWN, Status.PANIC,
69 @Test(expected = RFXComUnsupportedValueException.class)
70 public void testSomeInvalidSecurityMessage() throws RFXComException {
71 testSomeMessages("08FF0A1F0000000650", null, 0, null, 0, null, null, null, 0);