Simplify DateTimeType handling for OneBusAway

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-11-28 21:47:33 +01:00 committed by Ciprian Pascu
parent 9b8c161cb0
commit 17e03cdaa1

View File

@ -15,8 +15,6 @@ package org.openhab.binding.onebusaway.internal.handler;
import static org.openhab.binding.onebusaway.internal.OneBusAwayBindingConstants.*; import static org.openhab.binding.onebusaway.internal.OneBusAwayBindingConstants.*;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -168,8 +166,7 @@ public class RouteHandler extends BaseThingHandler implements RouteDataListener
private void publishChannel(ChannelUID channelUID, Calendar now, long lastUpdateTime, private void publishChannel(ChannelUID channelUID, Calendar now, long lastUpdateTime,
List<ArrivalAndDeparture> arrivalAndDepartures) { List<ArrivalAndDeparture> arrivalAndDepartures) {
if (channelUID.getId().equals(CHANNEL_ID_UPDATE)) { if (channelUID.getId().equals(CHANNEL_ID_UPDATE)) {
updateState(channelUID, new DateTimeType( updateState(channelUID, new DateTimeType(Instant.ofEpochMilli(lastUpdateTime)));
ZonedDateTime.ofInstant(Instant.ofEpochMilli(lastUpdateTime), ZoneId.systemDefault())));
return; return;
} }
@ -201,8 +198,7 @@ public class RouteHandler extends BaseThingHandler implements RouteDataListener
logger.debug("Not notifying {} because it is in the past.", channelUID.getId()); logger.debug("Not notifying {} because it is in the past.", channelUID.getId());
continue; continue;
} }
updateState(channelUID, updateState(channelUID, new DateTimeType(time.toInstant()));
new DateTimeType(ZonedDateTime.ofInstant(time.toInstant(), ZoneId.systemDefault())));
// Update properties only when we update arrival information. This is not perfect. // Update properties only when we update arrival information. This is not perfect.
if (channelUID.getId().equals(CHANNEL_ID_ARRIVAL)) { if (channelUID.getId().equals(CHANNEL_ID_ARRIVAL)) {