]> git.basschouten.com Git - openhab-addons.git/commitdiff
[boschindego] Add missing specialized text for unreachable device (#13058)
authorJacob Laursen <jacob-github@vindvejr.dk>
Tue, 5 Jul 2022 11:01:46 +0000 (13:01 +0200)
committerGitHub <noreply@github.com>
Tue, 5 Jul 2022 11:01:46 +0000 (13:01 +0200)
* Add missing specialized text for unreachable device
* Document IndegoUnreachableException on relevant paths

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/IndegoController.java
bundles/org.openhab.binding.boschindego/src/main/java/org/openhab/binding/boschindego/internal/handler/BoschIndegoHandler.java

index 1fe36dd1be6fdb31ed18aa01cce47c2b11c8fdf6..8ee4898f4c5e2e327b0bfcb9232faecbc23b2c2c 100644 (file)
@@ -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> T getRequestWithAuthentication(String path, Class<? extends T> 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> T getRequest(String path, Class<? extends T> 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);
     }
index f0c3e6774cffb94ea486c3a40f5916a000ce200c..a8b6634adc0ed5734af6ede176e4962c5a2452c2 100644 (file)
@@ -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);
     }