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.jupiter.api.Assertions.assertEquals;
16 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
17 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.LIGHTING4;
18 import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting4Message.Commands.*;
19 import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting4Message.SubType.PT2262;
21 import java.util.Arrays;
22 import java.util.List;
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.junit.jupiter.api.Test;
27 import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
28 import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfigurationBuilder;
29 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
30 import org.openhab.core.library.types.OnOffType;
31 import org.openhab.core.util.HexUtils;
34 * Test for RFXCom-binding
36 * @author Martin van Wingerden - Initial contribution
39 public class RFXComLighting4MessageTest {
41 public void basicBoundaryCheck() throws RFXComException {
42 RFXComLighting4Message message = (RFXComLighting4Message) RFXComMessageFactory.createMessage(LIGHTING4);
44 RFXComDeviceConfiguration build = new RFXComDeviceConfigurationBuilder().withDeviceId("90000").withPulse(300)
45 .withSubType("PT2262").build();
46 message.setConfig(build);
47 message.convertFromState(CHANNEL_COMMAND, OnOffType.ON);
49 byte[] binaryMessage = message.decodeMessage();
50 RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactory.createMessage(binaryMessage);
52 assertEquals("90000", msg.getDeviceId(), "Sensor Id");
55 private void testMessage(String hexMsg, RFXComLighting4Message.SubType subType, String deviceId,
56 @Nullable Integer pulse, RFXComLighting4Message.Commands command, @Nullable Integer seqNbr, int signalLevel,
57 int offCommand, int onCommand) throws RFXComException {
58 testMessage(hexMsg, subType, deviceId, pulse, command.toByte(), seqNbr, signalLevel, offCommand, onCommand);
61 private void testMessage(String hexMsg, RFXComLighting4Message.SubType subType, String deviceId,
62 @Nullable Integer pulse, byte commandByte, @Nullable Integer seqNbr, int signalLevel, int offCommand,
63 int onCommand) throws RFXComException {
64 RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactory
65 .createMessage(HexUtils.hexToBytes(hexMsg));
66 assertEquals(deviceId, msg.getDeviceId(), "Sensor Id");
67 assertEquals(commandByte, RFXComTestHelper.getActualIntValue(msg, CHANNEL_COMMAND_ID), "Command");
69 assertEquals(seqNbr.shortValue(), (short) (msg.seqNbr & 0xFF), "Seq Number");
71 assertEquals(signalLevel, RFXComTestHelper.getActualIntValue(msg, CHANNEL_SIGNAL_LEVEL), "Signal Level");
73 byte[] decoded = msg.decodeMessage();
75 assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back");
77 RFXComTestHelper.checkDiscoveryResult(msg, deviceId, pulse, subType.toString(), offCommand, onCommand);
81 public void testSomeMessages() throws RFXComException {
82 testMessage("091300E1D8AD59018F70", PT2262, "887509", 399, ON_9, 225, 2, 4, 9);
83 testMessage("0913005FA9A9C901A170", PT2262, "694940", 417, ON_9, 95, 2, 4, 9);
84 testMessage("091300021D155C01E960", PT2262, "119125", 489, ON_12, 2, 2, 4, 12);
85 testMessage("091300D345DD99018C50", PT2262, "286169", 396, ON_9, 211, 2, 4, 9);
86 testMessage("09130035D149A2017750", PT2262, "857242", 375, OFF_2, 53, 2, 2, 1);
87 testMessage("0913000B4E462A012280", PT2262, "320610", 290, ON_10, 11, 3, 4, 10);
88 testMessage("09130009232D2E013970", PT2262, "144082", 313, OFF_14, 9, 2, 14, 1);
89 testMessage("091300CA0F8D2801AA70", PT2262, "63698", 426, ON_8, 202, 2, 4, 8);
93 public void testSomeAlarmRemote() throws RFXComException {
94 testMessage("0913004A0D8998016E60", PT2262, "55449", 366, ON_8, 74, 2, 4, 8);
98 public void testCheapPirSensor() throws RFXComException {
99 testMessage("091300EF505FC6019670", PT2262, "329212", 406, ON_6, 239, 2, 4, 6);
103 public void testSomeConradMessages() throws RFXComException {
104 testMessage("0913003554545401A150", PT2262, "345413", 417, OFF_4, 53, 2, 4, 1);
108 public void testPhenixMessages() throws RFXComException {
109 List<String> onMessages = Arrays.asList("09130046044551013780", "09130048044551013780", "0913004A044551013980",
110 "0913004C044551013780", "0913004E044551013780");
112 for (String message : onMessages) {
113 testMessage(message, PT2262, "17493", null, ON_1, null, 3, 4, 1);
116 List<String> offMessages = Arrays.asList("09130051044554013980", "09130053044554013680", "09130055044554013680",
117 "09130057044554013680", "09130059044554013680", "0913005B044554013680", "0913005D044554013480",
118 "09130060044554013980", "09130062044554013680", "09130064044554013280");
120 for (String message : offMessages) {
121 testMessage(message, PT2262, "17493", null, OFF_4, null, 3, 4, 1);