Simplify DateTimeType handling for Doorbird

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-12-09 23:24:21 +01:00 committed by lsiepel
parent 9b4f1d769c
commit 4cea76be8e
2 changed files with 4 additions and 12 deletions

View File

@ -19,7 +19,6 @@ import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.openhab.binding.doorbird.internal.handler.ControllerHandler; import org.openhab.binding.doorbird.internal.handler.ControllerHandler;
import org.openhab.binding.doorbird.internal.handler.DoorbellHandler; 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.io.net.http.HttpClientFactory;
import org.openhab.core.thing.Thing; import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingTypeUID;
@ -39,13 +38,10 @@ import org.osgi.service.component.annotations.Reference;
@NonNullByDefault @NonNullByDefault
@Component(configurationPid = "binding.doorbird", service = ThingHandlerFactory.class) @Component(configurationPid = "binding.doorbird", service = ThingHandlerFactory.class)
public class DoorbirdHandlerFactory extends BaseThingHandlerFactory { public class DoorbirdHandlerFactory extends BaseThingHandlerFactory {
private final TimeZoneProvider timeZoneProvider;
private final HttpClient httpClient; private final HttpClient httpClient;
@Activate @Activate
public DoorbirdHandlerFactory(@Reference TimeZoneProvider timeZoneProvider, public DoorbirdHandlerFactory(@Reference HttpClientFactory httpClientFactory) {
@Reference HttpClientFactory httpClientFactory) {
this.timeZoneProvider = timeZoneProvider;
this.httpClient = httpClientFactory.getCommonHttpClient(); this.httpClient = httpClientFactory.getCommonHttpClient();
} }
@ -58,7 +54,7 @@ public class DoorbirdHandlerFactory extends BaseThingHandlerFactory {
protected @Nullable ThingHandler createHandler(Thing thing) { protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID(); ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (THING_TYPE_D101.equals(thingTypeUID) || THING_TYPE_D210X.equals(thingTypeUID)) { 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)) { } else if (THING_TYPE_A1081.equals(thingTypeUID)) {
return new ControllerHandler(thing); return new ControllerHandler(thing);
} }

View File

@ -45,7 +45,6 @@ import org.openhab.binding.doorbird.internal.config.DoorbellConfiguration;
import org.openhab.binding.doorbird.internal.listener.DoorbirdUdpListener; import org.openhab.binding.doorbird.internal.listener.DoorbirdUdpListener;
import org.openhab.core.audio.AudioSink; import org.openhab.core.audio.AudioSink;
import org.openhab.core.common.ThreadPoolManager; 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.DateTimeType;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.OnOffType;
@ -101,13 +100,10 @@ public class DoorbellHandler extends BaseThingHandler {
private @Nullable ServiceRegistration<AudioSink> audioSinkRegistration; private @Nullable ServiceRegistration<AudioSink> audioSinkRegistration;
private final TimeZoneProvider timeZoneProvider;
private final HttpClient httpClient; private final HttpClient httpClient;
public DoorbellHandler(Thing thing, TimeZoneProvider timeZoneProvider, HttpClient httpClient, public DoorbellHandler(Thing thing, HttpClient httpClient, BundleContext bundleContext) {
BundleContext bundleContext) {
super(thing); super(thing);
this.timeZoneProvider = timeZoneProvider;
this.httpClient = httpClient; this.httpClient = httpClient;
this.bundleContext = bundleContext; this.bundleContext = bundleContext;
udpListener = new DoorbirdUdpListener(this); udpListener = new DoorbirdUdpListener(this);
@ -582,6 +578,6 @@ public class DoorbellHandler extends BaseThingHandler {
} }
private DateTimeType getLocalDateTimeType(long dateTimeSeconds) { private DateTimeType getLocalDateTimeType(long dateTimeSeconds) {
return new DateTimeType(Instant.ofEpochSecond(dateTimeSeconds).atZone(timeZoneProvider.getTimeZone())); return new DateTimeType(Instant.ofEpochSecond(dateTimeSeconds));
} }
} }