From 68017157703290a5ad5e61f51b367b8ca21d1362 Mon Sep 17 00:00:00 2001 From: James Hewitt Date: Sun, 18 Jul 2021 20:37:44 +0100 Subject: [PATCH] [rfxcom] Add ability to properly receive configured command ids, deprecated hard-coded guesses. (#10940) Currently, when a message is received the command will be determined only from the hard-coded set of ON/OFF commands, which means if I configure a thing and attach it to a switch there is no guarantee that it will respond as expected to receive commands. This PR changes the message factory to require either bytes (from the RFXcom device) or all the details required to make a transmissable message, including the confguration of the associated Thing. At the moment, this is only used by lighting4 and raw types, but I expect it will be useful for others in the future. The hard-coded ON/OFF commands in lighting4 are based on experimentation with different devices, and are not at all consistent. This PR deprecates the use of those so that in a future release, Lighting4 devices will only work when configured with the correct command ids up front. This will resolve inconsistent behaviour where devices that have been discovered may work correctly, work only for ON or OFF but not both, have ON and OFF the wrong way around, turn ON one physical device and OFF another, or any combination of those possibilities. Signed-off-by: James Hewitt --- bundles/org.openhab.binding.rfxcom/README.md | 150 ++++++----- .../RFXComLighting4DeviceConfiguration.java | 4 + .../internal/handler/RFXComBridgeHandler.java | 4 +- .../internal/handler/RFXComHandler.java | 19 +- .../messages/RFXComBBQTemperatureMessage.java | 7 +- .../messages/RFXComBatteryDeviceMessage.java | 7 +- .../messages/RFXComBlinds1Message.java | 7 +- .../internal/messages/RFXComChimeMessage.java | 7 +- .../messages/RFXComCurrentEnergyMessage.java | 7 +- .../messages/RFXComCurrentMessage.java | 7 +- .../messages/RFXComCurtain1Message.java | 7 +- .../messages/RFXComDateTimeMessage.java | 7 +- .../messages/RFXComDeviceMessage.java | 11 +- .../messages/RFXComDeviceMessageImpl.java | 10 +- .../messages/RFXComEnergyMessage.java | 7 +- .../internal/messages/RFXComFanMessage.java | 7 +- .../messages/RFXComHomeConfortMessage.java | 7 +- .../messages/RFXComHumidityMessage.java | 7 +- .../messages/RFXComInterfaceMessage.java | 2 +- .../messages/RFXComLighting1Message.java | 16 +- .../messages/RFXComLighting2Message.java | 7 +- .../messages/RFXComLighting4Message.java | 195 ++++++++------- .../messages/RFXComLighting5Message.java | 7 +- .../messages/RFXComLighting6Message.java | 7 +- .../messages/RFXComMessageFactory.java | 7 +- .../messages/RFXComMessageFactoryImpl.java | 11 +- .../messages/RFXComRFXSensorMessage.java | 7 +- .../internal/messages/RFXComRainMessage.java | 7 +- .../internal/messages/RFXComRawMessage.java | 3 +- .../internal/messages/RFXComRfyMessage.java | 7 +- .../messages/RFXComSecurity1Message.java | 7 +- .../messages/RFXComSecurity2Message.java | 7 +- ...mTemperatureHumidityBarometricMessage.java | 7 +- .../RFXComTemperatureHumidityMessage.java | 7 +- .../messages/RFXComTemperatureMessage.java | 7 +- .../RFXComTemperatureRainMessage.java | 7 +- .../messages/RFXComThermostat1Message.java | 7 +- .../messages/RFXComThermostat3Message.java | 7 +- .../internal/messages/RFXComUVMessage.java | 7 +- .../messages/RFXComUndecodedRFMessage.java | 4 +- .../internal/messages/RFXComWindMessage.java | 7 +- .../main/resources/OH-INF/thing/lighting4.xml | 64 ++--- .../rfxcom/internal/RFXComTestHelper.java | 54 ++++ .../internal/handler/RFXComHandlerTest.java | 11 +- .../messages/RFXComBarometricMessageTest.java | 2 +- .../messages/RFXComCamera1MessageTest.java | 2 +- .../messages/RFXComCurtain1MessageTest.java | 21 +- .../messages/RFXComDateTimeMessageTest.java | 10 +- .../internal/messages/RFXComEdisioTest.java | 2 +- .../messages/RFXComFS20MessageTest.java | 2 +- .../messages/RFXComFanMessageTest.java | 36 ++- .../messages/RFXComGasMessageTest.java | 2 +- ...java => RFXComHomeConfortMessageTest.java} | 21 +- .../messages/RFXComIOLinesMessageTest.java | 2 +- .../messages/RFXComLighting1MessageTest.java | 37 ++- .../messages/RFXComLighting3MessageTest.java | 2 +- .../messages/RFXComLighting4MessageTest.java | 233 +++++++++++++++--- .../messages/RFXComLighting5MessageTest.java | 43 ++-- .../messages/RFXComPowerMessageTest.java | 4 +- .../messages/RFXComRFXMeterMessageTest.java | 2 +- .../messages/RFXComRFXSensorMessageTest.java | 2 +- .../messages/RFXComRadiator1MessageTest.java | 2 +- .../messages/RFXComRawMessageTest.java | 12 +- .../RFXComRemoteControlMessageTest.java | 2 +- .../messages/RFXComRfyMessageTest.java | 37 ++- .../internal/messages/RFXComTestHelper.java | 63 ----- .../RFXComThermostat2MessageTest.java | 2 +- .../RFXComThermostat3MessageTest.java | 187 +++++++------- .../RFXComThermostat4MessageTest.java | 2 +- .../RFXComUndecodedRFMessageTest.java | 12 +- .../messages/RFXComWaterMessageTest.java | 2 +- .../messages/RFXComWeightMessageTest.java | 2 +- 72 files changed, 916 insertions(+), 591 deletions(-) create mode 100644 bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/RFXComTestHelper.java rename bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/{RFXComHomeConfortTest.java => RFXComHomeConfortMessageTest.java} (63%) delete mode 100644 bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComTestHelper.java diff --git a/bundles/org.openhab.binding.rfxcom/README.md b/bundles/org.openhab.binding.rfxcom/README.md index 172b6c20fca4e..2931b23fb0599 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 - - * 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 OFF for this device. -#### Examples +* 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 -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. +There are a number of ways to detect the commandId values for your device. -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. +- 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. -For a USB attached RFXCOM on Windows the configuration could look like this (note that the `onCommandId`, `offCommandId` and `pulse` are all optional): +#### Examples + +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: - -``` -rule "Set random relay variations" - when - System started or - Time cron "/20 * * * * ?" - then - SwitchCommandId.sendCommand((Math::random * 15.9).intValue) -end -``` - -#### 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) | +#### Known commandIds + +These are some commandIds from the field that may match your devices. + +| 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 f1244edaf05f0..c4d54e5917811 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 092ebf4364769..8880881862e41 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 synchronized void send() throws IOException { 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 992015902859b..04a247e86b6a1 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 void handleCommand(ChannelUID channelUID, Command command) { 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 void onDeviceMessageReceived(ThingUID bridge, RFXComDeviceMessage message 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 void onDeviceMessageReceived(ThingUID bridge, RFXComDeviceMessage message 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 99d00360cec91..f4c27532f92c5 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 @@ 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 String getDeviceId() { } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { if (CHANNEL_FOOD_TEMPERATURE.equals(channelId)) { return new DecimalType(foodTemperature); } else if (CHANNEL_BBQ_TEMPERATURE.equals(channelId)) { return new DecimalType(bbqTemperature); } else { - 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/RFXComBatteryDeviceMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBatteryDeviceMessage.java index 92eec8e1ba497..f6f1e5cba157f 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBatteryDeviceMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBatteryDeviceMessage.java @@ -14,6 +14,8 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_BATTERY_LEVEL; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; +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.library.types.DecimalType; @@ -36,13 +38,14 @@ abstract class 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 11aa77bdbb32f..ed1648568c00e 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 @@ 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 String getDeviceId() { } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { if (CHANNEL_COMMAND.equals(channelId)) { return (command == Commands.CLOSE ? OpenClosedType.CLOSED : OpenClosedType.OPEN); } else { - 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/RFXComChimeMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComChimeMessage.java index 7640e56c15731..9d56a328a156a 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComChimeMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComChimeMessage.java @@ -15,7 +15,9 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_CHIME_SOUND; 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; @@ -133,11 +135,12 @@ public String getDeviceId() { } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { if (CHANNEL_CHIME_SOUND.equals(channelId)) { return new DecimalType(chimeSound); } else { - 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/RFXComCurrentEnergyMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurrentEnergyMessage.java index 44b123636633a..e1535d48a744f 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurrentEnergyMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurrentEnergyMessage.java @@ -15,7 +15,9 @@ 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; @@ -136,7 +138,8 @@ public byte[] decodeMessage() { } @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_CHANNEL1_AMPS: return new DecimalType(channel1Amps); @@ -151,7 +154,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new DecimalType(totalUsage); 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/RFXComCurrentMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurrentMessage.java index a4184fd3a7ad3..e4821229278e1 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurrentMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurrentMessage.java @@ -15,7 +15,9 @@ 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; @@ -125,7 +127,8 @@ public byte[] decodeMessage() { } @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_CHANNEL1_AMPS: return new DecimalType(channel1Amps); @@ -137,7 +140,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new DecimalType(channel3Amps); 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/RFXComCurtain1Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurtain1Message.java index f5cf61194a56f..4f09b3211380a 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurtain1Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurtain1Message.java @@ -15,7 +15,9 @@ 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; @@ -131,11 +133,12 @@ public String getDeviceId() { } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { if (channelId.equals(CHANNEL_COMMAND)) { return (command == Commands.CLOSE ? OpenClosedType.CLOSED : OpenClosedType.OPEN); } else { - 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/RFXComDateTimeMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDateTimeMessage.java index 0d77d92685e31..7d63b83a9c365 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDateTimeMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDateTimeMessage.java @@ -15,7 +15,9 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_DATE_TIME; 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; @@ -122,11 +124,12 @@ public byte[] decodeMessage() { } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { if (channelId.equals(CHANNEL_DATE_TIME)) { return new DateTimeType(dateTime); } else { - 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/RFXComDeviceMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDeviceMessage.java index 2628834589c9f..3737f8026cbb7 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDeviceMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDeviceMessage.java @@ -14,6 +14,7 @@ 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; @@ -31,21 +32,27 @@ public interface RFXComDeviceMessage 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 ed4de3e361b43..6eadde867d12b 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 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 @@ public void setConfig(RFXComDeviceConfiguration config) throws RFXComException { } @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 be24d3c4c8283..c679e018122b7 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 @@ 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 String getDeviceId() { } @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_INSTANT_POWER: return new DecimalType(instantPower); @@ -160,7 +163,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new DecimalType(totalAmpHour); 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/RFXComFanMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComFanMessage.java index feecca8979920..5931d37aaf2c5 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComFanMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComFanMessage.java @@ -21,7 +21,9 @@ import java.util.List; import org.eclipse.jdt.annotation.Nullable; +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; @@ -263,7 +265,8 @@ public SubType convertSubType(String subType) throws RFXComUnsupportedValueExcep } @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_FAN_LIGHT: return handleLightChannel(); @@ -278,7 +281,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return handleCommandStringChannel(); 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/RFXComHomeConfortMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortMessage.java index a5e289f1468ee..a20b19d639e4a 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortMessage.java @@ -15,7 +15,9 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_COMMAND; 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; @@ -125,11 +127,12 @@ public String getDeviceId() { } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { if (channelId.equals(CHANNEL_COMMAND)) { return (command == Commands.OFF || command == Commands.GROUP_OFF ? OnOffType.OFF : OnOffType.ON); } else { - 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/RFXComHumidityMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComHumidityMessage.java index be7435fafd80d..ba5fa8e544ccd 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComHumidityMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComHumidityMessage.java @@ -15,7 +15,9 @@ 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; @@ -129,7 +131,8 @@ public String getDeviceId() { } @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_HUMIDITY: return new DecimalType(humidity); @@ -138,7 +141,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new StringType(humidityStatus.toString()); 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/RFXComInterfaceMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComInterfaceMessage.java index d225a8a595ecd..1f83bd69b767e 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComInterfaceMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComInterfaceMessage.java @@ -271,7 +271,7 @@ private void encodeResponseMessage(byte[] data) throws RFXComException { transceiverType = TransceiverType._UNKNOWN; logger.warn( "The transceiver type reported ({}) isn't known to the RFXCom binding. Please raise an issue at https://github.com/openhab/openhab-addons/ to have it included.", - data[5]); + Byte.toUnsignedInt(data[5])); } hardwareVersion1 = data[11]; diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1Message.java index bdd6fa6f5071d..2a42d9e81945d 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1Message.java @@ -14,7 +14,9 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; +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; @@ -126,11 +128,11 @@ public void encodeMessage(byte[] data) throws RFXComException { // the message unless the last X 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 String getDeviceId() { } @Override - public Command convertToCommand(String channelId, DeviceState deviceState) - throws RFXComUnsupportedChannelException { + public Command convertToCommand(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { switch (channelId) { case CHANNEL_COMMAND: switch (command) { @@ -190,11 +192,13 @@ public Command convertToCommand(String channelId, DeviceState deviceState) } default: - return super.convertToCommand(channelId, deviceState); + return super.convertToCommand(channelId, config, deviceState); } } - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + @Override + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException { switch (channelId) { case CHANNEL_COMMAND: switch (command) { diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting2Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting2Message.java index 2c84bcbf71b6a..fb584c5c36401 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting2Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting2Message.java @@ -20,7 +20,9 @@ import java.math.BigDecimal; import java.math.RoundingMode; +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; @@ -173,7 +175,8 @@ public static PercentType getPercentTypeFromDimLevel(int value) { } @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_DIMMING_LEVEL: return RFXComLighting2Message.getPercentTypeFromDimLevel(dimmingLevel); @@ -211,7 +214,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF } 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/RFXComLighting4Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting4Message.java index 20321f6917548..2a74d0e5a4ae3 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting4Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting4Message.java @@ -13,12 +13,17 @@ package org.openhab.binding.rfxcom.internal.messages; import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*; -import static org.openhab.binding.rfxcom.internal.config.RFXComLighting4DeviceConfiguration.*; -import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte; +import static org.openhab.binding.rfxcom.internal.config.RFXComLighting4DeviceConfiguration.PULSE_LABEL; + +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; 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.exceptions.RFXComUnsupportedChannelException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException; import org.openhab.binding.rfxcom.internal.handler.DeviceState; @@ -28,8 +33,6 @@ import org.openhab.core.library.types.OpenClosedType; import org.openhab.core.types.State; import org.openhab.core.types.Type; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * RFXCOM data class for lighting4 message. @@ -57,14 +60,10 @@ * @author Alessandro Ballini (ITA) - Initial contribution * @author Pauli Anttila - Migrated to OH2 * @author Martin van Wingerden - Extended support for more complex PT2262 devices + * @author James Hewitt - Use the thing config to identify what incoming commandIds map to + * @author James Hewitt - Deprecate using previously discovered commandIds because they are unreliable */ public class RFXComLighting4Message 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 byte toByte() { } } - public enum Commands implements ByteEnumWrapper { - OFF_0(0, false), - ON_1(1, true), - OFF_2(2, false), - ON_3(3, true), - OFF_4(4, false), - ON_5(5, true), - ON_6(6, true), - ON_7(7, true), - ON_8(8, true), - ON_9(9, true), - ON_10(10, true), - ON_11(11, true), - ON_12(12, true), - OFF_14(14, false), - ON_15(15, true), - UNKNOWN(-1, false); - - private final int command; - private final boolean on; - - Commands(int command, boolean on) { - this.command = command; - this.on = on; - } - - @Override - public byte toByte() { - return (byte) command; - } - - public boolean isOn() { - return on; - } - - public static Commands fromByte(int input) { - for (Commands c : Commands.values()) { - if (c.command == input) { - return c; - } - } - LOGGER.info( - "A not completely supported command with value {} was received, we can send it but please report " - + "it as an issue including what the command means, this helps to extend the binding with better support.", - input); - return UNKNOWN; - } - } + // These are historical behaviour, are deprecated, and will be removed in a future openHAB release. + @Deprecated + private static final byte DEFAULT_OFF_COMMAND_ID = 4; + @Deprecated + private static final byte DEFAULT_ON_COMMAND_ID = 1; + @Deprecated + private Set 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 String toString() { str += super.toString(); str += ", Sub type = " + subType; str += ", Device Id = " + getDeviceId(); - str += ", Command = " + command + "(" + commandId + ")"; + str += ", Command Id = " + commandId; str += ", Pulse = " + pulse; return str; @@ -162,13 +120,10 @@ public String toString() { public void encodeMessage(byte[] data) throws RFXComException { super.encodeMessage(data); - subType = fromByte(SubType.class, super.subType); + subType = ByteEnumUtil.fromByte(SubType.class, super.subType); sensorId = (data[4] & 0xFF) << 12 | (data[5] & 0xFF) << 4 | (data[6] & 0xF0) >> 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 String getDeviceId() { } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration configuration, DeviceState deviceState) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { + RFXComLighting4DeviceConfiguration config = (RFXComLighting4DeviceConfiguration) configuration; + switch (channelId) { case CHANNEL_COMMAND: case CHANNEL_MOTION: - return command.isOn() ? OnOffType.ON : OnOffType.OFF; + if (config.onCommandId != null && commandId == config.onCommandId) { + return OnOffType.ON; + } + if (config.offCommandId != null && commandId == config.offCommandId) { + return OnOffType.OFF; + } + // Deprecated if statement - to be removed in a future release + if (config.onCommandId == null && config.offCommandId == null) { + return ON_COMMAND_IDS.contains(commandId) ? OnOffType.ON : OnOffType.OFF; + } + throw new RFXComInvalidStateException(channelId, Integer.toString(commandId), + "Device not configured for received commandId"); case CHANNEL_CONTACT: - return command.isOn() ? OpenClosedType.OPEN : OpenClosedType.CLOSED; + if (config.openCommandId != null && commandId == config.openCommandId) { + return OpenClosedType.OPEN; + } + if (config.closedCommandId != null && commandId == config.closedCommandId) { + return OpenClosedType.CLOSED; + } + // Deprecated if statement - to be removed in a future release + if (config.onCommandId == null && config.offCommandId == null) { + return ON_COMMAND_IDS.contains(commandId) ? OpenClosedType.OPEN : OpenClosedType.CLOSED; + } + throw new RFXComInvalidStateException(channelId, Integer.toString(commandId), + "Device not configured for received commandId"); case CHANNEL_COMMAND_ID: return new DecimalType(commandId); default: - return super.convertToState(channelId, deviceState); + return super.convertToState(channelId, config, deviceState); } } @@ -233,30 +213,70 @@ public void setDeviceId(String deviceId) { } @Override - public void convertFromState(String channelId, Type type) throws RFXComUnsupportedChannelException { + public void convertFromState(String channelId, Type type) + throws RFXComUnsupportedChannelException, RFXComInvalidStateException { switch (channelId) { case CHANNEL_COMMAND: if (type instanceof OnOffType) { - command = Commands.fromByte(type == OnOffType.ON ? onCommandId : offCommandId); - commandId = command.toByte(); + if (type == OnOffType.ON) { + if (config.onCommandId != null) { + commandId = config.onCommandId; + } else { + // Deprecated - to throw RFXComInvalidStateException in a future release, see contact + // channel + commandId = DEFAULT_ON_COMMAND_ID; + } + } + if (type == OnOffType.OFF) { + if (config.offCommandId != null) { + commandId = config.offCommandId; + } else { + // Deprecated - to throw RFXComInvalidStateException in a future release, see contact + // channel + commandId = DEFAULT_OFF_COMMAND_ID; + } + } + } else { + throw new RFXComInvalidStateException(channelId, type.toString(), + "Channel only supports OnOffType"); + } + break; + case CHANNEL_CONTACT: + if (type instanceof OpenClosedType) { + if (type == OpenClosedType.OPEN) { + if (config.openCommandId != null) { + commandId = config.openCommandId; + } else { + throw new RFXComInvalidStateException(channelId, type.toString(), + "openCommandId not configured for this device"); + } + } + if (type == OpenClosedType.CLOSED) { + if (config.closedCommandId != null) { + commandId = config.closedCommandId; + } else { + throw new RFXComInvalidStateException(channelId, type.toString(), + "closedCommandId not configured for this device"); + } + } } else { - throw new RFXComUnsupportedChannelException("Channel " + channelId + " does not accept " + type); + throw new RFXComInvalidStateException(channelId, type.toString(), + "Channel only supports OpenClosedType"); } break; case CHANNEL_COMMAND_ID: if (type instanceof DecimalType) { - commandId = ((DecimalType) type).toBigDecimal().byteValue(); - command = Commands.fromByte(commandId); - + commandId = (byte) ((DecimalType) type).intValue(); } else { - throw new RFXComUnsupportedChannelException("Channel " + channelId + " does not accept " + type); + throw new RFXComInvalidStateException(channelId, type.toString(), + "Channel only supports DecimalType"); } break; default: - throw new RFXComUnsupportedChannelException("Channel " + channelId + " is not relevant here"); + throw new RFXComUnsupportedChannelException("Channel " + channelId + " is not supported by Lighting4"); } } @@ -269,23 +289,12 @@ public SubType convertSubType(String subType) throws RFXComUnsupportedValueExcep public void addDevicePropertiesTo(DiscoveryResultBuilder discoveryResultBuilder) throws RFXComException { super.addDevicePropertiesTo(discoveryResultBuilder); discoveryResultBuilder.withProperty(PULSE_LABEL, pulse); - discoveryResultBuilder.withProperty(ON_COMMAND_ID_LABEL, onCommandId); - discoveryResultBuilder.withProperty(OFF_COMMAND_ID_LABEL, offCommandId); } @Override public void setConfig(RFXComDeviceConfiguration config) throws RFXComException { - RFXComLighting4DeviceConfiguration lighting4Config = (RFXComLighting4DeviceConfiguration) config; - super.setConfig(lighting4Config); - this.pulse = lighting4Config.pulse != null ? lighting4Config.pulse : 350; - this.onCommandId = valueOrDefault(lighting4Config.onCommandId, DEFAULT_ON_COMMAND_ID); - this.offCommandId = valueOrDefault(lighting4Config.offCommandId, DEFAULT_OFF_COMMAND_ID); - } - - private int valueOrDefault(Integer commandId, byte defaultValue) { - if (commandId != null) { - return commandId; - } - return defaultValue; + super.setConfig(config); + this.config = (RFXComLighting4DeviceConfiguration) config; + this.pulse = this.config.pulse != null ? this.config.pulse : 350; } } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5Message.java index 3602810be1ac8..9cf4e845a9989 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5Message.java @@ -21,7 +21,9 @@ import java.util.Arrays; import java.util.List; +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; @@ -234,7 +236,8 @@ public static PercentType getPercentTypeFromDimLevel(int value) { } @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_MOOD: switch (command) { @@ -292,7 +295,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF } 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/RFXComLighting6Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting6Message.java index ae35088023646..f468367a2f66c 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting6Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting6Message.java @@ -15,7 +15,9 @@ 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; @@ -134,7 +136,8 @@ public String getDeviceId() { } @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_COMMAND: switch (command) { @@ -165,7 +168,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF } 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/RFXComMessageFactory.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessageFactory.java index d555a32f58d32..c320e21022830 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessageFactory.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessageFactory.java @@ -12,8 +12,11 @@ */ package org.openhab.binding.rfxcom.internal.messages; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.types.Command; /** * Factory to create RFXCom messages from either bytes delivered by the RFXCom device @@ -21,9 +24,11 @@ * * @author Pauli Anttila - Initial contribution * @author James Hewitt-Thomas - Convert to interface to allow dependency injection + * @author James Hewitt-Thomas - Switch to making messages for a specific command */ public interface RFXComMessageFactory { - public RFXComMessage createMessage(PacketType packetType) throws RFXComException; + public RFXComMessage createMessage(PacketType packetType, RFXComDeviceConfiguration config, ChannelUID channelUID, + Command command) throws RFXComException; public RFXComMessage createMessage(byte[] packet) throws RFXComException; } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessageFactoryImpl.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessageFactoryImpl.java index 6098d437c563f..b45922dabbbaf 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessageFactoryImpl.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessageFactoryImpl.java @@ -18,9 +18,12 @@ import java.util.HashMap; import java.util.Map; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComMessageNotImplementedException; import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.types.Command; /** * Factory to create RFXCom messages from either bytes delivered by the RFXCom device @@ -98,13 +101,17 @@ public enum RFXComMessageFactoryImpl implements RFXComMessageFactory { * Create message for transmission from the packet type associated with the thing. */ @Override - public RFXComMessage createMessage(PacketType packetType) throws RFXComException { + public RFXComMessage createMessage(PacketType packetType, RFXComDeviceConfiguration config, ChannelUID channelUID, + Command command) throws RFXComException { try { Class 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 e5af3962a5eb4..539f92498f5f4 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 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 void setSubType(SubType subType) { } @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_TEMPERATURE: return subType == SubType.TEMPERATURE ? getTemperature() : null; @@ -219,7 +222,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return subType == SubType.A_D ? handlePressure(deviceState) : null; 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/RFXComRainMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRainMessage.java index 293f2bc8c9366..58303e741bf0d 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRainMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRainMessage.java @@ -15,7 +15,9 @@ 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; @@ -135,7 +137,8 @@ public String getDeviceId() { } @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_RAIN_RATE: return new DecimalType(rainRate); @@ -144,7 +147,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new DecimalType(rainTotal); 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/RFXComRawMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRawMessage.java index 1aa27620be3bf..bf28863ba939f 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRawMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRawMessage.java @@ -142,7 +142,8 @@ public void setConfig(RFXComDeviceConfiguration config) throws RFXComException { } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException { switch (channelId) { case CHANNEL_RAW_MESSAGE: return new StringType(HexUtils.bytesToHex(rawMessage)); diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessage.java index d5cf2e19a971a..b185389e698b0 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessage.java @@ -15,7 +15,9 @@ 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; @@ -134,13 +136,14 @@ public String getDeviceId() { } @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_COMMAND: return (command == Commands.DOWN ? OpenClosedType.CLOSED : OpenClosedType.OPEN); 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/RFXComSecurity1Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComSecurity1Message.java index 3e13fd8e22280..7385770bef21f 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComSecurity1Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComSecurity1Message.java @@ -15,7 +15,9 @@ 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; @@ -233,7 +235,8 @@ public String getDeviceId() { } @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_MOTION: switch (status) { @@ -263,7 +266,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new StringType(status.toString()); 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/RFXComSecurity2Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComSecurity2Message.java index 3dbb357d62f9d..7f7931e6ff888 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComSecurity2Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComSecurity2Message.java @@ -17,7 +17,9 @@ import java.util.Arrays; +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; @@ -115,7 +117,8 @@ public String getDeviceId() { } @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_CONTACT: return ((buttonStatus & BUTTON_0_BIT) == 0) ? OpenClosedType.CLOSED : OpenClosedType.OPEN; @@ -130,7 +133,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return ((buttonStatus & BUTTON_3_BIT) == 0) ? OpenClosedType.CLOSED : OpenClosedType.OPEN; 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/RFXComTemperatureHumidityBarometricMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureHumidityBarometricMessage.java index 349c5cc3fb83f..9c04bf120dd35 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureHumidityBarometricMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureHumidityBarometricMessage.java @@ -15,7 +15,9 @@ 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; @@ -178,7 +180,8 @@ public String getDeviceId() { } @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_TEMPERATURE: return new DecimalType(temperature); @@ -196,7 +199,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new StringType(forecastStatus.toString()); 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/RFXComTemperatureHumidityMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureHumidityMessage.java index ff3f21dd1b80e..17f850f8355b0 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureHumidityMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureHumidityMessage.java @@ -15,7 +15,9 @@ 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; @@ -158,7 +160,8 @@ public String getDeviceId() { } @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_TEMPERATURE: return new DecimalType(temperature); @@ -170,7 +173,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new StringType(humidityStatus.toString()); 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/RFXComTemperatureMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureMessage.java index f57298e3fe11c..eb6c113f15534 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureMessage.java @@ -15,7 +15,9 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_TEMPERATURE; 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; @@ -126,13 +128,14 @@ public String getDeviceId() { } @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_TEMPERATURE: return new DecimalType(temperature); 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/RFXComTemperatureRainMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureRainMessage.java index d591a9f05df36..b67d25a20bbd8 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureRainMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureRainMessage.java @@ -15,7 +15,9 @@ 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; @@ -120,7 +122,8 @@ public byte[] decodeMessage() { } @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_TEMPERATURE: return new DecimalType(temperature); @@ -129,7 +132,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new DecimalType(rainTotal); 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/RFXComThermostat1Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat1Message.java index eda9c10395a03..c5577e79cf04d 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat1Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat1Message.java @@ -15,7 +15,9 @@ 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; @@ -155,7 +157,8 @@ public String getDeviceId() { } @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_TEMPERATURE: return new DecimalType(temperature); @@ -174,7 +177,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF } 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/RFXComThermostat3Message.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat3Message.java index 24e628bb654f2..024d8fbbe61bc 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat3Message.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat3Message.java @@ -19,7 +19,9 @@ import java.util.Arrays; import java.util.List; +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; @@ -152,7 +154,8 @@ public byte[] decodeMessage() { } @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_COMMAND: switch (command) { @@ -202,7 +205,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return command == null ? UnDefType.UNDEF : StringType.valueOf(command.toString()); 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/RFXComUVMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComUVMessage.java index f64656ee3b386..f861bd0048dab 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComUVMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComUVMessage.java @@ -15,7 +15,9 @@ 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; @@ -125,7 +127,8 @@ public String getDeviceId() { } @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_UV: return new DecimalType(uv); @@ -134,7 +137,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return (subType == SubType.UV3 ? new DecimalType(temperature) : UnDefType.UNDEF); 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/RFXComUndecodedRFMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComUndecodedRFMessage.java index 456510707913e..387791ddd41d7 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComUndecodedRFMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComUndecodedRFMessage.java @@ -17,6 +17,7 @@ import java.util.Arrays; +import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration; import org.openhab.binding.rfxcom.internal.exceptions.RFXComException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComMessageTooLongException; import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException; @@ -140,7 +141,8 @@ public String getDeviceId() { } @Override - public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException { + public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState) + throws RFXComUnsupportedChannelException { switch (channelId) { case CHANNEL_RAW_MESSAGE: return new StringType(HexUtils.bytesToHex(rawMessage)); diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComWindMessage.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComWindMessage.java index a0c577ea82a76..75d70974b77ba 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComWindMessage.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComWindMessage.java @@ -15,7 +15,9 @@ 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; @@ -168,7 +170,8 @@ public String getDeviceId() { } @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_WIND_DIRECTION: return new DecimalType(windDirection); @@ -186,7 +189,7 @@ public State convertToState(String channelId, DeviceState deviceState) throws RF return new DecimalType(chillTemperature); default: - return super.convertToState(channelId, deviceState); + return super.convertToState(channelId, config, deviceState); } } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/resources/OH-INF/thing/lighting4.xml b/bundles/org.openhab.binding.rfxcom/src/main/resources/OH-INF/thing/lighting4.xml index 8bc6d8e8fc6bc..771e7f8fdbed6 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/resources/OH-INF/thing/lighting4.xml +++ b/bundles/org.openhab.binding.rfxcom/src/main/resources/OH-INF/thing/lighting4.xml @@ -38,51 +38,31 @@ Pulse 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 0000000000000..9aac7d55db0b5 --- /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 238f1a33fe6eb..52dff9c370376 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 @@ 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.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 @@ @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 @@ private void verifyStatusUpdated(ThingStatus status, ThingStatusDetail thingStat 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 4c07f477cef83..72c2de4762664 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 97f8b23241b5f..64c06af80bc6d 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 83ef0d5542b4f..383d05a268831 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 @@ */ @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 151458ec2dad8..cf5affcdb7708 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 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 @@ 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 void testSomeMessages() throws RFXComException { 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 b8463c3d78afe..736eed1bbf21b 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 e8ea4d13eddd6..1add4b37f3cab 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 c475507e8afe5..0eb7c6b2dc710 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 @@ 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 @@ */ @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 @@ private void testMessage(String hexMsg, int seqNbr, String deviceId, int signalL 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 @@ static void testCommand(RFXComFanMessage.SubType subType, String channel, State 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 b82f3df9cf894..d58e4c5d63b42 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 28de642f35383..549459e1eab9a 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 @@ * @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 044008fd42d2d..5ebe0b9e78bbb 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 54af0ef7dcc2f..787cbbbac5078 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 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 @@ @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 @@ private void testMessage(String hexMsg, RFXComLighting1Message.SubType subType, 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 void testCommandStringOff() throws RFXComUnsupportedChannelException { 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 void testCommandStringChime() throws RFXComUnsupportedChannelException { 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 void testCommandStringBright() throws RFXComUnsupportedChannelException { 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 void testCommandStringDim() throws RFXComUnsupportedChannelException { 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 655698e163991..fe671050827bc 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 aaea645133fa2..d4f01a4d832c5 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 @@ */ @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 void basicBoundaryCheck() throws RFXComException { 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 void testPhenixMessages() throws RFXComException { "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 void testPhenixMessages() throws RFXComException { "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 64aa2bf72003c..1bca6cf765139 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 @@ @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 void basicBoundaryCheck() throws RFXComException { // 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 639763e6d78c2..b75416a891ab7 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 5d0b48f24d9e6..45d19afc28737 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 2f9a401aadb9b..d3690a33d4c88 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 void testHumidity() throws RFXComException { 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 088f600b8b1f5..9cf34448f2edc 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 188c7fc8b6209..e22d4c7f6eff0 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 @@ */ @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 void testSomeRxMessages() throws RFXComException { 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 6480e870ebbad..6449de7407d36 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 bc51015ed478f..0511b43d4e779 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 @@ */ @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 fe7926078f5ee..0000000000000 --- 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 c582dc67426f9..fb61a52008ade 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 fc4319441bd56..431358e11ca9a 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 @@ 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 @@ */ @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 @@ private void testMessage(String hexMessage, RFXComThermostat3Message.SubType sub 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 a724aa902462b..d6e6d9faceec0 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 0fe249b5edfcc..09bc5d3a57bee 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.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 void testSomeMessages() throws RFXComException { @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 163fd5c635f06..52ebe29e008dd 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 96789f029278e..bb57550b64a91 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)); } }