Simplify DateTimeType handling for Meteo France

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-12-16 23:27:21 +01:00 committed by lsiepel
parent a1a61ff7c8
commit daabae72e0
3 changed files with 4 additions and 9 deletions

View File

@ -68,6 +68,6 @@ public class MeteoFranceHandlerFactory extends BaseThingHandlerFactory {
return BRIDGE_TYPE_API.equals(thingTypeUID) ? new MeteoFranceBridgeHandler((Bridge) thing, deserializer) return BRIDGE_TYPE_API.equals(thingTypeUID) ? new MeteoFranceBridgeHandler((Bridge) thing, deserializer)
: THING_TYPE_VIGILANCE.equals(thingTypeUID) ? new VigilanceHandler(thing, zoneId, iconProvider) : THING_TYPE_VIGILANCE.equals(thingTypeUID) ? new VigilanceHandler(thing, zoneId, iconProvider)
: THING_TYPE_RAIN_FORECAST.equals(thingTypeUID) ? new RainForecastHandler(thing, zoneId) : null; : THING_TYPE_RAIN_FORECAST.equals(thingTypeUID) ? new RainForecastHandler(thing) : null;
} }
} }

View File

@ -15,7 +15,6 @@ package org.openhab.binding.meteofrance.internal.handler;
import static org.openhab.binding.meteofrance.internal.MeteoFranceBindingConstants.*; import static org.openhab.binding.meteofrance.internal.MeteoFranceBindingConstants.*;
import static org.openhab.core.types.TimeSeries.Policy.REPLACE; import static org.openhab.core.types.TimeSeries.Policy.REPLACE;
import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.List; import java.util.List;
@ -58,15 +57,13 @@ import org.slf4j.LoggerFactory;
public class RainForecastHandler extends BaseThingHandler implements MeteoFranceChildHandler { public class RainForecastHandler extends BaseThingHandler implements MeteoFranceChildHandler {
private final Logger logger = LoggerFactory.getLogger(RainForecastHandler.class); private final Logger logger = LoggerFactory.getLogger(RainForecastHandler.class);
private final ChannelUID intensityChannelUID; private final ChannelUID intensityChannelUID;
private final ZoneId systemZoneId;
private Optional<ScheduledFuture<?>> refreshJob = Optional.empty(); private Optional<ScheduledFuture<?>> refreshJob = Optional.empty();
private Optional<PointType> location = Optional.empty(); private Optional<PointType> location = Optional.empty();
public RainForecastHandler(Thing thing, ZoneId zoneId) { public RainForecastHandler(Thing thing) {
super(thing); super(thing);
this.intensityChannelUID = new ChannelUID(getThing().getUID(), INTENSITY); this.intensityChannelUID = new ChannelUID(getThing().getUID(), INTENSITY);
this.systemZoneId = zoneId;
} }
@Override @Override
@ -169,9 +166,7 @@ public class RainForecastHandler extends BaseThingHandler implements MeteoFrance
private void updateDate(String channelId, @Nullable ZonedDateTime zonedDateTime) { private void updateDate(String channelId, @Nullable ZonedDateTime zonedDateTime) {
if (isLinked(channelId)) { if (isLinked(channelId)) {
updateState(channelId, updateState(channelId, zonedDateTime != null ? new DateTimeType(zonedDateTime) : UnDefType.NULL);
zonedDateTime != null ? new DateTimeType(zonedDateTime.withZoneSameInstant(systemZoneId))
: UnDefType.NULL);
} }
} }
} }

View File

@ -183,7 +183,7 @@ public class VigilanceHandler extends BaseThingHandler implements MeteoFranceChi
private void updateDate(String channelId, ZonedDateTime zonedDateTime) { private void updateDate(String channelId, ZonedDateTime zonedDateTime) {
if (isLinked(channelId)) { if (isLinked(channelId)) {
updateState(channelId, new DateTimeType(zonedDateTime.withZoneSameInstant(systemZoneId))); updateState(channelId, new DateTimeType(zonedDateTime));
} }
} }
} }