Skip to content

Commit

Permalink
[openweathermap] Do not update the discovery inbox while the location…
Browse files Browse the repository at this point in the history
… is unchanged (openhab#8078)

- Do not update the discovery inbox while the location is unchanged

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored and andrewfg committed Aug 31, 2020
1 parent e2f5d01 commit 1281230
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void deactivate() {
@Override
protected void startScan() {
logger.debug("Start manual OpenWeatherMap Location discovery scan.");
scanForNewLocation();
scanForNewLocation(false);
}

@Override
Expand All @@ -93,8 +93,9 @@ protected void startBackgroundDiscovery() {
if (discoveryJob == null || discoveryJob.isCancelled()) {
logger.debug("Start OpenWeatherMap Location background discovery job at interval {} s.",
DISCOVERY_INTERVAL_SECONDS);
discoveryJob = scheduler.scheduleWithFixedDelay(this::scanForNewLocation, 0, DISCOVERY_INTERVAL_SECONDS,
TimeUnit.SECONDS);
discoveryJob = scheduler.scheduleWithFixedDelay(() -> {
scanForNewLocation(true);
}, 0, DISCOVERY_INTERVAL_SECONDS, TimeUnit.SECONDS);
}
}

Expand All @@ -108,7 +109,7 @@ protected void stopBackgroundDiscovery() {
}
}

private void scanForNewLocation() {
private void scanForNewLocation(boolean updateOnlyIfNewLocation) {
PointType currentLocation = locationProvider.getLocation();
if (currentLocation == null) {
logger.debug("Location is not set -> Will not provide any discovery results.");
Expand All @@ -117,7 +118,7 @@ private void scanForNewLocation() {
currentLocation);
createResults(currentLocation);
previousLocation = currentLocation;
} else {
} else if (!updateOnlyIfNewLocation) {
createResults(currentLocation);
}
}
Expand Down

0 comments on commit 1281230

Please sign in to comment.