[infrastructure] add external null-annotations (#8848)
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
This commit is contained in:
@@ -17,6 +17,7 @@ import static org.openhab.binding.volvooncall.internal.VolvoOnCallBindingConstan
|
||||
import java.time.Duration;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -73,8 +74,14 @@ public class TripDetail {
|
||||
return getPositionAsState(endPosition);
|
||||
}
|
||||
|
||||
public long getDurationInMinutes() {
|
||||
return Duration.between(startTime, endTime).toMinutes();
|
||||
public Optional<Long> getDurationInMinutes() {
|
||||
Temporal start = startTime;
|
||||
Temporal end = endTime;
|
||||
if (start == null || end == null) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
return Optional.of(Duration.between(start, end).toMinutes());
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Integer> getFuelConsumption() {
|
||||
|
||||
@@ -131,8 +131,9 @@ public class VehicleHandler extends BaseThingHandler {
|
||||
thing.getProperties().entrySet().stream().filter(p -> "true".equals(p.getValue()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
|
||||
|
||||
if (thing.getProperties().containsKey(LAST_TRIP_ID)) {
|
||||
lastTripId = Long.parseLong(thing.getProperties().get(LAST_TRIP_ID));
|
||||
String lastTripIdString = thing.getProperties().get(LAST_TRIP_ID);
|
||||
if (lastTripIdString != null) {
|
||||
lastTripId = Long.parseLong(lastTripIdString);
|
||||
}
|
||||
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
@@ -294,7 +295,8 @@ public class VehicleHandler extends BaseThingHandler {
|
||||
case TRIP_END_TIME:
|
||||
return tripDetails.getEndTime();
|
||||
case TRIP_DURATION:
|
||||
return new QuantityType<>(tripDetails.getDurationInMinutes(), MINUTE);
|
||||
return tripDetails.getDurationInMinutes().map(value -> (State) new QuantityType<>(value, MINUTE))
|
||||
.orElse(UnDefType.UNDEF);
|
||||
case TRIP_START_ODOMETER:
|
||||
return new QuantityType<>((double) tripDetails.startOdometer / 1000, KILO(METRE));
|
||||
case TRIP_STOP_ODOMETER:
|
||||
|
||||
Reference in New Issue
Block a user