Simplify DateTimeType handling for Bosch Indego

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-27 23:29:51 +01:00 committed by Ciprian Pascu
parent b1eae44633
commit e7130bb4be

View File

@ -18,7 +18,6 @@ import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -448,12 +447,7 @@ public class BoschIndegoHandler extends BaseThingHandler implements Authorizatio
private void refreshLastCuttingTime() throws IndegoAuthenticationException, IndegoException { private void refreshLastCuttingTime() throws IndegoAuthenticationException, IndegoException {
if (isLinked(LAST_CUTTING)) { if (isLinked(LAST_CUTTING)) {
Instant lastCutting = controller.getPredictiveLastCutting(); Instant lastCutting = controller.getPredictiveLastCutting();
if (lastCutting != null) { updateState(LAST_CUTTING, lastCutting == null ? UnDefType.UNDEF : new DateTimeType(lastCutting));
updateState(LAST_CUTTING,
new DateTimeType(ZonedDateTime.ofInstant(lastCutting, timeZoneProvider.getTimeZone())));
} else {
updateState(LAST_CUTTING, UnDefType.UNDEF);
}
} }
} }
@ -472,8 +466,7 @@ public class BoschIndegoHandler extends BaseThingHandler implements Authorizatio
if (isLinked(NEXT_CUTTING)) { if (isLinked(NEXT_CUTTING)) {
Instant nextCutting = controller.getPredictiveNextCutting(); Instant nextCutting = controller.getPredictiveNextCutting();
if (nextCutting != null) { if (nextCutting != null) {
updateState(NEXT_CUTTING, updateState(NEXT_CUTTING, new DateTimeType(nextCutting));
new DateTimeType(ZonedDateTime.ofInstant(nextCutting, timeZoneProvider.getTimeZone())));
scheduleCuttingTimesRefresh(nextCutting); scheduleCuttingTimesRefresh(nextCutting);
} else { } else {
updateState(NEXT_CUTTING, UnDefType.UNDEF); updateState(NEXT_CUTTING, UnDefType.UNDEF);