Simplify DateTimeType handling for XmlTv

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Jacob Laursen 2024-12-17 22:00:10 +01:00 committed by Ciprian Pascu
parent 4023e72804
commit 10bf67525e
2 changed files with 4 additions and 13 deletions

View File

@ -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;

View File

@ -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<Programme> 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) {