From cb74dd6497d9ac3d1130add93b7b7f90d5e119bf Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 19 Nov 2024 21:17:30 +0100 Subject: [PATCH] Simplify DateTimeType handling for MQTT Signed-off-by: Jacob Laursen --- .../openhab/binding/mqtt/generic/values/DateTimeValue.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/DateTimeValue.java b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/DateTimeValue.java index 27056e8328b..ba9d93f1709 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/DateTimeValue.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/DateTimeValue.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.mqtt.generic.values; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.List; @@ -45,11 +47,12 @@ public class DateTimeValue extends Value { @Override public String getMQTTpublishValue(Command command, @Nullable String pattern) { + ZonedDateTime zonedDateTime = ((DateTimeType) command).getZonedDateTime(ZoneId.systemDefault()); String formatPattern = pattern; if (formatPattern == null || "%s".contentEquals(formatPattern)) { - return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(((DateTimeType) command).getZonedDateTime()); + return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(zonedDateTime); } - return String.format(formatPattern, ((DateTimeType) command).getZonedDateTime()); + return String.format(formatPattern, zonedDateTime); } @Override