diff --git a/bundles/org.openhab.binding.keba/src/main/java/org/openhab/binding/keba/internal/handler/KeContactHandler.java b/bundles/org.openhab.binding.keba/src/main/java/org/openhab/binding/keba/internal/handler/KeContactHandler.java index af2b999a9..5317db71c 100644 --- a/bundles/org.openhab.binding.keba/src/main/java/org/openhab/binding/keba/internal/handler/KeContactHandler.java +++ b/bundles/org.openhab.binding.keba/src/main/java/org/openhab/binding/keba/internal/handler/KeContactHandler.java @@ -181,51 +181,61 @@ public class KeContactHandler extends BaseThingHandler { 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); + + 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); + + 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); - response = cache.get(CACHE_REPORT_2); - if (response != null) { + response = cache.get(CACHE_REPORT_100); + if (response == null) { + logger.debug("Missing response from Keba station for 'report 100'"); + } else { onData(response); } - - Thread.sleep(REPORT_INTERVAL); - - response = cache.get(CACHE_REPORT_3); - if (response != null) { - onData(response); - } - - if (isReport100needed) { - Thread.sleep(REPORT_INTERVAL); - - response = cache.get(CACHE_REPORT_100); - if (response != null) { - onData(response); - } - isReport100needed = false; - } + 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);