From 328e91a7fc5829ca7b69c3dba9b05906ac9adda8 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Sat, 9 Nov 2024 22:49:56 +0100 Subject: [PATCH] Simplify DateTimeType handling for WeMo Signed-off-by: Jacob Laursen --- .../org/openhab/binding/wemo/internal/InsightParser.java | 6 +----- .../binding/wemo/internal/handler/WemoCoffeeHandler.java | 5 +---- .../binding/wemo/internal/handler/WemoDimmerHandler.java | 5 +---- .../java/org/openhab/binding/wemo/InsightParserTest.java | 7 +++---- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/InsightParser.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/InsightParser.java index 48cb39fd00b..0b61303a79c 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/InsightParser.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/InsightParser.java @@ -15,8 +15,6 @@ package org.openhab.binding.wemo.internal; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.Instant; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.HashMap; import java.util.Map; @@ -116,12 +114,10 @@ public class InsightParser { return UnDefType.UNDEF; } - State lastChangedAtState = new DateTimeType( - ZonedDateTime.ofInstant(Instant.ofEpochSecond(lastChangedAt), ZoneId.systemDefault())); if (lastChangedAt == 0) { return UnDefType.UNDEF; } - return lastChangedAtState; + return new DateTimeType(Instant.ofEpochSecond(lastChangedAt)); } private State getNumber(String value) { diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCoffeeHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCoffeeHandler.java index d6e5a6c5a46..49ba44fe2a3 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCoffeeHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCoffeeHandler.java @@ -17,9 +17,7 @@ import static org.openhab.binding.wemo.internal.WemoUtil.*; import java.io.StringReader; import java.time.Instant; -import java.time.ZonedDateTime; import java.util.Set; -import java.util.TimeZone; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -345,8 +343,7 @@ public class WemoCoffeeHandler extends WemoBaseThingHandler { getThing().getUID()); return null; } - ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochSecond(value), TimeZone.getDefault().toZoneId()); - State dateTimeState = new DateTimeType(zoned); + State dateTimeState = new DateTimeType(Instant.ofEpochSecond(value)); logger.trace("New attribute brewed '{}' received", dateTimeState); return dateTimeState; } diff --git a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoDimmerHandler.java b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoDimmerHandler.java index 14fab3c8d02..70a9dbfb0db 100644 --- a/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoDimmerHandler.java +++ b/bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoDimmerHandler.java @@ -16,12 +16,10 @@ import static org.openhab.binding.wemo.internal.WemoBindingConstants.*; import static org.openhab.binding.wemo.internal.WemoUtil.*; import java.time.Instant; -import java.time.ZonedDateTime; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; -import java.util.TimeZone; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -502,8 +500,7 @@ public class WemoDimmerHandler extends WemoBaseThingHandler { getThing().getUID()); return null; } - ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochSecond(value), TimeZone.getDefault().toZoneId()); - return new DateTimeType(zoned); + return new DateTimeType(Instant.ofEpochSecond(value)); } public void setBinaryState(String action, String argument, String value) { diff --git a/bundles/org.openhab.binding.wemo/src/test/java/org/openhab/binding/wemo/InsightParserTest.java b/bundles/org.openhab.binding.wemo/src/test/java/org/openhab/binding/wemo/InsightParserTest.java index 322129c18fe..0016a2bb876 100644 --- a/bundles/org.openhab.binding.wemo/src/test/java/org/openhab/binding/wemo/InsightParserTest.java +++ b/bundles/org.openhab.binding.wemo/src/test/java/org/openhab/binding/wemo/InsightParserTest.java @@ -15,7 +15,6 @@ package org.openhab.binding.wemo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import java.time.ZoneId; import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -47,7 +46,7 @@ public class InsightParserTest { "1|1645800647|109676|80323|1196960|1209600|44|41400|30288361|483361410|8000"); Map result = parser.parse(); assertEquals(OnOffType.ON, result.get(WemoBindingConstants.CHANNEL_STATE)); - assertEquals(DateTimeType.valueOf("2022-02-25T15:50:47.000+0100").toZone(ZoneId.systemDefault()), + assertEquals(DateTimeType.valueOf("2022-02-25T15:50:47.000+0100"), result.get(WemoBindingConstants.CHANNEL_LAST_CHANGED_AT)); assertEquals(new DecimalType(109_676), result.get(WemoBindingConstants.CHANNEL_LAST_ON_FOR)); assertEquals(new DecimalType(80_323), result.get(WemoBindingConstants.CHANNEL_ON_TODAY)); @@ -69,7 +68,7 @@ public class InsightParserTest { InsightParser parser = new InsightParser("8|1645967627|0|0|0|1209600|13|0|0|0.000000|8000"); Map result = parser.parse(); assertEquals(OnOffType.ON, result.get(WemoBindingConstants.CHANNEL_STATE)); - assertEquals(DateTimeType.valueOf("2022-02-27T14:13:47.000+0100").toZone(ZoneId.systemDefault()), + assertEquals(DateTimeType.valueOf("2022-02-27T14:13:47.000+0100"), result.get(WemoBindingConstants.CHANNEL_LAST_CHANGED_AT)); assertEquals(new DecimalType(0), result.get(WemoBindingConstants.CHANNEL_LAST_ON_FOR)); assertEquals(new DecimalType(0), result.get(WemoBindingConstants.CHANNEL_ON_TODAY)); @@ -92,7 +91,7 @@ public class InsightParserTest { "1|1645800647|109676|80323|1196960|1209600|44|41400|30288361|483361410"); Map result = parser.parse(); assertEquals(OnOffType.ON, result.get(WemoBindingConstants.CHANNEL_STATE)); - assertEquals(DateTimeType.valueOf("2022-02-25T15:50:47.000+0100").toZone(ZoneId.systemDefault()), + assertEquals(DateTimeType.valueOf("2022-02-25T15:50:47.000+0100"), result.get(WemoBindingConstants.CHANNEL_LAST_CHANGED_AT)); assertEquals(new DecimalType(109_676), result.get(WemoBindingConstants.CHANNEL_LAST_ON_FOR)); assertEquals(new DecimalType(80_323), result.get(WemoBindingConstants.CHANNEL_ON_TODAY));