[knx] Java17 instanceof pattern matching (#14718)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
parent
2c2ba4bed1
commit
dba83a33e5
|
@ -78,8 +78,7 @@ public class DPTUnits {
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
try {
|
try {
|
||||||
Object o = field.get(null);
|
Object o = field.get(null);
|
||||||
if (o instanceof DPT) {
|
if (o instanceof DPT dpt) {
|
||||||
DPT dpt = (DPT) o;
|
|
||||||
String unit = dpt.getUnit().replaceAll(" ", "");
|
String unit = dpt.getUnit().replaceAll(" ", "");
|
||||||
// Calimero provides some units (like "ms⁻²") that can't be parsed by our library because of the
|
// Calimero provides some units (like "ms⁻²") that can't be parsed by our library because of the
|
||||||
// negative exponent
|
// negative exponent
|
||||||
|
|
|
@ -87,8 +87,8 @@ public class ValueEncoder {
|
||||||
DPT dpt = translator.getType();
|
DPT dpt = translator.getType();
|
||||||
|
|
||||||
// check for HSBType first, because it extends PercentType as well
|
// check for HSBType first, because it extends PercentType as well
|
||||||
if (value instanceof HSBType) {
|
if (value instanceof HSBType type) {
|
||||||
return handleHSBType(dptId, (HSBType) value);
|
return handleHSBType(dptId, type);
|
||||||
} else if (value instanceof OnOffType) {
|
} else if (value instanceof OnOffType) {
|
||||||
return OnOffType.OFF.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue();
|
return OnOffType.OFF.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue();
|
||||||
} else if (value instanceof UpDownType) {
|
} else if (value instanceof UpDownType) {
|
||||||
|
@ -101,15 +101,15 @@ public class ValueEncoder {
|
||||||
return OpenClosedType.CLOSED.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue();
|
return OpenClosedType.CLOSED.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue();
|
||||||
} else if (value instanceof StopMoveType) {
|
} else if (value instanceof StopMoveType) {
|
||||||
return StopMoveType.STOP.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue();
|
return StopMoveType.STOP.equals(value) ? dpt.getLowerValue() : dpt.getUpperValue();
|
||||||
} else if (value instanceof PercentType) {
|
} else if (value instanceof PercentType type) {
|
||||||
int intValue = ((PercentType) value).intValue();
|
int intValue = type.intValue();
|
||||||
return "251.600".equals(dptId) ? String.format("- - - %d %%", intValue) : String.valueOf(intValue);
|
return "251.600".equals(dptId) ? String.format("- - - %d %%", intValue) : String.valueOf(intValue);
|
||||||
} else if (value instanceof DecimalType || value instanceof QuantityType<?>) {
|
} else if (value instanceof DecimalType || value instanceof QuantityType<?>) {
|
||||||
return handleNumericTypes(dptId, mainNumber, dpt, value);
|
return handleNumericTypes(dptId, mainNumber, dpt, value);
|
||||||
} else if (value instanceof StringType) {
|
} else if (value instanceof StringType) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
} else if (value instanceof DateTimeType) {
|
} else if (value instanceof DateTimeType type) {
|
||||||
return handleDateTimeType(dptId, (DateTimeType) value);
|
return handleDateTimeType(dptId, type);
|
||||||
}
|
}
|
||||||
} catch (KNXException e) {
|
} catch (KNXException e) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -366,9 +366,9 @@ public class DeviceThingHandler extends BaseThingHandler implements GroupAddress
|
||||||
if (oldFuture != null) {
|
if (oldFuture != null) {
|
||||||
oldFuture.cancel(true);
|
oldFuture.cancel(true);
|
||||||
}
|
}
|
||||||
if (value instanceof IncreaseDecreaseType) {
|
if (value instanceof IncreaseDecreaseType type) {
|
||||||
channelFutures.put(channelUID, scheduler.scheduleWithFixedDelay(
|
channelFutures.put(channelUID, scheduler.scheduleWithFixedDelay(
|
||||||
() -> postCommand(channelUID, (Command) value), 0, frequency, TimeUnit.MILLISECONDS));
|
() -> postCommand(channelUID, type), 0, frequency, TimeUnit.MILLISECONDS));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (value instanceof Command command) {
|
if (value instanceof Command command) {
|
||||||
|
|
Loading…
Reference in New Issue