[openweathermap] Improved exception handling (#11949)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
41d775c02b
commit
dee9ab891f
|
@ -1,63 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2010-2021 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.binding.openweathermap.internal.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The {@link OpenWeatherMapCommunicationException} is a communication exception for the connections to OpenWeatherMap
|
||||
* API.
|
||||
*
|
||||
* @author Christoph Weitkamp - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class OpenWeatherMapCommunicationException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Constructs a new exception with null as its detail message.
|
||||
*/
|
||||
public OpenWeatherMapCommunicationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message.
|
||||
*
|
||||
* @param message Detail message
|
||||
*/
|
||||
public OpenWeatherMapCommunicationException(@Nullable String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified cause.
|
||||
*
|
||||
* @param cause The cause
|
||||
*/
|
||||
public OpenWeatherMapCommunicationException(@Nullable Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message and cause.
|
||||
*
|
||||
* @param message Detail message
|
||||
* @param cause The cause
|
||||
*/
|
||||
public OpenWeatherMapCommunicationException(@Nullable String message, @Nullable Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2010-2021 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.binding.openweathermap.internal.connection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The {@link OpenWeatherMapConfigurationException} is a configuration exception for the connections to OpenWeatherMap
|
||||
* API.
|
||||
*
|
||||
* @author Christoph Weitkamp - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class OpenWeatherMapConfigurationException extends IllegalArgumentException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Constructs a new exception with null as its detail message.
|
||||
*/
|
||||
public OpenWeatherMapConfigurationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message.
|
||||
*
|
||||
* @param message Detail message
|
||||
*/
|
||||
public OpenWeatherMapConfigurationException(@Nullable String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified cause.
|
||||
*
|
||||
* @param cause The cause
|
||||
*/
|
||||
public OpenWeatherMapConfigurationException(@Nullable Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message and cause.
|
||||
*
|
||||
* @param message Detail message
|
||||
* @param cause The cause
|
||||
*/
|
||||
public OpenWeatherMapConfigurationException(@Nullable String message, @Nullable Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,6 @@ package org.openhab.binding.openweathermap.internal.connection;
|
|||
import static org.eclipse.jetty.http.HttpMethod.GET;
|
||||
import static org.eclipse.jetty.http.HttpStatus.*;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZoneId;
|
||||
|
@ -46,6 +45,8 @@ import org.openhab.binding.openweathermap.internal.dto.onecallhist.OpenWeatherMa
|
|||
import org.openhab.binding.openweathermap.internal.handler.OpenWeatherMapAPIHandler;
|
||||
import org.openhab.core.cache.ByteArrayFileCache;
|
||||
import org.openhab.core.cache.ExpiringCacheMap;
|
||||
import org.openhab.core.i18n.CommunicationException;
|
||||
import org.openhab.core.i18n.ConfigurationException;
|
||||
import org.openhab.core.io.net.http.HttpUtil;
|
||||
import org.openhab.core.library.types.PointType;
|
||||
import org.openhab.core.library.types.RawType;
|
||||
|
@ -121,11 +122,11 @@ public class OpenWeatherMapConnection {
|
|||
* @param location location represented as {@link PointType}
|
||||
* @return the current weather data
|
||||
* @throws JsonSyntaxException
|
||||
* @throws OpenWeatherMapCommunicationException
|
||||
* @throws OpenWeatherMapConfigurationException
|
||||
* @throws CommunicationException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public synchronized @Nullable OpenWeatherMapJsonWeatherData getWeatherData(@Nullable PointType location)
|
||||
throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws JsonSyntaxException, CommunicationException, ConfigurationException {
|
||||
return gson.fromJson(
|
||||
getResponseFromCache(
|
||||
buildURL(WEATHER_URL, getRequestParams(handler.getOpenWeatherMapAPIConfig(), location))),
|
||||
|
@ -139,14 +140,14 @@ public class OpenWeatherMapConnection {
|
|||
* @param count number of hours
|
||||
* @return the hourly forecast data
|
||||
* @throws JsonSyntaxException
|
||||
* @throws OpenWeatherMapCommunicationException
|
||||
* @throws OpenWeatherMapConfigurationException
|
||||
* @throws CommunicationException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public synchronized @Nullable OpenWeatherMapJsonHourlyForecastData getHourlyForecastData(
|
||||
@Nullable PointType location, int count)
|
||||
throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws JsonSyntaxException, CommunicationException, ConfigurationException {
|
||||
if (count <= 0) {
|
||||
throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-not-supported-number-of-hours");
|
||||
throw new ConfigurationException("@text/offline.conf-error-not-supported-number-of-hours");
|
||||
}
|
||||
|
||||
Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
|
||||
|
@ -163,14 +164,13 @@ public class OpenWeatherMapConnection {
|
|||
* @param count number of days
|
||||
* @return the daily forecast data
|
||||
* @throws JsonSyntaxException
|
||||
* @throws OpenWeatherMapCommunicationException
|
||||
* @throws OpenWeatherMapConfigurationException
|
||||
* @throws CommunicationException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public synchronized @Nullable OpenWeatherMapJsonDailyForecastData getDailyForecastData(@Nullable PointType location,
|
||||
int count)
|
||||
throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
int count) throws JsonSyntaxException, CommunicationException, ConfigurationException {
|
||||
if (count <= 0) {
|
||||
throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-not-supported-number-of-days");
|
||||
throw new ConfigurationException("@text/offline.conf-error-not-supported-number-of-days");
|
||||
}
|
||||
|
||||
Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
|
||||
|
@ -186,11 +186,11 @@ public class OpenWeatherMapConnection {
|
|||
* @param location location represented as {@link PointType}
|
||||
* @return the UV Index data
|
||||
* @throws JsonSyntaxException
|
||||
* @throws OpenWeatherMapCommunicationException
|
||||
* @throws OpenWeatherMapConfigurationException
|
||||
* @throws CommunicationException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public synchronized @Nullable OpenWeatherMapJsonUVIndexData getUVIndexData(@Nullable PointType location)
|
||||
throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws JsonSyntaxException, CommunicationException, ConfigurationException {
|
||||
return gson.fromJson(
|
||||
getResponseFromCache(
|
||||
buildURL(UVINDEX_URL, getRequestParams(handler.getOpenWeatherMapAPIConfig(), location))),
|
||||
|
@ -203,15 +203,14 @@ public class OpenWeatherMapConnection {
|
|||
* @param location location represented as {@link PointType}
|
||||
* @return the UV Index forecast data
|
||||
* @throws JsonSyntaxException
|
||||
* @throws OpenWeatherMapCommunicationException
|
||||
* @throws OpenWeatherMapConfigurationException
|
||||
* @throws CommunicationException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public synchronized @Nullable List<OpenWeatherMapJsonUVIndexData> getUVIndexForecastData(
|
||||
@Nullable PointType location, int count)
|
||||
throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws JsonSyntaxException, CommunicationException, ConfigurationException {
|
||||
if (count <= 0) {
|
||||
throw new OpenWeatherMapConfigurationException(
|
||||
"@text/offline.conf-error-not-supported-uvindex-number-of-days");
|
||||
throw new ConfigurationException("@text/offline.conf-error-not-supported-uvindex-number-of-days");
|
||||
}
|
||||
|
||||
Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
|
||||
|
@ -227,11 +226,11 @@ public class OpenWeatherMapConnection {
|
|||
* @param location location represented as {@link PointType}
|
||||
* @return the Air Pollution data
|
||||
* @throws JsonSyntaxException
|
||||
* @throws OpenWeatherMapCommunicationException
|
||||
* @throws OpenWeatherMapConfigurationException
|
||||
* @throws CommunicationException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public synchronized @Nullable OpenWeatherMapJsonAirPollutionData getAirPollutionData(@Nullable PointType location)
|
||||
throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws JsonSyntaxException, CommunicationException, ConfigurationException {
|
||||
return gson.fromJson(
|
||||
getResponseFromCache(
|
||||
buildURL(AIR_POLLUTION_URL, getRequestParams(handler.getOpenWeatherMapAPIConfig(), location))),
|
||||
|
@ -245,12 +244,11 @@ public class OpenWeatherMapConnection {
|
|||
* @param location location represented as {@link PointType}
|
||||
* @return the Air Pollution forecast data
|
||||
* @throws JsonSyntaxException
|
||||
* @throws OpenWeatherMapCommunicationException
|
||||
* @throws OpenWeatherMapConfigurationException
|
||||
* @throws CommunicationException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public synchronized @Nullable OpenWeatherMapJsonAirPollutionData getAirPollutionForecastData(
|
||||
@Nullable PointType location)
|
||||
throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
@Nullable PointType location) throws JsonSyntaxException, CommunicationException, ConfigurationException {
|
||||
return gson.fromJson(
|
||||
getResponseFromCache(buildURL(AIR_POLLUTION_FORECAST_URL,
|
||||
getRequestParams(handler.getOpenWeatherMapAPIConfig(), location))),
|
||||
|
@ -303,12 +301,12 @@ public class OpenWeatherMapConnection {
|
|||
* @param excludeDaily if true, will not fetch hourly forecast data from the server
|
||||
* @return
|
||||
* @throws JsonSyntaxException
|
||||
* @throws OpenWeatherMapCommunicationException
|
||||
* @throws OpenWeatherMapConfigurationException
|
||||
* @throws CommunicationException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public synchronized @Nullable OpenWeatherMapOneCallAPIData getOneCallAPIData(@Nullable PointType location,
|
||||
boolean excludeMinutely, boolean excludeHourly, boolean excludeDaily, boolean excludeAlerts)
|
||||
throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws JsonSyntaxException, CommunicationException, ConfigurationException {
|
||||
Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
|
||||
List<String> exclude = new ArrayList<>();
|
||||
if (excludeMinutely) {
|
||||
|
@ -339,12 +337,11 @@ public class OpenWeatherMapConnection {
|
|||
* @param days number of days in the past, relative to the current time.
|
||||
* @return
|
||||
* @throws JsonSyntaxException
|
||||
* @throws OpenWeatherMapCommunicationException
|
||||
* @throws OpenWeatherMapConfigurationException
|
||||
* @throws CommunicationException
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public synchronized @Nullable OpenWeatherMapOneCallHistAPIData getOneCallHistAPIData(@Nullable PointType location,
|
||||
int days)
|
||||
throws JsonSyntaxException, OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
int days) throws JsonSyntaxException, CommunicationException, ConfigurationException {
|
||||
Map<String, String> params = getRequestParams(handler.getOpenWeatherMapAPIConfig(), location);
|
||||
// the API requests the history as timestamp in Unix time format.
|
||||
params.put(PARAM_HISTORY_DATE,
|
||||
|
@ -355,14 +352,14 @@ public class OpenWeatherMapConnection {
|
|||
|
||||
private Map<String, String> getRequestParams(OpenWeatherMapAPIConfiguration config, @Nullable PointType location) {
|
||||
if (location == null) {
|
||||
throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-missing-location");
|
||||
throw new ConfigurationException("@text/offline.conf-error-missing-location");
|
||||
}
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
// API key (see https://openweathermap.org/appid)
|
||||
String apikey = config.apikey;
|
||||
if (apikey == null || (apikey = apikey.trim()).isEmpty()) {
|
||||
throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-missing-apikey");
|
||||
throw new ConfigurationException("@text/offline.conf-error-missing-apikey");
|
||||
}
|
||||
params.put(PARAM_APPID, apikey);
|
||||
|
||||
|
@ -387,15 +384,7 @@ public class OpenWeatherMapConnection {
|
|||
}
|
||||
|
||||
private String encodeParam(@Nullable String value) {
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return URLEncoder.encode(value, StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.debug("UnsupportedEncodingException occurred during execution: {}", e.getLocalizedMessage(), e);
|
||||
return "";
|
||||
}
|
||||
return value == null ? "" : URLEncoder.encode(value, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private @Nullable String getResponseFromCache(String url) {
|
||||
|
@ -421,26 +410,29 @@ public class OpenWeatherMapConnection {
|
|||
case NOT_FOUND_404:
|
||||
errorMessage = getErrorMessage(content);
|
||||
logger.debug("OpenWeatherMap server responded with status code {}: {}", httpStatus, errorMessage);
|
||||
throw new OpenWeatherMapConfigurationException(errorMessage);
|
||||
throw new ConfigurationException(errorMessage);
|
||||
case TOO_MANY_REQUESTS_429:
|
||||
// TODO disable refresh job temporarily (see https://openweathermap.org/appid#Accesslimitation)
|
||||
default:
|
||||
errorMessage = getErrorMessage(content);
|
||||
logger.debug("OpenWeatherMap server responded with status code {}: {}", httpStatus, errorMessage);
|
||||
throw new OpenWeatherMapCommunicationException(errorMessage);
|
||||
throw new CommunicationException(errorMessage);
|
||||
}
|
||||
} catch (ExecutionException e) {
|
||||
String errorMessage = e.getLocalizedMessage();
|
||||
logger.trace("Exception occurred during execution: {}", errorMessage, e);
|
||||
String errorMessage = e.getMessage();
|
||||
logger.debug("ExecutionException occurred during execution: {}", errorMessage, e);
|
||||
if (e.getCause() instanceof HttpResponseException) {
|
||||
logger.debug("OpenWeatherMap server responded with status code {}: Invalid API key.", UNAUTHORIZED_401);
|
||||
throw new OpenWeatherMapConfigurationException("@text/offline.conf-error-invalid-apikey", e.getCause());
|
||||
throw new ConfigurationException("@text/offline.conf-error-invalid-apikey", e.getCause());
|
||||
} else {
|
||||
throw new OpenWeatherMapCommunicationException(errorMessage, e.getCause());
|
||||
throw new CommunicationException(
|
||||
errorMessage == null ? "@text/offline.communication-error" : errorMessage, e.getCause());
|
||||
}
|
||||
} catch (InterruptedException | TimeoutException e) {
|
||||
logger.debug("Exception occurred during execution: {}", e.getLocalizedMessage(), e);
|
||||
throw new OpenWeatherMapCommunicationException(e.getLocalizedMessage(), e.getCause());
|
||||
String errorMessage = e.getMessage();
|
||||
logger.debug("InterruptedException or TimeoutException occurred during execution: {}", errorMessage, e);
|
||||
throw new CommunicationException(errorMessage == null ? "@text/offline.communication-error" : errorMessage,
|
||||
e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ import javax.measure.Unit;
|
|||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapLocationConfiguration;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
|
||||
import org.openhab.core.i18n.CommunicationException;
|
||||
import org.openhab.core.i18n.ConfigurationException;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
|
@ -137,9 +137,9 @@ public abstract class AbstractOpenWeatherMapHandler extends BaseThingHandler {
|
|||
updateChannels();
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
}
|
||||
} catch (OpenWeatherMapCommunicationException e) {
|
||||
} catch (CommunicationException e) {
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getLocalizedMessage());
|
||||
} catch (OpenWeatherMapConfigurationException e) {
|
||||
} catch (ConfigurationException e) {
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
@ -149,11 +149,11 @@ public abstract class AbstractOpenWeatherMapHandler extends BaseThingHandler {
|
|||
*
|
||||
* @param connection {@link OpenWeatherMapConnection} instance
|
||||
* @return true, if the request for the OpenWeatherMap data was successful
|
||||
* @throws OpenWeatherMapCommunicationException if there is a problem retrieving the data
|
||||
* @throws OpenWeatherMapConfigurationException if there is a configuration error
|
||||
* @throws CommunicationException if there is a problem retrieving the data
|
||||
* @throws ConfigurationException if there is a configuration error
|
||||
*/
|
||||
protected abstract boolean requestData(OpenWeatherMapConnection connection)
|
||||
throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException;
|
||||
throws CommunicationException, ConfigurationException;
|
||||
|
||||
/**
|
||||
* Updates all channels of this handler from the latest OpenWeatherMap data retrieved.
|
||||
|
|
|
@ -22,10 +22,10 @@ import java.util.regex.Pattern;
|
|||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapAirPollutionConfiguration;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
|
||||
import org.openhab.binding.openweathermap.internal.dto.OpenWeatherMapJsonAirPollutionData;
|
||||
import org.openhab.core.i18n.CommunicationException;
|
||||
import org.openhab.core.i18n.ConfigurationException;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.unit.Units;
|
||||
|
@ -111,7 +111,7 @@ public class OpenWeatherMapAirPollutionHandler extends AbstractOpenWeatherMapHan
|
|||
|
||||
@Override
|
||||
protected boolean requestData(OpenWeatherMapConnection connection)
|
||||
throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws CommunicationException, ConfigurationException {
|
||||
logger.debug("Update air pollution data of thing '{}'.", getThing().getUID());
|
||||
try {
|
||||
airPollutionData = connection.getAirPollutionData(location);
|
||||
|
@ -120,7 +120,7 @@ public class OpenWeatherMapAirPollutionHandler extends AbstractOpenWeatherMapHan
|
|||
}
|
||||
return true;
|
||||
} catch (JsonSyntaxException e) {
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ import java.util.regex.Pattern;
|
|||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapOneCallConfiguration;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
|
||||
import org.openhab.binding.openweathermap.internal.dto.onecall.Alert;
|
||||
import org.openhab.binding.openweathermap.internal.dto.onecall.FeelsLike;
|
||||
|
@ -34,6 +32,8 @@ import org.openhab.binding.openweathermap.internal.dto.onecall.OpenWeatherMapOne
|
|||
import org.openhab.binding.openweathermap.internal.dto.onecall.Rain;
|
||||
import org.openhab.binding.openweathermap.internal.dto.onecall.Snow;
|
||||
import org.openhab.binding.openweathermap.internal.dto.onecall.Temp;
|
||||
import org.openhab.core.i18n.CommunicationException;
|
||||
import org.openhab.core.i18n.ConfigurationException;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.thing.Channel;
|
||||
|
@ -215,14 +215,14 @@ public class OpenWeatherMapOneCallHandler extends AbstractOpenWeatherMapHandler
|
|||
|
||||
@Override
|
||||
protected boolean requestData(OpenWeatherMapConnection connection)
|
||||
throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws CommunicationException, ConfigurationException {
|
||||
logger.debug("Update weather and forecast data of thing '{}'.", getThing().getUID());
|
||||
try {
|
||||
weatherData = connection.getOneCallAPIData(location, forecastMinutes == 0, forecastHours == 0,
|
||||
forecastDays == 0, numberOfAlerts == 0);
|
||||
return true;
|
||||
} catch (JsonSyntaxException e) {
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ import java.util.regex.Pattern;
|
|||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapOneCallHistoryConfiguration;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
|
||||
import org.openhab.binding.openweathermap.internal.dto.onecallhist.Hourly;
|
||||
import org.openhab.binding.openweathermap.internal.dto.onecallhist.OpenWeatherMapOneCallHistAPIData;
|
||||
import org.openhab.binding.openweathermap.internal.dto.onecallhist.Rain;
|
||||
import org.openhab.binding.openweathermap.internal.dto.onecallhist.Snow;
|
||||
import org.openhab.core.i18n.CommunicationException;
|
||||
import org.openhab.core.i18n.ConfigurationException;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
|
@ -90,13 +90,13 @@ public class OpenWeatherMapOneCallHistoryHandler extends AbstractOpenWeatherMapH
|
|||
|
||||
@Override
|
||||
protected boolean requestData(OpenWeatherMapConnection connection)
|
||||
throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws CommunicationException, ConfigurationException {
|
||||
logger.debug("Update weather and forecast data of thing '{}'.", getThing().getUID());
|
||||
try {
|
||||
weatherData = connection.getOneCallHistAPIData(location, day);
|
||||
return true;
|
||||
} catch (JsonSyntaxException e) {
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ import java.util.regex.Pattern;
|
|||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapUVIndexConfiguration;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
|
||||
import org.openhab.binding.openweathermap.internal.dto.OpenWeatherMapJsonUVIndexData;
|
||||
import org.openhab.core.i18n.CommunicationException;
|
||||
import org.openhab.core.i18n.ConfigurationException;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.thing.Channel;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
|
@ -116,7 +116,7 @@ public class OpenWeatherMapUVIndexHandler extends AbstractOpenWeatherMapHandler
|
|||
|
||||
@Override
|
||||
protected boolean requestData(OpenWeatherMapConnection connection)
|
||||
throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws CommunicationException, ConfigurationException {
|
||||
logger.debug("Update UV Index data of thing '{}'.", getThing().getUID());
|
||||
try {
|
||||
uvindexData = connection.getUVIndexData(location);
|
||||
|
@ -125,7 +125,7 @@ public class OpenWeatherMapUVIndexHandler extends AbstractOpenWeatherMapHandler
|
|||
}
|
||||
return true;
|
||||
} catch (JsonSyntaxException e) {
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.jetty.client.HttpResponseException;
|
||||
import org.openhab.binding.openweathermap.internal.config.OpenWeatherMapWeatherAndForecastConfiguration;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapCommunicationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConfigurationException;
|
||||
import org.openhab.binding.openweathermap.internal.connection.OpenWeatherMapConnection;
|
||||
import org.openhab.binding.openweathermap.internal.dto.OpenWeatherMapJsonDailyForecastData;
|
||||
import org.openhab.binding.openweathermap.internal.dto.OpenWeatherMapJsonHourlyForecastData;
|
||||
|
@ -37,6 +35,8 @@ import org.openhab.binding.openweathermap.internal.dto.base.Rain;
|
|||
import org.openhab.binding.openweathermap.internal.dto.base.Snow;
|
||||
import org.openhab.binding.openweathermap.internal.dto.forecast.daily.FeelsLikeTemp;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
import org.openhab.core.i18n.CommunicationException;
|
||||
import org.openhab.core.i18n.ConfigurationException;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.thing.Channel;
|
||||
|
@ -163,7 +163,7 @@ public class OpenWeatherMapWeatherAndForecastHandler extends AbstractOpenWeather
|
|||
|
||||
@Override
|
||||
protected boolean requestData(OpenWeatherMapConnection connection)
|
||||
throws OpenWeatherMapCommunicationException, OpenWeatherMapConfigurationException {
|
||||
throws CommunicationException, ConfigurationException {
|
||||
logger.debug("Update weather and forecast data of thing '{}'.", getThing().getUID());
|
||||
try {
|
||||
weatherData = connection.getWeatherData(location);
|
||||
|
@ -173,7 +173,7 @@ public class OpenWeatherMapWeatherAndForecastHandler extends AbstractOpenWeather
|
|||
if (forecastDays > 0) {
|
||||
try {
|
||||
dailyForecastData = connection.getDailyForecastData(location, forecastDays);
|
||||
} catch (OpenWeatherMapConfigurationException e) {
|
||||
} catch (ConfigurationException e) {
|
||||
if (e.getCause() instanceof HttpResponseException) {
|
||||
forecastDays = 0;
|
||||
Configuration editConfig = editConfiguration();
|
||||
|
@ -193,7 +193,7 @@ public class OpenWeatherMapWeatherAndForecastHandler extends AbstractOpenWeather
|
|||
}
|
||||
return true;
|
||||
} catch (JsonSyntaxException e) {
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getLocalizedMessage(), e);
|
||||
logger.debug("JsonSyntaxException occurred during execution: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -357,6 +357,7 @@ offline.conf-error-not-supported-onecall-number-of-minutes = The 'forecastMinute
|
|||
offline.conf-error-not-supported-onecall-number-of-hours = The 'forecastHours' parameter must be between 0 and 48.
|
||||
offline.conf-error-not-supported-onecall-number-of-days = The 'forecastDays' parameter must be between 0 and 7.
|
||||
offline.conf-error-not-supported-onecall-number-of-alerts = The 'numberOfAlerts' parameter must be greater than or equals to 0.
|
||||
offline.communication-error = An unexpected exception occurred during execution.
|
||||
|
||||
# discovery result
|
||||
|
||||
|
|
Loading…
Reference in New Issue