]> git.basschouten.com Git - openhab-addons.git/commitdiff
[rfxcom] Add ability to properly receive configured command ids, deprecated hard...
authorJames Hewitt <james.hewitt@uk.ibm.com>
Sun, 18 Jul 2021 19:37:44 +0000 (20:37 +0100)
committerGitHub <noreply@github.com>
Sun, 18 Jul 2021 19:37:44 +0000 (21:37 +0200)
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 <james.hewitt@uk.ibm.com>
73 files changed:
bundles/org.openhab.binding.rfxcom/README.md
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/config/RFXComLighting4DeviceConfiguration.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComBridgeHandler.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandler.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBBQTemperatureMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBatteryDeviceMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComBlinds1Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComChimeMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurrentEnergyMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurrentMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurtain1Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDateTimeMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDeviceMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComDeviceMessageImpl.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComEnergyMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComFanMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComHumidityMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComInterfaceMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting2Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting4Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting6Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessageFactory.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessageFactoryImpl.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRainMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRawMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComSecurity1Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComSecurity2Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureHumidityBarometricMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureHumidityMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureRainMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat1Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat3Message.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComUVMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComUndecodedRFMessage.java
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComWindMessage.java
bundles/org.openhab.binding.rfxcom/src/main/resources/OH-INF/thing/lighting4.xml
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/RFXComTestHelper.java [new file with mode: 0644]
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/handler/RFXComHandlerTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComBarometricMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCamera1MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComCurtain1MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComDateTimeMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComEdisioTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFS20MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComFanMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComGasMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortMessageTest.java [new file with mode: 0644]
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortTest.java [deleted file]
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComIOLinesMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting1MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting3MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting4MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComLighting5MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComPowerMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXMeterMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRFXSensorMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRadiator1MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRawMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRemoteControlMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComRfyMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComTestHelper.java [deleted file]
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat2MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat3MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComThermostat4MessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComUndecodedRFMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWaterMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComWeightMessageTest.java

index 172b6c20fca4e65604742e47f60b03cda01f6eb1..2931b23fb05991ce7be408356cfff193174b4d23 100644 (file)
@@ -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
+  `<Logger level="DEBUG" name="org.openhab.binding.rfxcom"/>`
+  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
 
index f1244edaf05f089e5e4767185d313afa08d74501..c4d54e591781103eb2914cce06e5ddd298e63976 100644 (file)
@@ -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;
 }
index 092ebf4364769b7adf692de840b950af1c06d991..8880881862e41de7ed71db25c89879148809cfb6 100644 (file)
@@ -102,8 +102,10 @@ public class RFXComBridgeHandler extends BaseBridgeHandler {
                 RFXComBaseMessage msg = queue.peek();
 
                 try {
-                    logger.debug("Transmitting message '{}'", msg);
                     byte[] data = msg.decodeMessage();
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("Transmitting bytes '{}' for message '{}'", HexUtils.bytesToHex(data), msg);
+                    }
                     connector.sendMessage(data);
                     break;
                 } catch (RFXComException rfxe) {
index 992015902859b35a9b506427ceaeba4ca4957d6d..04a247e86b6a10998f4b1fad9e18bdfdf7fc16dd 100644 (file)
@@ -95,10 +95,7 @@ public class RFXComHandler extends BaseThingHandler implements DeviceMessageList
                     PacketType packetType = RFXComMessageFactoryImpl
                             .convertPacketType(getThing().getThingTypeUID().getId().toUpperCase());
 
-                    RFXComMessage msg = messageFactory.createMessage(packetType);
-
-                    msg.setConfig(config);
-                    msg.convertFromState(channelUID.getId(), command);
+                    RFXComMessage msg = messageFactory.createMessage(packetType, config, channelUID, command);
 
                     bridgeHandler.sendMessage(msg);
                 } catch (RFXComMessageNotImplementedException e) {
@@ -180,9 +177,9 @@ public class RFXComHandler extends BaseThingHandler implements DeviceMessageList
         try {
             if (config.matchesMessage(message)) {
                 String receivedId = PACKET_TYPE_THING_TYPE_UID_MAP.get(message.getPacketType()).getId();
-                logger.debug("Received message from bridge: {} message: {}", bridge, message);
-
                 if (receivedId.equals(getThing().getThingTypeUID().getId())) {
+                    logger.debug("Message from bridge [{}] matches thing [{}] message: {}", bridge,
+                            getThing().getUID().toString(), message);
                     updateStatus(ThingStatus.ONLINE);
 
                     for (Channel channel : getThing().getChannels()) {
@@ -194,19 +191,21 @@ public class RFXComHandler extends BaseThingHandler implements DeviceMessageList
                                 case CHANNEL_COMMAND:
                                 case CHANNEL_CHIME_SOUND:
                                 case CHANNEL_MOOD:
-                                    postNullableCommand(uid, message.convertToCommand(channelId, this));
+                                    postNullableCommand(uid, message.convertToCommand(channelId, config, this));
                                     break;
 
                                 case CHANNEL_LOW_BATTERY:
                                     updateNullableState(uid,
-                                            isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL, this)));
+                                            isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL, config, this)));
                                     break;
 
                                 default:
-                                    updateNullableState(uid, message.convertToState(channelId, this));
+                                    updateNullableState(uid, message.convertToState(channelId, config, this));
                                     break;
                             }
-                        } catch (RFXComException e) {
+                        } catch (RFXComInvalidStateException e) {
+                            logger.trace("{} not configured for {}", channelId, message);
+                        } catch (RFXComUnsupportedChannelException e) {
                             logger.trace("{} does not handle {}", channelId, message);
                         }
                     }
index 99d00360cec91489d926a6831bd77ff6761a6501..f4c27532f92c582a41c5f08c7e2cf4f7d6e4e8d7 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -124,13 +126,14 @@ public class RFXComBBQTemperatureMessage extends RFXComBatteryDeviceMessage<RFXC
     }
 
     @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);
         }
     }
 
index 92eec8e1ba497cf707c43a397726cd632fd6bd82..f6f1e5cba157f01bf5eb991297459c8c3a94c41c 100644 (file)
@@ -14,6 +14,8 @@ package org.openhab.binding.rfxcom.internal.messages;
 
 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<T> extends RFXComDeviceMessageImpl<T>
     }
 
     @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);
         }
     }
 
index 11aa77bdbb32f5e618371b6b48fe3c081d386ab6..ed1648568c00e8918d419f9ca570622316997ada 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -174,11 +176,12 @@ public class RFXComBlinds1Message extends RFXComBatteryDeviceMessage<RFXComBlind
     }
 
     @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);
         }
     }
 
index 7640e56c15731d0fa296d9f62cffbaa639c0aa78..9d56a328a156a6d3b933f637bb44922f2876f1e5 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 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 class RFXComChimeMessage extends RFXComDeviceMessageImpl<RFXComChimeMessa
     }
 
     @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);
         }
     }
 
index 44b123636633a87433cc3f0894a0f7896c07f626..e1535d48a744f8d0c66d5acc7a3189e8e0bc93f5 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -136,7 +138,8 @@ public class RFXComCurrentEnergyMessage extends RFXComBatteryDeviceMessage<RFXCo
     }
 
     @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 class RFXComCurrentEnergyMessage extends RFXComBatteryDeviceMessage<RFXCo
                 return new DecimalType(totalUsage);
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index a4184fd3a7ad3f228b47a92105c4ab55c31e56b0..e4821229278e14f2fabe9d6ca4abbd738a49cc5c 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -125,7 +127,8 @@ public class RFXComCurrentMessage extends RFXComBatteryDeviceMessage<RFXComCurre
     }
 
     @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 class RFXComCurrentMessage extends RFXComBatteryDeviceMessage<RFXComCurre
                 return new DecimalType(channel3Amps);
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index f5cf61194a56f4e1e6fb9dedf2e59256c31d9f43..4f09b3211380a952cb4fe4835d1f229631923a83 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -131,11 +133,12 @@ public class RFXComCurtain1Message extends RFXComBatteryDeviceMessage<RFXComCurt
     }
 
     @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);
         }
     }
 
index 0d77d92685e310f9f6e89e578909fa5ac5a9ede7..7d63b83a9c3656c182665cd85ee06bd03a0b415c 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 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 class RFXComDateTimeMessage extends RFXComBatteryDeviceMessage<RFXComDate
     }
 
     @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);
         }
     }
 
index 2628834589c9f5e90f665b353b919b3f7704b8ef..3737f8026cbb71d443ad997623c10f89877a7ccb 100644 (file)
@@ -14,6 +14,7 @@ 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.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<T> 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.
index ed4de3e361b439126dcc000ff08aebab1271dd13..6eadde867d12b1cd5be23f348349eb3a640372de 100644 (file)
@@ -17,6 +17,7 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL
 import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
@@ -48,13 +49,14 @@ abstract class RFXComDeviceMessageImpl<T> extends RFXComBaseMessage implements R
     }
 
     @Override
-    public Command convertToCommand(String channelId, DeviceState deviceState)
-            throws RFXComUnsupportedChannelException {
-        return (Command) convertToState(channelId, deviceState);
+    public Command convertToCommand(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
+            throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
+        return (Command) convertToState(channelId, config, deviceState);
     }
 
     @Override
-    public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
+    public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
+            throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
         switch (channelId) {
             case CHANNEL_SIGNAL_LEVEL:
                 return convertSignalLevelToSystemWideLevel(signalLevel);
index be24d3c4c8283795c2d03056ff32445102cd99f2..c679e018122b782d3bd469fbfde9c3e65a87f012 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -145,7 +147,8 @@ public class RFXComEnergyMessage extends RFXComBatteryDeviceMessage<RFXComEnergy
     }
 
     @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 class RFXComEnergyMessage extends RFXComBatteryDeviceMessage<RFXComEnergy
                 return new DecimalType(totalAmpHour);
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index feecca8979920616acc51c72adb75c366c2e47b4..5931d37aaf2c509e0dd8dae480f4c331e823d97c 100644 (file)
@@ -21,7 +21,9 @@ import java.util.Arrays;
 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 class RFXComFanMessage extends RFXComDeviceMessageImpl<RFXComFanMessage.S
     }
 
     @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 class RFXComFanMessage extends RFXComDeviceMessageImpl<RFXComFanMessage.S
                 return handleCommandStringChannel();
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index a5e289f1468ee08e80ae97e28bc70db5a9965c12..a20b19d639e4a1dde383664d6bf2792abf51abe3 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 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 class RFXComHomeConfortMessage extends RFXComDeviceMessageImpl<RFXComHome
     }
 
     @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);
         }
     }
 
index be7435fafd80d80238ac28f3d9e7fdb2e28b5b6a..ba5fa8e544ccdbe17437accfa75dedc41393b91d 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -129,7 +131,8 @@ public class RFXComHumidityMessage extends RFXComBatteryDeviceMessage<RFXComHumi
     }
 
     @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 class RFXComHumidityMessage extends RFXComBatteryDeviceMessage<RFXComHumi
                 return new StringType(humidityStatus.toString());
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index d225a8a595ecd06e4b285779081ae47d2c880d6e..1f83bd69b767e8c3df34b70c4061b43fffb85eae 100644 (file)
@@ -271,7 +271,7 @@ public class RFXComInterfaceMessage extends RFXComBaseMessage {
             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];
index bdd6fa6f5071d2fb0ca64bab55291e68a2e53a12..2a42d9e81945d41705012f8565bf66eb2b87084d 100644 (file)
@@ -14,7 +14,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 
 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 class RFXComLighting1Message extends RFXComDeviceMessageImpl<RFXComLighti
             // the message unless the last X<n> ON they saw was for them. So we
             // redirect an incoming broadcast DIM/BRIGHT to the correct item
             // based on the last X<n> we saw or sent.
-            unitCode = lastUnit[(int) houseCode - (int) 'A'];
+            unitCode = lastUnit[houseCode - 'A'];
         } else {
             unitCode = data[5];
             if (command == Commands.ON) {
-                lastUnit[(int) houseCode - (int) 'A'] = unitCode;
+                lastUnit[houseCode - 'A'] = unitCode;
             }
         }
 
@@ -162,8 +164,8 @@ public class RFXComLighting1Message extends RFXComDeviceMessageImpl<RFXComLighti
     }
 
     @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 class RFXComLighting1Message extends RFXComDeviceMessageImpl<RFXComLighti
                 }
 
             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) {
index 2c84bcbf71b6a6f8df34643e67b108245ad744b1..fb584c5c36401d47de21a2fc687e2fdfef8646f2 100644 (file)
@@ -20,7 +20,9 @@ import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting2Messag
 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 class RFXComLighting2Message extends RFXComDeviceMessageImpl<RFXComLighti
     }
 
     @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 class RFXComLighting2Message extends RFXComDeviceMessageImpl<RFXComLighti
                 }
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index 20321f69175482b0ca390301897db8425ea8fb0d..2a74d0e5a4ae3b8f781578475268f3267fb3cc85 100644 (file)
 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.OnOffType;
 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 @@ import org.slf4j.LoggerFactory;
  * @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<RFXComLighting4Message.SubType> {
-    // this logger is used from a static context, so is static as well
-    private static final Logger LOGGER = LoggerFactory.getLogger(RFXComLighting4Message.class);
-
-    private static final byte DEFAULT_OFF_COMMAND_ID = Commands.OFF_4.toByte();
-    private static final byte DEFAULT_ON_COMMAND_ID = Commands.ON_1.toByte();
-
     public enum SubType implements ByteEnumWrapper {
         PT2262(0);
 
@@ -80,62 +79,21 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
         }
     }
 
-    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<Integer> ON_COMMAND_IDS = Stream.of(1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15)
+            .collect(Collectors.toCollection(HashSet::new));
 
     private SubType subType;
     private int sensorId;
     private int pulse;
-    private Commands command;
     private int commandId;
-    private int offCommandId;
-    private int onCommandId;
+
+    private RFXComLighting4DeviceConfiguration config;
 
     public RFXComLighting4Message() {
         super(PacketType.LIGHTING4);
@@ -152,7 +110,7 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
         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 class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
     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 class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
     }
 
     @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 class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
     }
 
     @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 class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
     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;
     }
 }
index 3602810be1ac8f988f41d0b32b11d53c1c309671..9cf4e845a9989eee61101292e1c7ff98ec652eaa 100644 (file)
@@ -21,7 +21,9 @@ import java.math.RoundingMode;
 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 class RFXComLighting5Message extends RFXComDeviceMessageImpl<RFXComLighti
     }
 
     @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 class RFXComLighting5Message extends RFXComDeviceMessageImpl<RFXComLighti
                 }
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index ae35088023646d662b423782a40ff92026d6987f..f468367a2f66cbc8843014f43a3720bbe4ff7b3b 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -134,7 +136,8 @@ public class RFXComLighting6Message extends RFXComDeviceMessageImpl<RFXComLighti
     }
 
     @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 class RFXComLighting6Message extends RFXComDeviceMessageImpl<RFXComLighti
                 }
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index d555a32f58d329a9dfd24411dcee0edb43b7f71c..c320e210228305c03ab60758da669565c62f67c0 100644 (file)
  */
 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 @@ import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType
  *
  * @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;
 }
index 6098d437c563f3733af4db3ca3e1c65b08614078..b45922dabbbaf773b55bf9df2bbfc329529771e2 100644 (file)
@@ -18,9 +18,12 @@ import java.util.Collections;
 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<? extends RFXComMessage> 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);
         }
index e5af3962a5eb4041185370fda38b2682083ed310..539f92498f5f451367dd78d8fa10b639467b271d 100644 (file)
@@ -18,7 +18,9 @@ import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte
 
 import java.math.BigDecimal;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -201,7 +203,8 @@ public class RFXComRFXSensorMessage extends RFXComDeviceMessageImpl<RFXComRFXSen
     }
 
     @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 class RFXComRFXSensorMessage extends RFXComDeviceMessageImpl<RFXComRFXSen
                 return subType == SubType.A_D ? handlePressure(deviceState) : null;
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index 293f2bc8c93666e7b138ecf93ed2e549df0e5daa..58303e741bf0dc69e68b4de78c72029fa22de61a 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -135,7 +137,8 @@ public class RFXComRainMessage extends RFXComBatteryDeviceMessage<RFXComRainMess
     }
 
     @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 class RFXComRainMessage extends RFXComBatteryDeviceMessage<RFXComRainMess
                 return new DecimalType(rainTotal);
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index 1aa27620be3bfe0018612211a43a7594e8add1d2..bf28863ba939ffdcb7f4c984ce9d9ccbddd2fa15 100644 (file)
@@ -142,7 +142,8 @@ public class RFXComRawMessage extends RFXComDeviceMessageImpl<RFXComRawMessage.S
     }
 
     @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));
index d5cf2e19a971ac05f81e525c44fd65bf9d06e230..b185389e698b0f6f864ba14a186bd85e3ccbe666 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -134,13 +136,14 @@ public class RFXComRfyMessage extends RFXComDeviceMessageImpl<RFXComRfyMessage.S
     }
 
     @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);
         }
     }
 
index 3e13fd8e2228077095bb73bdc115c076e376db07..7385770bef21fa6088767e33073ce96f9c491c59 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -233,7 +235,8 @@ public class RFXComSecurity1Message extends RFXComBatteryDeviceMessage<RFXComSec
     }
 
     @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 class RFXComSecurity1Message extends RFXComBatteryDeviceMessage<RFXComSec
                 return new StringType(status.toString());
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index 3dbb357d62f9dd8b0bd86155607086e3397c604e..7f7931e6ff888bc8d1bda233aa883eb297518209 100644 (file)
@@ -17,7 +17,9 @@ import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte
 
 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 class RFXComSecurity2Message extends RFXComBatteryDeviceMessage<RFXComSec
     }
 
     @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 class RFXComSecurity2Message extends RFXComBatteryDeviceMessage<RFXComSec
                 return ((buttonStatus & BUTTON_3_BIT) == 0) ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index 349c5cc3fb83f5a64be427c46bcf5e2080f89a13..9c04bf120dd352d4b0b3d2cf98ac259caf23413a 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -178,7 +180,8 @@ public class RFXComTemperatureHumidityBarometricMessage
     }
 
     @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 class RFXComTemperatureHumidityBarometricMessage
                 return new StringType(forecastStatus.toString());
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index ff3f21dd1b80e990c1044c83c8498491cc62a1c6..17f850f8355b0ce625ff014f225e90888a3ee131 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -158,7 +160,8 @@ public class RFXComTemperatureHumidityMessage
     }
 
     @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 class RFXComTemperatureHumidityMessage
                 return new StringType(humidityStatus.toString());
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index f57298e3fe11ca45a57909ce3858426acba429d8..eb6c113f155347b8958a9445a39cf611908bee07 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 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 class RFXComTemperatureMessage extends RFXComBatteryDeviceMessage<RFXComT
     }
 
     @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);
         }
     }
 
index d591a9f05df36880a6415d7228ee07b9c12e63da..b67d25a20bbd86c89a7f2b94267206a6be2c9413 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -120,7 +122,8 @@ public class RFXComTemperatureRainMessage extends RFXComBatteryDeviceMessage<RFX
     }
 
     @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 class RFXComTemperatureRainMessage extends RFXComBatteryDeviceMessage<RFX
                 return new DecimalType(rainTotal);
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index eda9c10395a03149c95940d18e8025fb94717b9d..c5577e79cf04de4d4e015b7b4b9a3d73c90b49c0 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -155,7 +157,8 @@ public class RFXComThermostat1Message extends RFXComDeviceMessageImpl<RFXComTher
     }
 
     @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 class RFXComThermostat1Message extends RFXComDeviceMessageImpl<RFXComTher
                 }
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index 24e628bb654f20eb97d77cb68dff27530e08aa61..024d8fbbe61bcb9b2e3f3721891107c79761789c 100644 (file)
@@ -19,7 +19,9 @@ import static org.openhab.binding.rfxcom.internal.messages.RFXComThermostat3Mess
 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 class RFXComThermostat3Message extends RFXComDeviceMessageImpl<RFXComTher
     }
 
     @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 class RFXComThermostat3Message extends RFXComDeviceMessageImpl<RFXComTher
                 return command == null ? UnDefType.UNDEF : StringType.valueOf(command.toString());
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index f64656ee3b3864d697cfa40fe852f471ba6714b3..f861bd0048dabd69784512027c0e526bd9fa89ad 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -125,7 +127,8 @@ public class RFXComUVMessage extends RFXComBatteryDeviceMessage<RFXComUVMessage.
     }
 
     @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 class RFXComUVMessage extends RFXComBatteryDeviceMessage<RFXComUVMessage.
                 return (subType == SubType.UV3 ? new DecimalType(temperature) : UnDefType.UNDEF);
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index 456510707913ec8bee72898c587f08bbe3e9ad64..387791ddd41d706d7e561a23118a29d742687d20 100644 (file)
@@ -17,6 +17,7 @@ import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.Pac
 
 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 class RFXComUndecodedRFMessage extends RFXComDeviceMessageImpl<RFXComUnde
     }
 
     @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));
index a0c577ea82a763524a0eb5caf854331b54787cad..75d70974b77bab7267b1dc65ef547973eff42c01 100644 (file)
@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
 
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -168,7 +170,8 @@ public class RFXComWindMessage extends RFXComBatteryDeviceMessage<RFXComWindMess
     }
 
     @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 class RFXComWindMessage extends RFXComBatteryDeviceMessage<RFXComWindMess
                 return new DecimalType(chillTemperature);
 
             default:
-                return super.convertToState(channelId, deviceState);
+                return super.convertToState(channelId, config, deviceState);
         }
     }
 
index 8bc6d8e8fc6bcafa7fd89451f39930fcffd1c5e9..771e7f8fdbed67c5c5b3745b01d3983d189ec5e4 100644 (file)
                                <description>Pulse length of the device</description>
                                <default>350</default>
                        </parameter>
-                       <parameter name="onCommandId" type="integer" required="true">
+                       <parameter name="onCommandId" type="integer" required="false" min="0" max="15">
                                <label>On Command</label>
-                               <description>Specifies command to be send when ON must be transmitted</description>
-                               <options>
-                                       <option value="0">OFF (value 0)</option>
-                                       <option value="1">ON (value 1)</option>
-                                       <option value="2">OFF (value 2)</option>
-                                       <option value="3">ON (value 3)</option>
-                                       <option value="4">OFF (value 4)</option>
-                                       <option value="5">ON (value 5)</option>
-                                       <option value="6">value 5</option>
-                                       <option value="7">ON (value 7)</option>
-                                       <option value="8">value 8</option>
-                                       <option value="9">ON (value 9)</option>
-                                       <option value="10">ON (value 10)</option>
-                                       <option value="11">ON (value 11)</option>
-                                       <option value="12">ON (value 12)</option>
-                                       <option value="13">value 13</option>
-                                       <option value="14">OFF (value 14)</option>
-                                       <option value="15">value 15</option>
-                               </options>
-                               <default>1</default>
+                               <description>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.</description>
                        </parameter>
-                       <parameter name="offCommandId" type="integer" required="true">
+                       <parameter name="offCommandId" type="integer" required="false" min="0" max="15">
                                <label>Off Command</label>
-                               <description>Specifies command to be send when OFF must be transmitted</description>
-                               <options>
-                                       <option value="0">OFF (value 0)</option>
-                                       <option value="1">ON (value 1)</option>
-                                       <option value="2">OFF (value 2)</option>
-                                       <option value="3">ON (value 3)</option>
-                                       <option value="4">OFF (value 4)</option>
-                                       <option value="5">ON (value 5)</option>
-                                       <option value="6">value 5</option>
-                                       <option value="7">ON (value 7)</option>
-                                       <option value="8">value 8</option>
-                                       <option value="9">ON (value 9)</option>
-                                       <option value="10">ON (value 10)</option>
-                                       <option value="11">ON (value 11)</option>
-                                       <option value="12">ON (value 12)</option>
-                                       <option value="13">value 13</option>
-                                       <option value="14">OFF (value 14)</option>
-                                       <option value="15">value 15</option>
-                               </options>
-                               <default>4</default>
+                               <description>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.</description>
+                       </parameter>
+                       <parameter name="openCommandId" type="integer" required="false" min="0" max="15">
+                               <label>Open Command</label>
+                               <description>Specifies command that represents OPEN for this device.</description>
+                       </parameter>
+                       <parameter name="closedCommandId" type="integer" required="false" min="0" max="15">
+                               <label>Closed Command</label>
+                               <description>Specifies command that represents CLOSED for this device.</description>
                        </parameter>
                </config-description>
        </thing-type>
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 (file)
index 0000000..9aac7d5
--- /dev/null
@@ -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();
+    }
+}
index 238f1a33fe6eb763bcc2df6ef9a07974fb25ffe8..52dff9c370376f983bc5e0dabfc1b912895210e9 100644 (file)
@@ -15,6 +15,7 @@ package org.openhab.binding.rfxcom.internal.handler;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
+import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.*;
 
 import java.util.Map;
 
@@ -41,8 +42,6 @@ import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingStatus;
 import org.openhab.core.thing.ThingStatusDetail;
 import org.openhab.core.thing.ThingStatusInfo;
-import org.openhab.core.thing.ThingTypeUID;
-import org.openhab.core.thing.ThingUID;
 import org.openhab.core.thing.binding.ThingHandlerCallback;
 import org.openhab.core.types.Command;
 
@@ -54,10 +53,6 @@ import org.openhab.core.types.Command;
 @ExtendWith(MockitoExtension.class)
 public class RFXComHandlerTest {
 
-    static ThingUID bridgeUID = new ThingUID("rfxcom", "tcpbridge", "rfxtrx0");
-    static ThingUID thingUID = new ThingUID("rfxcom", bridgeUID, "mocked");
-    static ThingTypeUID thingTypeUID = new ThingTypeUID("rfxcom", "raw");
-
     @Mock
     Bridge bridge;
 
@@ -114,10 +109,10 @@ public class RFXComHandlerTest {
 
     private RFXComGenericDeviceConfiguration sendMessageToGetConfig(String channel, Command command)
             throws RFXComException {
-        when(messageFactory.createMessage(any(PacketType.class))).thenReturn(message);
         ChannelUID cuid = new ChannelUID(thing.getUID(), channel);
         handler.handleCommand(cuid, command);
-        verify(message).setConfig(deviceConfigurationCaptor.capture());
+        verify(messageFactory).createMessage(any(PacketType.class), deviceConfigurationCaptor.capture(), eq(cuid),
+                eq(command));
         return deviceConfigurationCaptor.getValue();
     }
 
index 4c07f477cef837e542eb05b2e21b36311e7b53d8..72c2de4762664656d4f13c8fb20287995048596c 100644 (file)
@@ -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));
     }
 }
index 97f8b23241b5f8f5723a6d4d3990c51d5e4aa1cc..64c06af80bc6d7edfb26abac7d4b827aa71157f7 100644 (file)
@@ -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));
     }
 }
index 83ef0d5542b4f913bbf2fe229d1306ea3a818a1a..383d05a268831be5cbd7112124bd735c5f1f20ad 100644 (file)
  */
 package org.openhab.binding.rfxcom.internal.messages;
 
+import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.thingUID;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.CURTAIN1;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.junit.jupiter.api.Test;
+import org.openhab.binding.rfxcom.internal.RFXComBindingConstants;
+import org.openhab.binding.rfxcom.internal.RFXComTestHelper;
+import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.core.library.types.OpenClosedType;
+import org.openhab.core.thing.ChannelUID;
 
 /**
  * Test for RFXCom-binding
@@ -25,18 +31,23 @@ import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
  */
 @NonNullByDefault
 public class RFXComCurtain1MessageTest {
+    private static ChannelUID shutterChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_SHUTTER);
+    private static RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+
+    static {
+        config.deviceId = "1.2";
+        config.subType = RFXComCurtain1Message.SubType.HARRISON.toString();
+    }
+
     @Test
     public void checkForSupportTest() throws RFXComException {
-        RFXComMessageFactoryImpl.INSTANCE.createMessage(CURTAIN1);
+        RFXComMessageFactoryImpl.INSTANCE.createMessage(CURTAIN1, config, shutterChannelUID, OpenClosedType.OPEN);
     }
 
     @Test
     public void basicBoundaryCheck() throws RFXComException {
         RFXComCurtain1Message message = (RFXComCurtain1Message) RFXComMessageFactoryImpl.INSTANCE
-                .createMessage(CURTAIN1);
-
-        message.subType = RFXComCurtain1Message.SubType.HARRISON;
-        message.command = RFXComCurtain1Message.Commands.OPEN;
+                .createMessage(CURTAIN1, config, shutterChannelUID, OpenClosedType.OPEN);
 
         RFXComTestHelper.basicBoundaryCheck(CURTAIN1, message);
     }
index 151458ec2dad8e299d3b299f8f92647c833d23db..cf5affcdb77086defa6dd99a71c741920de6e963 100644 (file)
@@ -17,6 +17,8 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.junit.jupiter.api.Test;
+import org.openhab.binding.rfxcom.internal.RFXComTestHelper;
+import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
 import org.openhab.core.library.types.DateTimeType;
 import org.openhab.core.util.HexUtils;
@@ -30,6 +32,10 @@ import org.openhab.core.util.HexUtils;
 public class RFXComDateTimeMessageTest {
     @Test
     public void testSomeMessages() throws RFXComException {
+        RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+        config.deviceId = "47360";
+        config.subType = RFXComDateTimeMessage.SubType.RTGR328N.toString();
+
         String hexMessage = "0D580117B90003041D030D150A69";
         byte[] message = HexUtils.hexToBytes(hexMessage);
         RFXComDateTimeMessage msg = (RFXComDateTimeMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(message);
@@ -37,10 +43,10 @@ public class RFXComDateTimeMessageTest {
         assertEquals(23, (short) (msg.seqNbr & 0xFF), "Seq Number");
         assertEquals("47360", msg.getDeviceId(), "Sensor Id");
         assertEquals("2003-04-29T13:21:10", msg.dateTime, "Date time");
-        assertEquals(2, RFXComTestHelper.getActualIntValue(msg, CHANNEL_SIGNAL_LEVEL), "Signal Level");
+        assertEquals(2, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_SIGNAL_LEVEL), "Signal Level");
 
         assertEquals(DateTimeType.valueOf("2003-04-29T13:21:10"),
-                msg.convertToState(CHANNEL_DATE_TIME, new MockDeviceState()), "Converted value");
+                msg.convertToState(CHANNEL_DATE_TIME, config, new MockDeviceState()), "Converted value");
 
         byte[] decoded = msg.decodeMessage();
 
index b8463c3d78afee8547ec2b24abb4f6e26fa9d066..736eed1bbf21b6f796c102c8a75395cc61ac97f3 100644 (file)
@@ -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));
     }
 }
index e8ea4d13eddd6ac0b7979c0af2afd14001fa6b75..1add4b37f3cab65d2fc1d7d40f891678476e6866 100644 (file)
@@ -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));
     }
 }
index c475507e8afe58783e6cac727f876f8af1cadccd..0eb7c6b2dc71082eda4d3008a34c2b919cc155c7 100644 (file)
@@ -14,15 +14,20 @@ package org.openhab.binding.rfxcom.internal.messages;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
+import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.thingUID;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.FAN;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComFanMessage.SubType.CASAFAN;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.junit.jupiter.api.Test;
+import org.openhab.binding.rfxcom.internal.RFXComBindingConstants;
+import org.openhab.binding.rfxcom.internal.RFXComTestHelper;
+import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.StringType;
+import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.types.State;
 import org.openhab.core.types.UnDefType;
 import org.openhab.core.util.HexUtils;
@@ -34,19 +39,26 @@ import org.openhab.core.util.HexUtils;
  */
 @NonNullByDefault
 public class RFXComFanMessageTest {
+    private static RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+    private static ChannelUID fanSpeedChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_FAN_SPEED);
+    private static StringType fanSpeedOff = StringType.valueOf("OFF");
+
+    static {
+        config.deviceId = "5428224";
+        config.subType = RFXComFanMessage.SubType.CASAFAN.toString();
+    }
+
     private static final MockDeviceState DEVICE_STATE = new MockDeviceState();
 
     @Test
     public void checkForSupportTest() throws RFXComException {
-        RFXComMessageFactoryImpl.INSTANCE.createMessage(FAN);
+        RFXComMessageFactoryImpl.INSTANCE.createMessage(FAN, config, fanSpeedChannelUID, fanSpeedOff);
     }
 
     @Test
     public void basicBoundaryCheck() throws RFXComException {
-        RFXComFanMessage message = (RFXComFanMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(FAN);
-
-        message.setSubType(RFXComFanMessage.SubType.CASAFAN);
-        message.convertFromState(CHANNEL_FAN_SPEED, StringType.valueOf("OFF"));
+        RFXComFanMessage message = (RFXComFanMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(FAN, config,
+                fanSpeedChannelUID, fanSpeedOff);
 
         RFXComTestHelper.basicBoundaryCheck(FAN, message);
     }
@@ -60,9 +72,9 @@ public class RFXComFanMessageTest {
         assertEquals(deviceId, msg.getDeviceId(), "Sensor Id");
         assertEquals(signalLevel, msg.signalLevel, "Signal Level");
 
-        assertEquals(expectedCommand, msg.convertToState(CHANNEL_COMMAND, DEVICE_STATE));
-        assertEquals(expectedLightCommand, msg.convertToState(CHANNEL_FAN_LIGHT, DEVICE_STATE));
-        assertEquals(expectedFanSpeed, msg.convertToState(CHANNEL_FAN_SPEED, DEVICE_STATE));
+        assertEquals(expectedCommand, msg.convertToState(CHANNEL_COMMAND, config, DEVICE_STATE));
+        assertEquals(expectedLightCommand, msg.convertToState(CHANNEL_FAN_LIGHT, config, DEVICE_STATE));
+        assertEquals(expectedFanSpeed, msg.convertToState(CHANNEL_FAN_SPEED, config, DEVICE_STATE));
 
         assertEquals(packetType, msg.getPacketType());
 
@@ -139,10 +151,10 @@ public class RFXComFanMessageTest {
     private static void assertValues(RFXComFanMessage msg, @Nullable OnOffType expectedCommand,
             State expectedLightCommand, @Nullable State expectedFanSpeed, RFXComBaseMessage.PacketType packetType,
             State expectedCommandString) throws RFXComException {
-        assertEquals(expectedCommand, msg.convertToState(CHANNEL_COMMAND, DEVICE_STATE));
-        assertEquals(expectedLightCommand, msg.convertToState(CHANNEL_FAN_LIGHT, DEVICE_STATE));
-        assertEquals(expectedFanSpeed, msg.convertToState(CHANNEL_FAN_SPEED, DEVICE_STATE));
-        assertEquals(expectedCommandString, msg.convertToState(CHANNEL_COMMAND_STRING, DEVICE_STATE));
+        assertEquals(expectedCommand, msg.convertToState(CHANNEL_COMMAND, config, DEVICE_STATE));
+        assertEquals(expectedLightCommand, msg.convertToState(CHANNEL_FAN_LIGHT, config, DEVICE_STATE));
+        assertEquals(expectedFanSpeed, msg.convertToState(CHANNEL_FAN_SPEED, config, DEVICE_STATE));
+        assertEquals(expectedCommandString, msg.convertToState(CHANNEL_COMMAND_STRING, config, DEVICE_STATE));
         assertEquals(packetType, msg.getPacketType());
     }
 }
index b82f3df9cf8946bbd0bcca67fc451ee2d60f6385..d58e4c5d63b426a2f45cb5977c144a0694ab0620 100644 (file)
@@ -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/RFXComHomeConfortMessageTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortMessageTest.java
new file mode 100644 (file)
index 0000000..549459e
--- /dev/null
@@ -0,0 +1,52 @@
+/**
+ * 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.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.SubType;
+import org.openhab.core.library.types.OnOffType;
+import org.openhab.core.types.Command;
+import org.openhab.core.util.HexUtils;
+
+/**
+ * Test for RFXCom-binding
+ *
+ * @author Martin van Wingerden - Initial contribution
+ * @author Mike Jagdis - added message handling and real test
+ */
+@NonNullByDefault
+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, config, commandChannelUID, command);
+
+        assertArrayEquals(HexUtils.hexToBytes(data), message.decodeMessage());
+    }
+
+    @Test
+    public void testMessage1() throws RFXComException {
+        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/RFXComHomeConfortTest.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComHomeConfortTest.java
deleted file mode 100644 (file)
index 28de642..0000000
+++ /dev/null
@@ -1,47 +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.assertArrayEquals;
-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.exceptions.RFXComException;
-import org.openhab.binding.rfxcom.internal.messages.RFXComHomeConfortMessage.Commands;
-import org.openhab.binding.rfxcom.internal.messages.RFXComHomeConfortMessage.SubType;
-import org.openhab.core.util.HexUtils;
-
-/**
- * Test for RFXCom-binding
- *
- * @author Martin van Wingerden - Initial contribution
- * @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 {
-        RFXComHomeConfortMessage message = (RFXComHomeConfortMessage) RFXComMessageFactoryImpl.INSTANCE
-                .createMessage(HOME_CONFORT);
-        message.setSubType(subType);
-        message.command = command;
-        message.setDeviceId(deviceId);
-
-        assertArrayEquals(HexUtils.hexToBytes(data), message.decodeMessage());
-    }
-
-    @Test
-    public void testMessage1() throws RFXComException {
-        testMessage(SubType.TEL_010, Commands.GROUP_ON, "1118739.A.4", "0C1B0000111213410403000000");
-    }
-}
index 044008fd42d2d73fc60a8738779cf256348dda22..5ebe0b9e78bbbf0b9399fa8790b85d5ea464bef8 100644 (file)
@@ -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));
     }
 }
index 54af0ef7dcc2f622d9264af27be7b0753d9917fc..787cbbbac5078d4c7ab4a83147aef21809ee65ea 100644 (file)
@@ -17,6 +17,7 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.junit.jupiter.api.Test;
+import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.binding.rfxcom.internal.messages.RFXComLighting1Message.Commands;
@@ -33,6 +34,12 @@ import org.openhab.core.util.HexUtils;
 @NonNullByDefault
 public class RFXComLighting1MessageTest {
     private final MockDeviceState deviceState = new MockDeviceState();
+    private static final RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+
+    static {
+        config.deviceId = "A.1";
+        config.subType = RFXComLighting1Message.SubType.ARC.toString();
+    }
 
     private void testMessage(String hexMsg, RFXComLighting1Message.SubType subType, int seqNbr, String deviceId,
             byte signalLevel, Commands command, String commandString) throws RFXComException {
@@ -43,7 +50,11 @@ public class RFXComLighting1MessageTest {
         assertEquals(deviceId, msg.getDeviceId(), "Sensor Id");
         assertEquals(signalLevel, msg.signalLevel, "Signal Level");
         assertEquals(command, msg.command, "Command");
-        assertEquals(commandString, msg.convertToState(CHANNEL_COMMAND_STRING, deviceState).toString(),
+
+        RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+        config.deviceId = deviceId;
+        config.subType = subType.toString();
+        assertEquals(commandString, msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState).toString(),
                 "Command String");
 
         byte[] decoded = msg.decodeMessage();
@@ -72,9 +83,9 @@ public class RFXComLighting1MessageTest {
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OFF"));
 
-        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OpenClosedType.CLOSED, msg.convertToState(CHANNEL_CONTACT, deviceState));
-        assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OpenClosedType.CLOSED, msg.convertToState(CHANNEL_CONTACT, config, deviceState));
+        assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
     }
 
     @Test
@@ -83,9 +94,9 @@ public class RFXComLighting1MessageTest {
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("chime"));
 
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OpenClosedType.OPEN, msg.convertToState(CHANNEL_CONTACT, deviceState));
-        assertEquals(StringType.valueOf("CHIME"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OpenClosedType.OPEN, msg.convertToState(CHANNEL_CONTACT, config, deviceState));
+        assertEquals(StringType.valueOf("CHIME"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
     }
 
     @Test
@@ -94,9 +105,9 @@ public class RFXComLighting1MessageTest {
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("bright"));
 
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OpenClosedType.OPEN, msg.convertToState(CHANNEL_CONTACT, deviceState));
-        assertEquals(StringType.valueOf("BRIGHT"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OpenClosedType.OPEN, msg.convertToState(CHANNEL_CONTACT, config, deviceState));
+        assertEquals(StringType.valueOf("BRIGHT"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
     }
 
     @Test
@@ -105,8 +116,8 @@ public class RFXComLighting1MessageTest {
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("dim"));
 
-        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OpenClosedType.CLOSED, msg.convertToState(CHANNEL_CONTACT, deviceState));
-        assertEquals(StringType.valueOf("DIM"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OpenClosedType.CLOSED, msg.convertToState(CHANNEL_CONTACT, config, deviceState));
+        assertEquals(StringType.valueOf("DIM"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
     }
 }
index 655698e1639919db14d0ffe1d0654dbaefc4d132..fe671050827bc0855e9b7a23ca75a6ad786c0ccf 100644 (file)
@@ -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));
     }
 }
index aaea645133fa222b56afe28f82f3fd4273ded800..d4f01a4d832c585e4f2829e6d0bfedd77f8cb717 100644 (file)
  */
 package org.openhab.binding.rfxcom.internal.messages;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.*;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
+import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.*;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.LIGHTING4;
-import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting4Message.Commands.*;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting4Message.SubType.PT2262;
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.junit.jupiter.api.Test;
+import org.openhab.binding.rfxcom.internal.RFXComTestHelper;
+import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.config.RFXComLighting4DeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
+import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
+import org.openhab.core.config.discovery.DiscoveryResultBuilder;
 import org.openhab.core.library.types.OnOffType;
+import org.openhab.core.library.types.OpenClosedType;
+import org.openhab.core.thing.ChannelUID;
+import org.openhab.core.thing.ThingUID;
+import org.openhab.core.types.Command;
 import org.openhab.core.util.HexUtils;
 
 /**
@@ -36,17 +46,33 @@ import org.openhab.core.util.HexUtils;
  */
 @NonNullByDefault
 public class RFXComLighting4MessageTest {
+    static public final ChannelUID contactChannelUID = new ChannelUID(thingUID, CHANNEL_CONTACT);
+
+    static public void checkDiscoveryResult(RFXComDeviceMessage<RFXComLighting4Message.SubType> 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<String, Object> properties = builder.build().getProperties();
+        assertEquals(deviceId, properties.get("deviceId"), "Device Id");
+        assertEquals(subType, properties.get("subType"), "Sub type");
+        if (pulse != null) {
+            assertEquals(pulse, properties.get("pulse"), "Pulse");
+        }
+    }
+
     @Test
     public void basicBoundaryCheck() throws RFXComException {
-        RFXComLighting4Message message = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE
-                .createMessage(LIGHTING4);
-
         RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration();
         config.deviceId = "90000";
         config.subType = "PT2262";
         config.pulse = 300;
-        message.setConfig(config);
-        message.convertFromState(CHANNEL_COMMAND, OnOffType.ON);
+
+        RFXComLighting4Message message = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE
+                .createMessage(LIGHTING4, config, commandChannelUID, OnOffType.ON);
 
         byte[] binaryMessage = message.decodeMessage();
         RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE
@@ -55,56 +81,59 @@ public class RFXComLighting4MessageTest {
         assertEquals("90000", msg.getDeviceId(), "Sensor Id");
     }
 
-    private void testMessage(String hexMsg, RFXComLighting4Message.SubType subType, String deviceId,
-            @Nullable Integer pulse, RFXComLighting4Message.Commands command, @Nullable Integer seqNbr, int signalLevel,
-            int offCommand, int onCommand) throws RFXComException {
-        testMessage(hexMsg, subType, deviceId, pulse, command.toByte(), seqNbr, signalLevel, offCommand, onCommand);
-    }
+    private void testMessageWithoutCommandIds(String hexMsg, RFXComLighting4Message.SubType subType, String deviceId,
+            @Nullable Integer pulse, int commandByte, @Nullable Integer seqNbr, int signalLevel, Command command)
+            throws RFXComException {
+        // These tests rely on the deprecated behaviour of a "known" set of ON/OFF values and will
+        // be removed in a later release to be replaced with test that check we throw an exception
+        // if the config isn't specified (see the open/closed tests).
+        RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration();
+        config.deviceId = deviceId;
+        config.subType = subType.toString();
 
-    private void testMessage(String hexMsg, RFXComLighting4Message.SubType subType, String deviceId,
-            @Nullable Integer pulse, byte commandByte, @Nullable Integer seqNbr, int signalLevel, int offCommand,
-            int onCommand) throws RFXComException {
         RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE
                 .createMessage(HexUtils.hexToBytes(hexMsg));
         assertEquals(deviceId, msg.getDeviceId(), "Sensor Id");
-        assertEquals(commandByte, RFXComTestHelper.getActualIntValue(msg, CHANNEL_COMMAND_ID), "Command");
+        assertEquals(commandByte, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_COMMAND_ID), "Command");
         if (seqNbr != null) {
             assertEquals(seqNbr.shortValue(), (short) (msg.seqNbr & 0xFF), "Seq Number");
         }
-        assertEquals(signalLevel, RFXComTestHelper.getActualIntValue(msg, CHANNEL_SIGNAL_LEVEL), "Signal Level");
+        assertEquals(signalLevel, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_SIGNAL_LEVEL),
+                "Signal Level");
+        assertEquals(command, msg.convertToCommand(CHANNEL_COMMAND, config, null));
 
         byte[] decoded = msg.decodeMessage();
 
         assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back");
 
-        RFXComTestHelper.checkDiscoveryResult(msg, deviceId, pulse, subType.toString(), offCommand, onCommand);
+        checkDiscoveryResult(msg, deviceId, pulse, subType.toString());
     }
 
     @Test
     public void testSomeMessages() throws RFXComException {
-        testMessage("091300E1D8AD59018F70", PT2262, "887509", 399, ON_9, 225, 2, 4, 9);
-        testMessage("0913005FA9A9C901A170", PT2262, "694940", 417, ON_9, 95, 2, 4, 9);
-        testMessage("091300021D155C01E960", PT2262, "119125", 489, ON_12, 2, 2, 4, 12);
-        testMessage("091300D345DD99018C50", PT2262, "286169", 396, ON_9, 211, 2, 4, 9);
-        testMessage("09130035D149A2017750", PT2262, "857242", 375, OFF_2, 53, 2, 2, 1);
-        testMessage("0913000B4E462A012280", PT2262, "320610", 290, ON_10, 11, 3, 4, 10);
-        testMessage("09130009232D2E013970", PT2262, "144082", 313, OFF_14, 9, 2, 14, 1);
-        testMessage("091300CA0F8D2801AA70", PT2262, "63698", 426, ON_8, 202, 2, 4, 8);
+        testMessageWithoutCommandIds("091300E1D8AD59018F70", PT2262, "887509", 399, 9, 225, 2, OnOffType.ON);
+        testMessageWithoutCommandIds("0913005FA9A9C901A170", PT2262, "694940", 417, 9, 95, 2, OnOffType.ON);
+        testMessageWithoutCommandIds("091300021D155C01E960", PT2262, "119125", 489, 12, 2, 2, OnOffType.ON);
+        testMessageWithoutCommandIds("091300D345DD99018C50", PT2262, "286169", 396, 9, 211, 2, OnOffType.ON);
+        testMessageWithoutCommandIds("09130035D149A2017750", PT2262, "857242", 375, 2, 53, 2, OnOffType.OFF);
+        testMessageWithoutCommandIds("0913000B4E462A012280", PT2262, "320610", 290, 10, 11, 3, OnOffType.ON);
+        testMessageWithoutCommandIds("09130009232D2E013970", PT2262, "144082", 313, 14, 9, 2, OnOffType.OFF);
+        testMessageWithoutCommandIds("091300CA0F8D2801AA70", PT2262, "63698", 426, 8, 202, 2, OnOffType.ON);
     }
 
     @Test
     public void testSomeAlarmRemote() throws RFXComException {
-        testMessage("0913004A0D8998016E60", PT2262, "55449", 366, ON_8, 74, 2, 4, 8);
+        testMessageWithoutCommandIds("0913004A0D8998016E60", PT2262, "55449", 366, 8, 74, 2, OnOffType.ON);
     }
 
     @Test
     public void testCheapPirSensor() throws RFXComException {
-        testMessage("091300EF505FC6019670", PT2262, "329212", 406, ON_6, 239, 2, 4, 6);
+        testMessageWithoutCommandIds("091300EF505FC6019670", PT2262, "329212", 406, 6, 239, 2, OnOffType.ON);
     }
 
     @Test
     public void testSomeConradMessages() throws RFXComException {
-        testMessage("0913003554545401A150", PT2262, "345413", 417, OFF_4, 53, 2, 4, 1);
+        testMessageWithoutCommandIds("0913003554545401A150", PT2262, "345413", 417, 4, 53, 2, OnOffType.OFF);
     }
 
     @Test
@@ -113,7 +142,7 @@ public class RFXComLighting4MessageTest {
                 "0913004C044551013780", "0913004E044551013780");
 
         for (String message : onMessages) {
-            testMessage(message, PT2262, "17493", null, ON_1, null, 3, 4, 1);
+            testMessageWithoutCommandIds(message, PT2262, "17493", null, 1, null, 3, OnOffType.ON);
         }
 
         List<String> offMessages = Arrays.asList("09130051044554013980", "09130053044554013680", "09130055044554013680",
@@ -121,7 +150,149 @@ public class RFXComLighting4MessageTest {
                 "09130060044554013980", "09130062044554013680", "09130064044554013280");
 
         for (String message : offMessages) {
-            testMessage(message, PT2262, "17493", null, OFF_4, null, 3, 4, 1);
+            testMessageWithoutCommandIds(message, PT2262, "17493", null, 4, null, 3, OnOffType.OFF);
+        }
+    }
+
+    private void testRxWithConfig(String hexMsg, RFXComDeviceConfiguration config,
+            RFXComLighting4Message.SubType subType, String deviceId, @Nullable Integer pulse, int commandByte,
+            @Nullable Integer seqNbr, int signalLevel, ChannelUID channelUID, Command command) throws RFXComException {
+        RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE
+                .createMessage(HexUtils.hexToBytes(hexMsg));
+        assertEquals(deviceId, msg.getDeviceId(), "Sensor Id");
+        assertEquals(commandByte, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_COMMAND_ID), "Command");
+        if (seqNbr != null) {
+            assertEquals(seqNbr.shortValue(), (short) (msg.seqNbr & 0xFF), "Seq Number");
         }
+        assertEquals(signalLevel, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_SIGNAL_LEVEL),
+                "Signal Level");
+        assertEquals(command, msg.convertToCommand(channelUID.getId(), config, null));
+
+        byte[] decoded = msg.decodeMessage();
+
+        assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Message converted back");
+
+        checkDiscoveryResult(msg, deviceId, pulse, subType.toString());
+    }
+
+    @Test
+    public void testRxWithFullConfig() throws RFXComException {
+        RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration();
+        config.deviceId = "12345";
+        config.subType = PT2262.toString();
+        config.onCommandId = 0xA;
+        config.offCommandId = 0xB;
+        config.openCommandId = 0xC;
+        config.closedCommandId = 0xD;
+
+        testRxWithConfig("0913003503039A01A150", config, PT2262, "12345", 417, 0xA, 53, 2, commandChannelUID,
+                OnOffType.ON);
+        testRxWithConfig("0913003503039B01A150", config, PT2262, "12345", 417, 0xB, 53, 2, commandChannelUID,
+                OnOffType.OFF);
+        testRxWithConfig("0913003503039C01A150", config, PT2262, "12345", 417, 0xC, 53, 2, contactChannelUID,
+                OpenClosedType.OPEN);
+        testRxWithConfig("0913003503039D01A150", config, PT2262, "12345", 417, 0xD, 53, 2, contactChannelUID,
+                OpenClosedType.CLOSED);
+    }
+
+    @Test
+    public void testRxWithPartialConfig() throws RFXComException {
+        RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration();
+        config.deviceId = "12345";
+        config.subType = PT2262.toString();
+        config.onCommandId = 0xA;
+        config.openCommandId = 0xC;
+
+        testRxWithConfig("0913003503039A01A150", config, PT2262, "12345", 417, 0xA, 53, 2, commandChannelUID,
+                OnOffType.ON);
+        assertThrows(RFXComInvalidStateException.class, () -> testRxWithConfig("0913003503039B01A150", config, PT2262,
+                "12345", 417, 0xB, 53, 2, commandChannelUID, OnOffType.OFF));
+        testRxWithConfig("0913003503039C01A150", config, PT2262, "12345", 417, 0xC, 53, 2, contactChannelUID,
+                OpenClosedType.OPEN);
+        assertThrows(RFXComInvalidStateException.class, () -> testRxWithConfig("0913003503039D01A150", config, PT2262,
+                "12345", 417, 0xD, 53, 2, contactChannelUID, OpenClosedType.CLOSED));
+    }
+
+    @Test
+    public void testRxWithNoConfig() throws RFXComException {
+        RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration();
+        config.deviceId = "12345";
+        config.subType = PT2262.toString();
+
+        // These will fall back on deprecated behaviour, but should all be assertThrows in the future.
+        testRxWithConfig("0913003503039A01A150", config, PT2262, "12345", 417, 0xA, 53, 2, commandChannelUID,
+                OnOffType.ON);
+        testRxWithConfig("0913003503039B01A150", config, PT2262, "12345", 417, 0xB, 53, 2, commandChannelUID,
+                OnOffType.ON);
+        testRxWithConfig("0913003503039C01A150", config, PT2262, "12345", 417, 0xC, 53, 2, contactChannelUID,
+                OpenClosedType.OPEN);
+        testRxWithConfig("0913003503039D01A150", config, PT2262, "12345", 417, 0xD, 53, 2, contactChannelUID,
+                OpenClosedType.OPEN);
+    }
+
+    private void testTxWithConfig(RFXComDeviceConfiguration config, ChannelUID channelUID, Command command,
+            RFXComLighting4Message.SubType subType, String deviceId, @Nullable Integer pulse, int commandByte,
+            String hexMsg) throws RFXComException {
+        RFXComLighting4Message msg = (RFXComLighting4Message) RFXComMessageFactoryImpl.INSTANCE
+                .createMessage(PacketType.LIGHTING4, config, channelUID, command);
+        assertEquals(deviceId, msg.getDeviceId(), "Sensor Id");
+        assertEquals(commandByte, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_COMMAND_ID), "Command");
+        assertEquals(0, msg.seqNbr & 0xFF, "Seq Number");
+        assertEquals(0, RFXComTestHelper.getActualIntValue(msg, config, CHANNEL_SIGNAL_LEVEL), "Signal Level");
+        assertEquals(hexMsg, HexUtils.bytesToHex(msg.decodeMessage()), "Message bytes");
+    }
+
+    @Test
+    void testTxWithFullConfig() throws RFXComException {
+        RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration();
+        config.deviceId = "703696";
+        config.subType = PT2262.toString();
+        config.onCommandId = 0xA;
+        config.offCommandId = 0xB;
+        config.openCommandId = 0xC;
+        config.closedCommandId = 0xD;
+        config.pulse = 417;
+
+        testTxWithConfig(config, commandChannelUID, OnOffType.ON, PT2262, "703696", 417, 0xA, "09130000ABCD0A01A100");
+        testTxWithConfig(config, commandChannelUID, OnOffType.OFF, PT2262, "703696", 417, 0xB, "09130000ABCD0B01A100");
+        testTxWithConfig(config, contactChannelUID, OpenClosedType.OPEN, PT2262, "703696", 417, 0xC,
+                "09130000ABCD0C01A100");
+        testTxWithConfig(config, contactChannelUID, OpenClosedType.CLOSED, PT2262, "703696", 417, 0xD,
+                "09130000ABCD0D01A100");
+    }
+
+    @Test
+    void testTxWithPartialConfig() throws RFXComException {
+        RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration();
+        config.deviceId = "703696";
+        config.subType = PT2262.toString();
+        config.onCommandId = 0xA;
+        config.openCommandId = 0xC;
+        config.pulse = 417;
+
+        testTxWithConfig(config, commandChannelUID, OnOffType.ON, PT2262, "703696", 417, 0xA, "09130000ABCD0A01A100");
+        // Falls back on deprecated behaviour, but should be assertThrows in the future.
+        testTxWithConfig(config, commandChannelUID, OnOffType.OFF, PT2262, "703696", 417, 0x4, "09130000ABCD0401A100");
+        testTxWithConfig(config, contactChannelUID, OpenClosedType.OPEN, PT2262, "703696", 417, 0xC,
+                "09130000ABCD0C01A100");
+        assertThrows(RFXComInvalidStateException.class, () -> testTxWithConfig(config, contactChannelUID,
+                OpenClosedType.CLOSED, PT2262, "703696", 417, 0xD, "??"));
+    }
+
+    @Test
+    void testTxWithNoConfig() throws RFXComException {
+        RFXComLighting4DeviceConfiguration config = new RFXComLighting4DeviceConfiguration();
+        config.deviceId = "703696";
+        config.subType = PT2262.toString();
+        config.pulse = 417;
+
+        // Falls back on deprecated behaviour, but should be assertThrows in the future.
+        testTxWithConfig(config, commandChannelUID, OnOffType.ON, PT2262, "703696", 417, 0x1, "09130000ABCD0101A100");
+        // Falls back on deprecated behaviour, but should be assertThrows in the future.
+        testTxWithConfig(config, commandChannelUID, OnOffType.OFF, PT2262, "703696", 417, 0x4, "09130000ABCD0401A100");
+        assertThrows(RFXComInvalidStateException.class, () -> testTxWithConfig(config, contactChannelUID,
+                OpenClosedType.OPEN, PT2262, "703696", 417, 0xC, "??"));
+        assertThrows(RFXComInvalidStateException.class, () -> testTxWithConfig(config, contactChannelUID,
+                OpenClosedType.CLOSED, PT2262, "703696", 417, 0xD, "??"));
     }
 }
index 64aa2bf72003c882f955d02377116a00cb43f8a0..1bca6cf76513927a6973cb9c6e44f23296a6a701 100644 (file)
 package org.openhab.binding.rfxcom.internal.messages;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
+import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_COMMAND_STRING;
+import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.commandChannelUID;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.LIGHTING5;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.Commands.*;
-import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting5Message.SubType.IT;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.junit.jupiter.api.Test;
+import org.openhab.binding.rfxcom.internal.RFXComTestHelper;
+import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
-import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.StringType;
 import org.openhab.core.util.HexUtils;
@@ -34,30 +35,33 @@ import org.openhab.core.util.HexUtils;
 @NonNullByDefault
 public class RFXComLighting5MessageTest {
     private final MockDeviceState deviceState = new MockDeviceState();
+    private static final RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+    static {
+        config.deviceId = "2061.1";
+        config.subType = RFXComLighting5Message.SubType.IT.toString();
+    }
 
     @Test
     public void convertFromStateItMessage() throws RFXComException {
-        RFXComDeviceMessage itMessageObject = (RFXComDeviceMessage) RFXComMessageFactoryImpl.INSTANCE
-                .createMessage(LIGHTING5);
-        itMessageObject.setDeviceId("2061.1");
-        itMessageObject.setSubType(IT);
-        itMessageObject.convertFromState(CHANNEL_COMMAND, OnOffType.ON);
+        RFXComMessage itMessageObject = RFXComMessageFactoryImpl.INSTANCE.createMessage(LIGHTING5, config,
+                commandChannelUID, OnOffType.ON);
         byte[] message = itMessageObject.decodeMessage();
         String hexMessage = HexUtils.bytesToHex(message);
         assertEquals("0A140F0000080D01010000", hexMessage, "Message is not as expected");
         RFXComLighting5Message msg = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE.createMessage(message);
-        assertEquals(IT, msg.subType, "SubType");
+        assertEquals(RFXComLighting5Message.SubType.IT, msg.subType, "SubType");
         assertEquals("2061.1", msg.getDeviceId(), "Sensor Id");
         assertEquals(ON, msg.command, "Command");
     }
 
     @Test
     public void basicBoundaryCheck() throws RFXComException {
-        RFXComLighting5Message message = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE
-                .createMessage(LIGHTING5);
+        RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+        config.deviceId = "206.1";
+        config.subType = RFXComLighting5Message.SubType.LIGHTWAVERF.toString();
 
-        message.subType = RFXComLighting5Message.SubType.LIGHTWAVERF;
-        message.command = ON;
+        RFXComLighting5Message message = (RFXComLighting5Message) RFXComMessageFactoryImpl.INSTANCE
+                .createMessage(LIGHTING5, config, commandChannelUID, OnOffType.ON);
 
         RFXComTestHelper.basicBoundaryCheck(LIGHTING5, message);
     }
@@ -65,29 +69,30 @@ public class RFXComLighting5MessageTest {
     // TODO please add more tests for different messages
 
     @Test
-    public void testStringCommandOpenRelay() throws RFXComUnsupportedChannelException {
+    public void testStringCommandOpenRelay() throws RFXComException {
         RFXComLighting5Message msg = new RFXComLighting5Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OPEN_RELAY"));
-        assertEquals(StringType.valueOf("OPEN_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(StringType.valueOf("OPEN_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
         assertEquals(OPEN_RELAY, msg.command);
     }
 
     @Test
-    public void testStringCommandCloseRelay() throws RFXComUnsupportedChannelException {
+    public void testStringCommandCloseRelay() throws RFXComException {
         RFXComLighting5Message msg = new RFXComLighting5Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("CLOSE_RELAY"));
-        assertEquals(StringType.valueOf("CLOSE_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(StringType.valueOf("CLOSE_RELAY"),
+                msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
         assertEquals(CLOSE_RELAY, msg.command);
     }
 
     @Test
-    public void testStringCommandStopRelay() throws RFXComUnsupportedChannelException {
+    public void testStringCommandStopRelay() throws RFXComException {
         RFXComLighting5Message msg = new RFXComLighting5Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("STOP_RELAY"));
-        assertEquals(StringType.valueOf("STOP_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(StringType.valueOf("STOP_RELAY"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
         assertEquals(STOP_RELAY, msg.command);
     }
 }
index 639763e6d78c22fdbb69eb1889d11d7bee737fa2..b75416a891ab7936b6a22fdc4f275a98101585d6 100644 (file)
@@ -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));
     }
 }
index 5d0b48f24d9e61a3c16a7e38240996977f4145e1..45d19afc2873775c43ff903382fb7bb54146660a 100644 (file)
@@ -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));
     }
 }
index 2f9a401aadb9bd05d50bc091df389781daacbd7c..d3690a33d4c88f1ca40033bd150d553d21d7dc16 100644 (file)
@@ -89,7 +89,7 @@ public class RFXComRFXSensorMessageTest {
 
     private @Nullable Double getChannelAsDouble(String channelId, RFXComRFXSensorMessage msg, DeviceState deviceState)
             throws RFXComException {
-        return getStateAsDouble(msg.convertToState(channelId, deviceState));
+        return getStateAsDouble(msg.convertToState(channelId, null, deviceState));
     }
 
     private @Nullable Double getStateAsDouble(State state) {
index 088f600b8b1f5805ae60c6b817e56953dc0fbfcf..9cf34448f2edc4aaca037092258ad7cdc063fd4e 100644 (file)
@@ -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));
     }
 }
index 188c7fc8b6209c990f9e53a0fcc4176241165edd..e22d4c7f6eff01e01e0798a1737d1ea825b0e1be 100644 (file)
 package org.openhab.binding.rfxcom.internal.messages;
 
 import static org.junit.jupiter.api.Assertions.*;
+import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.commandChannelUID;
 
 import java.nio.ByteBuffer;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.junit.jupiter.api.Test;
-import org.openhab.binding.rfxcom.internal.RFXComBindingConstants;
 import org.openhab.binding.rfxcom.internal.config.RFXComRawDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
 import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
 import org.openhab.core.library.types.OnOffType;
-import org.openhab.core.types.Type;
+import org.openhab.core.types.Command;
 import org.openhab.core.util.HexUtils;
 
 /**
@@ -34,7 +34,6 @@ import org.openhab.core.util.HexUtils;
  */
 @NonNullByDefault
 public class RFXComRawMessageTest {
-
     private void testMessageRx(String hexMsg, RFXComRawMessage.SubType subType, int seqNbr, int repeat, String pulses)
             throws RFXComException {
         final RFXComRawMessage msg = (RFXComRawMessage) RFXComMessageFactoryImpl.INSTANCE
@@ -53,11 +52,10 @@ public class RFXComRawMessageTest {
         testMessageRx("087F0027051356ECC0", RFXComRawMessage.SubType.RAW_PACKET1, 0x27, 5, "1356ECC0");
     }
 
-    private void testMessageTx(RFXComRawDeviceConfiguration config, Type command, String hexMsg)
+    private void testMessageTx(RFXComRawDeviceConfiguration config, Command command, String hexMsg)
             throws RFXComException {
-        RFXComRawMessage msg = (RFXComRawMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.RAW);
-        msg.setConfig(config);
-        msg.convertFromState(RFXComBindingConstants.CHANNEL_COMMAND, command);
+        RFXComRawMessage msg = (RFXComRawMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(PacketType.RAW,
+                config, commandChannelUID, command);
         byte[] decoded = msg.decodeMessage();
 
         assertEquals(hexMsg, HexUtils.bytesToHex(decoded), "Transmitted message");
index 6480e870ebbadfc84df99fb430987345cdf64efa..6449de7407d365b4d2c87f9e59f022ad29a25a98 100644 (file)
@@ -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));
     }
 }
index bc51015ed478f81e7e376c6a69926a74773b7520..0511b43d4e779ad29b0d256f735729457c6ec94a 100644 (file)
 package org.openhab.binding.rfxcom.internal.messages;
 
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.thingUID;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.RFY;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.junit.jupiter.api.Test;
+import org.openhab.binding.rfxcom.internal.RFXComBindingConstants;
+import org.openhab.binding.rfxcom.internal.RFXComTestHelper;
+import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
-import org.openhab.binding.rfxcom.internal.messages.RFXComRfyMessage.Commands;
 import org.openhab.binding.rfxcom.internal.messages.RFXComRfyMessage.SubType;
+import org.openhab.core.library.types.IncreaseDecreaseType;
+import org.openhab.core.library.types.OpenClosedType;
+import org.openhab.core.library.types.UpDownType;
+import org.openhab.core.thing.ChannelUID;
+import org.openhab.core.types.Command;
 import org.openhab.core.util.HexUtils;
 
 /**
@@ -29,33 +37,40 @@ import org.openhab.core.util.HexUtils;
  */
 @NonNullByDefault
 public class RFXComRfyMessageTest {
+    private static ChannelUID shutterChannelUID = new ChannelUID(thingUID, RFXComBindingConstants.CHANNEL_SHUTTER);
+    private static ChannelUID venetionBlindChannelUID = new ChannelUID(thingUID,
+            RFXComBindingConstants.CHANNEL_VENETIAN_BLIND);
 
     @Test
     public void basicBoundaryCheck() throws RFXComException {
-        RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY);
+        RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+        config.deviceId = "1.1";
+        config.subType = SubType.RFY.toString();
 
-        message.subType = SubType.RFY;
-        message.command = Commands.UP;
+        RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY, config,
+                shutterChannelUID, UpDownType.UP);
 
         RFXComTestHelper.basicBoundaryCheck(RFY, message);
     }
 
-    private void testMessage(SubType subType, Commands command, String deviceId, String data) throws RFXComException {
-        RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY);
-        message.setSubType(subType);
-        message.command = command;
-        message.setDeviceId(deviceId);
+    private void testMessage(SubType subType, Command command, String deviceId, String data) throws RFXComException {
+        RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+        config.deviceId = "66051.4";
+        config.subType = subType.toString();
+
+        RFXComRfyMessage message = (RFXComRfyMessage) RFXComMessageFactoryImpl.INSTANCE.createMessage(RFY, config,
+                venetionBlindChannelUID, command);
 
         assertArrayEquals(HexUtils.hexToBytes(data), message.decodeMessage());
     }
 
     @Test
     public void testMessage1() throws RFXComException {
-        testMessage(SubType.RFY, Commands.UP_SHORT, "66051.4", "0C1A0000010203040F00000000");
+        testMessage(SubType.RFY, OpenClosedType.OPEN, "66051.4", "0C1A0000010203040F00000000");
     }
 
     @Test
     public void testMessage2() throws RFXComException {
-        testMessage(SubType.ASA, Commands.DOWN_LONG, "66051.4", "0C1A0300010203041200000000");
+        testMessage(SubType.ASA, IncreaseDecreaseType.INCREASE, "66051.4", "0C1A0300010203041200000000");
     }
 }
diff --git a/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComTestHelper.java b/bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComTestHelper.java
deleted file mode 100644 (file)
index fe79260..0000000
+++ /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<String, Object> 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();
-    }
-}
index c582dc67426f9da6247f18b358fb19ebea283771..fb61a52008adea8509e2fe319d15f98de743893a 100644 (file)
@@ -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));
     }
 }
index fc4319441bd56ebd84ff3378909c44048944c216..431358e11ca9acfebc81af51c8bbaab0c89c3dd7 100644 (file)
@@ -14,14 +14,16 @@ package org.openhab.binding.rfxcom.internal.messages;
 
 import static org.junit.jupiter.api.Assertions.*;
 import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
+import static org.openhab.binding.rfxcom.internal.RFXComTestHelper.commandChannelUID;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.THERMOSTAT3;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComThermostat3Message.SubType.*;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.junit.jupiter.api.Test;
+import org.openhab.binding.rfxcom.internal.RFXComTestHelper;
+import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
-import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.StopMoveType;
 import org.openhab.core.library.types.StringType;
@@ -37,20 +39,24 @@ import org.openhab.core.util.HexUtils;
  */
 @NonNullByDefault
 public class RFXComThermostat3MessageTest {
+    private static RFXComGenericDeviceConfiguration config = new RFXComGenericDeviceConfiguration();
+
+    static {
+        config.deviceId = "106411";
+        config.subType = RFXComThermostat3Message.SubType.MERTIK__G6R_H4S_TRANSMIT_ONLY.toString();
+    }
+
     private final MockDeviceState deviceState = new MockDeviceState();
 
     @Test
     public void checkForSupportTest() throws RFXComException {
-        RFXComMessageFactoryImpl.INSTANCE.createMessage(THERMOSTAT3);
+        RFXComMessageFactoryImpl.INSTANCE.createMessage(THERMOSTAT3, config, commandChannelUID, OnOffType.ON);
     }
 
     @Test
     public void basicBoundaryCheck() throws RFXComException {
         RFXComThermostat3Message message = (RFXComThermostat3Message) RFXComMessageFactoryImpl.INSTANCE
-                .createMessage(THERMOSTAT3);
-
-        message.subType = RFXComThermostat3Message.SubType.MERTIK__G6R_H4S_TRANSMIT_ONLY;
-        message.command = RFXComThermostat3Message.Commands.ON;
+                .createMessage(THERMOSTAT3, config, commandChannelUID, OnOffType.ON);
 
         RFXComTestHelper.basicBoundaryCheck(THERMOSTAT3, message);
     }
@@ -77,213 +83,212 @@ public class RFXComThermostat3MessageTest {
         assertEquals(command, msg.command, CHANNEL_COMMAND);
         assertEquals(signalLevel, msg.signalLevel, "Signal Level");
 
-        assertEquals(commandChannel, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(secondCommandChannel, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
-        assertEquals(controlChannel, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(commandStringChannel, msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(commandChannel, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(secondCommandChannel, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
+        assertEquals(controlChannel, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(commandStringChannel, msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
 
         byte[] decoded = msg.decodeMessage();
 
         assertEquals(hexMessage, HexUtils.bytesToHex(decoded), "Message converted back");
     }
-    // TODO please add tests for real messages
 
     @Test
-    public void testCommandChannelOn() throws RFXComUnsupportedChannelException {
+    public void testCommandChannelOn() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND, OnOffType.ON);
 
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("ON"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("ON"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testCommandChannelOff() throws RFXComUnsupportedChannelException {
+    public void testCommandChannelOff() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND, OnOffType.OFF);
 
-        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
-        assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
+        assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
     }
 
     @Test
-    public void testSecondCommandChannelOn() throws RFXComUnsupportedChannelException {
+    public void testSecondCommandChannelOn() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_SECOND, OnOffType.ON);
 
-        assertNull(msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
-        assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("SECOND_ON"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("SECOND_ON"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
     }
 
     @Test
-    public void testSecondCommandChannelOff() throws RFXComUnsupportedChannelException {
+    public void testSecondCommandChannelOff() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_SECOND, OnOffType.OFF);
 
-        assertNull(msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
-        assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("SECOND_OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("SECOND_OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
     }
 
     @Test
-    public void testControlUp() throws RFXComUnsupportedChannelException {
+    public void testControlUp() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_CONTROL, UpDownType.UP);
 
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("UP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("UP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
 
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testControlDown() throws RFXComUnsupportedChannelException {
+    public void testControlDown() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_CONTROL, UpDownType.DOWN);
 
-        assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
 
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testControlStop() throws RFXComUnsupportedChannelException {
+    public void testControlStop() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_CONTROL, StopMoveType.STOP);
 
-        assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(StringType.valueOf("STOP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(StringType.valueOf("STOP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
 
-        assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testCommandStringOff() throws RFXComUnsupportedChannelException {
+    public void testCommandStringOff() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("OFF"));
 
-        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testCommandStringOn() throws RFXComUnsupportedChannelException {
+    public void testCommandStringOn() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("On"));
 
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("ON"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("ON"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testCommandStringUp() throws RFXComUnsupportedChannelException {
+    public void testCommandStringUp() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("UP"));
 
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("UP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("UP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
 
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testCommandStringDown() throws RFXComUnsupportedChannelException {
+    public void testCommandStringDown() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("down"));
 
-        assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testCommandStringRunUp() throws RFXComUnsupportedChannelException {
+    public void testCommandStringRunUp() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("RUN_UP"));
 
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("RUN_UP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(UpDownType.UP, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("RUN_UP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testCommandStringRunDown() throws RFXComUnsupportedChannelException {
+    public void testCommandStringRunDown() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("RUN_DOWN"));
 
-        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertEquals(StringType.valueOf("RUN_DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(UpDownType.DOWN, msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertEquals(StringType.valueOf("RUN_DOWN"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testCommandStringStop() throws RFXComUnsupportedChannelException {
+    public void testCommandStringStop() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("STOP"));
 
-        assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertEquals(StringType.valueOf("STOP"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(UnDefType.UNDEF, msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertEquals(StringType.valueOf("STOP"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
 
-        assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState));
-        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
+        assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
     }
 
     @Test
-    public void testCommandStringSecondOn() throws RFXComUnsupportedChannelException {
+    public void testCommandStringSecondOn() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("SECOND_ON"));
 
-        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
-        assertEquals(StringType.valueOf("SECOND_ON"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(OnOffType.ON, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
+        assertEquals(StringType.valueOf("SECOND_ON"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
 
-        assertNull(msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState));
     }
 
     @Test
-    public void testCommandStringSecondOff() throws RFXComUnsupportedChannelException {
+    public void testCommandStringSecondOff() throws RFXComException {
         RFXComThermostat3Message msg = new RFXComThermostat3Message();
 
         msg.convertFromState(CHANNEL_COMMAND_STRING, StringType.valueOf("SECOND_OFF"));
 
-        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND_SECOND, deviceState));
-        assertEquals(StringType.valueOf("SECOND_OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, deviceState));
+        assertEquals(OnOffType.OFF, msg.convertToState(CHANNEL_COMMAND_SECOND, config, deviceState));
+        assertEquals(StringType.valueOf("SECOND_OFF"), msg.convertToState(CHANNEL_COMMAND_STRING, config, deviceState));
 
-        assertNull(msg.convertToState(CHANNEL_COMMAND, deviceState));
-        assertNull(msg.convertToState(CHANNEL_CONTROL, deviceState));
+        assertNull(msg.convertToState(CHANNEL_COMMAND, config, deviceState));
+        assertNull(msg.convertToState(CHANNEL_CONTROL, config, deviceState));
     }
 }
index a724aa902462bad4da592e10c3efc987fd2c45da..d6e6d9faceec0e04f722d6915192d6aab2178c49 100644 (file)
@@ -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));
     }
 }
index 0fe249b5edfcc9c33ba3c5f84bbec8411abbacb9..09bc5d3a57bee105a3223885e0719c5c91c2bfb4 100644 (file)
@@ -18,7 +18,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.junit.jupiter.api.Test;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComMessageTooLongException;
-import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
 import org.openhab.core.util.HexUtils;
 
 /**
@@ -51,12 +50,9 @@ public class RFXComUndecodedRFMessageTest {
 
     @Test
     public void testLongMessage() throws RFXComException {
-        RFXComUndecodedRFMessage msg = (RFXComUndecodedRFMessage) RFXComMessageFactoryImpl.INSTANCE
-                .createMessage(PacketType.UNDECODED_RF_MESSAGE);
-        msg.subType = RFXComUndecodedRFMessage.SubType.ARC;
-        msg.seqNbr = 1;
-        msg.rawPayload = HexUtils.hexToBytes("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021");
-
-        assertThrows(RFXComMessageTooLongException.class, () -> msg.decodeMessage());
+        assertThrows(RFXComMessageTooLongException.class,
+                () -> testMessage("25030101000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021",
+                        RFXComUndecodedRFMessage.SubType.ARC, 0x01,
+                        "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021"));
     }
 }
index 163fd5c635f06cb5a1e77483bbb2705a04914644..52ebe29e008dd4c3f040b546ccc05363e634d824 100644 (file)
@@ -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));
     }
 }
index 96789f029278e7aee4d0cbf4adcdc3d4dd1d37c4..bb57550b64a91d83f492bee9d99badc62ceba4af 100644 (file)
@@ -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));
     }
 }