]> git.basschouten.com Git - openhab-addons.git/blob
504c0acab1ed8e572d1f096f57c919be9daba0af
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.Assert.assertEquals;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.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  */
27 @NonNullByDefault
28 public class RFXComCurrentEnergyMessageTest {
29     private void testMessage(String hexMsg, RFXComCurrentEnergyMessage.SubType subType, int seqNbr, String deviceId,
30             int count, double channel1, double channel2, double channel3, double totalUsage, int signalLevel,
31             int batteryLevel) throws RFXComException {
32         final RFXComCurrentEnergyMessage msg = (RFXComCurrentEnergyMessage) RFXComMessageFactory
33                 .createMessage(HexUtils.hexToBytes(hexMsg));
34         assertEquals("SubType", subType, msg.subType);
35         assertEquals("Seq Number", seqNbr, (short) (msg.seqNbr & 0xFF));
36         assertEquals("Sensor Id", deviceId, msg.getDeviceId());
37         assertEquals("Count", count, msg.count);
38         assertEquals("Channel 1", channel1, msg.channel1Amps, 0.01);
39         assertEquals("Channel 2", channel2, msg.channel2Amps, 0.01);
40         assertEquals("Channel 3", channel3, msg.channel3Amps, 0.01);
41         assertEquals("Total usage", totalUsage, msg.totalUsage, 0.05);
42         assertEquals("Signal Level", signalLevel, msg.signalLevel);
43         assertEquals("Battery Level", batteryLevel, msg.batteryLevel);
44
45         byte[] decoded = msg.decodeMessage();
46
47         assertEquals("Message converted back", hexMsg, HexUtils.bytesToHex(decoded));
48     }
49
50     @Test
51     public void testSomeMessages() throws RFXComException {
52         testMessage("135B0106B800000016000000000000006F148889", RFXComCurrentEnergyMessage.SubType.ELEC4, 6, "47104", 0,
53                 2.2d, 0d, 0d, 32547.4d, 8, 9);
54         testMessage("135B014FB80002001D0000000000000000000079", RFXComCurrentEnergyMessage.SubType.ELEC4, 79, "47104",
55                 2, 2.9d, 0d, 0d, 0d, 7, 9);
56     }
57 }