Skip to content

Commit

Permalink
Prevent a timeout from the server from stopping the binding (openhab#…
Browse files Browse the repository at this point in the history
…11555)

Signed-off-by: EvilPingu <[email protected]>
  • Loading branch information
EvilPingu authored and andan67 committed Nov 5, 2022
1 parent d9a9653 commit 5b8a177
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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}
Expand All @@ -29,6 +31,7 @@
public class RefreshGroupContentService {

private final List<GroupContent> groupContentList;
private final Logger logger = LoggerFactory.getLogger(RefreshGroupContentService.class);
private List<Thing> things;

/**
Expand All @@ -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.");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,21 @@ public void onComplete(@Nullable Result result) {
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();
}
}
}
}
Expand Down

0 comments on commit 5b8a177

Please sign in to comment.