Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lutron] Add debug logging in leapbridge #9554

Merged
merged 1 commit into from
Dec 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -727,19 +727,30 @@ public int getButton(int integrationID, int component) {
}
}

/**
* 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()));
// Reconnect if no response is received within KEEPALIVE_TIMEOUT_SECONDS.
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;
Expand All @@ -751,6 +762,15 @@ private void reconnectTaskCancel(boolean interrupt) {
}
}

/**
* 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)) {
Expand Down