2 * Copyright (c) 2010-2023 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.jupiter.api.Assertions.*;
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.jupiter.api.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) RFXComMessageFactoryImpl.INSTANCE.createMessage(message);
41 assertEquals(subType, msg.subType, "SubType");
42 assertEquals(sequenceNumber, (short) (msg.seqNbr & 0xFF), "Seq Number");
43 assertEquals(deviceId, msg.getDeviceId(), "Sensor Id");
44 assertEquals(batteryLevel, msg.batteryLevel, "Battery level");
45 assertEquals(contact, msg.contact, "Contact");
46 assertEquals(motion, msg.motion, "Motion");
47 assertEquals(status, msg.status, "Status");
48 assertEquals(signalLevel, msg.signalLevel, "Signal Level");
50 byte[] decoded = msg.decodeMessage();
52 assertEquals(hexMessage, HexUtils.bytesToHex(decoded), "Message converted back");
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,
70 public void testSomeInvalidSecurityMessage() {
71 assertThrows(RFXComUnsupportedValueException.class,
72 () -> testSomeMessages("08FF0A1F0000000650", null, 0, null, 0, null, null, null, 0));