From 2c7acbcc217be8d5131c62d881d2cac332fe844b Mon Sep 17 00:00:00 2001 From: Christian Kittel Date: Fri, 12 Nov 2021 00:45:50 +0100 Subject: [PATCH] Prevent a timeout from the server from stopping the binding (#11555) Signed-off-by: EvilPingu --- .../services/RefreshGroupContentService.java | 6 ++++++ .../internal/services/RefreshService.java | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshGroupContentService.java b/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshGroupContentService.java index 6f1f6f91e..711357eb0 100644 --- a/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshGroupContentService.java +++ b/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshGroupContentService.java @@ -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 groupContentList; + private final Logger logger = LoggerFactory.getLogger(RefreshGroupContentService.class); private List things; /** @@ -40,6 +43,9 @@ public class RefreshGroupContentService { public RefreshGroupContentService(List groupContents, List things) { this.groupContentList = groupContents; this.things = things; + if (this.things.isEmpty()) { + logger.warn("Bridge contains no thermostats."); + } } /** diff --git a/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshService.java b/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshService.java index d082991f9..adf646bf2 100644 --- a/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshService.java +++ b/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/services/RefreshService.java @@ -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(); + } } } }