]> git.basschouten.com Git - openhab-addons.git/blob
c50d79e14e08551481d7513046785cbeca3537b8
[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 import static org.openhab.binding.rfxcom.internal.messages.RFXComTemperatureMessage.SubType.*;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
21 import org.openhab.core.util.HexUtils;
22
23 /**
24  * Test for RFXCom-binding
25  *
26  * @author Martin van Wingerden - Initial contribution
27  */
28 @NonNullByDefault
29 public class RFXComTemperatureMessageTest {
30     private void testMessage(String hexMsg, RFXComTemperatureMessage.SubType subType, int seqNbr, String deviceId,
31             double temperature, int signalLevel, int bateryLevel) throws RFXComException {
32         final RFXComTemperatureMessage msg = (RFXComTemperatureMessage) RFXComMessageFactoryImpl.INSTANCE
33                 .createMessage(HexUtils.hexToBytes(hexMsg));
34         assertEquals(subType, msg.subType, "SubType");
35         assertEquals(seqNbr, (short) (msg.seqNbr & 0xFF), "Seq Number");
36         assertEquals(deviceId, msg.getDeviceId(), "Sensor Id");
37         assertEquals(temperature, msg.temperature, 0.001, "Temperature");
38         assertEquals(signalLevel, msg.signalLevel, "Signal Level");
39         assertEquals(bateryLevel, msg.batteryLevel, "Battery");
40
41         byte[] decoded = msg.decodeMessage();
42
43         assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back");
44     }
45
46     @Test
47     public void testSomeMessages() throws RFXComException {
48         testMessage("08500110000180BC69", TEMP1, 16, "1", -18.8d, 6, 9);
49         testMessage("0850021DFB0100D770", TEMP2, 29, "64257", 21.5d, 7, 0);
50         testMessage("08500502770000D389", TEMP5, 2, "30464", 21.1d, 8, 9);
51         testMessage("0850091A00C3800689", TEMP9, 26, "195", -0.6d, 8, 9);
52         testMessage("0850097200C300E089", TEMP9, 114, "195", 22.4d, 8, 9);
53     }
54 }