From 4cea76be8ebc5226ef631a68128d85bc5443102f Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Mon, 9 Dec 2024 23:24:21 +0100 Subject: [PATCH] Simplify DateTimeType handling for Doorbird Signed-off-by: Jacob Laursen --- .../binding/doorbird/internal/DoorbirdHandlerFactory.java | 8 ++------ .../doorbird/internal/handler/DoorbellHandler.java | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/DoorbirdHandlerFactory.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/DoorbirdHandlerFactory.java index 7efc1e461d7..8f06ed49732 100644 --- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/DoorbirdHandlerFactory.java +++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/DoorbirdHandlerFactory.java @@ -19,7 +19,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.doorbird.internal.handler.ControllerHandler; import org.openhab.binding.doorbird.internal.handler.DoorbellHandler; -import org.openhab.core.i18n.TimeZoneProvider; import org.openhab.core.io.net.http.HttpClientFactory; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; @@ -39,13 +38,10 @@ import org.osgi.service.component.annotations.Reference; @NonNullByDefault @Component(configurationPid = "binding.doorbird", service = ThingHandlerFactory.class) public class DoorbirdHandlerFactory extends BaseThingHandlerFactory { - private final TimeZoneProvider timeZoneProvider; private final HttpClient httpClient; @Activate - public DoorbirdHandlerFactory(@Reference TimeZoneProvider timeZoneProvider, - @Reference HttpClientFactory httpClientFactory) { - this.timeZoneProvider = timeZoneProvider; + public DoorbirdHandlerFactory(@Reference HttpClientFactory httpClientFactory) { this.httpClient = httpClientFactory.getCommonHttpClient(); } @@ -58,7 +54,7 @@ public class DoorbirdHandlerFactory extends BaseThingHandlerFactory { protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (THING_TYPE_D101.equals(thingTypeUID) || THING_TYPE_D210X.equals(thingTypeUID)) { - return new DoorbellHandler(thing, timeZoneProvider, httpClient, bundleContext); + return new DoorbellHandler(thing, httpClient, bundleContext); } else if (THING_TYPE_A1081.equals(thingTypeUID)) { return new ControllerHandler(thing); } diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java index 71a0fd23108..5e8eecdaf0a 100644 --- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java +++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java @@ -45,7 +45,6 @@ import org.openhab.binding.doorbird.internal.config.DoorbellConfiguration; import org.openhab.binding.doorbird.internal.listener.DoorbirdUdpListener; import org.openhab.core.audio.AudioSink; import org.openhab.core.common.ThreadPoolManager; -import org.openhab.core.i18n.TimeZoneProvider; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.OnOffType; @@ -101,13 +100,10 @@ public class DoorbellHandler extends BaseThingHandler { private @Nullable ServiceRegistration audioSinkRegistration; - private final TimeZoneProvider timeZoneProvider; private final HttpClient httpClient; - public DoorbellHandler(Thing thing, TimeZoneProvider timeZoneProvider, HttpClient httpClient, - BundleContext bundleContext) { + public DoorbellHandler(Thing thing, HttpClient httpClient, BundleContext bundleContext) { super(thing); - this.timeZoneProvider = timeZoneProvider; this.httpClient = httpClient; this.bundleContext = bundleContext; udpListener = new DoorbirdUdpListener(this); @@ -582,6 +578,6 @@ public class DoorbellHandler extends BaseThingHandler { } private DateTimeType getLocalDateTimeType(long dateTimeSeconds) { - return new DateTimeType(Instant.ofEpochSecond(dateTimeSeconds).atZone(timeZoneProvider.getTimeZone())); + return new DateTimeType(Instant.ofEpochSecond(dateTimeSeconds)); } }