Skip to content
Merged
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 @@ -14,6 +14,7 @@

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -45,6 +46,21 @@ public abstract class AbstractThingHandlerDiscoveryService<T extends ThingHandle
// initialized when the type is generic, so we have to initialize it with "something"
protected @NonNullByDefault({}) T thingHandler = (@NonNull T) null;

/**
* Creates a new instance of this class with the specified parameters.
*
* @param thingClazz the {@link ThingHandler} class.
* @param supportedThingTypes the list of Thing types which are supported (can be {@code null}).
* @param timeout the discovery timeout in seconds after which the discovery
* service automatically stops its forced discovery process (>= 0).
* @param backgroundDiscoveryEnabledByDefault defines, whether the default for this discovery service is to
* enable background discovery or not.
* @param scanInputLabel the label of the optional input parameter to start the discovery or null if no input
* parameter supported.
* @param scanInputDescription the description of the optional input parameter to start the discovery or null if no
* input parameter supported.
* @throws IllegalArgumentException if {@code timeout < 0}.
*/
protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes,
int timeout, boolean backgroundDiscoveryEnabledByDefault, @Nullable String scanInputLabel,
@Nullable String scanInputDescription) throws IllegalArgumentException {
Expand All @@ -53,20 +69,79 @@ protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Se
this.backgroundDiscoveryEnabled = backgroundDiscoveryEnabledByDefault;
}

/**
* Creates a new instance of this class with the specified parameters and with {@code scanInputLabel} and
* {@code scanInputDescription} set to {@code null}.
*
* @param thingClazz the {@link ThingHandler} class.
* @param supportedThingTypes the list of Thing types which are supported (can be {@code null}).
* @param timeout the discovery timeout in seconds after which the discovery
* service automatically stops its forced discovery process (>= 0).
* @param backgroundDiscoveryEnabledByDefault defines, whether the default for this discovery service is to
* enable background discovery or not.
* @throws IllegalArgumentException if {@code timeout < 0}.
*/
protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes,
int timeout, boolean backgroundDiscoveryEnabledByDefault) throws IllegalArgumentException {
this(thingClazz, supportedThingTypes, timeout, backgroundDiscoveryEnabledByDefault, null, null);
}

/**
* Creates a new instance of this class with the specified parameters and with {@code scanInputLabel} and
* {@code scanInputDescription} set to {@code null}, and {@code backgroundDiscoveryEnabledByDefault} enabled.
*
* @param thingClazz the {@link ThingHandler} class.
* @param supportedThingTypes the list of Thing types which are supported (can be {@code null}).
* @param timeout the discovery timeout in seconds after which the discovery
* service automatically stops its forced discovery process (>= 0).
* @throws IllegalArgumentException if {@code timeout < 0}.
*/
protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes,
int timeout) throws IllegalArgumentException {
this(thingClazz, supportedThingTypes, timeout, true);
}

/**
* Creates a new instance of this class with the specified parameters and with {@code scanInputLabel} and
* {@code scanInputDescription} set to {@code null}, without any {@code supportedThingTypes}, and
* {@code backgroundDiscoveryEnabledByDefault} enabled.
*
* @param thingClazz the {@link ThingHandler} class.
* @param timeout the discovery timeout in seconds after which the discovery
* service automatically stops its forced discovery process (>= 0).
* @throws IllegalArgumentException if {@code timeout < 0}.
*/
protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, int timeout) throws IllegalArgumentException {
this(thingClazz, null, timeout);
}

/**
* Creates a new instance of this class with the specified parameters.
* <p>
* <b>For use by tests only</b>, allows setting a different {@link ScheduledExecutorService} like
* {@link org.openhab.core.util.SameThreadExecutorService} for synchronous behavior during testing.
*
* @param thingClazz the {@link ThingHandler} class.
* @param supportedThingTypes the list of Thing types which are supported (can be {@code null}).
* @param timeout the discovery timeout in seconds after which the discovery
* service automatically stops its forced discovery process (>= 0).
* @param backgroundDiscoveryEnabledByDefault defines, whether the default for this discovery service is to
* enable background discovery or not.
* @param scanInputLabel the label of the optional input parameter to start the discovery or null if no input
* parameter supported.
* @param scanInputDescription the description of the optional input parameter to start the discovery or null if no
* input parameter supported.
* @throws IllegalArgumentException if {@code timeout < 0}.
*/
protected AbstractThingHandlerDiscoveryService(ScheduledExecutorService scheduler, Class<T> thingClazz,
@Nullable Set<ThingTypeUID> supportedThingTypes, int timeout, boolean backgroundDiscoveryEnabledByDefault,
@Nullable String scanInputLabel, @Nullable String scanInputDescription) throws IllegalArgumentException {
super(scheduler, supportedThingTypes, timeout, backgroundDiscoveryEnabledByDefault, scanInputLabel,
scanInputDescription);
this.thingClazz = thingClazz;
this.backgroundDiscoveryEnabled = backgroundDiscoveryEnabledByDefault;
}

@Override
protected abstract void startScan();

Expand All @@ -82,7 +157,7 @@ public void setThingHandler(ThingHandler handler) {
}

@Override
public @Nullable ThingHandler getThingHandler() {
public @Nullable T getThingHandler() {
return thingHandler;
}

Expand Down