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.assertArrayEquals;
16 import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.thingUID;
17 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.RFY;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.rfxcom.internal.RFXComBindingConstants;
22 import org.openhab.binding.rfxcom.internal.RFXComTestHelper;
23 import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
24 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
25 import org.openhab.binding.rfxcom.internal.messages.RFXComRfyMessage.SubType;
26 import org.openhab.core.library.types.IncreaseDecreaseType;
27 import org.openhab.core.library.types.OpenClosedType;
28 import org.openhab.core.library.types.UpDownType;
29 import org.openhab.core.thing.ChannelUID;
30 import org.openhab.core.types.Command;
31 import org.openhab.core.util.HexUtils;
34 * Test for RFXCom-binding
36 * @author Martin van Wingerden - Initial contribution
39 public class RFXComRfyMessageTest {
40 private static ChannelUID shutterChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_SHUTTER);
41 private static ChannelUID venetionBlindChannelUID = new ChannelUID(thingUID,
42 RFXComBindingConstants.CHANNEL_VENETIAN_BLIND);
45 public void basicBoundaryCheck() throws RFXComException {
46 RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
47 config.deviceId = "1.1";
48 config.subType = SubType.RFY.toString();
50 RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY, config,
51 shutterChannelUID, UpDownType.UP);
53 RFXComTestHelper.basicBoundaryCheck(RFY, message);
56 private void testMessage(SubType subType, Command command, String deviceId, String data) throws RFXComException {
57 RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
58 config.deviceId = "66051.4";
59 config.subType = subType.toString();
61 RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY, config,
62 venetionBlindChannelUID, command);
64 assertArrayEquals(HexUtils.hexToBytes(data), message.decodeMessage());
68 public void testMessage1() throws RFXComException {
69 testMessage(SubType.RFY, OpenClosedType.OPEN, "66051.4", "0C1A0000010203040F00000000");
73 public void testMessage2() throws RFXComException {
74 testMessage(SubType.ASA, IncreaseDecreaseType.INCREASE, "66051.4", "0C1A0300010203041200000000");