diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/discovery/VeluxBridgeFinder.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/discovery/VeluxBridgeFinder.java index 1c3511307f9bc..2233d84aa8a92 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/discovery/VeluxBridgeFinder.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/discovery/VeluxBridgeFinder.java @@ -105,7 +105,6 @@ public Set 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; diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/discovery/VeluxDiscoveryService.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/discovery/VeluxDiscoveryService.java index 4eadd57ae1cda..fc1761b0edb48 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/discovery/VeluxDiscoveryService.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/discovery/VeluxDiscoveryService.java @@ -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; @@ -60,6 +63,9 @@ public class VeluxDiscoveryService extends AbstractDiscoveryService implements R private Localization localization = Localization.UNKNOWN; private final Set bridgeHandlers = new HashSet<>(); + @Nullable + private ScheduledFuture backgroundTask = null; + // Private private void updateLocalization() { @@ -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); + } + } }