From 1231e7d2e9873cf004595adeb9912c6d854648fc Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 10 Dec 2024 21:32:54 +0100 Subject: [PATCH] Simplify DateTimeType handling for AVM FRITZ! Signed-off-by: Jacob Laursen --- .../internal/handler/AVMFritzBaseThingHandler.java | 6 ++---- .../internal/handler/AVMFritzButtonHandler.java | 10 +++------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java index ff4e72c294e..167cfe87e75 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java @@ -59,7 +59,6 @@ import static org.openhab.binding.avmfritz.internal.dto.HeatingModel.toCelsius; import java.math.BigDecimal; import java.time.Instant; -import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Map; @@ -314,9 +313,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen NextChangeModel nextChange = heatingModel.getNextchange(); if (nextChange != null) { int endPeriod = nextChange.getEndperiod(); - updateThingChannelState(CHANNEL_NEXT_CHANGE, endPeriod == 0 ? UnDefType.UNDEF - : new DateTimeType( - ZonedDateTime.ofInstant(Instant.ofEpochSecond(endPeriod), ZoneId.systemDefault()))); + updateThingChannelState(CHANNEL_NEXT_CHANGE, + endPeriod == 0 ? UnDefType.UNDEF : new DateTimeType(Instant.ofEpochSecond(endPeriod))); BigDecimal nextTemperature = nextChange.getTchange(); updateThingChannelState(CHANNEL_NEXTTEMP, TEMP_FRITZ_UNDEFINED.equals(nextTemperature) ? UnDefType.UNDEF : new QuantityType<>(toCelsius(nextTemperature), SIUnits.CELSIUS)); diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java index 5af35748fb2..5078413186b 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java @@ -16,8 +16,6 @@ import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*; import java.math.BigDecimal; import java.time.Instant; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.List; import java.util.Optional; @@ -189,13 +187,11 @@ public class AVMFritzButtonHandler extends DeviceHandler { : channelGroupId + ChannelUID.CHANNEL_GROUP_SEPARATOR + CHANNEL_LAST_CHANGE, UnDefType.UNDEF); } else { - ZonedDateTime timestamp = ZonedDateTime.ofInstant(Instant.ofEpochSecond(lastPressedTimestamp), - ZoneId.systemDefault()); - Instant then = timestamp.toInstant(); + Instant timestamp = Instant.ofEpochSecond(lastPressedTimestamp); // Avoid dispatching events if "lastpressedtimestamp" is older than now "lastTimestamp" (e.g. during // restart) - if (then.isAfter(lastTimestamp)) { - lastTimestamp = then; + if (timestamp.isAfter(lastTimestamp)) { + lastTimestamp = timestamp; triggerThingChannel(channelGroupId == null ? CHANNEL_PRESS : channelGroupId + ChannelUID.CHANNEL_GROUP_SEPARATOR + CHANNEL_PRESS, event); }