From 9d03fc63696f654b58713f30ff41a52c94947cc0 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Sat, 2 Nov 2024 21:32:31 +0100 Subject: [PATCH] Review comment: cast Signed-off-by: Laurent Garnier --- .../handler/AnnotationActionHandler.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java index fb5acde39f8..14a4d114015 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java @@ -144,16 +144,27 @@ public AnnotationActionHandler(Action module, ActionType mt, Method method, Obje method, moduleType.getUID(), ex.getMessage()); } // we allow simple data types as return values and put them under the context key "result". - } else if (result instanceof Boolean || result instanceof String || result instanceof Byte - || result instanceof Short || result instanceof Integer || result instanceof Long - || result instanceof Float || result instanceof Double) { - output.put(MODULE_RESULT, result); + } else if (result instanceof Boolean booleanValue) { + output.put(MODULE_RESULT, booleanValue); + } else if (result instanceof String stringValue) { + output.put(MODULE_RESULT, stringValue); + } else if (result instanceof Byte byteValue) { + output.put(MODULE_RESULT, byteValue); + } else if (result instanceof Short shortValue) { + output.put(MODULE_RESULT, shortValue); + } else if (result instanceof Integer integerValue) { + output.put(MODULE_RESULT, integerValue); + } else if (result instanceof Long longValue) { + output.put(MODULE_RESULT, longValue); + } else if (result instanceof Double doubleValue) { + output.put(MODULE_RESULT, doubleValue); + } else if (result instanceof Float floatValue) { + output.put(MODULE_RESULT, floatValue); } else if (result instanceof BigDecimal bigDecimalValue) { output.put(MODULE_RESULT, bigDecimalValue.doubleValue()); - } else if (result instanceof QuantityType quantity) { - output.put(MODULE_RESULT, quantity.toString()); - } else if (result instanceof LocalDate || result instanceof LocalTime || result instanceof LocalDateTime - || result instanceof ZonedDateTime || result instanceof Instant || result instanceof Duration) { + } else if (result instanceof QuantityType || result instanceof LocalDate || result instanceof LocalTime + || result instanceof LocalDateTime || result instanceof ZonedDateTime || result instanceof Instant + || result instanceof Duration) { output.put(MODULE_RESULT, result.toString()); } else { logger.warn("Non compatible return type '{}' on action method.", result.getClass());