]> git.basschouten.com Git - openhab-addons.git/commitdiff
Prevent a timeout from the server from stopping the binding (#11555)
authorChristian Kittel <EvilPingu@users.noreply.github.com>
Thu, 11 Nov 2021 23:45:50 +0000 (00:45 +0100)
committerGitHub <noreply@github.com>
Thu, 11 Nov 2021 23:45:50 +0000 (00:45 +0100)
Signed-off-by: EvilPingu <ckittel@gmx.de>
bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshGroupContentService.java
bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshService.java

index 6f1f6f91efc8d45e778b8dc95027fe9a68e8ba08..711357eb044b66b1b0e683053a7d6382f7281c92 100644 (file)
@@ -19,6 +19,8 @@ import org.openhab.binding.ojelectronics.internal.ThermostatHandler;
 import org.openhab.binding.ojelectronics.internal.models.Thermostat;
 import org.openhab.binding.ojelectronics.internal.models.groups.GroupContent;
 import org.openhab.core.thing.Thing;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Refreshes values of {@link ThermostatHandler}
@@ -29,6 +31,7 @@ import org.openhab.core.thing.Thing;
 public class RefreshGroupContentService {
 
     private final List<GroupContent> groupContentList;
+    private final Logger logger = LoggerFactory.getLogger(RefreshGroupContentService.class);
     private List<Thing> things;
 
     /**
@@ -40,6 +43,9 @@ public class RefreshGroupContentService {
     public RefreshGroupContentService(List<GroupContent> groupContents, List<Thing> things) {
         this.groupContentList = groupContents;
         this.things = things;
+        if (this.things.isEmpty()) {
+            logger.warn("Bridge contains no thermostats.");
+        }
     }
 
     /**
index d082991f98e5f234834c70a8e8a1b78efcb19b49..adf646bf2e582e56d55d7fe05a0f3598ff712418 100644 (file)
@@ -115,14 +115,21 @@ public final class RefreshService implements AutoCloseable {
                 if (!destroyed) {
                     if (result == null || result.isFailed()) {
                         handleConnectionLost();
-                    } else if (result.getResponse().getStatus() == HttpStatus.FORBIDDEN_403) {
-                        if (unauthorized != null) {
-                            unauthorized.run();
-                        }
-                    } else if (result.getResponse().getStatus() == HttpStatus.FORBIDDEN_403) {
-                        handleConnectionLost();
                     } else {
-                        handleRefreshDone(getContentAsString());
+                        int status = result.getResponse().getStatus();
+                        logger.trace("HTTP-Status {}", status);
+                        if (status == HttpStatus.FORBIDDEN_403) {
+                            if (unauthorized != null) {
+                                unauthorized.run();
+                            } else {
+                                handleConnectionLost();
+                            }
+                        } else if (status == HttpStatus.OK_200) {
+                            handleRefreshDone(getContentAsString());
+                        } else {
+                            logger.warn("unsupported HTTP-Status {}", status);
+                            handleConnectionLost();
+                        }
                     }
                 }
             }