Skip to content

Commit

Permalink
Simplify DateTimeType handling for Video Disk Recorder
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur committed Nov 10, 2024
1 parent 9bdb91d commit 86ec8a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
package org.openhab.binding.vdr.internal;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
Expand All @@ -29,7 +27,6 @@
import org.openhab.binding.vdr.internal.svdrp.SVDRPException;
import org.openhab.binding.vdr.internal.svdrp.SVDRPParseResponseException;
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.DecimalType;
import org.openhab.core.library.types.OnOffType;
Expand Down Expand Up @@ -60,15 +57,12 @@ public class VDRHandler extends BaseThingHandler {

private final Logger logger = LoggerFactory.getLogger(VDRHandler.class);

private final TimeZoneProvider timeZoneProvider;

private VDRConfiguration config = new VDRConfiguration();

private @Nullable ScheduledFuture<?> refreshThreadFuture = null;

public VDRHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
public VDRHandler(Thing thing) {
super(thing);
this.timeZoneProvider = timeZoneProvider;
}

/**
Expand Down Expand Up @@ -229,13 +223,11 @@ private void onVDRRefresh() {
break;
case VDRBindingConstants.CHANNEL_UID_CURRENT_EVENT_BEGIN:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NOW);
result = new DateTimeType(LocalDateTime.ofInstant(entry.getBegin(), ZoneId.systemDefault())
.atZone(timeZoneProvider.getTimeZone()));
result = new DateTimeType(entry.getBegin());
break;
case VDRBindingConstants.CHANNEL_UID_CURRENT_EVENT_END:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NOW);
result = new DateTimeType(LocalDateTime.ofInstant(entry.getEnd(), ZoneId.systemDefault())
.atZone(timeZoneProvider.getTimeZone()));
result = new DateTimeType(entry.getEnd());
break;
case VDRBindingConstants.CHANNEL_UID_NEXT_EVENT_TITLE:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NEXT);
Expand All @@ -251,13 +243,11 @@ private void onVDRRefresh() {
break;
case VDRBindingConstants.CHANNEL_UID_NEXT_EVENT_BEGIN:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NEXT);
result = new DateTimeType(LocalDateTime.ofInstant(entry.getBegin(), ZoneId.systemDefault())
.atZone(timeZoneProvider.getTimeZone()));
result = new DateTimeType(entry.getBegin());
break;
case VDRBindingConstants.CHANNEL_UID_NEXT_EVENT_END:
entry = con.getEpgEvent(SVDRPEpgEvent.TYPE.NEXT);
result = new DateTimeType(LocalDateTime.ofInstant(entry.getEnd(), ZoneId.systemDefault())
.atZone(timeZoneProvider.getTimeZone()));
result = new DateTimeType(entry.getEnd());
break;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
import org.openhab.core.thing.binding.ThingHandler;
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.Reference;

/**
* The {@link VDRHandlerFactory} is responsible for creating things and thing
Expand All @@ -40,13 +37,6 @@ public class VDRHandlerFactory extends BaseThingHandlerFactory {

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
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
Expand All @@ -57,7 +47,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();

if (THING_TYPE_VDR.equals(thingTypeUID)) {
return new VDRHandler(thing, timeZoneProvider);
return new VDRHandler(thing);
}

return null;
Expand Down

0 comments on commit 86ec8a2

Please sign in to comment.