From aae122465865c23a6c063a8018478dd18ad9449e Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 17 Dec 2024 22:00:10 +0100 Subject: [PATCH] Simplify DateTimeType handling for XmlTv Signed-off-by: Jacob Laursen --- .../binding/xmltv/internal/XmlTVHandlerFactory.java | 8 ++------ .../binding/xmltv/internal/handler/ChannelHandler.java | 9 ++------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/bundles/org.openhab.binding.xmltv/src/main/java/org/openhab/binding/xmltv/internal/XmlTVHandlerFactory.java b/bundles/org.openhab.binding.xmltv/src/main/java/org/openhab/binding/xmltv/internal/XmlTVHandlerFactory.java index 156df364506..409a9193bd8 100644 --- a/bundles/org.openhab.binding.xmltv/src/main/java/org/openhab/binding/xmltv/internal/XmlTVHandlerFactory.java +++ b/bundles/org.openhab.binding.xmltv/src/main/java/org/openhab/binding/xmltv/internal/XmlTVHandlerFactory.java @@ -25,7 +25,6 @@ import org.openhab.binding.xmltv.internal.handler.ChannelHandler; import org.openhab.binding.xmltv.internal.handler.XmlTVHandler; import org.openhab.binding.xmltv.internal.jaxb.Tv; import org.openhab.core.config.core.Configuration; -import org.openhab.core.i18n.TimeZoneProvider; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; @@ -35,7 +34,6 @@ 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 XmlTVHandlerFactory} is responsible for creating things and thing @@ -47,12 +45,10 @@ import org.osgi.service.component.annotations.Reference; @Component(configurationPid = "binding.xmltv", service = ThingHandlerFactory.class) public class XmlTVHandlerFactory extends BaseThingHandlerFactory { private final XMLInputFactory xif = XMLInputFactory.newFactory(); - private final TimeZoneProvider timeZoneProvider; private final Unmarshaller unmarshaller; @Activate - public XmlTVHandlerFactory(final @Reference TimeZoneProvider timeZoneProvider) throws JAXBException { - this.timeZoneProvider = timeZoneProvider; + public XmlTVHandlerFactory() throws JAXBException { this.unmarshaller = JAXBContext.newInstance(Tv.class).createUnmarshaller(); xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); @@ -88,7 +84,7 @@ public class XmlTVHandlerFactory extends BaseThingHandlerFactory { if (XMLTV_FILE_BRIDGE_TYPE.equals(thingTypeUID)) { return new XmlTVHandler((Bridge) thing, xif, unmarshaller); } else if (XMLTV_CHANNEL_THING_TYPE.equals(thingTypeUID)) { - return new ChannelHandler(thing, timeZoneProvider.getTimeZone()); + return new ChannelHandler(thing); } return null; diff --git a/bundles/org.openhab.binding.xmltv/src/main/java/org/openhab/binding/xmltv/internal/handler/ChannelHandler.java b/bundles/org.openhab.binding.xmltv/src/main/java/org/openhab/binding/xmltv/internal/handler/ChannelHandler.java index c60bc6fb7fa..8e44cb9e92d 100644 --- a/bundles/org.openhab.binding.xmltv/src/main/java/org/openhab/binding/xmltv/internal/handler/ChannelHandler.java +++ b/bundles/org.openhab.binding.xmltv/src/main/java/org/openhab/binding/xmltv/internal/handler/ChannelHandler.java @@ -16,8 +16,6 @@ import static org.openhab.binding.xmltv.internal.XmlTVBindingConstants.*; import java.time.Duration; import java.time.Instant; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -65,11 +63,9 @@ public class ChannelHandler extends BaseThingHandler { private State mediaIcon = UnDefType.UNDEF; public final List programmes = new ArrayList<>(); - private final ZoneId zoneId; - public ChannelHandler(Thing thing, ZoneId zoneId) { + public ChannelHandler(Thing thing) { super(thing); - this.zoneId = zoneId; } @Override @@ -224,8 +220,7 @@ public class ChannelHandler extends BaseThingHandler { } private void updateDateTimeChannel(ChannelUID channelUID, Instant instant) { - ZonedDateTime zds = ZonedDateTime.ofInstant(instant, zoneId); - updateState(channelUID, new DateTimeType(zds)); + updateState(channelUID, new DateTimeType(instant)); } private QuantityType getDurationInSeconds(Instant from, Instant to) {