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

View File

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