package org.openhab.binding.openuv.internal.discovery;
import static org.openhab.binding.openuv.internal.OpenUVBindingConstants.*;
+import static org.openhab.binding.openuv.internal.config.ReportConfiguration.LOCATION;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.openuv.internal.config.ReportConfiguration;
import org.openhab.binding.openuv.internal.handler.OpenUVBridgeHandler;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
PointType location = bridge.getLocation();
if (location != null) {
ThingUID bridgeUID = bridge.getThing().getUID();
- thingDiscovered(DiscoveryResultBuilder
- .create(new ThingUID(LOCATION_REPORT_THING_TYPE, bridgeUID, LOCAL))
- .withLabel("@text/discovery.openuv.uvreport.local.label")
- .withProperty(ReportConfiguration.LOCATION, location.toString())
- .withRepresentationProperty(ReportConfiguration.LOCATION).withBridge(bridgeUID).build());
+ thingDiscovered(
+ DiscoveryResultBuilder.create(new ThingUID(LOCATION_REPORT_THING_TYPE, bridgeUID, LOCAL))
+ .withLabel("@text/discovery.openuv.uvreport.local.label")
+ .withProperty(LOCATION, location.toString()).withRepresentationProperty(LOCATION)
+ .withBridge(bridgeUID).build());
} else {
logger.debug("LocationProvider.getLocation() is not set -> Will not provide any discovery results");
}
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
/**
* {@link OpenUVBridgeHandler} is the handler for OpenUV API and connects it
}
public @Nullable OpenUVResult getUVData(String latitude, String longitude, String altitude) {
+ String url = String.format(QUERY_URL, latitude, longitude, altitude);
+ String jsonData = "";
try {
- String jsonData = HttpUtil.executeUrl("GET", String.format(QUERY_URL, latitude, longitude, altitude),
- header, null, null, REQUEST_TIMEOUT_MS);
+ jsonData = HttpUtil.executeUrl("GET", url, header, null, null, REQUEST_TIMEOUT_MS);
OpenUVResponse uvResponse = gson.fromJson(jsonData, OpenUVResponse.class);
if (uvResponse != null) {
String error = uvResponse.getError();
}
throw new OpenUVException(error);
}
+ } catch (JsonSyntaxException e) {
+ logger.debug("No valid json received when calling `{}` : {}", url, jsonData);
} catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
} catch (OpenUVException e) {
if (e.isQuotaError()) {
- LocalDate today = LocalDate.now();
- LocalDate tomorrow = today.plusDays(1);
- LocalDateTime tomorrowMidnight = tomorrow.atStartOfDay().plusMinutes(2);
+ LocalDateTime tomorrowMidnight = LocalDate.now().plusDays(1).atStartOfDay().plusMinutes(2);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, String
.format("@text/offline.comm-error-quota-exceeded [ \"%s\" ]", tomorrowMidnight.toString()));