diff --git a/bundles/org.openhab.binding.rfxcom/README.md b/bundles/org.openhab.binding.rfxcom/README.md index 172b6c20f..2931b23fb 100644 --- a/bundles/org.openhab.binding.rfxcom/README.md +++ b/bundles/org.openhab.binding.rfxcom/README.md @@ -136,15 +136,10 @@ Bridge rfxcom:tcpbridge:sunflower [ host="sunflower", port=10001 ] { ## Thing Configuration -Available configuration parameters are: - -| Applies to | Parameter Label | Parameter ID | Description | Required | Default | -|------------|-----------------|--------------|----------------------------------------------------------------------|----------|---------| -| All things | Device ID | deviceId | (Unique) id of the device, for example "100001.1", "B.8" or "286169" | true | | -| All things | Sub type | subType | Sub type, note that every thing-type has its own sub types | true | | -| Lighting4 | Pulse | pulse | Pulse length used by the device, only used when sending | false | 350 | -| Lighting4 | On command ID | onCommandId | Id of the command which should be send to turn the device ON | false | 1 | -| Lighting4 | Off command ID | offCommandId | Id of the command which should be send to turn the device OFF | false | 4 | +Configuration parameters are listed alongside each thing type. Most devices only require a deviceId and +a subType, but some things require additional configuration. The deviceId is used both when receiving and +transmitting messages, the subType is mainly used when sending messages, but it can vary between device +types. ## Channels @@ -690,7 +685,27 @@ A Lighting2 device ### lighting4 - RFXCOM Lighting4 Actuator -A Lighting4 device +A Lighting4 device. The specification for the PT2262 protocol includes 3 bytes for data. By +convention, the first 20 bits of this is used for deviceId, and the last 4 bits is used for +command, which gives us a total of 16 commands per device. + +Depending on your device, you may have only one command, one pair of commands (on/off), or +any other multiple, for example, a set of 4 sockets with an on/off pair for each and an +additional pair for "all". + +Different device manufactures using this protocol will use different schemes for their +commands, so to configure a thing using the lighting4 protocol, you must specify at least +one commandId in the thing configuration. If a device has multiple sets of commands, you +can configure multiple things with the same device id, but different commandIds. + +Some devices will expect a specific pulse length. If required, that can also be specified +as a thing configuration parameter. + +Previously, openHAB would attempt to guess at the meaning of a commandId if it was not +specified in the thing configuration based on devices seen in the wild. Due to the varying +nature of devices, this behaviour is deprecated and will be removed in a future openHAB +version. Until then, commands 1, 3, 5-13 and 15 are considered ON and 0, 2, 4 and 14 are +considered OFF when the `onCommandId` or `offCommandId` for a device is not specified. #### Channels @@ -709,64 +724,46 @@ A Lighting4 device * subType - Sub Type * Specifies device sub type. - * PT2262 - PT2262 + * PT2262 - PT2262 * pulse - Pulse length * Pulse length of the device * onCommandId - On command - * Specifies command to be send when ON must be transmitted - - * 0 - OFF (value 0) - * 1 - ON (value 1) - * 2 - OFF (value 2) - * 3 - ON (value 3) - * 4 - OFF (value 4) - * 5 - ON (value 5) - * 6 - value 6 - * 7 - ON (value 7) - * 8 - value 8 - * 9 - ON (value 9) - * 10 - ON (value 10) - * 11 - ON (value 11) - * 12 - ON (value 12) - * 13 - value 13 - * 14 - OFF (value 14) - * 15 - value 15 + * Specifies command that represents ON for this device. * offCommandId - Off command - * Specifies command to be send when OFF must be transmitted + * Specifies command that represents OFF for this device. - * 0 - OFF (value 0) - * 1 - ON (value 1) - * 2 - OFF (value 2) - * 3 - ON (value 3) - * 4 - OFF (value 4) - * 5 - ON (value 5) - * 6 - value 6 - * 7 - ON (value 7) - * 8 - value 8 - * 9 - ON (value 9) - * 10 - ON (value 10) - * 11 - ON (value 11) - * 12 - ON (value 12) - * 13 - value 13 - * 14 - OFF (value 14) - * 15 - value 15 +* openCommandId - Open command + * Specifies command that represents OPEN for this device. + +* closedCommandId - Closed command + * Specifies command that represents CLOSED for this device. + +#### Discovering commandId values + +There are a number of ways to detect the commandId values for your device. + +- You can turn on DEBUG messages for the rfxcom binding by adding the line + `` + to your `log4j2.xml`. You will then be able to see the commandId in the log + file when you trigger the device. + +- You can link a Number Item to the commandId channel. The item will be updated with the + detected commandId when you trigger the device. + +- You can use RFXmngr to look at the data from the device. Use the last letter/number + of the hexadecimal "Code", and convert it from hexadecimal to decimal. #### Examples -The support for lighting 4 in RFXCOM is less complete because a lot of different devices use the same chips and can not easily be distinguished. - -So some extra configuration can be used for fine tuning the behavior of your Lighting4 devices. -When configuring, three extra fields are available, being the the pulse length, and a separate command id for both on and off. -If your item is auto-discovered normally the on or off command should be recognized properly. - -For a USB attached RFXCOM on Windows the configuration could look like this (note that the `onCommandId`, `offCommandId` and `pulse` are all optional): +For a USB attached RFXCOM on Windows the configuration could look like this (note the `pulse` is optional): ``` Bridge rfxcom:bridge:238adf67 [ serialPort="COM4" ] { - Thing lighting4 17745 [deviceId="17745", subType="PT2262", onCommandId=7, offCommandId=4, pulse=800] + Thing lighting4 17745a [deviceId="17745", subType="PT2262", onCommandId=7, offCommandId=4] + Thing lighting4 17745b [deviceId="17745", subType="PT2262", onCommandId=10, offCommandId=2] Thing lighting4 motion [deviceId="286169", subType="PT2262", onCommandId=9, pulse=392] } ``` @@ -774,30 +771,31 @@ Bridge rfxcom:bridge:238adf67 [ serialPort="COM4" ] { Your items file could look like this: ``` -Switch Switch {channel="rfxcom:lighting4:238adf67:17745:command"} -Number SwitchCommandId "Command ID [%d]" {channel="rfxcom:lighting4:238adf67:17745:commandId"} +Number SocketCommandId {channel="rfxcom:lighting4:238adf67:17745a:commandId"} +Switch SocketA {channel="rfxcom:lighting4:238adf67:17745a:command"} +Switch SocketB {channel="rfxcom:lighting4:238adf67:17745b:command"} ``` -And if you want random actions on your relay you could for example do like this: +#### Known commandIds -``` -rule "Set random relay variations" - when - System started or - Time cron "/20 * * * * ?" - then - SwitchCommandId.sendCommand((Math::random * 15.9).intValue) -end -``` +These are some commandIds from the field that may match your devices. -#### Devices: - -| Brand | What | Action | Command ID | Supported | Source | -|-------|---------------|-------------|------------|-----------|--------| -| Kerui | Motion Sensor | Motion | 10 | as ON | [#3103](https://github.com/openhab/openhab-addons/issues/3103) | -| Kerui | Door Contact | door open | 14 | as OFF | [#3103](https://github.com/openhab/openhab-addons/issues/3103) | -| Kerui | Door Contact | door closed | 7 | as ON | [#3103](https://github.com/openhab/openhab-addons/issues/3103) | -| Kerui | Door Contact | tamper | 7 | as ON | [#3103](https://github.com/openhab/openhab-addons/issues/3103) | +| Brand | What | Action | Command ID | Source | +|-------|---------------|-------------|------------|--------| +| Kerui | Motion Sensor | Motion | 10 | [#3103](https://github.com/openhab/openhab-addons/issues/3103) | +| Kerui | Door Contact | door open | 14 | [#3103](https://github.com/openhab/openhab-addons/issues/3103) | +| Kerui | Door Contact | door closed | 7 | [#3103](https://github.com/openhab/openhab-addons/issues/3103) | +| Kerui | Door Contact | tamper | 11 | [#3103](https://github.com/openhab/openhab-addons/issues/3103) | +| Energenie | 4 Socket Power Bar | Socket 1 on | 15 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | +| Energenie | 4 Socket Power Bar | Socket 1 off | 14 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | +| Energenie | 4 Socket Power Bar | Socket 2 on | 7 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | +| Energenie | 4 Socket Power Bar | Socket 2 off | 6 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | +| Energenie | 4 Socket Power Bar | Socket 3 on | 11 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | +| Energenie | 4 Socket Power Bar | Socket 3 off | 10 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | +| Energenie | 4 Socket Power Bar | Socket 4 on | 3 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | +| Energenie | 4 Socket Power Bar | Socket 4 off | 2 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | +| Energenie | 4 Socket Power Bar | All on | 13 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | +| Energenie | 4 Socket Power Bar | All off | 12 | [Community](https://community.openhab.org/t/rfxcom-looking-to-improve-lighting4-call-for-users/123674) | ### lighting5 - RFXCOM Lighting5 Actuator diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/config/RFXComLighting4DeviceConfiguration.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/config/RFXComLighting4DeviceConfiguration.java index f1244edaf..c4d54e591 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/config/RFXComLighting4DeviceConfiguration.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/config/RFXComLighting4DeviceConfiguration.java @@ -21,7 +21,11 @@ public class RFXComLighting4DeviceConfiguration extends RFXComGenericDeviceConfi public static final String PULSE_LABEL = "pulse"; public static final String ON_COMMAND_ID_LABEL = "onCommandId"; public static final String OFF_COMMAND_ID_LABEL = "offCommandId"; + public static final String OPEN_COMMAND_ID_LABEL = "openCommandId"; + public static final String CLOSED_COMMAND_ID_LABEL = "closedCommandId"; public Integer pulse; public Integer onCommandId; public Integer offCommandId; + public Integer openCommandId; + public Integer closedCommandId; } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComBridgeHandler.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComBridgeHandler.java index 092ebf436..888088186 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComBridgeHandler.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComBridgeHandler.java @@ -102,8 +102,10 @@ public class RFXComBridgeHandler extends BaseBridgeHandler { RFXComBaseMessage msg = queue.peek(); try { - logger.debug("Transmitting message '{}'", msg); byte[] data = msg.decodeMessage(); + if (logger.isDebugEnabled()) { + logger.debug("Transmitting bytes '{}' for message '{}'", HexUtils.bytesToHex(data), msg); + } connector.sendMessage(data); break; } catch (RFXComException rfxe) { diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandler.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandler.java index 992015902..04a247e86 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandler.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandler.java @@ -95,10 +95,7 @@ public class RFXComHandler extends BaseThingHandler implements DeviceMessageList PacketType packetType = RFXComMessageFactoryImpl .convertPacketType(getThing().getThingTypeUID().getId().toUpperCase()); - RFXComMessage msg = messageFactory.createMessage(packetType); - - msg.setConfig(config); - msg.convertFromState(channelUID.getId(), command); + RFXComMessage msg = messageFactory.createMessage(packetType, config, channelUID, command); bridgeHandler.sendMessage(msg); } catch (RFXComMessageNotImplementedException e) { @@ -180,9 +177,9 @@ public class RFXComHandler extends BaseThingHandler implements DeviceMessageList try { if (config.matchesMessage(message)) { String receivedId = PACKET_TYPE_THING_TYPE_UID_MAP.get(message.getPacketType()).getId(); - logger.debug("Received message from bridge: {} message: {}", bridge, message); - if (receivedId.equals(getThing().getThingTypeUID().getId())) { + logger.debug("Message from bridge [{}] matches thing [{}] message: {}", bridge, + getThing().getUID().toString(), message); updateStatus(ThingStatus.ONLINE); for (Channel channel : getThing().getChannels()) { @@ -194,19 +191,21 @@ public class RFXComHandler extends BaseThingHandler implements DeviceMessageList case CHANNEL_COMMAND: case CHANNEL_CHIME_SOUND: case CHANNEL_MOOD: - postNullableCommand(uid, message.convertToCommand(channelId, this)); + postNullableCommand(uid, message.convertToCommand(channelId, config, this)); break; case CHANNEL_LOW_BATTERY: updateNullableState(uid, - isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL, this))); + isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL, config, this))); break; default: - updateNullableState(uid, message.convertToState(channelId, this)); + updateNullableState(uid, message.convertToState(channelId, config, this)); break; } - } catch (RFXComException e) { + } catch (RFXComInvalidStateException e) { + logger.trace("{} not configured for {}", channelId, message); + } catch (RFXComUnsupportedChannelException e) { logger.trace("{} does not handle {}", channelId, message); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBBQTemperatureMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBBQTemperatureMessage.java index 99d00360c..f4c27532f 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBBQTemperatureMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBBQTemperatureMessage.java @@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; +import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException; import org.openhab.binding.rfxcom.internal.handler.DeviceState; @@ -124,13 +126,14 @@ public class RFXComBBQTemperatureMessage extends RFXComBatteryDeviceMessage extends RFXComDeviceMessageImpl } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { switch (channelId) { case CHANNEL_BATTERY_LEVEL: return convertBatteryLevelToSystemWideLevel(batteryLevel); default: - return super.convertToState(channelId, deviceState); + return super.convertToState(channelId, config, deviceState); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBlinds1Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBlinds1Message.java index 11aa77bdb..ed1648568 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBlinds1Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBlinds1Message.java @@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; +import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException; import org.openhab.binding.rfxcom.internal.handler.DeviceState; @@ -174,11 +176,12 @@ public class RFXComBlinds1Message extends RFXComBatteryDeviceMessage extends RFXComMessage { * Procedure for converting RFXCOM value to openHAB command. * * @param channelId id of the channel + * @param config Configuration of the thing being handled * @param deviceState * @return openHAB command. * @throws RFXComUnsupportedChannelException if the channel is not supported + * @throws RFXComInvalidStateException if the channel is supported, but the device is not configured for the value */ - Command convertToCommand(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException; + Command convertToCommand(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException; /** * Procedure for converting RFXCOM value to openHAB state. * * @param channelId id of the channel + * @param config configuration of the thing being handled * @param deviceState * @return openHAB state. * @throws RFXComUnsupportedChannelException if the channel is not supported + * @throws RFXComInvalidStateException if the channel is supported, but the device is not configured for the value */ - State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException; + State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException; /** * Procedure to get device id. diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDeviceMessageImpl.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDeviceMessageImpl.java index ed4de3e36..6eadde867 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDeviceMessageImpl.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDeviceMessageImpl.java @@ -17,6 +17,7 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; +import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; import org.openhab.binding.rfxcom.internal.handler.DeviceState; import org.openhab.core.config.discovery.DiscoveryResultBuilder; @@ -48,13 +49,14 @@ abstract class RFXComDeviceMessageImpl extends RFXComBaseMessage implements R } @Override - public Command convertToCommand(String channelId, DeviceState deviceState) - throws RFXComUnsupportedChannelException { - return (Command) convertToState(channelId, deviceState); + public Command convertToCommand(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { + return (Command) convertToState(channelId, config, deviceState); } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { switch (channelId) { case CHANNEL_SIGNAL_LEVEL: return convertSignalLevelToSystemWideLevel(signalLevel); diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComEnergyMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComEnergyMessage.java index be24d3c4c..c679e0181 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComEnergyMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComEnergyMessage.java @@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; +import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException; import org.openhab.binding.rfxcom.internal.handler.DeviceState; @@ -145,7 +147,8 @@ public class RFXComEnergyMessage extends RFXComBatteryDeviceMessage ON they saw was for them. So we // redirect an incoming broadcast DIM/BRIGHT to the correct item // based on the last X we saw or sent. - unitCode = lastUnit[(int) houseCode - (int) 'A']; + unitCode = lastUnit[houseCode - 'A']; } else { unitCode = data[5]; if (command == Commands.ON) { - lastUnit[(int) houseCode - (int) 'A'] = unitCode; + lastUnit[houseCode - 'A'] = unitCode; } } @@ -162,8 +164,8 @@ public class RFXComLighting1Message extends RFXComDeviceMessageImpl { - // this logger is used from a static context, so is static as well - private static final Logger LOGGER = LoggerFactory.getLogger(RFXComLighting4Message.class); - - private static final byte DEFAULT_OFF_COMMAND_ID = Commands.OFF_4.toByte(); - private static final byte DEFAULT_ON_COMMAND_ID = Commands.ON_1.toByte(); - public enum SubType implements ByteEnumWrapper { PT2262(0); @@ -80,62 +79,21 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl ON_COMMAND_IDS = Stream.of(1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15) + .collect(Collectors.toCollection(HashSet::new)); private SubType subType; private int sensorId; private int pulse; - private Commands command; private int commandId; - private int offCommandId; - private int onCommandId; + + private RFXComLighting4DeviceConfiguration config; public RFXComLighting4Message() { super(PacketType.LIGHTING4); @@ -152,7 +110,7 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl> 4; commandId = (data[6] & 0x0F); - command = Commands.fromByte(commandId); - onCommandId = command.isOn() ? commandId : DEFAULT_ON_COMMAND_ID; - offCommandId = command.isOn() ? DEFAULT_OFF_COMMAND_ID : commandId; pulse = (data[7] & 0xFF) << 8 | (data[8] & 0xFF); @@ -205,20 +160,45 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl cl = MESSAGE_CLASSES.get(packetType); if (cl == null) { throw new RFXComMessageNotImplementedException("Message " + packetType + " not implemented"); } - return cl.getDeclaredConstructor().newInstance(); + RFXComMessage msg = cl.getDeclaredConstructor().newInstance(); + msg.setConfig(config); + msg.convertFromState(channelUID.getId(), command); + return msg; } catch (ReflectiveOperationException e) { throw new RFXComException(e); } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessage.java index e5af3962a..539f92498 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessage.java @@ -18,7 +18,9 @@ import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte import java.math.BigDecimal; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; +import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException; import org.openhab.binding.rfxcom.internal.handler.DeviceState; @@ -201,7 +203,8 @@ public class RFXComRFXSensorMessage extends RFXComDeviceMessageImplPulse length of the device 350 - + - Specifies command to be send when ON must be transmitted - - - - - - - - - - - - - - - - - - - 1 + Specifies command that represents ON for this device. If not + specified, will treat 1, 3, 5-13 and 15 as + ON commands for receiving message, and will send 1 as an ON + command. This behaviour is deprecated. In a future + version, if this is not specified, the on command will + not be available. - + - Specifies command to be send when OFF must be transmitted - - - - - - - - - - - - - - - - - - - 4 + Specifies command that represents OFF for this device. For historical reasons, if not + specified, will + treat 0, 2, 4 and 14 as OFF commands for receiving message, and will send 4 as an OFF + command. This behaviour is + deprecated. In a future version, if this is not specified, the off command will + not be available. + + + + Specifies command that represents OPEN for this device. + + + + Specifies command that represents CLOSED for this device. diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/RFXComTestHelper.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/RFXComTestHelper.java new file mode 100644 index 000000000..9aac7d55d --- /dev/null +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/RFXComTestHelper.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.rfxcom.internal; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; +import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; +import org.openhab.binding.rfxcom.internal.messages.MockDeviceState; +import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType; +import org.openhab.binding.rfxcom.internal.messages.RFXComDeviceMessage; +import org.openhab.binding.rfxcom.internal.messages.RFXComMessage; +import org.openhab.core.library.types.DecimalType; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.ThingTypeUID; +import org.openhab.core.thing.ThingUID; + +/** + * Helper class for testing the RFXCom-binding + * + * @author Martin van Wingerden - Initial contribution + */ +@NonNullByDefault +public class RFXComTestHelper { + static final public ThingUID bridgeUID = new ThingUID("rfxcom", "tcpbridge", "rfxtrx0"); + static final public ThingUID thingUID = new ThingUID("rfxcom", bridgeUID, "mocked"); + static final public ThingTypeUID thingTypeUID = new ThingTypeUID("rfxcom", "raw"); + + static final public ChannelUID commandChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_COMMAND); + + static public void basicBoundaryCheck(PacketType packetType, RFXComMessage message) throws RFXComException { + // This is a place where its easy to make mistakes in coding, and can result in errors, normally + // array bounds errors + byte[] binaryMessage = message.decodeMessage(); + assertEquals(binaryMessage[0], binaryMessage.length - 1, "Wrong packet length"); + assertEquals(packetType.toByte(), binaryMessage[1], "Wrong packet type"); + } + + static public int getActualIntValue(RFXComDeviceMessage msg, RFXComDeviceConfiguration config, String channelId) + throws RFXComException { + return ((DecimalType) msg.convertToState(channelId, config, new MockDeviceState())).intValue(); + } +} diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandlerTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandlerTest.java index 238f1a33f..52dff9c37 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandlerTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandlerTest.java @@ -15,6 +15,7 @@ package org.openhab.binding.rfxcom.internal.handler; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.*; import java.util.Map; @@ -41,8 +42,6 @@ import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusInfo; -import org.openhab.core.thing.ThingTypeUID; -import org.openhab.core.thing.ThingUID; import org.openhab.core.thing.binding.ThingHandlerCallback; import org.openhab.core.types.Command; @@ -54,10 +53,6 @@ import org.openhab.core.types.Command; @ExtendWith(MockitoExtension.class) public class RFXComHandlerTest { - static ThingUID bridgeUID = new ThingUID("rfxcom", "tcpbridge", "rfxtrx0"); - static ThingUID thingUID = new ThingUID("rfxcom", bridgeUID, "mocked"); - static ThingTypeUID thingTypeUID = new ThingTypeUID("rfxcom", "raw"); - @Mock Bridge bridge; @@ -114,10 +109,10 @@ public class RFXComHandlerTest { private RFXComGenericDeviceConfiguration sendMessageToGetConfig(String channel, Command command) throws RFXComException { - when(messageFactory.createMessage(any(PacketType.class))).thenReturn(message); ChannelUID cuid = new ChannelUID(thing.getUID(), channel); handler.handleCommand(cuid, command); - verify(message).setConfig(deviceConfigurationCaptor.capture()); + verify(messageFactory).createMessage(any(PacketType.class), deviceConfigurationCaptor.capture(), eq(cuid), + eq(command)); return deviceConfigurationCaptor.getValue(); } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComBarometricMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComBarometricMessageTest.java index 4c07f477c..72c2de476 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComBarometricMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComBarometricMessageTest.java @@ -29,6 +29,6 @@ public class RFXComBarometricMessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.BAROMETRIC)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.BAROMETRIC, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCamera1MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCamera1MessageTest.java index 97f8b2324..64c06af80 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCamera1MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCamera1MessageTest.java @@ -29,6 +29,6 @@ public class RFXComCamera1MessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.CAMERA1)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.CAMERA1, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurtain1MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurtain1MessageTest.java index 83ef0d554..383d05a26 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurtain1MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurtain1MessageTest.java @@ -12,11 +12,17 @@ */ package org.openhab.binding.rfxcom.internal.messages; +import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.thingUID; import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.CURTAIN1; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; +import org.openhab.binding.rfxcom.internal.RFXComBindingConstants; +import org.openhab.binding.rfxcom.internal.RFXComTestHelper; +import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; +import org.openhab.core.library.types.OpenClosedType; +import org.openhab.core.thing.ChannelUID; /** * Test for RFXCom-binding @@ -25,18 +31,23 @@ import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; */ @NonNullByDefault public class RFXComCurtain1MessageTest { + private static ChannelUID shutterChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_SHUTTER); + private static RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + + static { + config.deviceId = "1.2"; + config.subType = RFXComCurtain1Message.SubType.HARRISON.toString(); + } + @Test public void checkForSupportTest() throws RFXComException { - RFXComMessageFactoryImpl.INSTANCE.createMessage(CURTAIN1); + RFXComMessageFactoryImpl.INSTANCE.createMessage(CURTAIN1, config, shutterChannelUID, OpenClosedType.OPEN); } @Test public void basicBoundaryCheck() throws RFXComException { RFXComCurtain1Message message = (RFXComCurtain1Message) RFXComMessageFactoryImpl.INSTANCE - .createMessage(CURTAIN1); - - message.subType = RFXComCurtain1Message.SubType.HARRISON; - message.command = RFXComCurtain1Message.Commands.OPEN; + .createMessage(CURTAIN1, config, shutterChannelUID, OpenClosedType.OPEN); RFXComTestHelper.basicBoundaryCheck(CURTAIN1, message); } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComDateTimeMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComDateTimeMessageTest.java index 151458ec2..cf5affcdb 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComDateTimeMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComDateTimeMessageTest.java @@ -17,6 +17,8 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; +import org.openhab.binding.rfxcom.internal.RFXComTestHelper; +import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.util.HexUtils; @@ -30,6 +32,10 @@ import org.openhab.core.util.HexUtils; public class RFXComDateTimeMessageTest { @Test public void testSomeMessages() throws RFXComException { + RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + config.deviceId = "47360"; + config.subType = RFXComDateTimeMessage.SubType.RTGR328N.toString(); + String hexMessage = "0D580117B90003041D030D150A69"; byte[] message = HexUtils.hexToBytes(hexMessage); RFXComDateTimeMessage msg = (RFXComDateTimeMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(message); @@ -37,10 +43,10 @@ public class RFXComDateTimeMessageTest { assertEquals(23, (short) (msg.seqNbr & 0xFF), "Seq Number"); assertEquals("47360", msg.getDeviceId(), "Sensor Id"); assertEquals("2003-04-29T13:21:10", msg.dateTime, "Date time"); - assertEquals(2, RFXComTestHelper.getActualIntValue(msg, CHANNEL_SIGNAL_LEVEL), "Signal Level"); + assertEquals(2, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_SIGNAL_LEVEL), "Signal Level"); assertEquals(DateTimeType.valueOf("2003-04-29T13:21:10"), - msg.convertToState(CHANNEL_DATE_TIME, new MockDeviceState()), "Converted value"); + msg.convertToState(CHANNEL_DATE_TIME, config, new MockDeviceState()), "Converted value"); byte[] decoded = msg.decodeMessage(); diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComEdisioTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComEdisioTest.java index b8463c3d7..736eed1bb 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComEdisioTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComEdisioTest.java @@ -29,6 +29,6 @@ public class RFXComEdisioTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(EDISIO)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(EDISIO, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFS20MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFS20MessageTest.java index e8ea4d13e..1add4b37f 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFS20MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFS20MessageTest.java @@ -30,6 +30,6 @@ public class RFXComFS20MessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.FS20)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.FS20, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFanMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFanMessageTest.java index c475507e8..0eb7c6b2d 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFanMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFanMessageTest.java @@ -14,15 +14,20 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; +import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.thingUID; import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.FAN; import static org.openhab.binding.rfxcom.internal.messages.RFXComFanMessage.SubType.CASAFAN; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.Test; +import org.openhab.binding.rfxcom.internal.RFXComBindingConstants; +import org.openhab.binding.rfxcom.internal.RFXComTestHelper; +import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.StringType; +import org.openhab.core.thing.ChannelUID; import org.openhab.core.types.State; import org.openhab.core.types.UnDefType; import org.openhab.core.util.HexUtils; @@ -34,19 +39,26 @@ import org.openhab.core.util.HexUtils; */ @NonNullByDefault public class RFXComFanMessageTest { + private static RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + private static ChannelUID fanSpeedChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_FAN_SPEED); + private static StringType fanSpeedOff = StringType.valueOf("OFF"); + + static { + config.deviceId = "5428224"; + config.subType = RFXComFanMessage.SubType.CASAFAN.toString(); + } + private static final MockDeviceState DEVICE_STATE = new MockDeviceState(); @Test public void checkForSupportTest() throws RFXComException { - RFXComMessageFactoryImpl.INSTANCE.createMessage(FAN); + RFXComMessageFactoryImpl.INSTANCE.createMessage(FAN, config, fanSpeedChannelUID, fanSpeedOff); } @Test public void basicBoundaryCheck() throws RFXComException { - RFXComFanMessage message = (RFXComFanMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(FAN); - - message.setSubType(RFXComFanMessage.SubType.CASAFAN); - message.convertFromState(CHANNEL_FAN_SPEED, StringType.valueOf("OFF")); + RFXComFanMessage message = (RFXComFanMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(FAN, config, + fanSpeedChannelUID, fanSpeedOff); RFXComTestHelper.basicBoundaryCheck(FAN, message); } @@ -60,9 +72,9 @@ public class RFXComFanMessageTest { assertEquals(deviceId, msg.getDeviceId(), "Sensor Id"); assertEquals(signalLevel, msg.signalLevel, "Signal Level"); - assertEquals(expectedCommand, msg.convertToState(CHANNEL_COMMAND, DEVICE_STATE)); - assertEquals(expectedLightCommand, msg.convertToState(CHANNEL_FAN_LIGHT, DEVICE_STATE)); - assertEquals(expectedFanSpeed, msg.convertToState(CHANNEL_FAN_SPEED, DEVICE_STATE)); + assertEquals(expectedCommand, msg.convertToState(CHANNEL_COMMAND, config, DEVICE_STATE)); + assertEquals(expectedLightCommand, msg.convertToState(CHANNEL_FAN_LIGHT, config, DEVICE_STATE)); + assertEquals(expectedFanSpeed, msg.convertToState(CHANNEL_FAN_SPEED, config, DEVICE_STATE)); assertEquals(packetType, msg.getPacketType()); @@ -139,10 +151,10 @@ public class RFXComFanMessageTest { private static void assertValues(RFXComFanMessage msg, @Nullable OnOffType expectedCommand, State expectedLightCommand, @Nullable State expectedFanSpeed, RFXComBaseMessage.PacketType packetType, State expectedCommandString) throws RFXComException { - assertEquals(expectedCommand, msg.convertToState(CHANNEL_COMMAND, DEVICE_STATE)); - assertEquals(expectedLightCommand, msg.convertToState(CHANNEL_FAN_LIGHT, DEVICE_STATE)); - assertEquals(expectedFanSpeed, msg.convertToState(CHANNEL_FAN_SPEED, DEVICE_STATE)); - assertEquals(expectedCommandString, msg.convertToState(CHANNEL_COMMAND_STRING, DEVICE_STATE)); + assertEquals(expectedCommand, msg.convertToState(CHANNEL_COMMAND, config, DEVICE_STATE)); + assertEquals(expectedLightCommand, msg.convertToState(CHANNEL_FAN_LIGHT, config, DEVICE_STATE)); + assertEquals(expectedFanSpeed, msg.convertToState(CHANNEL_FAN_SPEED, config, DEVICE_STATE)); + assertEquals(expectedCommandString, msg.convertToState(CHANNEL_COMMAND_STRING, config, DEVICE_STATE)); assertEquals(packetType, msg.getPacketType()); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComGasMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComGasMessageTest.java index b82f3df9c..d58e4c5d6 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComGasMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComGasMessageTest.java @@ -30,6 +30,6 @@ public class RFXComGasMessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.GAS)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.GAS, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortMessageTest.java similarity index 63% rename from bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortTest.java rename to bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortMessageTest.java index 28de642f3..549459e1e 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortMessageTest.java @@ -13,13 +13,16 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.commandChannelUID; import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.HOME_CONFORT; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; +import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; -import org.openhab.binding.rfxcom.internal.messages.RFXComHomeConfortMessage.Commands; import org.openhab.binding.rfxcom.internal.messages.RFXComHomeConfortMessage.SubType; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.types.Command; import org.openhab.core.util.HexUtils; /** @@ -29,19 +32,21 @@ import org.openhab.core.util.HexUtils; * @author Mike Jagdis - added message handling and real test */ @NonNullByDefault -public class RFXComHomeConfortTest { - private void testMessage(SubType subType, Commands command, String deviceId, String data) throws RFXComException { +public class RFXComHomeConfortMessageTest { + private void testMessage(SubType subType, Command command, String deviceId, String data) throws RFXComException { + RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + + config.deviceId = deviceId; + config.subType = subType.toString(); + RFXComHomeConfortMessage message = (RFXComHomeConfortMessage) RFXComMessageFactoryImpl.INSTANCE - .createMessage(HOME_CONFORT); - message.setSubType(subType); - message.command = command; - message.setDeviceId(deviceId); + .createMessage(HOME_CONFORT, config, commandChannelUID, command); assertArrayEquals(HexUtils.hexToBytes(data), message.decodeMessage()); } @Test public void testMessage1() throws RFXComException { - testMessage(SubType.TEL_010, Commands.GROUP_ON, "1118739.A.4", "0C1B0000111213410403000000"); + testMessage(SubType.TEL_010, OnOffType.ON, "1118739.A.4", "0C1B0000111213410401000000"); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComIOLinesMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComIOLinesMessageTest.java index 044008fd4..5ebe0b9e7 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComIOLinesMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComIOLinesMessageTest.java @@ -30,6 +30,6 @@ public class RFXComIOLinesMessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.IO_LINES)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.IO_LINES, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1MessageTest.java index 54af0ef7d..787cbbbac 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1MessageTest.java @@ -17,6 +17,7 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; +import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; import org.openhab.binding.rfxcom.internal.messages.RFXComLighting1Message.Commands; @@ -33,6 +34,12 @@ import org.openhab.core.util.HexUtils; @NonNullByDefault public class RFXComLighting1MessageTest { private final MockDeviceState deviceState = new MockDeviceState(); + private static final RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + + static { + config.deviceId = "A.1"; + config.subType = RFXComLighting1Message.SubType.ARC.toString(); + } private void testMessage(String hexMsg, RFXComLighting1Message.SubType subType, int seqNbr, String deviceId, byte signalLevel, Commands command, String commandString) throws RFXComException { @@ -43,7 +50,11 @@ public class RFXComLighting1MessageTest { assertEquals(deviceId, msg.getDeviceId(), "Sensor Id"); assertEquals(signalLevel, msg.signalLevel, "Signal Level"); assertEquals(command, msg.command, "Command"); - assertEquals(commandString, msg.convertToState(CHANNEL_COMMAND_STRING, deviceState).toString(), + + RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + config.deviceId = deviceId; + config.subType = subType.toString(); + assertEquals(commandString, msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState).toString(), "Command String"); byte[] decoded = msg.decodeMessage(); @@ -72,9 +83,9 @@ public class RFXComLighting1MessageTest { msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OFF")); - assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OpenClosedType.CLOSED, msg.convertToState(CHANNEL_CONTACT, deviceState)); - assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OpenClosedType.CLOSED, msg.convertToState(CHANNEL_CONTACT, config, deviceState)); + assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); } @Test @@ -83,9 +94,9 @@ public class RFXComLighting1MessageTest { msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("chime")); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OpenClosedType.OPEN, msg.convertToState(CHANNEL_CONTACT, deviceState)); - assertEquals(StringType.valueOf("CHIME"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OpenClosedType.OPEN, msg.convertToState(CHANNEL_CONTACT, config, deviceState)); + assertEquals(StringType.valueOf("CHIME"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); } @Test @@ -94,9 +105,9 @@ public class RFXComLighting1MessageTest { msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("bright")); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OpenClosedType.OPEN, msg.convertToState(CHANNEL_CONTACT, deviceState)); - assertEquals(StringType.valueOf("BRIGHT"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OpenClosedType.OPEN, msg.convertToState(CHANNEL_CONTACT, config, deviceState)); + assertEquals(StringType.valueOf("BRIGHT"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); } @Test @@ -105,8 +116,8 @@ public class RFXComLighting1MessageTest { msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("dim")); - assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OpenClosedType.CLOSED, msg.convertToState(CHANNEL_CONTACT, deviceState)); - assertEquals(StringType.valueOf("DIM"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OpenClosedType.CLOSED, msg.convertToState(CHANNEL_CONTACT, config, deviceState)); + assertEquals(StringType.valueOf("DIM"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting3MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting3MessageTest.java index 655698e16..fe6710508 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting3MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting3MessageTest.java @@ -31,6 +31,6 @@ public class RFXComLighting3MessageTest { public void checkNotImplemented() { // TODO Note that this message is supported in the 1.9 binding assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.LIGHTING3)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.LIGHTING3, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting4MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting4MessageTest.java index aaea64513..d4f01a4d8 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting4MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting4MessageTest.java @@ -12,21 +12,31 @@ */ package org.openhab.binding.rfxcom.internal.messages; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; +import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.*; import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.LIGHTING4; -import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting4Message.Commands.*; import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting4Message.SubType.PT2262; import java.util.Arrays; import java.util.List; +import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.Test; +import org.openhab.binding.rfxcom.internal.RFXComTestHelper; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; import org.openhab.binding.rfxcom.internal.config.RFXComLighting4DeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; +import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException; +import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType; +import org.openhab.core.config.discovery.DiscoveryResultBuilder; import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.OpenClosedType; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.ThingUID; +import org.openhab.core.types.Command; import org.openhab.core.util.HexUtils; /** @@ -36,17 +46,33 @@ import org.openhab.core.util.HexUtils; */ @NonNullByDefault public class RFXComLighting4MessageTest { + static public final ChannelUID contactChannelUID = new ChannelUID(thingUID, CHANNEL_CONTACT); + + static public void checkDiscoveryResult(RFXComDeviceMessage msg, String deviceId, + @Nullable Integer pulse, String subType) throws RFXComException { + String thingUID = "homeduino:rfxcom:fssfsd:thing"; + DiscoveryResultBuilder builder = DiscoveryResultBuilder.create(new ThingUID(thingUID)); + + // check whether the pulse is stored + msg.addDevicePropertiesTo(builder); + + Map properties = builder.build().getProperties(); + assertEquals(deviceId, properties.get("deviceId"), "Device Id"); + assertEquals(subType, properties.get("subType"), "Sub type"); + if (pulse != null) { + assertEquals(pulse, properties.get("pulse"), "Pulse"); + } + } + @Test public void basicBoundaryCheck() throws RFXComException { - RFXComLighting4Message message = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE - .createMessage(LIGHTING4); - RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration(); config.deviceId = "90000"; config.subType = "PT2262"; config.pulse = 300; - message.setConfig(config); - message.convertFromState(CHANNEL_COMMAND, OnOffType.ON); + + RFXComLighting4Message message = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE + .createMessage(LIGHTING4, config, commandChannelUID, OnOffType.ON); byte[] binaryMessage = message.decodeMessage(); RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE @@ -55,56 +81,59 @@ public class RFXComLighting4MessageTest { assertEquals("90000", msg.getDeviceId(), "Sensor Id"); } - private void testMessage(String hexMsg, RFXComLighting4Message.SubType subType, String deviceId, - @Nullable Integer pulse, RFXComLighting4Message.Commands command, @Nullable Integer seqNbr, int signalLevel, - int offCommand, int onCommand) throws RFXComException { - testMessage(hexMsg, subType, deviceId, pulse, command.toByte(), seqNbr, signalLevel, offCommand, onCommand); - } + private void testMessageWithoutCommandIds(String hexMsg, RFXComLighting4Message.SubType subType, String deviceId, + @Nullable Integer pulse, int commandByte, @Nullable Integer seqNbr, int signalLevel, Command command) + throws RFXComException { + // These tests rely on the deprecated behaviour of a "known" set of ON/OFF values and will + // be removed in a later release to be replaced with test that check we throw an exception + // if the config isn't specified (see the open/closed tests). + RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration(); + config.deviceId = deviceId; + config.subType = subType.toString(); - private void testMessage(String hexMsg, RFXComLighting4Message.SubType subType, String deviceId, - @Nullable Integer pulse, byte commandByte, @Nullable Integer seqNbr, int signalLevel, int offCommand, - int onCommand) throws RFXComException { RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE .createMessage(HexUtils.hexToBytes(hexMsg)); assertEquals(deviceId, msg.getDeviceId(), "Sensor Id"); - assertEquals(commandByte, RFXComTestHelper.getActualIntValue(msg, CHANNEL_COMMAND_ID), "Command"); + assertEquals(commandByte, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_COMMAND_ID), "Command"); if (seqNbr != null) { assertEquals(seqNbr.shortValue(), (short) (msg.seqNbr & 0xFF), "Seq Number"); } - assertEquals(signalLevel, RFXComTestHelper.getActualIntValue(msg, CHANNEL_SIGNAL_LEVEL), "Signal Level"); + assertEquals(signalLevel, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_SIGNAL_LEVEL), + "Signal Level"); + assertEquals(command, msg.convertToCommand(CHANNEL_COMMAND, config, null)); byte[] decoded = msg.decodeMessage(); assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back"); - RFXComTestHelper.checkDiscoveryResult(msg, deviceId, pulse, subType.toString(), offCommand, onCommand); + checkDiscoveryResult(msg, deviceId, pulse, subType.toString()); } @Test public void testSomeMessages() throws RFXComException { - testMessage("091300E1D8AD59018F70", PT2262, "887509", 399, ON_9, 225, 2, 4, 9); - testMessage("0913005FA9A9C901A170", PT2262, "694940", 417, ON_9, 95, 2, 4, 9); - testMessage("091300021D155C01E960", PT2262, "119125", 489, ON_12, 2, 2, 4, 12); - testMessage("091300D345DD99018C50", PT2262, "286169", 396, ON_9, 211, 2, 4, 9); - testMessage("09130035D149A2017750", PT2262, "857242", 375, OFF_2, 53, 2, 2, 1); - testMessage("0913000B4E462A012280", PT2262, "320610", 290, ON_10, 11, 3, 4, 10); - testMessage("09130009232D2E013970", PT2262, "144082", 313, OFF_14, 9, 2, 14, 1); - testMessage("091300CA0F8D2801AA70", PT2262, "63698", 426, ON_8, 202, 2, 4, 8); + testMessageWithoutCommandIds("091300E1D8AD59018F70", PT2262, "887509", 399, 9, 225, 2, OnOffType.ON); + testMessageWithoutCommandIds("0913005FA9A9C901A170", PT2262, "694940", 417, 9, 95, 2, OnOffType.ON); + testMessageWithoutCommandIds("091300021D155C01E960", PT2262, "119125", 489, 12, 2, 2, OnOffType.ON); + testMessageWithoutCommandIds("091300D345DD99018C50", PT2262, "286169", 396, 9, 211, 2, OnOffType.ON); + testMessageWithoutCommandIds("09130035D149A2017750", PT2262, "857242", 375, 2, 53, 2, OnOffType.OFF); + testMessageWithoutCommandIds("0913000B4E462A012280", PT2262, "320610", 290, 10, 11, 3, OnOffType.ON); + testMessageWithoutCommandIds("09130009232D2E013970", PT2262, "144082", 313, 14, 9, 2, OnOffType.OFF); + testMessageWithoutCommandIds("091300CA0F8D2801AA70", PT2262, "63698", 426, 8, 202, 2, OnOffType.ON); } @Test public void testSomeAlarmRemote() throws RFXComException { - testMessage("0913004A0D8998016E60", PT2262, "55449", 366, ON_8, 74, 2, 4, 8); + testMessageWithoutCommandIds("0913004A0D8998016E60", PT2262, "55449", 366, 8, 74, 2, OnOffType.ON); } @Test public void testCheapPirSensor() throws RFXComException { - testMessage("091300EF505FC6019670", PT2262, "329212", 406, ON_6, 239, 2, 4, 6); + testMessageWithoutCommandIds("091300EF505FC6019670", PT2262, "329212", 406, 6, 239, 2, OnOffType.ON); } @Test public void testSomeConradMessages() throws RFXComException { - testMessage("0913003554545401A150", PT2262, "345413", 417, OFF_4, 53, 2, 4, 1); + testMessageWithoutCommandIds("0913003554545401A150", PT2262, "345413", 417, 4, 53, 2, OnOffType.OFF); } @Test @@ -113,7 +142,7 @@ public class RFXComLighting4MessageTest { "0913004C044551013780", "0913004E044551013780"); for (String message : onMessages) { - testMessage(message, PT2262, "17493", null, ON_1, null, 3, 4, 1); + testMessageWithoutCommandIds(message, PT2262, "17493", null, 1, null, 3, OnOffType.ON); } List offMessages = Arrays.asList("09130051044554013980", "09130053044554013680", "09130055044554013680", @@ -121,7 +150,149 @@ public class RFXComLighting4MessageTest { "09130060044554013980", "09130062044554013680", "09130064044554013280"); for (String message : offMessages) { - testMessage(message, PT2262, "17493", null, OFF_4, null, 3, 4, 1); + testMessageWithoutCommandIds(message, PT2262, "17493", null, 4, null, 3, OnOffType.OFF); } } + + private void testRxWithConfig(String hexMsg, RFXComDeviceConfiguration config, + RFXComLighting4Message.SubType subType, String deviceId, @Nullable Integer pulse, int commandByte, + @Nullable Integer seqNbr, int signalLevel, ChannelUID channelUID, Command command) throws RFXComException { + RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE + .createMessage(HexUtils.hexToBytes(hexMsg)); + assertEquals(deviceId, msg.getDeviceId(), "Sensor Id"); + assertEquals(commandByte, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_COMMAND_ID), "Command"); + if (seqNbr != null) { + assertEquals(seqNbr.shortValue(), (short) (msg.seqNbr & 0xFF), "Seq Number"); + } + assertEquals(signalLevel, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_SIGNAL_LEVEL), + "Signal Level"); + assertEquals(command, msg.convertToCommand(channelUID.getId(), config, null)); + + byte[] decoded = msg.decodeMessage(); + + assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back"); + + checkDiscoveryResult(msg, deviceId, pulse, subType.toString()); + } + + @Test + public void testRxWithFullConfig() throws RFXComException { + RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration(); + config.deviceId = "12345"; + config.subType = PT2262.toString(); + config.onCommandId = 0xA; + config.offCommandId = 0xB; + config.openCommandId = 0xC; + config.closedCommandId = 0xD; + + testRxWithConfig("0913003503039A01A150", config, PT2262, "12345", 417, 0xA, 53, 2, commandChannelUID, + OnOffType.ON); + testRxWithConfig("0913003503039B01A150", config, PT2262, "12345", 417, 0xB, 53, 2, commandChannelUID, + OnOffType.OFF); + testRxWithConfig("0913003503039C01A150", config, PT2262, "12345", 417, 0xC, 53, 2, contactChannelUID, + OpenClosedType.OPEN); + testRxWithConfig("0913003503039D01A150", config, PT2262, "12345", 417, 0xD, 53, 2, contactChannelUID, + OpenClosedType.CLOSED); + } + + @Test + public void testRxWithPartialConfig() throws RFXComException { + RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration(); + config.deviceId = "12345"; + config.subType = PT2262.toString(); + config.onCommandId = 0xA; + config.openCommandId = 0xC; + + testRxWithConfig("0913003503039A01A150", config, PT2262, "12345", 417, 0xA, 53, 2, commandChannelUID, + OnOffType.ON); + assertThrows(RFXComInvalidStateException.class, () -> testRxWithConfig("0913003503039B01A150", config, PT2262, + "12345", 417, 0xB, 53, 2, commandChannelUID, OnOffType.OFF)); + testRxWithConfig("0913003503039C01A150", config, PT2262, "12345", 417, 0xC, 53, 2, contactChannelUID, + OpenClosedType.OPEN); + assertThrows(RFXComInvalidStateException.class, () -> testRxWithConfig("0913003503039D01A150", config, PT2262, + "12345", 417, 0xD, 53, 2, contactChannelUID, OpenClosedType.CLOSED)); + } + + @Test + public void testRxWithNoConfig() throws RFXComException { + RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration(); + config.deviceId = "12345"; + config.subType = PT2262.toString(); + + // These will fall back on deprecated behaviour, but should all be assertThrows in the future. + testRxWithConfig("0913003503039A01A150", config, PT2262, "12345", 417, 0xA, 53, 2, commandChannelUID, + OnOffType.ON); + testRxWithConfig("0913003503039B01A150", config, PT2262, "12345", 417, 0xB, 53, 2, commandChannelUID, + OnOffType.ON); + testRxWithConfig("0913003503039C01A150", config, PT2262, "12345", 417, 0xC, 53, 2, contactChannelUID, + OpenClosedType.OPEN); + testRxWithConfig("0913003503039D01A150", config, PT2262, "12345", 417, 0xD, 53, 2, contactChannelUID, + OpenClosedType.OPEN); + } + + private void testTxWithConfig(RFXComDeviceConfiguration config, ChannelUID channelUID, Command command, + RFXComLighting4Message.SubType subType, String deviceId, @Nullable Integer pulse, int commandByte, + String hexMsg) throws RFXComException { + RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE + .createMessage(PacketType.LIGHTING4, config, channelUID, command); + assertEquals(deviceId, msg.getDeviceId(), "Sensor Id"); + assertEquals(commandByte, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_COMMAND_ID), "Command"); + assertEquals(0, msg.seqNbr & 0xFF, "Seq Number"); + assertEquals(0, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_SIGNAL_LEVEL), "Signal Level"); + assertEquals(hexMsg, HexUtils.bytesToHex(msg.decodeMessage()), "Message bytes"); + } + + @Test + void testTxWithFullConfig() throws RFXComException { + RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration(); + config.deviceId = "703696"; + config.subType = PT2262.toString(); + config.onCommandId = 0xA; + config.offCommandId = 0xB; + config.openCommandId = 0xC; + config.closedCommandId = 0xD; + config.pulse = 417; + + testTxWithConfig(config, commandChannelUID, OnOffType.ON, PT2262, "703696", 417, 0xA, "09130000ABCD0A01A100"); + testTxWithConfig(config, commandChannelUID, OnOffType.OFF, PT2262, "703696", 417, 0xB, "09130000ABCD0B01A100"); + testTxWithConfig(config, contactChannelUID, OpenClosedType.OPEN, PT2262, "703696", 417, 0xC, + "09130000ABCD0C01A100"); + testTxWithConfig(config, contactChannelUID, OpenClosedType.CLOSED, PT2262, "703696", 417, 0xD, + "09130000ABCD0D01A100"); + } + + @Test + void testTxWithPartialConfig() throws RFXComException { + RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration(); + config.deviceId = "703696"; + config.subType = PT2262.toString(); + config.onCommandId = 0xA; + config.openCommandId = 0xC; + config.pulse = 417; + + testTxWithConfig(config, commandChannelUID, OnOffType.ON, PT2262, "703696", 417, 0xA, "09130000ABCD0A01A100"); + // Falls back on deprecated behaviour, but should be assertThrows in the future. + testTxWithConfig(config, commandChannelUID, OnOffType.OFF, PT2262, "703696", 417, 0x4, "09130000ABCD0401A100"); + testTxWithConfig(config, contactChannelUID, OpenClosedType.OPEN, PT2262, "703696", 417, 0xC, + "09130000ABCD0C01A100"); + assertThrows(RFXComInvalidStateException.class, () -> testTxWithConfig(config, contactChannelUID, + OpenClosedType.CLOSED, PT2262, "703696", 417, 0xD, "??")); + } + + @Test + void testTxWithNoConfig() throws RFXComException { + RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration(); + config.deviceId = "703696"; + config.subType = PT2262.toString(); + config.pulse = 417; + + // Falls back on deprecated behaviour, but should be assertThrows in the future. + testTxWithConfig(config, commandChannelUID, OnOffType.ON, PT2262, "703696", 417, 0x1, "09130000ABCD0101A100"); + // Falls back on deprecated behaviour, but should be assertThrows in the future. + testTxWithConfig(config, commandChannelUID, OnOffType.OFF, PT2262, "703696", 417, 0x4, "09130000ABCD0401A100"); + assertThrows(RFXComInvalidStateException.class, () -> testTxWithConfig(config, contactChannelUID, + OpenClosedType.OPEN, PT2262, "703696", 417, 0xC, "??")); + assertThrows(RFXComInvalidStateException.class, () -> testTxWithConfig(config, contactChannelUID, + OpenClosedType.CLOSED, PT2262, "703696", 417, 0xD, "??")); + } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5MessageTest.java index 64aa2bf72..1bca6cf76 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5MessageTest.java @@ -13,15 +13,16 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; +import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_COMMAND_STRING; +import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.commandChannelUID; import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.LIGHTING5; import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.Commands.*; -import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.SubType.IT; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; +import org.openhab.binding.rfxcom.internal.RFXComTestHelper; +import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; -import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.StringType; import org.openhab.core.util.HexUtils; @@ -34,30 +35,33 @@ import org.openhab.core.util.HexUtils; @NonNullByDefault public class RFXComLighting5MessageTest { private final MockDeviceState deviceState = new MockDeviceState(); + private static final RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + static { + config.deviceId = "2061.1"; + config.subType = RFXComLighting5Message.SubType.IT.toString(); + } @Test public void convertFromStateItMessage() throws RFXComException { - RFXComDeviceMessage itMessageObject = (RFXComDeviceMessage) RFXComMessageFactoryImpl.INSTANCE - .createMessage(LIGHTING5); - itMessageObject.setDeviceId("2061.1"); - itMessageObject.setSubType(IT); - itMessageObject.convertFromState(CHANNEL_COMMAND, OnOffType.ON); + RFXComMessage itMessageObject = RFXComMessageFactoryImpl.INSTANCE.createMessage(LIGHTING5, config, + commandChannelUID, OnOffType.ON); byte[] message = itMessageObject.decodeMessage(); String hexMessage = HexUtils.bytesToHex(message); assertEquals("0A140F0000080D01010000", hexMessage, "Message is not as expected"); RFXComLighting5Message msg = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE.createMessage(message); - assertEquals(IT, msg.subType, "SubType"); + assertEquals(RFXComLighting5Message.SubType.IT, msg.subType, "SubType"); assertEquals("2061.1", msg.getDeviceId(), "Sensor Id"); assertEquals(ON, msg.command, "Command"); } @Test public void basicBoundaryCheck() throws RFXComException { - RFXComLighting5Message message = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE - .createMessage(LIGHTING5); + RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + config.deviceId = "206.1"; + config.subType = RFXComLighting5Message.SubType.LIGHTWAVERF.toString(); - message.subType = RFXComLighting5Message.SubType.LIGHTWAVERF; - message.command = ON; + RFXComLighting5Message message = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE + .createMessage(LIGHTING5, config, commandChannelUID, OnOffType.ON); RFXComTestHelper.basicBoundaryCheck(LIGHTING5, message); } @@ -65,29 +69,30 @@ public class RFXComLighting5MessageTest { // TODO please add more tests for different messages @Test - public void testStringCommandOpenRelay() throws RFXComUnsupportedChannelException { + public void testStringCommandOpenRelay() throws RFXComException { RFXComLighting5Message msg = new RFXComLighting5Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OPEN_RELAY")); - assertEquals(StringType.valueOf("OPEN_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(StringType.valueOf("OPEN_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); assertEquals(OPEN_RELAY, msg.command); } @Test - public void testStringCommandCloseRelay() throws RFXComUnsupportedChannelException { + public void testStringCommandCloseRelay() throws RFXComException { RFXComLighting5Message msg = new RFXComLighting5Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("CLOSE_RELAY")); - assertEquals(StringType.valueOf("CLOSE_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(StringType.valueOf("CLOSE_RELAY"), + msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); assertEquals(CLOSE_RELAY, msg.command); } @Test - public void testStringCommandStopRelay() throws RFXComUnsupportedChannelException { + public void testStringCommandStopRelay() throws RFXComException { RFXComLighting5Message msg = new RFXComLighting5Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("STOP_RELAY")); - assertEquals(StringType.valueOf("STOP_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(StringType.valueOf("STOP_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); assertEquals(STOP_RELAY, msg.command); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComPowerMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComPowerMessageTest.java index 639763e6d..b75416a89 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComPowerMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComPowerMessageTest.java @@ -28,7 +28,7 @@ public class RFXComPowerMessageTest { @Test public void checkNotImplemented() { // TODO Note that this message is supported in the 1.9 binding - assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(RFXComBaseMessage.PacketType.POWER)); + assertThrows(RFXComMessageNotImplementedException.class, () -> RFXComMessageFactoryImpl.INSTANCE + .createMessage(RFXComBaseMessage.PacketType.POWER, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXMeterMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXMeterMessageTest.java index 5d0b48f24..45d19afc2 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXMeterMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXMeterMessageTest.java @@ -30,6 +30,6 @@ public class RFXComRFXMeterMessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.RFXMETER)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.RFXMETER, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessageTest.java index 2f9a401aa..d3690a33d 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessageTest.java @@ -89,7 +89,7 @@ public class RFXComRFXSensorMessageTest { private @Nullable Double getChannelAsDouble(String channelId, RFXComRFXSensorMessage msg, DeviceState deviceState) throws RFXComException { - return getStateAsDouble(msg.convertToState(channelId, deviceState)); + return getStateAsDouble(msg.convertToState(channelId, null, deviceState)); } private @Nullable Double getStateAsDouble(State state) { diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRadiator1MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRadiator1MessageTest.java index 088f600b8..9cf34448f 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRadiator1MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRadiator1MessageTest.java @@ -29,6 +29,6 @@ public class RFXComRadiator1MessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(RADIATOR1)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(RADIATOR1, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRawMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRawMessageTest.java index 188c7fc8b..e22d4c7f6 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRawMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRawMessageTest.java @@ -13,18 +13,18 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.junit.jupiter.api.Assertions.*; +import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.commandChannelUID; import java.nio.ByteBuffer; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; -import org.openhab.binding.rfxcom.internal.RFXComBindingConstants; import org.openhab.binding.rfxcom.internal.config.RFXComRawDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException; import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType; import org.openhab.core.library.types.OnOffType; -import org.openhab.core.types.Type; +import org.openhab.core.types.Command; import org.openhab.core.util.HexUtils; /** @@ -34,7 +34,6 @@ import org.openhab.core.util.HexUtils; */ @NonNullByDefault public class RFXComRawMessageTest { - private void testMessageRx(String hexMsg, RFXComRawMessage.SubType subType, int seqNbr, int repeat, String pulses) throws RFXComException { final RFXComRawMessage msg = (RFXComRawMessage) RFXComMessageFactoryImpl.INSTANCE @@ -53,11 +52,10 @@ public class RFXComRawMessageTest { testMessageRx("087F0027051356ECC0", RFXComRawMessage.SubType.RAW_PACKET1, 0x27, 5, "1356ECC0"); } - private void testMessageTx(RFXComRawDeviceConfiguration config, Type command, String hexMsg) + private void testMessageTx(RFXComRawDeviceConfiguration config, Command command, String hexMsg) throws RFXComException { - RFXComRawMessage msg = (RFXComRawMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.RAW); - msg.setConfig(config); - msg.convertFromState(RFXComBindingConstants.CHANNEL_COMMAND, command); + RFXComRawMessage msg = (RFXComRawMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.RAW, + config, commandChannelUID, command); byte[] decoded = msg.decodeMessage(); assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Transmitted message"); diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRemoteControlMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRemoteControlMessageTest.java index 6480e870e..6449de740 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRemoteControlMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRemoteControlMessageTest.java @@ -29,6 +29,6 @@ public class RFXComRemoteControlMessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.REMOTE_CONTROL)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.REMOTE_CONTROL, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessageTest.java index bc51015ed..0511b43d4 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessageTest.java @@ -13,13 +13,21 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.thingUID; import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.RFY; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; +import org.openhab.binding.rfxcom.internal.RFXComBindingConstants; +import org.openhab.binding.rfxcom.internal.RFXComTestHelper; +import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; -import org.openhab.binding.rfxcom.internal.messages.RFXComRfyMessage.Commands; import org.openhab.binding.rfxcom.internal.messages.RFXComRfyMessage.SubType; +import org.openhab.core.library.types.IncreaseDecreaseType; +import org.openhab.core.library.types.OpenClosedType; +import org.openhab.core.library.types.UpDownType; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.types.Command; import org.openhab.core.util.HexUtils; /** @@ -29,33 +37,40 @@ import org.openhab.core.util.HexUtils; */ @NonNullByDefault public class RFXComRfyMessageTest { + private static ChannelUID shutterChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_SHUTTER); + private static ChannelUID venetionBlindChannelUID = new ChannelUID(thingUID, + RFXComBindingConstants.CHANNEL_VENETIAN_BLIND); @Test public void basicBoundaryCheck() throws RFXComException { - RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY); + RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + config.deviceId = "1.1"; + config.subType = SubType.RFY.toString(); - message.subType = SubType.RFY; - message.command = Commands.UP; + RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY, config, + shutterChannelUID, UpDownType.UP); RFXComTestHelper.basicBoundaryCheck(RFY, message); } - private void testMessage(SubType subType, Commands command, String deviceId, String data) throws RFXComException { - RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY); - message.setSubType(subType); - message.command = command; - message.setDeviceId(deviceId); + private void testMessage(SubType subType, Command command, String deviceId, String data) throws RFXComException { + RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + config.deviceId = "66051.4"; + config.subType = subType.toString(); + + RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY, config, + venetionBlindChannelUID, command); assertArrayEquals(HexUtils.hexToBytes(data), message.decodeMessage()); } @Test public void testMessage1() throws RFXComException { - testMessage(SubType.RFY, Commands.UP_SHORT, "66051.4", "0C1A0000010203040F00000000"); + testMessage(SubType.RFY, OpenClosedType.OPEN, "66051.4", "0C1A0000010203040F00000000"); } @Test public void testMessage2() throws RFXComException { - testMessage(SubType.ASA, Commands.DOWN_LONG, "66051.4", "0C1A0300010203041200000000"); + testMessage(SubType.ASA, IncreaseDecreaseType.INCREASE, "66051.4", "0C1A0300010203041200000000"); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComTestHelper.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComTestHelper.java deleted file mode 100644 index fe7926078..000000000 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComTestHelper.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.rfxcom.internal.messages; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; -import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType; -import org.openhab.core.config.discovery.DiscoveryResultBuilder; -import org.openhab.core.library.types.DecimalType; -import org.openhab.core.thing.ThingUID; - -/** - * Helper class for testing the RFXCom-binding - * - * @author Martin van Wingerden - Initial contribution - */ -@NonNullByDefault -class RFXComTestHelper { - static void basicBoundaryCheck(PacketType packetType, RFXComMessage message) throws RFXComException { - // This is a place where its easy to make mistakes in coding, and can result in errors, normally - // array bounds errors - byte[] binaryMessage = message.decodeMessage(); - assertEquals(binaryMessage[0], binaryMessage.length - 1, "Wrong packet length"); - assertEquals(packetType.toByte(), binaryMessage[1], "Wrong packet type"); - } - - static void checkDiscoveryResult(RFXComDeviceMessage msg, String deviceId, @Nullable Integer pulse, String subType, - int offCommand, int onCommand) throws RFXComException { - String thingUID = "homeduino:rfxcom:fssfsd:thing"; - DiscoveryResultBuilder builder = DiscoveryResultBuilder.create(new ThingUID(thingUID)); - - // check whether the pulse is stored - msg.addDevicePropertiesTo(builder); - - Map properties = builder.build().getProperties(); - assertEquals(deviceId, properties.get("deviceId"), "Device Id"); - assertEquals(subType, properties.get("subType"), "Sub type"); - if (pulse != null) { - assertEquals(pulse, properties.get("pulse"), "Pulse"); - } - assertEquals(onCommand, properties.get("onCommandId"), "On command"); - assertEquals(offCommand, properties.get("offCommandId"), "Off command"); - } - - static int getActualIntValue(RFXComDeviceMessage msg, String channelId) throws RFXComException { - return ((DecimalType) msg.convertToState(channelId, new MockDeviceState())).intValue(); - } -} diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat2MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat2MessageTest.java index c582dc674..fb61a5200 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat2MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat2MessageTest.java @@ -30,6 +30,6 @@ public class RFXComThermostat2MessageTest { public void checkNotImplemented() { // TODO Note that this message is supported in the 1.9 binding assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.THERMOSTAT2)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.THERMOSTAT2, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat3MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat3MessageTest.java index fc4319441..431358e11 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat3MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat3MessageTest.java @@ -14,14 +14,16 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.junit.jupiter.api.Assertions.*; import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; +import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.commandChannelUID; import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.THERMOSTAT3; import static org.openhab.binding.rfxcom.internal.messages.RFXComThermostat3Message.SubType.*; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.jupiter.api.Test; +import org.openhab.binding.rfxcom.internal.RFXComTestHelper; +import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; -import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.StopMoveType; import org.openhab.core.library.types.StringType; @@ -37,20 +39,24 @@ import org.openhab.core.util.HexUtils; */ @NonNullByDefault public class RFXComThermostat3MessageTest { + private static RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration(); + + static { + config.deviceId = "106411"; + config.subType = RFXComThermostat3Message.SubType.MERTIK__G6R_H4S_TRANSMIT_ONLY.toString(); + } + private final MockDeviceState deviceState = new MockDeviceState(); @Test public void checkForSupportTest() throws RFXComException { - RFXComMessageFactoryImpl.INSTANCE.createMessage(THERMOSTAT3); + RFXComMessageFactoryImpl.INSTANCE.createMessage(THERMOSTAT3, config, commandChannelUID, OnOffType.ON); } @Test public void basicBoundaryCheck() throws RFXComException { RFXComThermostat3Message message = (RFXComThermostat3Message) RFXComMessageFactoryImpl.INSTANCE - .createMessage(THERMOSTAT3); - - message.subType = RFXComThermostat3Message.SubType.MERTIK__G6R_H4S_TRANSMIT_ONLY; - message.command = RFXComThermostat3Message.Commands.ON; + .createMessage(THERMOSTAT3, config, commandChannelUID, OnOffType.ON); RFXComTestHelper.basicBoundaryCheck(THERMOSTAT3, message); } @@ -77,213 +83,212 @@ public class RFXComThermostat3MessageTest { assertEquals(command, msg.command, CHANNEL_COMMAND); assertEquals(signalLevel, msg.signalLevel, "Signal Level"); - assertEquals(commandChannel, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(secondCommandChannel, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); - assertEquals(controlChannel, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(commandStringChannel, msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(commandChannel, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(secondCommandChannel, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); + assertEquals(controlChannel, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(commandStringChannel, msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); byte[] decoded = msg.decodeMessage(); assertEquals(hexMessage, HexUtils.bytesToHex(decoded), "Message converted back"); } - // TODO please add tests for real messages @Test - public void testCommandChannelOn() throws RFXComUnsupportedChannelException { + public void testCommandChannelOn() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND, OnOffType.ON); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("ON"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("ON"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testCommandChannelOff() throws RFXComUnsupportedChannelException { + public void testCommandChannelOff() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND, OnOffType.OFF); - assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); - assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); + assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); } @Test - public void testSecondCommandChannelOn() throws RFXComUnsupportedChannelException { + public void testSecondCommandChannelOn() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_SECOND, OnOffType.ON); - assertNull(msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); - assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("SECOND_ON"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("SECOND_ON"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); } @Test - public void testSecondCommandChannelOff() throws RFXComUnsupportedChannelException { + public void testSecondCommandChannelOff() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_SECOND, OnOffType.OFF); - assertNull(msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); - assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("SECOND_OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("SECOND_OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); } @Test - public void testControlUp() throws RFXComUnsupportedChannelException { + public void testControlUp() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_CONTROL, UpDownType.UP); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("UP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("UP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testControlDown() throws RFXComUnsupportedChannelException { + public void testControlDown() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_CONTROL, UpDownType.DOWN); - assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testControlStop() throws RFXComUnsupportedChannelException { + public void testControlStop() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_CONTROL, StopMoveType.STOP); - assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(StringType.valueOf("STOP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(StringType.valueOf("STOP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); - assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testCommandStringOff() throws RFXComUnsupportedChannelException { + public void testCommandStringOff() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OFF")); - assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testCommandStringOn() throws RFXComUnsupportedChannelException { + public void testCommandStringOn() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("On")); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("ON"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("ON"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testCommandStringUp() throws RFXComUnsupportedChannelException { + public void testCommandStringUp() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("UP")); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("UP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("UP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testCommandStringDown() throws RFXComUnsupportedChannelException { + public void testCommandStringDown() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("down")); - assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testCommandStringRunUp() throws RFXComUnsupportedChannelException { + public void testCommandStringRunUp() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("RUN_UP")); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("RUN_UP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("RUN_UP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testCommandStringRunDown() throws RFXComUnsupportedChannelException { + public void testCommandStringRunDown() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("RUN_DOWN")); - assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertEquals(StringType.valueOf("RUN_DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertEquals(StringType.valueOf("RUN_DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testCommandStringStop() throws RFXComUnsupportedChannelException { + public void testCommandStringStop() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("STOP")); - assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertEquals(StringType.valueOf("STOP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertEquals(StringType.valueOf("STOP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); - assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); + assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); } @Test - public void testCommandStringSecondOn() throws RFXComUnsupportedChannelException { + public void testCommandStringSecondOn() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("SECOND_ON")); - assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); - assertEquals(StringType.valueOf("SECOND_ON"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); + assertEquals(StringType.valueOf("SECOND_ON"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState)); } @Test - public void testCommandStringSecondOff() throws RFXComUnsupportedChannelException { + public void testCommandStringSecondOff() throws RFXComException { RFXComThermostat3Message msg = new RFXComThermostat3Message(); msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("SECOND_OFF")); - assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState)); - assertEquals(StringType.valueOf("SECOND_OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState)); + assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState)); + assertEquals(StringType.valueOf("SECOND_OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState)); - assertNull(msg.convertToState(CHANNEL_COMMAND, deviceState)); - assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState)); + assertNull(msg.convertToState(CHANNEL_COMMAND, config, deviceState)); + assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat4MessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat4MessageTest.java index a724aa902..d6e6d9fac 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat4MessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat4MessageTest.java @@ -29,6 +29,6 @@ public class RFXComThermostat4MessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(THERMOSTAT4)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(THERMOSTAT4, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComUndecodedRFMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComUndecodedRFMessageTest.java index 0fe249b5e..09bc5d3a5 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComUndecodedRFMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComUndecodedRFMessageTest.java @@ -18,7 +18,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComMessageTooLongException; -import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType; import org.openhab.core.util.HexUtils; /** @@ -51,12 +50,9 @@ public class RFXComUndecodedRFMessageTest { @Test public void testLongMessage() throws RFXComException { - RFXComUndecodedRFMessage msg = (RFXComUndecodedRFMessage) RFXComMessageFactoryImpl.INSTANCE - .createMessage(PacketType.UNDECODED_RF_MESSAGE); - msg.subType = RFXComUndecodedRFMessage.SubType.ARC; - msg.seqNbr = 1; - msg.rawPayload = HexUtils.hexToBytes("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021"); - - assertThrows(RFXComMessageTooLongException.class, () -> msg.decodeMessage()); + assertThrows(RFXComMessageTooLongException.class, + () -> testMessage("25030101000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021", + RFXComUndecodedRFMessage.SubType.ARC, 0x01, + "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021")); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWaterMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWaterMessageTest.java index 163fd5c63..52ebe29e0 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWaterMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWaterMessageTest.java @@ -30,6 +30,6 @@ public class RFXComWaterMessageTest { @Test public void checkNotImplemented() { assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.WATER)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.WATER, null, null, null)); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWeightMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWeightMessageTest.java index 96789f029..bb57550b6 100644 --- a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWeightMessageTest.java +++ b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWeightMessageTest.java @@ -30,6 +30,6 @@ public class RFXComWeightMessageTest { public void checkNotImplemented() { // TODO Note that this message is supported in the 1.9 binding assertThrows(RFXComMessageNotImplementedException.class, - () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.WEIGHT)); + () -> RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.WEIGHT, null, null, null)); } }