mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[rfxcom] Add firmware type, avoid crashing on unknown. (#10879)
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>
This commit is contained in:
parent
60c199c9c9
commit
ae4ac7d36c
@ -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]);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user