[openuv] Correcting an uncatched exception in json deserialization (#12511)
* Correcting an uncatched exception in json deserialization Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
parent
5cd28f7096
commit
107a05aa5e
|
@ -47,6 +47,6 @@ public class OpenUVBindingConstants {
|
||||||
public static final String SAFE_EXPOSURE = "SafeExposure";
|
public static final String SAFE_EXPOSURE = "SafeExposure";
|
||||||
public static final String ELEVATION = "elevation";
|
public static final String ELEVATION = "elevation";
|
||||||
|
|
||||||
public static final Set<ThingTypeUID> BRIDGE_THING_TYPES_UIDS = Set.of(APIBRIDGE_THING_TYPE);
|
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(APIBRIDGE_THING_TYPE,
|
||||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(LOCATION_REPORT_THING_TYPE);
|
LOCATION_REPORT_THING_TYPE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class OpenUVHandlerFactory extends BaseThingHandlerFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
||||||
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID) || BRIDGE_THING_TYPES_UIDS.contains(thingTypeUID);
|
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
package org.openhab.binding.openuv.internal.discovery;
|
package org.openhab.binding.openuv.internal.discovery;
|
||||||
|
|
||||||
import static org.openhab.binding.openuv.internal.OpenUVBindingConstants.*;
|
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.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
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.binding.openuv.internal.handler.OpenUVBridgeHandler;
|
||||||
import org.openhab.core.config.discovery.AbstractDiscoveryService;
|
import org.openhab.core.config.discovery.AbstractDiscoveryService;
|
||||||
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
|
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
|
||||||
|
@ -75,11 +75,11 @@ public class OpenUVDiscoveryService extends AbstractDiscoveryService implements
|
||||||
PointType location = bridge.getLocation();
|
PointType location = bridge.getLocation();
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
ThingUID bridgeUID = bridge.getThing().getUID();
|
ThingUID bridgeUID = bridge.getThing().getUID();
|
||||||
thingDiscovered(DiscoveryResultBuilder
|
thingDiscovered(
|
||||||
.create(new ThingUID(LOCATION_REPORT_THING_TYPE, bridgeUID, LOCAL))
|
DiscoveryResultBuilder.create(new ThingUID(LOCATION_REPORT_THING_TYPE, bridgeUID, LOCAL))
|
||||||
.withLabel("@text/discovery.openuv.uvreport.local.label")
|
.withLabel("@text/discovery.openuv.uvreport.local.label")
|
||||||
.withProperty(ReportConfiguration.LOCATION, location.toString())
|
.withProperty(LOCATION, location.toString()).withRepresentationProperty(LOCATION)
|
||||||
.withRepresentationProperty(ReportConfiguration.LOCATION).withBridge(bridgeUID).build());
|
.withBridge(bridgeUID).build());
|
||||||
} else {
|
} else {
|
||||||
logger.debug("LocationProvider.getLocation() is not set -> Will not provide any discovery results");
|
logger.debug("LocationProvider.getLocation() is not set -> Will not provide any discovery results");
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link OpenUVBridgeHandler} is the handler for OpenUV API and connects it
|
* {@link OpenUVBridgeHandler} is the handler for OpenUV API and connects it
|
||||||
|
@ -114,9 +115,10 @@ public class OpenUVBridgeHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable OpenUVResult getUVData(String latitude, String longitude, String altitude) {
|
public @Nullable OpenUVResult getUVData(String latitude, String longitude, String altitude) {
|
||||||
|
String url = String.format(QUERY_URL, latitude, longitude, altitude);
|
||||||
|
String jsonData = "";
|
||||||
try {
|
try {
|
||||||
String jsonData = HttpUtil.executeUrl("GET", String.format(QUERY_URL, latitude, longitude, altitude),
|
jsonData = HttpUtil.executeUrl("GET", url, header, null, null, REQUEST_TIMEOUT_MS);
|
||||||
header, null, null, REQUEST_TIMEOUT_MS);
|
|
||||||
OpenUVResponse uvResponse = gson.fromJson(jsonData, OpenUVResponse.class);
|
OpenUVResponse uvResponse = gson.fromJson(jsonData, OpenUVResponse.class);
|
||||||
if (uvResponse != null) {
|
if (uvResponse != null) {
|
||||||
String error = uvResponse.getError();
|
String error = uvResponse.getError();
|
||||||
|
@ -126,13 +128,13 @@ public class OpenUVBridgeHandler extends BaseBridgeHandler {
|
||||||
}
|
}
|
||||||
throw new OpenUVException(error);
|
throw new OpenUVException(error);
|
||||||
}
|
}
|
||||||
|
} catch (JsonSyntaxException e) {
|
||||||
|
logger.debug("No valid json received when calling `{}` : {}", url, jsonData);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
|
||||||
} catch (OpenUVException e) {
|
} catch (OpenUVException e) {
|
||||||
if (e.isQuotaError()) {
|
if (e.isQuotaError()) {
|
||||||
LocalDate today = LocalDate.now();
|
LocalDateTime tomorrowMidnight = LocalDate.now().plusDays(1).atStartOfDay().plusMinutes(2);
|
||||||
LocalDate tomorrow = today.plusDays(1);
|
|
||||||
LocalDateTime tomorrowMidnight = tomorrow.atStartOfDay().plusMinutes(2);
|
|
||||||
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, String
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, String
|
||||||
.format("@text/offline.comm-error-quota-exceeded [ \"%s\" ]", tomorrowMidnight.toString()));
|
.format("@text/offline.comm-error-quota-exceeded [ \"%s\" ]", tomorrowMidnight.toString()));
|
||||||
|
|
|
@ -159,13 +159,13 @@ public class OpenUVReportHandler extends BaseThingHandler {
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
logger.debug("Disposing the OpenUV handler.");
|
logger.debug("Disposing the OpenUV handler.");
|
||||||
ScheduledFuture<?> refresh = this.refreshJob;
|
ScheduledFuture<?> refresh = refreshJob;
|
||||||
if (refresh != null && !refresh.isCancelled()) {
|
if (refresh != null && !refresh.isCancelled()) {
|
||||||
refresh.cancel(true);
|
refresh.cancel(true);
|
||||||
}
|
}
|
||||||
refreshJob = null;
|
refreshJob = null;
|
||||||
|
|
||||||
ScheduledFuture<?> uxMax = this.uvMaxJob;
|
ScheduledFuture<?> uxMax = uvMaxJob;
|
||||||
if (uxMax != null && !uxMax.isCancelled()) {
|
if (uxMax != null && !uxMax.isCancelled()) {
|
||||||
uxMax.cancel(true);
|
uxMax.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue