]> git.basschouten.com Git - openhab-addons.git/blob
e7422fb15045ac137ec911fc05b934636e8f4a2e
[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;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
19 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
20 import org.openhab.binding.rfxcom.internal.messages.MockDeviceState;
21 import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
22 import org.openhab.binding.rfxcom.internal.messages.RFXComDeviceMessage;
23 import org.openhab.binding.rfxcom.internal.messages.RFXComMessage;
24 import org.openhab.core.library.types.DecimalType;
25 import org.openhab.core.thing.ChannelUID;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.ThingUID;
28
29 /**
30  * Helper class for testing the RFXCom-binding
31  *
32  * @author Martin van Wingerden - Initial contribution
33  */
34 @NonNullByDefault
35 public class RFXComTestHelper {
36     public static final ThingUID bridgeUID = new ThingUID("rfxcom", "tcpbridge", "rfxtrx0");
37     public static final ThingUID thingUID = new ThingUID("rfxcom", bridgeUID, "mocked");
38     public static final ThingTypeUID thingTypeUID = new ThingTypeUID("rfxcom", "raw");
39
40     public static final ChannelUID commandChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_COMMAND);
41
42     public static void basicBoundaryCheck(PacketType packetType, RFXComMessage message) throws RFXComException {
43         // This is a place where its easy to make mistakes in coding, and can result in errors, normally
44         // array bounds errors
45         byte[] binaryMessage = message.decodeMessage();
46         assertEquals(binaryMessage[0], binaryMessage.length - 1, "Wrong packet length");
47         assertEquals(packetType.toByte(), binaryMessage[1], "Wrong packet type");
48     }
49
50     public static int getActualIntValue(RFXComDeviceMessage msg, RFXComDeviceConfiguration config, String channelId)
51             throws RFXComException {
52         return ((DecimalType) msg.convertToState(channelId, config, new MockDeviceState())).intValue();
53     }
54 }