Prevent a timeout from the server from stopping the binding (#11555)

Signed-off-by: EvilPingu <ckittel@gmx.de>
This commit is contained in:
Christian Kittel 2021-11-12 00:45:50 +01:00 committed by GitHub
parent afdbd09eb3
commit 2c7acbcc21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View 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.");
}
}
/**

View 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();
}
}
}
}