]> git.basschouten.com Git - openhab-addons.git/blob
156ed4693a1cb16950de6b586b37acdd78b2fa9d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.assertEquals;
16 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
17 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.LIGHTING5;
18 import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.Commands.*;
19 import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.SubType.IT;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
24 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
25 import org.openhab.core.library.types.OnOffType;
26 import org.openhab.core.library.types.StringType;
27 import org.openhab.core.util.HexUtils;
28
29 /**
30  * Test for RFXCom-binding
31  *
32  * @author Martin van Wingerden - Initial contribution
33  */
34 @NonNullByDefault
35 public class RFXComLighting5MessageTest {
36     private final MockDeviceState deviceState = new MockDeviceState();
37
38     @Test
39     public void convertFromStateItMessage() throws RFXComException {
40         RFXComDeviceMessage itMessageObject = (RFXComDeviceMessage) RFXComMessageFactory.createMessage(LIGHTING5);
41         itMessageObject.setDeviceId("2061.1");
42         itMessageObject.setSubType(IT);
43         itMessageObject.convertFromState(CHANNEL_COMMAND, OnOffType.ON);
44         byte[] message = itMessageObject.decodeMessage();
45         String hexMessage = HexUtils.bytesToHex(message);
46         assertEquals("0A140F0000080D01010000", hexMessage, "Message is not as expected");
47         RFXComLighting5Message msg = (RFXComLighting5Message) RFXComMessageFactory.createMessage(message);
48         assertEquals(IT, msg.subType, "SubType");
49         assertEquals("2061.1", msg.getDeviceId(), "Sensor Id");
50         assertEquals(ON, msg.command, "Command");
51     }
52
53     @Test
54     public void basicBoundaryCheck() throws RFXComException {
55         RFXComLighting5Message message = (RFXComLighting5Message) RFXComMessageFactory.createMessage(LIGHTING5);
56
57         message.subType = RFXComLighting5Message.SubType.LIGHTWAVERF;
58         message.command = ON;
59
60         RFXComTestHelper.basicBoundaryCheck(LIGHTING5, message);
61     }
62
63     // TODO please add more tests for different messages
64
65     @Test
66     public void testStringCommandOpenRelay() throws RFXComUnsupportedChannelException {
67         RFXComLighting5Message msg = new RFXComLighting5Message();
68
69         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OPEN_RELAY"));
70         assertEquals(StringType.valueOf("OPEN_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
71         assertEquals(OPEN_RELAY, msg.command);
72     }
73
74     @Test
75     public void testStringCommandCloseRelay() throws RFXComUnsupportedChannelException {
76         RFXComLighting5Message msg = new RFXComLighting5Message();
77
78         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("CLOSE_RELAY"));
79         assertEquals(StringType.valueOf("CLOSE_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
80         assertEquals(CLOSE_RELAY, msg.command);
81     }
82
83     @Test
84     public void testStringCommandStopRelay() throws RFXComUnsupportedChannelException {
85         RFXComLighting5Message msg = new RFXComLighting5Message();
86
87         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("STOP_RELAY"));
88         assertEquals(StringType.valueOf("STOP_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
89         assertEquals(STOP_RELAY, msg.command);
90     }
91 }