From d00d654976846c0ede24e74418be43ef1bb736ad Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Sun, 24 Nov 2024 23:28:31 +0100 Subject: [PATCH] Simplify DateTimeType handling for Ruuvi Gateway MQTT Signed-off-by: Jacob Laursen --- .../mqtt/ruuvigateway/internal/RuuviCachedDateTimeState.java | 5 +---- .../openhab/binding/mqtt/ruuvigateway/RuuviGatewayTest.java | 5 ++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.mqtt.ruuvigateway/src/main/java/org/openhab/binding/mqtt/ruuvigateway/internal/RuuviCachedDateTimeState.java b/bundles/org.openhab.binding.mqtt.ruuvigateway/src/main/java/org/openhab/binding/mqtt/ruuvigateway/internal/RuuviCachedDateTimeState.java index 67f59d7e4dd..e8830efab85 100644 --- a/bundles/org.openhab.binding.mqtt.ruuvigateway/src/main/java/org/openhab/binding/mqtt/ruuvigateway/internal/RuuviCachedDateTimeState.java +++ b/bundles/org.openhab.binding.mqtt.ruuvigateway/src/main/java/org/openhab/binding/mqtt/ruuvigateway/internal/RuuviCachedDateTimeState.java @@ -13,7 +13,6 @@ package org.openhab.binding.mqtt.ruuvigateway.internal; import java.time.Instant; -import java.time.ZoneId; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.mqtt.generic.ChannelConfig; @@ -33,8 +32,6 @@ import org.openhab.core.thing.ChannelUID; @NonNullByDefault public class RuuviCachedDateTimeState extends ChannelState { - private static final ZoneId UTC = ZoneId.of("UTC"); - /** * Construct cache for DateTime values * @@ -51,6 +48,6 @@ public class RuuviCachedDateTimeState extends ChannelState { * @param value instant representing value */ public void update(Instant value) { - cachedValue.update(new DateTimeType(value.atZone(UTC))); + cachedValue.update(new DateTimeType(value)); } } diff --git a/itests/org.openhab.binding.mqtt.ruuvigateway.tests/src/main/java/org/openhab/binding/mqtt/ruuvigateway/RuuviGatewayTest.java b/itests/org.openhab.binding.mqtt.ruuvigateway.tests/src/main/java/org/openhab/binding/mqtt/ruuvigateway/RuuviGatewayTest.java index dc81e45efaa..fabb226ce3d 100644 --- a/itests/org.openhab.binding.mqtt.ruuvigateway.tests/src/main/java/org/openhab/binding/mqtt/ruuvigateway/RuuviGatewayTest.java +++ b/itests/org.openhab.binding.mqtt.ruuvigateway.tests/src/main/java/org/openhab/binding/mqtt/ruuvigateway/RuuviGatewayTest.java @@ -24,7 +24,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; import java.time.Instant; -import java.time.ZoneId; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -360,8 +359,8 @@ public class RuuviGatewayTest extends MqttOSGiTest { assertEquals(new QuantityType<>(new BigDecimal(rssiDecibelMilliwatts), Units.DECIBEL_MILLIWATTS), channelStateGetter.apply(CHANNEL_ID_RSSI)); - assertEquals(new DateTimeType(ts.atZone(ZoneId.of("UTC"))), channelStateGetter.apply(CHANNEL_ID_TS)); - assertEquals(new DateTimeType(gwts.atZone(ZoneId.of("UTC"))), channelStateGetter.apply(CHANNEL_ID_GWTS)); + assertEquals(new DateTimeType(ts), channelStateGetter.apply(CHANNEL_ID_TS)); + assertEquals(new DateTimeType(gwts), channelStateGetter.apply(CHANNEL_ID_GWTS)); assertEquals(new StringType(gwMac), channelStateGetter.apply(CHANNEL_ID_GWMAC)); }