]> git.basschouten.com Git - openhab-addons.git/commitdiff
[lutron] Add debug logging in leapbridge (#9554)
authorBob A <bobadair@users.noreply.github.com>
Mon, 28 Dec 2020 06:40:05 +0000 (01:40 -0500)
committerGitHub <noreply@github.com>
Mon, 28 Dec 2020 06:40:05 +0000 (22:40 -0800)
Signed-off-by: Bob Adair <bob.github@att.net>
bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/LeapBridgeHandler.java

index c2a29dd35457db0ecc3943c4bcb435985fbf8023..1290e7342fc9e66bad0ab92b0309bbb454d763ac 100644 (file)
@@ -727,6 +727,9 @@ public class LeapBridgeHandler extends LutronBridgeHandler implements LeapMessag
         }
     }
 
+    /**
+     * Executed by keepAliveJob. Sends a LEAP ping request and schedules a reconnect task.
+     */
     private void sendKeepAlive() {
         logger.trace("Sending keepalive query");
         sendCommand(new LeapCommand(Request.ping()));
@@ -734,12 +737,20 @@ public class LeapBridgeHandler extends LutronBridgeHandler implements LeapMessag
         reconnectTaskSchedule();
     }
 
+    /**
+     * Schedules the reconnect task keepAliveReconnectJob to execute in KEEPALIVE_TIMEOUT_SECONDS. This should be
+     * cancelled by calling reconnectTaskCancel() if a valid response is received from the bridge.
+     */
     private void reconnectTaskSchedule() {
         synchronized (keepAliveReconnectLock) {
-            keepAliveReconnectJob = scheduler.schedule(this::reconnect, KEEPALIVE_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+            keepAliveReconnectJob = scheduler.schedule(this::keepaliveTimeoutExpired, KEEPALIVE_TIMEOUT_SECONDS,
+                    TimeUnit.SECONDS);
         }
     }
 
+    /**
+     * Cancels the reconnect task keepAliveReconnectJob.
+     */
     private void reconnectTaskCancel(boolean interrupt) {
         synchronized (keepAliveReconnectLock) {
             ScheduledFuture<?> keepAliveReconnectJob = this.keepAliveReconnectJob;
@@ -751,6 +762,15 @@ public class LeapBridgeHandler extends LutronBridgeHandler implements LeapMessag
         }
     }
 
+    /**
+     * Executed by keepAliveReconnectJob if it is not cancelled by the LEAP message parser calling
+     * validMessageReceived() which in turn calls reconnectTaskCancel().
+     */
+    private void keepaliveTimeoutExpired() {
+        logger.debug("Keepalive response timeout expired. Initiating reconnect.");
+        reconnect();
+    }
+
     @Override
     public void handleCommand(ChannelUID channelUID, Command command) {
         if (channelUID.getId().equals(CHANNEL_COMMAND)) {