mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for VolvoOnCall
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
6d16d2890a
commit
23172a6f12
@ -15,7 +15,6 @@ package org.openhab.binding.volvooncall.internal.dto;
|
||||
import static org.openhab.binding.volvooncall.internal.VolvoOnCallBindingConstants.UNDEFINED;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.util.Optional;
|
||||
@ -47,8 +46,7 @@ public class TripDetail {
|
||||
private @NonNullByDefault({}) PositionData endPosition;
|
||||
|
||||
private State ZonedDateTimeToState(@Nullable ZonedDateTime datetime) {
|
||||
return datetime != null ? new DateTimeType(datetime.withZoneSameInstant(ZoneId.systemDefault()))
|
||||
: UnDefType.NULL;
|
||||
return datetime != null ? new DateTimeType(datetime) : UnDefType.NULL;
|
||||
}
|
||||
|
||||
private State getPositionAsState(PositionData details) {
|
||||
|
@ -17,7 +17,8 @@ import static org.openhab.core.library.unit.MetricPrefix.KILO;
|
||||
import static org.openhab.core.library.unit.SIUnits.*;
|
||||
import static org.openhab.core.library.unit.Units.*;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -426,7 +427,8 @@ public class VehicleHandler extends BaseThingHandler {
|
||||
: UnDefType.UNDEF;
|
||||
case CHARGING_END:
|
||||
return hvBattery.timeToHVBatteryFullyCharged != UNDEFINED && hvBattery.timeToHVBatteryFullyCharged > 0
|
||||
? new DateTimeType(ZonedDateTime.now().plusMinutes(hvBattery.timeToHVBatteryFullyCharged))
|
||||
? new DateTimeType(
|
||||
Instant.now().plus(hvBattery.timeToHVBatteryFullyCharged, ChronoUnit.MINUTES))
|
||||
: UnDefType.UNDEF;
|
||||
}
|
||||
return UnDefType.NULL;
|
||||
|
@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.volvooncall.internal.wrapper;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -86,7 +85,6 @@ public class VehiclePositionWrapper {
|
||||
|
||||
public State getTimestamp() {
|
||||
return Objects.requireNonNull(Optional.ofNullable(this.position).flatMap(pos -> pos.getTimestamp())
|
||||
.map(dt -> (State) new DateTimeType(dt.withZoneSameInstant(ZoneId.systemDefault())))
|
||||
.orElse(UnDefType.NULL));
|
||||
.map(dt -> (State) new DateTimeType(dt)).orElse(UnDefType.NULL));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user