Simplify DateTimeType handling for Video Disk Recorder

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-11-10 21:33:52 +01:00 committed by lsiepel
parent 7c1892fd57
commit 1a76e5522c
2 changed files with 6 additions and 26 deletions

View File

@ -12,8 +12,6 @@
*/ */
package org.openhab.binding.vdr.internal; package org.openhab.binding.vdr.internal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -29,7 +27,6 @@ import org.openhab.binding.vdr.internal.svdrp.SVDRPEpgEvent;
import org.openhab.binding.vdr.internal.svdrp.SVDRPException; import org.openhab.binding.vdr.internal.svdrp.SVDRPException;
import org.openhab.binding.vdr.internal.svdrp.SVDRPParseResponseException; import org.openhab.binding.vdr.internal.svdrp.SVDRPParseResponseException;
import org.openhab.binding.vdr.internal.svdrp.SVDRPVolume; import org.openhab.binding.vdr.internal.svdrp.SVDRPVolume;
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;
@ -60,15 +57,12 @@ public class VDRHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(VDRHandler.class); private final Logger logger = LoggerFactory.getLogger(VDRHandler.class);
private final TimeZoneProvider timeZoneProvider;
private VDRConfiguration config = new VDRConfiguration(); private VDRConfiguration config = new VDRConfiguration();
private @Nullable ScheduledFuture<?> refreshThreadFuture = null; private @Nullable ScheduledFuture<?> refreshThreadFuture = null;
public VDRHandler(Thing thing, TimeZoneProvider timeZoneProvider) { public VDRHandler(Thing thing) {
super(thing); super(thing);
this.timeZoneProvider = timeZoneProvider;
} }
/** /**
@ -229,13 +223,11 @@ public class VDRHandler extends BaseThingHandler {
break; break;
case VDRBindingConstants.CHANNEL_UID_CURRENT_EVENT_BEGIN: case VDRBindingConstants.CHANNEL_UID_CURRENT_EVENT_BEGIN:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NOW); entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NOW);
result = new DateTimeType(LocalDateTime.ofInstant(entry.getBegin(), ZoneId.systemDefault()) result = new DateTimeType(entry.getBegin());
.atZone(timeZoneProvider.getTimeZone()));
break; break;
case VDRBindingConstants.CHANNEL_UID_CURRENT_EVENT_END: case VDRBindingConstants.CHANNEL_UID_CURRENT_EVENT_END:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NOW); entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NOW);
result = new DateTimeType(LocalDateTime.ofInstant(entry.getEnd(), ZoneId.systemDefault()) result = new DateTimeType(entry.getEnd());
.atZone(timeZoneProvider.getTimeZone()));
break; break;
case VDRBindingConstants.CHANNEL_UID_NEXT_EVENT_TITLE: case VDRBindingConstants.CHANNEL_UID_NEXT_EVENT_TITLE:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NEXT); entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NEXT);
@ -251,13 +243,11 @@ public class VDRHandler extends BaseThingHandler {
break; break;
case VDRBindingConstants.CHANNEL_UID_NEXT_EVENT_BEGIN: case VDRBindingConstants.CHANNEL_UID_NEXT_EVENT_BEGIN:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NEXT); entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NEXT);
result = new DateTimeType(LocalDateTime.ofInstant(entry.getBegin(), ZoneId.systemDefault()) result = new DateTimeType(entry.getBegin());
.atZone(timeZoneProvider.getTimeZone()));
break; break;
case VDRBindingConstants.CHANNEL_UID_NEXT_EVENT_END: case VDRBindingConstants.CHANNEL_UID_NEXT_EVENT_END:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NEXT); entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NEXT);
result = new DateTimeType(LocalDateTime.ofInstant(entry.getEnd(), ZoneId.systemDefault()) result = new DateTimeType(entry.getEnd());
.atZone(timeZoneProvider.getTimeZone()));
break; break;
} }

View File

@ -18,15 +18,12 @@ import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.thing.Thing; import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory; import org.openhab.core.thing.binding.BaseThingHandlerFactory;
import org.openhab.core.thing.binding.ThingHandler; import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerFactory; import org.openhab.core.thing.binding.ThingHandlerFactory;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/** /**
* The {@link VDRHandlerFactory} is responsible for creating things and thing * The {@link VDRHandlerFactory} is responsible for creating things and thing
@ -40,13 +37,6 @@ public class VDRHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_VDR); private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_VDR);
private final TimeZoneProvider timeZoneProvider;
@Activate
public VDRHandlerFactory(final @Reference TimeZoneProvider timeZoneProvider) {
this.timeZoneProvider = timeZoneProvider;
}
@Override @Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) { public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
@ -57,7 +47,7 @@ public class VDRHandlerFactory extends BaseThingHandlerFactory {
ThingTypeUID thingTypeUID = thing.getThingTypeUID(); ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (THING_TYPE_VDR.equals(thingTypeUID)) { if (THING_TYPE_VDR.equals(thingTypeUID)) {
return new VDRHandler(thing, timeZoneProvider); return new VDRHandler(thing);
} }
return null; return null;