import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Collection;
+import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
private final TranslationProvider i18nProvider;
private final LocaleProvider localeProvider;
- private @Nullable ScheduledFuture<?> reconnectJob;
+ private Optional<ScheduledFuture<?>> reconnectJob = Optional.empty();
public OpenUVBridgeHandler(Bridge bridge, LocationProvider locationProvider, TranslationProvider i18nProvider,
LocaleProvider localeProvider, Gson gson) {
@Override
public void dispose() {
- ScheduledFuture<?> job = this.reconnectJob;
- if (job != null && !job.isCancelled()) {
- job.cancel(true);
- }
- reconnectJob = null;
+ reconnectJob.ifPresent(job -> job.cancel(true));
+ reconnectJob = Optional.empty();
}
@Override
throw new OpenUVException(error);
}
} catch (JsonSyntaxException e) {
- logger.debug("No valid json received when calling `{}` : {}", url, jsonData);
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+ String.format("Invalid json received when calling `%s` : %s", url, jsonData));
} catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
} catch (OpenUVException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, String
.format("@text/offline.comm-error-quota-exceeded [ \"%s\" ]", tomorrowMidnight.toString()));
- reconnectJob = scheduler.schedule(this::initiateConnexion,
- Duration.between(LocalDateTime.now(), tomorrowMidnight).toMinutes(), TimeUnit.MINUTES);
+ reconnectJob = Optional.of(scheduler.schedule(this::initiateConnexion,
+ Duration.between(LocalDateTime.now(), tomorrowMidnight).toMinutes(), TimeUnit.MINUTES));
} else {
updateStatus(ThingStatus.OFFLINE,
e.isApiKeyError() ? ThingStatusDetail.CONFIGURATION_ERROR : ThingStatusDetail.NONE,
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler;
+import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
return openUVData.getUVMaxTime();
case UV_TIME:
return openUVData.getUVTime();
- case SAFE_EXPOSURE:
- SafeExposureConfiguration configuration = channel.getConfiguration()
- .as(SafeExposureConfiguration.class);
- return openUVData.getSafeExposureTime(configuration.index);
+ }
+ ChannelTypeUID channelType = channel.getChannelTypeUID();
+ if (channelType != null && SAFE_EXPOSURE.equals(channelType.getId())) {
+ SafeExposureConfiguration configuration = channel.getConfiguration().as(SafeExposureConfiguration.class);
+ return openUVData.getSafeExposureTime(configuration.index);
}
return UnDefType.NULL;
}
import com.google.gson.annotations.SerializedName;
/**
- * The {@link OpenUVResult} is responsible for storing
- * the "result" node from the OpenUV JSON response
+ * The {@link OpenUVResult} is responsible for storing the result node from the OpenUV JSON response
*
* @author Gaël L'hopital - Initial contribution
*/
}
private double uv;
- private @Nullable ZonedDateTime uvTime;
private double uvMax;
- private @Nullable ZonedDateTime uvMaxTime;
private double ozone;
+ private @Nullable ZonedDateTime uvTime;
+ private @Nullable ZonedDateTime uvMaxTime;
private @Nullable ZonedDateTime ozoneTime;
private Map<FitzpatrickType, @Nullable Integer> safeExposureTime = new HashMap<>();
return ozone;
}
+ private State getValueOrNull(@Nullable ZonedDateTime value) {
+ return value == null ? UnDefType.NULL : new DateTimeType(value);
+ }
+
public State getUVTime() {
- ZonedDateTime value = uvTime;
- return value != null ? new DateTimeType(value) : UnDefType.NULL;
+ return getValueOrNull(uvTime);
}
public State getUVMaxTime() {
- ZonedDateTime value = uvMaxTime;
- return value != null ? new DateTimeType(value) : UnDefType.NULL;
+ return getValueOrNull(uvMaxTime);
}
public State getOzoneTime() {
- ZonedDateTime value = ozoneTime;
- return value != null ? new DateTimeType(value) : UnDefType.NULL;
+ return getValueOrNull(ozoneTime);
}
public State getSafeExposureTime(String index) {
FitzpatrickType value = FitzpatrickType.valueOf(index);
Integer duration = safeExposureTime.get(value);
if (duration != null) {
- return new QuantityType<>(duration, Units.MINUTE);
+ return QuantityType.valueOf(duration, Units.MINUTE);
}
} catch (IllegalArgumentException e) {
logger.warn("Unexpected Fitzpatrick index value '{}' : {}", index, e.getMessage());