]> git.basschouten.com Git - openhab-addons.git/blob
c1daa40674761a0f85135ca78054c77193dc76b4
[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.assertArrayEquals;
16 import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.thingUID;
17 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.RFY;
18
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;
32
33 /**
34  * Test for RFXCom-binding
35  *
36  * @author Martin van Wingerden - Initial contribution
37  */
38 @NonNullByDefault
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);
43
44     @Test
45     public void basicBoundaryCheck() throws RFXComException {
46         RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
47         config.deviceId = "1.1";
48         config.subType = SubType.RFY.toString();
49
50         RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY, config,
51                 shutterChannelUID, UpDownType.UP);
52
53         RFXComTestHelper.basicBoundaryCheck(RFY, message);
54     }
55
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();
60
61         RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY, config,
62                 venetionBlindChannelUID, command);
63
64         assertArrayEquals(HexUtils.hexToBytes(data), message.decodeMessage());
65     }
66
67     @Test
68     public void testMessage1() throws RFXComException {
69         testMessage(SubType.RFY, OpenClosedType.OPEN, "66051.4", "0C1A0000010203040F00000000");
70     }
71
72     @Test
73     public void testMessage2() throws RFXComException {
74         testMessage(SubType.ASA, IncreaseDecreaseType.INCREASE, "66051.4", "0C1A0300010203041200000000");
75     }
76 }