[keba] Robustness improvements on communication error (#10399)
Signed-off-by: Michael Weger <weger.michael@gmx.net>
This commit is contained in:
parent
8258d9d722
commit
fb1d6a283b
@ -181,25 +181,31 @@ public class KeContactHandler extends BaseThingHandler {
|
|||||||
long stamp = System.currentTimeMillis();
|
long stamp = System.currentTimeMillis();
|
||||||
if (!isKebaReachable()) {
|
if (!isKebaReachable()) {
|
||||||
logger.debug("isKebaReachable() timed out after '{}' milliseconds", System.currentTimeMillis() - stamp);
|
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 {
|
} else {
|
||||||
if (getThing().getStatus() == ThingStatus.ONLINE) {
|
|
||||||
ByteBuffer response = cache.get(CACHE_REPORT_1);
|
ByteBuffer response = cache.get(CACHE_REPORT_1);
|
||||||
if (response != null) {
|
if (response == null) {
|
||||||
|
logger.debug("Missing response from Keba station for 'report 1'");
|
||||||
|
} else {
|
||||||
onData(response);
|
onData(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(REPORT_INTERVAL);
|
Thread.sleep(REPORT_INTERVAL);
|
||||||
|
|
||||||
response = cache.get(CACHE_REPORT_2);
|
response = cache.get(CACHE_REPORT_2);
|
||||||
if (response != null) {
|
if (response == null) {
|
||||||
|
logger.debug("Missing response from Keba station for 'report 2'");
|
||||||
|
} else {
|
||||||
onData(response);
|
onData(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(REPORT_INTERVAL);
|
Thread.sleep(REPORT_INTERVAL);
|
||||||
|
|
||||||
response = cache.get(CACHE_REPORT_3);
|
response = cache.get(CACHE_REPORT_3);
|
||||||
if (response != null) {
|
if (response == null) {
|
||||||
|
logger.debug("Missing response from Keba station for 'report 3'");
|
||||||
|
} else {
|
||||||
onData(response);
|
onData(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,25 +213,29 @@ public class KeContactHandler extends BaseThingHandler {
|
|||||||
Thread.sleep(REPORT_INTERVAL);
|
Thread.sleep(REPORT_INTERVAL);
|
||||||
|
|
||||||
response = cache.get(CACHE_REPORT_100);
|
response = cache.get(CACHE_REPORT_100);
|
||||||
if (response != null) {
|
if (response == null) {
|
||||||
|
logger.debug("Missing response from Keba station for 'report 100'");
|
||||||
|
} else {
|
||||||
onData(response);
|
onData(response);
|
||||||
}
|
}
|
||||||
isReport100needed = false;
|
isReport100needed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
} catch (NumberFormatException | IOException e) {
|
logger.debug("An error occurred while polling the KEBA KeContact '{}': {}", getThing().getUID(),
|
||||||
logger.debug("An exception occurred while polling the KEBA KeContact '{}': {}", getThing().getUID(),
|
|
||||||
e.getMessage(), e);
|
e.getMessage(), e);
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
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) {
|
} catch (InterruptedException e) {
|
||||||
logger.debug("Polling job has been interrupted for handler of thing '{}'.", getThing().getUID());
|
logger.debug("Polling job has been interrupted for handler of thing '{}'.", getThing().getUID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onData(ByteBuffer byteBuffer) {
|
protected void onData(ByteBuffer byteBuffer) {
|
||||||
|
if (getThing().getStatus() != ThingStatus.ONLINE) {
|
||||||
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
}
|
||||||
|
|
||||||
String response = new String(byteBuffer.array(), 0, byteBuffer.limit());
|
String response = new String(byteBuffer.array(), 0, byteBuffer.limit());
|
||||||
response = StringUtils.chomp(response);
|
response = StringUtils.chomp(response);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user