diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/DPTUnits.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/DPTUnits.java index 21ae84111..d7a1be02d 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/DPTUnits.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/DPTUnits.java @@ -78,8 +78,7 @@ public class DPTUnits { for (Field field : fields) { try { Object o = field.get(null); - if (o instanceof DPT) { - DPT dpt = (DPT) o; + if (o instanceof DPT dpt) { String unit = dpt.getUnit().replaceAll(" ", ""); // Calimero provides some units (like "ms⁻²") that can't be parsed by our library because of the // negative exponent diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueEncoder.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueEncoder.java index 91e102ada..40af768bc 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueEncoder.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/dpt/ValueEncoder.java @@ -87,8 +87,8 @@ public class ValueEncoder { DPT dpt = translator.getType(); // check for HSBType first, because it extends PercentType as well - if (value instanceof HSBType) { - return handleHSBType(dptId, (HSBType) value); + if (value instanceof HSBType type) { + return handleHSBType(dptId, type); } else if (value instanceof OnOffType) { return OnOffType.OFF.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue(); } else if (value instanceof UpDownType) { @@ -101,15 +101,15 @@ public class ValueEncoder { return OpenClosedType.CLOSED.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue(); } else if (value instanceof StopMoveType) { return StopMoveType.STOP.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue(); - } else if (value instanceof PercentType) { - int intValue = ((PercentType) value).intValue(); + } else if (value instanceof PercentType type) { + int intValue = type.intValue(); return "251.600".equals(dptId) ? String.format("- - - %d %%", intValue) : String.valueOf(intValue); } else if (value instanceof DecimalType || value instanceof QuantityType) { return handleNumericTypes(dptId, mainNumber, dpt, value); } else if (value instanceof StringType) { return value.toString(); - } else if (value instanceof DateTimeType) { - return handleDateTimeType(dptId, (DateTimeType) value); + } else if (value instanceof DateTimeType type) { + return handleDateTimeType(dptId, type); } } catch (KNXException e) { return null; diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/DeviceThingHandler.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/DeviceThingHandler.java index b7612cdd1..be5828a82 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/DeviceThingHandler.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/DeviceThingHandler.java @@ -366,9 +366,9 @@ public class DeviceThingHandler extends BaseThingHandler implements GroupAddress if (oldFuture != null) { oldFuture.cancel(true); } - if (value instanceof IncreaseDecreaseType) { + if (value instanceof IncreaseDecreaseType type) { channelFutures.put(channelUID, scheduler.scheduleWithFixedDelay( - () -> postCommand(channelUID, (Command) value), 0, frequency, TimeUnit.MILLISECONDS)); + () -> postCommand(channelUID, type), 0, frequency, TimeUnit.MILLISECONDS)); } } else { if (value instanceof Command command) {