From e794c6a0f6c3660c8c368ddd4b94157f4892e761 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Sat, 9 Nov 2024 23:06:35 +0100 Subject: [PATCH] Simplify DateTimeType handling for InfluxDB Signed-off-by: Jacob Laursen --- .../influxdb/internal/InfluxDBStateConvertUtils.java | 8 ++------ .../influxdb/internal/InfluxDBStateConvertUtilsTest.java | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtils.java b/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtils.java index 5fa30bbc892..1163847aaa3 100644 --- a/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtils.java +++ b/bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtils.java @@ -14,8 +14,6 @@ package org.openhab.persistence.influxdb.internal; import java.math.BigDecimal; import java.time.Instant; -import java.time.ZonedDateTime; -import java.util.TimeZone; import javax.measure.Unit; @@ -85,7 +83,7 @@ public class InfluxDBStateConvertUtils { } else if (state instanceof OpenClosedType) { value = state == OpenClosedType.OPEN ? DIGITAL_VALUE_ON : DIGITAL_VALUE_OFF; } else if (state instanceof DateTimeType type) { - value = type.getZonedDateTime().toInstant().toEpochMilli(); + value = type.getInstant().toEpochMilli(); } else { value = state.toFullString(); } @@ -140,9 +138,7 @@ public class InfluxDBStateConvertUtils { } else if (item instanceof RollershutterItem) { return new PercentType(valueStr); } else if (item instanceof DateTimeItem) { - Instant i = Instant.ofEpochMilli(new BigDecimal(valueStr).longValue()); - ZonedDateTime z = ZonedDateTime.ofInstant(i, TimeZone.getDefault().toZoneId()); - return new DateTimeType(z); + return new DateTimeType(Instant.ofEpochMilli(new BigDecimal(valueStr).longValue())); } else if (item instanceof PlayerItem) { try { return PlayPauseType.valueOf(valueStr); diff --git a/bundles/org.openhab.persistence.influxdb/src/test/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtilsTest.java b/bundles/org.openhab.persistence.influxdb/src/test/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtilsTest.java index 22329153219..2ec1bcc54e2 100644 --- a/bundles/org.openhab.persistence.influxdb/src/test/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtilsTest.java +++ b/bundles/org.openhab.persistence.influxdb/src/test/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtilsTest.java @@ -21,7 +21,6 @@ import static org.mockito.Mockito.when; import java.math.BigDecimal; import java.time.Instant; -import java.time.ZoneId; import java.time.ZonedDateTime; import javax.measure.Unit; @@ -130,8 +129,7 @@ public class InfluxDBStateConvertUtilsTest { long val = System.currentTimeMillis(); DateTimeItem item = new DateTimeItem("name"); - DateTimeType expected = new DateTimeType( - ZonedDateTime.ofInstant(Instant.ofEpochMilli(val), ZoneId.systemDefault())); + DateTimeType expected = new DateTimeType(Instant.ofEpochMilli(val)); assertThat(InfluxDBStateConvertUtils.objectToState(val, item), equalTo(expected)); }