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

[velux] Enabled background discovery #9477

Merged
merged 3 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
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 @@ -105,7 +105,6 @@ public Set<String> call() throws Exception {

// create a multicast listener socket
try (MulticastSocket rcvSocket = new MulticastSocket(MDNS_PORT)) {

final byte[] rcvBytes = new byte[BUFFER_SIZE];
final long finishTime = System.currentTimeMillis() + SEARCH_DURATION_MSECS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.velux.internal.VeluxBindingConstants;
import org.openhab.binding.velux.internal.VeluxBindingProperties;
import org.openhab.binding.velux.internal.config.VeluxBridgeConfiguration;
Expand Down Expand Up @@ -60,6 +63,9 @@ public class VeluxDiscoveryService extends AbstractDiscoveryService implements R
private Localization localization = Localization.UNKNOWN;
private final Set<VeluxBridgeHandler> bridgeHandlers = new HashSet<>();

@Nullable
private ScheduledFuture<?> backgroundTask = null;

// Private

private void updateLocalization() {
Expand Down Expand Up @@ -303,4 +309,21 @@ private void discoverBridges() {
thingDiscovered(result);
}
}

@Override
protected void startBackgroundDiscovery() {
logger.trace("startBackgroundDiscovery() called.");
if (backgroundTask == null || backgroundTask.isCancelled()) {
this.backgroundTask = scheduler.scheduleWithFixedDelay(this::startScan, 10, 600, TimeUnit.SECONDS);
}
}

@Override
protected void stopBackgroundDiscovery() {
logger.trace("stopBackgroundDiscovery() called.");
ScheduledFuture<?> task = this.backgroundTask;
if (task != null) {
task.cancel(true);
}
}
}