From 9c19aa70e9f6eaeb5777f6ab9ff31d9a627fb4cf Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 26 Nov 2024 23:00:30 +0100 Subject: [PATCH] Simplify DateTimeType handling for VolvoOnCall Signed-off-by: Jacob Laursen --- .../binding/volvooncall/internal/dto/TripDetail.java | 4 +--- .../volvooncall/internal/handler/VehicleHandler.java | 6 ++++-- .../internal/wrapper/VehiclePositionWrapper.java | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/dto/TripDetail.java b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/dto/TripDetail.java index 46b2ab8c06d..5568e175fb6 100644 --- a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/dto/TripDetail.java +++ b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/dto/TripDetail.java @@ -15,7 +15,6 @@ package org.openhab.binding.volvooncall.internal.dto; import static org.openhab.binding.volvooncall.internal.VolvoOnCallBindingConstants.UNDEFINED; import java.time.Duration; -import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.temporal.Temporal; import java.util.Optional; @@ -47,8 +46,7 @@ public class TripDetail { private @NonNullByDefault({}) PositionData endPosition; private State ZonedDateTimeToState(@Nullable ZonedDateTime datetime) { - return datetime != null ? new DateTimeType(datetime.withZoneSameInstant(ZoneId.systemDefault())) - : UnDefType.NULL; + return datetime != null ? new DateTimeType(datetime) : UnDefType.NULL; } private State getPositionAsState(PositionData details) { diff --git a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/handler/VehicleHandler.java b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/handler/VehicleHandler.java index 01d0c190214..fc65a8892a6 100644 --- a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/handler/VehicleHandler.java +++ b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/handler/VehicleHandler.java @@ -17,7 +17,8 @@ import static org.openhab.core.library.unit.MetricPrefix.KILO; import static org.openhab.core.library.unit.SIUnits.*; import static org.openhab.core.library.unit.Units.*; -import java.time.ZonedDateTime; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -426,7 +427,8 @@ public class VehicleHandler extends BaseThingHandler { : UnDefType.UNDEF; case CHARGING_END: return hvBattery.timeToHVBatteryFullyCharged != UNDEFINED && hvBattery.timeToHVBatteryFullyCharged > 0 - ? new DateTimeType(ZonedDateTime.now().plusMinutes(hvBattery.timeToHVBatteryFullyCharged)) + ? new DateTimeType( + Instant.now().plus(hvBattery.timeToHVBatteryFullyCharged, ChronoUnit.MINUTES)) : UnDefType.UNDEF; } return UnDefType.NULL; diff --git a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/wrapper/VehiclePositionWrapper.java b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/wrapper/VehiclePositionWrapper.java index 1fdfe7e27f6..02f758367c2 100644 --- a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/wrapper/VehiclePositionWrapper.java +++ b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/wrapper/VehiclePositionWrapper.java @@ -12,7 +12,6 @@ */ package org.openhab.binding.volvooncall.internal.wrapper; -import java.time.ZoneId; import java.util.Objects; import java.util.Optional; @@ -86,7 +85,6 @@ public class VehiclePositionWrapper { public State getTimestamp() { return Objects.requireNonNull(Optional.ofNullable(this.position).flatMap(pos -> pos.getTimestamp()) - .map(dt -> (State) new DateTimeType(dt.withZoneSameInstant(ZoneId.systemDefault()))) - .orElse(UnDefType.NULL)); + .map(dt -> (State) new DateTimeType(dt)).orElse(UnDefType.NULL)); } }