Skip to content

Commit

Permalink
[keba] Robustness improvements on communication error (openhab#10399)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Weger <weger.michael@gmx.net>
  • Loading branch information
MikeTheTux authored Apr 17, 2021
1 parent 0bf2cf3 commit e46f686
Showing 1 changed file with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,51 +181,61 @@ private void pollingRunnable() {
long stamp = System.currentTimeMillis();
if (!isKebaReachable()) {
logger.debug("isKebaReachable() timed out after '{}' milliseconds", System.currentTimeMillis() - stamp);
transceiver.unRegisterHandler(getHandler());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"An timeout occurred while polling the charging station");
} else {
if (getThing().getStatus() == ThingStatus.ONLINE) {
ByteBuffer response = cache.get(CACHE_REPORT_1);
if (response != null) {
onData(response);
}
ByteBuffer response = cache.get(CACHE_REPORT_1);
if (response == null) {
logger.debug("Missing response from Keba station for 'report 1'");
} else {
onData(response);
}

Thread.sleep(REPORT_INTERVAL);
Thread.sleep(REPORT_INTERVAL);

response = cache.get(CACHE_REPORT_2);
if (response != null) {
onData(response);
}
response = cache.get(CACHE_REPORT_2);
if (response == null) {
logger.debug("Missing response from Keba station for 'report 2'");
} else {
onData(response);
}

Thread.sleep(REPORT_INTERVAL);
Thread.sleep(REPORT_INTERVAL);

response = cache.get(CACHE_REPORT_3);
if (response != null) {
onData(response);
}
response = cache.get(CACHE_REPORT_3);
if (response == null) {
logger.debug("Missing response from Keba station for 'report 3'");
} else {
onData(response);
}

if (isReport100needed) {
Thread.sleep(REPORT_INTERVAL);
if (isReport100needed) {
Thread.sleep(REPORT_INTERVAL);

response = cache.get(CACHE_REPORT_100);
if (response != null) {
onData(response);
}
isReport100needed = false;
response = cache.get(CACHE_REPORT_100);
if (response == null) {
logger.debug("Missing response from Keba station for 'report 100'");
} else {
onData(response);
}
isReport100needed = false;
}
}
} catch (NumberFormatException | IOException e) {
logger.debug("An exception occurred while polling the KEBA KeContact '{}': {}", getThing().getUID(),
} catch (IOException e) {
logger.debug("An error occurred while polling the KEBA KeContact '{}': {}", getThing().getUID(),
e.getMessage(), e);
Thread.currentThread().interrupt();
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"An exception occurred while while polling the charging station");
"An error occurred while polling the charging station");
} catch (InterruptedException e) {
logger.debug("Polling job has been interrupted for handler of thing '{}'.", getThing().getUID());
}
}

protected void onData(ByteBuffer byteBuffer) {
if (getThing().getStatus() != ThingStatus.ONLINE) {
updateStatus(ThingStatus.ONLINE);
}

String response = new String(byteBuffer.array(), 0, byteBuffer.limit());
response = StringUtils.chomp(response);

Expand Down

0 comments on commit e46f686

Please sign in to comment.