]> git.basschouten.com Git - openhab-addons.git/blob
489ab8ca4a0ffda070c0598620c0a0269ff2edc4
[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.assertEquals;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
20 import org.openhab.core.util.HexUtils;
21
22 /**
23  * Test for RFXCom-binding
24  *
25  * @author Martin van Wingerden - Initial contribution
26  * @author Mike Jagdis - Added actual functional tests
27  */
28 @NonNullByDefault
29 public class RFXComUVMessageTest {
30     @Test
31     public void testMessage1() throws RFXComException {
32         String hexMessage = "095703123421194731E9";
33
34         byte[] message = HexUtils.hexToBytes(hexMessage);
35         RFXComUVMessage msg = (RFXComUVMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(message);
36
37         assertEquals(RFXComUVMessage.SubType.UV3, msg.subType, "SubType");
38         assertEquals(18, msg.seqNbr, "Seq Number");
39         assertEquals("13345", msg.getDeviceId(), "Sensor Id");
40
41         assertEquals(2.5, msg.uv, 0.001, "UV");
42         assertEquals(1822.5, msg.temperature, 0.001, "Temperature");
43
44         assertEquals(14, msg.signalLevel, "Signal Level");
45         assertEquals(9, msg.batteryLevel, "Battery Level");
46
47         byte[] decoded = msg.decodeMessage();
48
49         assertEquals(hexMessage, HexUtils.bytesToHex(decoded), "Message converted back");
50     }
51
52     @Test
53     public void testMessage2() throws RFXComException {
54         String hexMessage = "09570312342119C731E9";
55
56         byte[] message = HexUtils.hexToBytes(hexMessage);
57         RFXComUVMessage msg = (RFXComUVMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(message);
58
59         assertEquals(RFXComUVMessage.SubType.UV3, msg.subType, "SubType");
60         assertEquals(18, msg.seqNbr, "Seq Number");
61         assertEquals("13345", msg.getDeviceId(), "Sensor Id");
62
63         assertEquals(2.5, msg.uv, 0.001, "UV");
64         assertEquals(-1822.5, msg.temperature, 0.001, "Temperature");
65
66         assertEquals(14, msg.signalLevel, "Signal Level");
67         assertEquals(9, msg.batteryLevel, "Battery Level");
68
69         byte[] decoded = msg.decodeMessage();
70
71         assertEquals(hexMessage, HexUtils.bytesToHex(decoded), "Message converted back");
72     }
73 }