Java 17 features (N-S) (#15565)
- add missing @override - Java style array syntax - remove redundant modifiers - always move String constants to left side in comparisons - simplify lambda expressions and return statements - use replace instead of replaceAll w/o regex - instanceof matching and multiline strings Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -116,7 +116,6 @@ public class RFXComBridgeDiscovery extends AbstractDiscoveryService {
|
||||
}
|
||||
|
||||
logger.debug("Discovery done");
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error("Error occurred during discovery", e);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
|
||||
@@ -53,8 +53,8 @@ public class RFXComDeviceDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
@Override
|
||||
public void setThingHandler(ThingHandler handler) {
|
||||
if (handler instanceof RFXComBridgeHandler) {
|
||||
bridgeHandler = (RFXComBridgeHandler) handler;
|
||||
if (handler instanceof RFXComBridgeHandler rfxComBridgeHandler) {
|
||||
bridgeHandler = rfxComBridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ package org.openhab.binding.rfxcom.internal.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@@ -133,7 +133,7 @@ public class RFXComBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(RFXComDeviceDiscoveryService.class);
|
||||
return Set.of(RFXComDeviceDiscoveryService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -226,11 +226,14 @@ public class RFXComBridgeHandler extends BaseBridgeHandler {
|
||||
logger.error("Connection to RFXCOM transceiver failed", e);
|
||||
if ("device not opened (3)".equalsIgnoreCase(e.getMessage())) {
|
||||
if (connector instanceof RFXComJD2XXConnector) {
|
||||
logger.info("Automatically Discovered RFXCOM bridges use FTDI chip driver (D2XX)."
|
||||
+ " Reason for this error normally is related to operating system native FTDI drivers,"
|
||||
+ " which prevent D2XX driver to open device."
|
||||
+ " To solve this problem, uninstall OS FTDI native drivers or add manually universal bridge 'RFXCOM USB Transceiver',"
|
||||
+ " which use normal serial port driver rather than D2XX.");
|
||||
logger.info(
|
||||
"""
|
||||
Automatically Discovered RFXCOM bridges use FTDI chip driver (D2XX).\
|
||||
Reason for this error normally is related to operating system native FTDI drivers,\
|
||||
which prevent D2XX driver to open device.\
|
||||
To solve this problem, uninstall OS FTDI native drivers or add manually universal bridge 'RFXCOM USB Transceiver',\
|
||||
which use normal serial port driver rather than D2XX.\
|
||||
""");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -259,8 +262,7 @@ public class RFXComBridgeHandler extends BaseBridgeHandler {
|
||||
RFXComMessage message = messageFactory.createMessage(packet);
|
||||
logger.debug("Message received: {}", message);
|
||||
|
||||
if (message instanceof RFXComInterfaceMessage) {
|
||||
RFXComInterfaceMessage msg = (RFXComInterfaceMessage) message;
|
||||
if (message instanceof RFXComInterfaceMessage msg) {
|
||||
if (msg.subType == SubType.RESPONSE) {
|
||||
if (msg.command == Commands.GET_STATUS) {
|
||||
logger.debug("RFXCOM transceiver/receiver type: {}, hw version: {}.{}, fw version: {}",
|
||||
@@ -322,25 +324,24 @@ public class RFXComBridgeHandler extends BaseBridgeHandler {
|
||||
logger.debug("Interface response received: {}", msg);
|
||||
transmitQueue.sendNext();
|
||||
}
|
||||
} else if (message instanceof RFXComTransmitterMessage) {
|
||||
RFXComTransmitterMessage resp = (RFXComTransmitterMessage) message;
|
||||
|
||||
} else if (message instanceof RFXComTransmitterMessage resp) {
|
||||
logger.debug("Transmitter response received: {}", resp);
|
||||
|
||||
transmitQueue.sendNext();
|
||||
} else if (message instanceof RFXComDeviceMessage) {
|
||||
} else if (message instanceof RFXComDeviceMessage deviceMessage) {
|
||||
for (DeviceMessageListener deviceStatusListener : deviceStatusListeners) {
|
||||
try {
|
||||
deviceStatusListener.onDeviceMessageReceived(getThing().getUID(),
|
||||
(RFXComDeviceMessage) message);
|
||||
deviceStatusListener.onDeviceMessageReceived(getThing().getUID(), deviceMessage);
|
||||
} catch (Exception e) {
|
||||
// catch all exceptions give all handlers a fair chance of handling the messages
|
||||
logger.error("An exception occurred while calling the DeviceStatusListener", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warn("The received message cannot be processed, please create an "
|
||||
+ "issue at the relevant tracker. Received message: {}", message);
|
||||
logger.warn("""
|
||||
The received message cannot be processed, please create an \
|
||||
issue at the relevant tracker. Received message: {}\
|
||||
""", message);
|
||||
}
|
||||
} catch (RFXComMessageNotImplementedException e) {
|
||||
logger.debug("Message not supported, data: {}", HexUtils.bytesToHex(packet));
|
||||
|
||||
@@ -160,8 +160,8 @@ public class RFXComChimeMessage extends RFXComDeviceMessageImpl<RFXComChimeMessa
|
||||
@Override
|
||||
public void convertFromState(String channelId, Type type) throws RFXComUnsupportedChannelException {
|
||||
if (CHANNEL_CHIME_SOUND.equals(channelId)) {
|
||||
if (type instanceof DecimalType) {
|
||||
chimeSound = ((DecimalType) type).intValue();
|
||||
if (type instanceof DecimalType decimalCommand) {
|
||||
chimeSound = decimalCommand.intValue();
|
||||
} else {
|
||||
throw new RFXComUnsupportedChannelException("Channel " + channelId + " does not accept " + type);
|
||||
}
|
||||
|
||||
@@ -442,8 +442,8 @@ public class RFXComFanMessage extends RFXComDeviceMessageImpl<RFXComFanMessage.S
|
||||
case "OFF":
|
||||
return Commands.valueOf(stringCommand);
|
||||
}
|
||||
} else if (type instanceof DecimalType) {
|
||||
Commands speedCommand = Commands.bySpeed(subType, ((DecimalType) type).intValue());
|
||||
} else if (type instanceof DecimalType decimalCommand) {
|
||||
Commands speedCommand = Commands.bySpeed(subType, decimalCommand.intValue());
|
||||
if (speedCommand != null) {
|
||||
return speedCommand;
|
||||
}
|
||||
|
||||
@@ -263,9 +263,9 @@ public class RFXComLighting2Message extends RFXComDeviceMessageImpl<RFXComLighti
|
||||
command = (type == OnOffType.ON ? Commands.ON : Commands.OFF);
|
||||
dimmingLevel = 0;
|
||||
|
||||
} else if (type instanceof PercentType) {
|
||||
} else if (type instanceof PercentType percentCommand) {
|
||||
command = Commands.SET_LEVEL;
|
||||
dimmingLevel = (byte) getDimLevelFromPercentType((PercentType) type);
|
||||
dimmingLevel = (byte) getDimLevelFromPercentType(percentCommand);
|
||||
|
||||
if (dimmingLevel == 0) {
|
||||
command = Commands.OFF;
|
||||
|
||||
@@ -267,8 +267,8 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
|
||||
break;
|
||||
|
||||
case CHANNEL_COMMAND_ID:
|
||||
if (type instanceof DecimalType) {
|
||||
commandId = (byte) ((DecimalType) type).intValue();
|
||||
if (type instanceof DecimalType decimalCommand) {
|
||||
commandId = (byte) decimalCommand.intValue();
|
||||
} else {
|
||||
throw new RFXComInvalidStateException(channelId, type.toString(),
|
||||
"Channel only supports DecimalType");
|
||||
|
||||
@@ -337,9 +337,9 @@ public class RFXComLighting5Message extends RFXComDeviceMessageImpl<RFXComLighti
|
||||
command = (type == OnOffType.ON ? Commands.ON : Commands.OFF);
|
||||
dimmingLevel = 0;
|
||||
|
||||
} else if (type instanceof PercentType) {
|
||||
} else if (type instanceof PercentType percentCommand) {
|
||||
command = Commands.SET_LEVEL;
|
||||
dimmingLevel = (byte) getDimLevelFromPercentType((PercentType) type);
|
||||
dimmingLevel = (byte) getDimLevelFromPercentType(percentCommand);
|
||||
|
||||
if (dimmingLevel == 0) {
|
||||
command = Commands.OFF;
|
||||
|
||||
@@ -233,8 +233,8 @@ public class RFXComThermostat3Message extends RFXComDeviceMessageImpl<RFXComTher
|
||||
command = (type == UpDownType.UP ? Commands.UP : Commands.DOWN);
|
||||
} else if (type == StopMoveType.STOP) {
|
||||
command = Commands.STOP;
|
||||
} else if (type instanceof PercentType) {
|
||||
command = ((PercentType) type).as(UpDownType.class) == UpDownType.UP ? Commands.UP : Commands.DOWN;
|
||||
} else if (type instanceof PercentType percentCommand) {
|
||||
command = percentCommand.as(UpDownType.class) == UpDownType.UP ? Commands.UP : Commands.DOWN;
|
||||
} else {
|
||||
throw new RFXComUnsupportedChannelException("Channel " + channelId + " does not accept " + type);
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ public class RFXComRFXSensorMessageTest {
|
||||
}
|
||||
|
||||
private @Nullable Double getStateAsDouble(State state) {
|
||||
if (state instanceof DecimalType) {
|
||||
return ((DecimalType) state).doubleValue();
|
||||
if (state instanceof DecimalType decimalCommand) {
|
||||
return decimalCommand.doubleValue();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user