Skip to content

Commit

Permalink
Start and stop polling with bridge status changes
Browse files Browse the repository at this point in the history
Signed-off-by: Sara Damiano <[email protected]>
  • Loading branch information
SRGDamia1 committed Jun 21, 2020
1 parent b58426c commit bdeee2b
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,22 @@ private synchronized void startPollingJob() {
this.pollingJob = scheduler.scheduleWithFixedDelay(pollingCommand, 60, 300, TimeUnit.SECONDS);
}
}

@Override
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE
&& getThing().getStatusInfo().getStatusDetail() == ThingStatusDetail.BRIDGE_OFFLINE) {
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
// restart the polling job when the bridge goes back online
startPollingJob();
} else if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
// stop the polling job when the bridge goes offline
ScheduledFuture<?> pollingJob = this.pollingJob;
if (pollingJob != null) {
pollingJob.cancel(true);
this.pollingJob = null;
}
}
}
}

0 comments on commit bdeee2b

Please sign in to comment.