]> git.basschouten.com Git - openhab-addons.git/commitdiff
[rfxcom] Add firmware type, avoid crashing on unknown. (#10879)
authorJames Hewitt <james.hewitt@uk.ibm.com>
Sat, 19 Jun 2021 09:29:58 +0000 (10:29 +0100)
committerGitHub <noreply@github.com>
Sat, 19 Jun 2021 09:29:58 +0000 (11:29 +0200)
New firmware type reported from the community that's not in the SDK. Also,
we don't actually _use_ the firmware type or device type for anything, so
lets not crash if we don't match the bytes - lets just flag it unknown.

https://community.openhab.org/t/rfxcom-binding-unsupported-value/123615/12

Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/messages/RFXComInterfaceMessage.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComInterfaceControlMessageTest.java
bundles/org.openhab.binding.rfxcom/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComInterfaceMessageTest.java

index bf09db4bff2821b10cfa270cfae12073fe8ad267..13b89fd79be062b829bd4e3a4ac8446fa7a02cae 100644 (file)
@@ -18,7 +18,10 @@ import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 
 import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
+import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
 import org.openhab.core.types.Type;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * RFXCOM data class for interface message.
@@ -28,6 +31,8 @@ import org.openhab.core.types.Type;
  */
 public class RFXComInterfaceMessage extends RFXComBaseMessage {
 
+    private final Logger logger = LoggerFactory.getLogger(RFXComInterfaceMessage.class);
+
     public enum SubType implements ByteEnumWrapper {
         UNKNOWN_COMMAND(-1),
         RESPONSE(0),
@@ -89,7 +94,8 @@ public class RFXComInterfaceMessage extends RFXComBaseMessage {
         _868_95MHZ_FSK(0x5B, "RFXtrx868X operating at 868.95MHz"),
         _433_92MHZ_IOT(0x5C, "RFXtrxIOT operating at 433.92MHz"),
         _868_00MHZ_IOT(0x5D, "RFXtrxIOT operating at 868MHz"),
-        _434_50MHZ(0x5F, "RFXtrx433 operating at 434.50MHz");
+        _434_50MHZ(0x5F, "RFXtrx433 operating at 434.50MHz"),
+        _UNKNOWN(0xFF, "Unknown");
 
         private final int type;
         private final String name;
@@ -118,7 +124,9 @@ public class RFXComInterfaceMessage extends RFXComBaseMessage {
         EXT2(0x04, "Ext2"),
         PRO1(0x05, "Pro1"),
         PRO2(0x06, "Pro2"),
-        PROXL1(0x10, "ProXL 1");
+        PROXL1(0x10, "ProXL1"),
+        PROXL2(0x12, "ProXL2"), // Discovered in the wild (not from RFXtrx SDK)
+        UNKNOWN(0xFF, "Unknown");
 
         private final int type;
         private final String name;
@@ -257,7 +265,14 @@ public class RFXComInterfaceMessage extends RFXComBaseMessage {
 
     private void encodeResponseMessage(byte[] data) throws RFXComException {
         command = fromByte(Commands.class, data[4]);
-        transceiverType = fromByte(TransceiverType.class, data[5]);
+        try {
+            transceiverType = fromByte(TransceiverType.class, data[5]);
+        } catch (RFXComUnsupportedValueException e) {
+            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]);
+        }
 
         hardwareVersion1 = data[11];
         hardwareVersion2 = data[12];
@@ -279,7 +294,14 @@ public class RFXComInterfaceMessage extends RFXComBaseMessage {
          */
         if (data.length > 14) {
             firmwareVersion = Byte.toUnsignedInt(data[6]) + 1000;
-            firmwareType = fromByte(FirmwareType.class, data[14]);
+            try {
+                firmwareType = fromByte(FirmwareType.class, data[14]);
+            } catch (RFXComUnsupportedValueException e) {
+                firmwareType = FirmwareType.UNKNOWN;
+                logger.warn(
+                        "The firmware 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[14]);
+            }
         } else {
             firmwareVersion = Byte.toUnsignedInt(data[6]);
 
index e530d0ab5cd8570ec5888afdcbded64c727d158e..a94c43f291de236df8768489913fa91185c8a1d9 100644 (file)
@@ -12,7 +12,7 @@
  */
 package org.openhab.binding.rfxcom.internal.messages;
 
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.openhab.binding.rfxcom.internal.messages.RFXComInterfaceMessage.TransceiverType._433_92MHZ_TRANSCEIVER;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
index 16a45f9221ba453fa4d6546f1157046cc5e33e8b..b0168b485235921e99b62208248368850a21c0fe 100644 (file)
@@ -112,4 +112,15 @@ public class RFXComInterfaceMessageTest {
         testStatus("1401000102530C0800270001031C04524658434F4D", TransceiverType._433_92MHZ_TRANSCEIVER,
                 FirmwareType.EXT2, 1012);
     }
+
+    @Test
+    public void testStatus_Unknown_Ext2_1012() throws RFXComException {
+        testStatus("1401000102AA0C0800270001031C04524658434F4D", TransceiverType._UNKNOWN, FirmwareType.EXT2, 1012);
+    }
+
+    @Test
+    public void testStatus_Rfxtrx433_Unknown_1012() throws RFXComException {
+        testStatus("1401000102530C0800270001031CAA524658434F4D", TransceiverType._433_92MHZ_TRANSCEIVER,
+                FirmwareType.UNKNOWN, 1012);
+    }
 }