Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rfxcom] Add firmware type, avoid crashing on unknown. #10879

Merged
merged 1 commit into from
Jun 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"), // Discovered in the wild (not from RFXtrx SDK)
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);
}
}