[velux] Enabled background discovery (#9477)
* [velux] enable background discovery * [velux] spotless * [velux] adopt reviewer feedback Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
parent
8cbd358b84
commit
27a02cac5a
|
@ -105,7 +105,6 @@ public class VeluxBridgeFinder implements Closeable {
|
||||||
|
|
||||||
// create a multicast listener socket
|
// create a multicast listener socket
|
||||||
try (MulticastSocket rcvSocket = new MulticastSocket(MDNS_PORT)) {
|
try (MulticastSocket rcvSocket = new MulticastSocket(MDNS_PORT)) {
|
||||||
|
|
||||||
final byte[] rcvBytes = new byte[BUFFER_SIZE];
|
final byte[] rcvBytes = new byte[BUFFER_SIZE];
|
||||||
final long finishTime = System.currentTimeMillis() + SEARCH_DURATION_MSECS;
|
final long finishTime = System.currentTimeMillis() + SEARCH_DURATION_MSECS;
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,11 @@ import static org.openhab.binding.velux.internal.VeluxBindingConstants.*;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
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.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.velux.internal.VeluxBindingConstants;
|
import org.openhab.binding.velux.internal.VeluxBindingConstants;
|
||||||
import org.openhab.binding.velux.internal.VeluxBindingProperties;
|
import org.openhab.binding.velux.internal.VeluxBindingProperties;
|
||||||
import org.openhab.binding.velux.internal.config.VeluxBridgeConfiguration;
|
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 Localization localization = Localization.UNKNOWN;
|
||||||
private final Set<VeluxBridgeHandler> bridgeHandlers = new HashSet<>();
|
private final Set<VeluxBridgeHandler> bridgeHandlers = new HashSet<>();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private ScheduledFuture<?> backgroundTask = null;
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
private void updateLocalization() {
|
private void updateLocalization() {
|
||||||
|
@ -303,4 +309,21 @@ public class VeluxDiscoveryService extends AbstractDiscoveryService implements R
|
||||||
thingDiscovered(result);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue