From f5eabf0ba2915f49c7de2b351596b9df7a70e5de Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 5 Jul 2022 13:01:46 +0200 Subject: [PATCH] [boschindego] Add missing specialized text for unreachable device (#13058) * Add missing specialized text for unreachable device * Document IndegoUnreachableException on relevant paths Signed-off-by: Jacob Laursen --- .../boschindego/internal/IndegoController.java | 10 +++++++--- .../internal/handler/BoschIndegoHandler.java | 13 +++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java index 1fe36dd1be..8ee4898f4c 100644 --- a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java +++ b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java @@ -189,10 +189,11 @@ public class IndegoController { * @param dtoClass the DTO class to which the JSON result should be deserialized * @return the deserialized DTO from the JSON response * @throws IndegoAuthenticationException if request was rejected as unauthorized + * @throws IndegoUnreachableException if device cannot be reached (gateway timeout error) * @throws IndegoException if any communication or parsing error occurred */ private T getRequestWithAuthentication(String path, Class dtoClass) - throws IndegoAuthenticationException, IndegoException { + throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException { if (!session.isValid()) { authenticate(); } @@ -218,10 +219,11 @@ public class IndegoController { * @param dtoClass the DTO class to which the JSON result should be deserialized * @return the deserialized DTO from the JSON response * @throws IndegoAuthenticationException if request was rejected as unauthorized + * @throws IndegoUnreachableException if device cannot be reached (gateway timeout error) * @throws IndegoException if any communication or parsing error occurred */ private T getRequest(String path, Class dtoClass) - throws IndegoAuthenticationException, IndegoException { + throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException { try { Request request = httpClient.newRequest(BASE_URL + path).method(HttpMethod.GET).header(CONTEXT_HEADER_NAME, session.getContextId()); @@ -521,9 +523,11 @@ public class IndegoController { * * @return the device state * @throws IndegoAuthenticationException if request was rejected as unauthorized + * @throws IndegoUnreachableException if device cannot be reached (gateway timeout error) * @throws IndegoException if any communication or parsing error occurred */ - public OperatingDataResponse getOperatingData() throws IndegoAuthenticationException, IndegoException { + public OperatingDataResponse getOperatingData() + throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException { return getRequestWithAuthentication(SERIAL_NUMBER_SUBPATH + this.getSerialNumber() + "/operatingData", OperatingDataResponse.class); } diff --git a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java index f0c3e6774c..a8b6634adc 100644 --- a/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java +++ b/bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java @@ -31,6 +31,7 @@ import org.openhab.binding.boschindego.internal.dto.response.DeviceStateResponse import org.openhab.binding.boschindego.internal.dto.response.OperatingDataResponse; import org.openhab.binding.boschindego.internal.exceptions.IndegoAuthenticationException; import org.openhab.binding.boschindego.internal.exceptions.IndegoException; +import org.openhab.binding.boschindego.internal.exceptions.IndegoUnreachableException; import org.openhab.core.i18n.TimeZoneProvider; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DecimalType; @@ -145,12 +146,16 @@ public class BoschIndegoHandler extends BaseThingHandler { } catch (IndegoAuthenticationException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "@text/offline.comm-error.authentication-failure"); + } catch (IndegoUnreachableException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "@text/offline.comm-error.unreachable"); } catch (IndegoException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); } } - private void handleRefreshCommand(String channelId) throws IndegoAuthenticationException, IndegoException { + private void handleRefreshCommand(String channelId) + throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException { switch (channelId) { case STATE: case TEXTUAL_STATE: @@ -212,6 +217,9 @@ public class BoschIndegoHandler extends BaseThingHandler { } catch (IndegoAuthenticationException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "@text/offline.comm-error.authentication-failure"); + } catch (IndegoUnreachableException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "@text/offline.comm-error.unreachable"); } catch (IndegoException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); } @@ -233,7 +241,8 @@ public class BoschIndegoHandler extends BaseThingHandler { } } - private void refreshOperatingData() throws IndegoAuthenticationException, IndegoException { + private void refreshOperatingData() + throws IndegoAuthenticationException, IndegoUnreachableException, IndegoException { updateOperatingData(controller.getOperatingData()); updateStatus(ThingStatus.ONLINE); } -- 2.47.3