Skip to content

Commit

Permalink
[rfxcom] Add firmware type, avoid crashing on unknown.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jamstah committed Jun 18, 2021
1 parent 36d7dc2 commit 951c460
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
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.
Expand All @@ -28,6 +31,8 @@
*/
public class RFXComInterfaceMessage extends RFXComBaseMessage {

private final Logger logger = LoggerFactory.getLogger(RFXComInterfaceMessage.class);

public enum SubType implements ByteEnumWrapper {
UNKNOWN_COMMAND(-1),
RESPONSE(0),
Expand Down Expand Up @@ -89,7 +94,8 @@ public enum TransceiverType implements ByteEnumWrapper {
_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;
Expand Down Expand Up @@ -118,7 +124,9 @@ public enum FirmwareType implements ByteEnumWrapper {
EXT2(0x04, "Ext2"),
PRO1(0x05, "Pro1"),
PRO2(0x06, "Pro2"),
PROXL1(0x10, "ProXL 1");
PROXL1(0x10, "ProXL1"),
PROXL2(0x12, "ProXL2"),
UNKNOWN(0xFF, "Unknown");

private final int type;
private final String name;
Expand Down Expand Up @@ -257,7 +265,14 @@ public void encodeMessage(byte[] data) throws RFXComException {

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];
Expand All @@ -279,7 +294,14 @@ private void encodeResponseMessage(byte[] data) throws RFXComException {
*/
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]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,15 @@ public void testStatus_Rfxtrx443_Ext2_1012() throws RFXComException {
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);
}
}

0 comments on commit 951c460

Please sign in to comment.