2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.rfxcom.internal;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
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;
30 * Helper class for testing the RFXCom-binding
32 * @author Martin van Wingerden - Initial contribution
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");
40 public static final ChannelUID commandChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_COMMAND);
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");
50 public static int getActualIntValue(RFXComDeviceMessage msg, RFXComDeviceConfiguration config, String channelId)
51 throws RFXComException {
52 return ((DecimalType) msg.convertToState(channelId, config, new MockDeviceState())).intValue();