2 * Copyright (c) 2010-2020 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.messages;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
22 import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
23 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
24 import org.openhab.core.library.types.DecimalType;
25 import org.openhab.core.thing.ThingUID;
28 * Helper class for testing the RFXCom-binding
30 * @author Martin van Wingerden - Initial contribution
33 class RFXComTestHelper {
34 static void basicBoundaryCheck(PacketType packetType, RFXComMessage message) throws RFXComException {
35 // This is a place where its easy to make mistakes in coding, and can result in errors, normally
36 // array bounds errors
37 byte[] binaryMessage = message.decodeMessage();
38 assertEquals(binaryMessage[0], binaryMessage.length - 1, "Wrong packet length");
39 assertEquals(packetType.toByte(), binaryMessage[1], "Wrong packet type");
42 static void checkDiscoveryResult(RFXComDeviceMessage msg, String deviceId, @Nullable Integer pulse, String subType,
43 int offCommand, int onCommand) throws RFXComException {
44 String thingUID = "homeduino:rfxcom:fssfsd:thing";
45 DiscoveryResultBuilder builder = DiscoveryResultBuilder.create(new ThingUID(thingUID));
47 // check whether the pulse is stored
48 msg.addDevicePropertiesTo(builder);
50 Map<String, Object> properties = builder.build().getProperties();
51 assertEquals(deviceId, properties.get("deviceId"), "Device Id");
52 assertEquals(subType, properties.get("subType"), "Sub type");
54 assertEquals(pulse, properties.get("pulse"), "Pulse");
56 assertEquals(onCommand, properties.get("onCommandId"), "On command");
57 assertEquals(offCommand, properties.get("offCommandId"), "Off command");
60 static int getActualIntValue(RFXComDeviceMessage msg, String channelId) throws RFXComException {
61 return ((DecimalType) msg.convertToState(channelId, new MockDeviceState())).intValue();