Class AbstractThingHandlerDiscoveryService<T extends ThingHandler>
java.lang.Object
org.openhab.core.config.discovery.AbstractDiscoveryService
org.openhab.core.config.discovery.AbstractThingHandlerDiscoveryService<T>
- All Implemented Interfaces:
DiscoveryService,ThingHandlerService
@NonNullByDefault
public abstract class AbstractThingHandlerDiscoveryService<T extends ThingHandler>
extends AbstractDiscoveryService
implements ThingHandlerService
The
AbstractThingHandlerDiscoveryService extends the AbstractDiscoveryService for thing-based
discovery services.
It handles the injection of the ThingHandler- Author:
- Jan N. Klug - Initial contribution, Laurent Garnier - Added discovery with an optional input parameter
-
Field Summary
FieldsFields inherited from class org.openhab.core.config.discovery.AbstractDiscoveryService
i18nProvider, localeProvider, scanListener, schedulerFields inherited from interface org.openhab.core.config.discovery.DiscoveryService
CONFIG_PROPERTY_BACKGROUND_DISCOVERY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractThingHandlerDiscoveryService(Class<T> thingClazz, int timeout) Creates a new instance of this class with the specified parameters and withscanInputLabelandscanInputDescriptionset tonull, without anysupportedThingTypes, andbackgroundDiscoveryEnabledByDefaultenabled.protectedAbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes, int timeout) Creates a new instance of this class with the specified parameters and withscanInputLabelandscanInputDescriptionset tonull, andbackgroundDiscoveryEnabledByDefaultenabled.protectedAbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes, int timeout, boolean backgroundDiscoveryEnabledByDefault) Creates a new instance of this class with the specified parameters and withscanInputLabelandscanInputDescriptionset tonull.protectedAbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes, int timeout, boolean backgroundDiscoveryEnabledByDefault, @Nullable String scanInputLabel, @Nullable String scanInputDescription) Creates a new instance of this class with the specified parameters.protectedAbstractThingHandlerDiscoveryService(ScheduledExecutorService scheduler, Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes, int timeout, boolean backgroundDiscoveryEnabledByDefault, @Nullable String scanInputLabel, @Nullable String scanInputDescription) Creates a new instance of this class with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled on component activation, if the implementation of this class is an OSGi declarative service and does not override the method.voidCalled on component deactivation, if the implementation of this class is an OSGi declarative service and does not override the method.voiddispose()This method is used by the framework during de-activation of the service.@Nullable TGets the ThingHandler on which the actions (methods) should be calledvoidThis method is used by the framework during activation of the service.voidCalled when the configuration for the discovery service is changed.voidsetThingHandler(ThingHandler handler) Sets the ThingHandler on which the actions (methods) should be calledprotected abstract voidThis method is called by theAbstractDiscoveryService.startScan(ScanListener)implementation of theAbstractDiscoveryService.Methods inherited from class org.openhab.core.config.discovery.AbstractDiscoveryService
abortScan, addDiscoveryListener, getLocalizedDiscoveryResult, getScanInputDescription, getScanInputLabel, getScanTimeout, getSupportedThingTypes, getTimestampOfLastScan, isBackgroundDiscoveryEnabled, isScanInputSupported, removeDiscoveryListener, removeOlderResults, removeOlderResults, removeOlderResults, startBackgroundDiscovery, startScan, startScan, startScan, stopBackgroundDiscovery, stopScan, thingDiscovered, thingRemovedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openhab.core.thing.binding.ThingHandlerService
activate
-
Field Details
-
thingHandler
-
-
Constructor Details
-
AbstractThingHandlerDiscoveryService
protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes, int timeout, boolean backgroundDiscoveryEnabledByDefault, @Nullable String scanInputLabel, @Nullable String scanInputDescription) throws IllegalArgumentException Creates a new instance of this class with the specified parameters.- Parameters:
thingClazz- theThingHandlerclass.supportedThingTypes- the list of Thing types which are supported (can benull).timeout- the discovery timeout in seconds after which the discovery service automatically stops its forced discovery process (>= 0).backgroundDiscoveryEnabledByDefault- defines, whether the default for this discovery service is to enable background discovery or not.scanInputLabel- the label of the optional input parameter to start the discovery or null if no input parameter supported.scanInputDescription- the description of the optional input parameter to start the discovery or null if no input parameter supported.- Throws:
IllegalArgumentException- iftimeout < 0.
-
AbstractThingHandlerDiscoveryService
protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes, int timeout, boolean backgroundDiscoveryEnabledByDefault) throws IllegalArgumentException Creates a new instance of this class with the specified parameters and withscanInputLabelandscanInputDescriptionset tonull.- Parameters:
thingClazz- theThingHandlerclass.supportedThingTypes- the list of Thing types which are supported (can benull).timeout- the discovery timeout in seconds after which the discovery service automatically stops its forced discovery process (>= 0).backgroundDiscoveryEnabledByDefault- defines, whether the default for this discovery service is to enable background discovery or not.- Throws:
IllegalArgumentException- iftimeout < 0.
-
AbstractThingHandlerDiscoveryService
protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes, int timeout) throws IllegalArgumentException Creates a new instance of this class with the specified parameters and withscanInputLabelandscanInputDescriptionset tonull, andbackgroundDiscoveryEnabledByDefaultenabled.- Parameters:
thingClazz- theThingHandlerclass.supportedThingTypes- the list of Thing types which are supported (can benull).timeout- the discovery timeout in seconds after which the discovery service automatically stops its forced discovery process (>= 0).- Throws:
IllegalArgumentException- iftimeout < 0.
-
AbstractThingHandlerDiscoveryService
protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, int timeout) throws IllegalArgumentException Creates a new instance of this class with the specified parameters and withscanInputLabelandscanInputDescriptionset tonull, without anysupportedThingTypes, andbackgroundDiscoveryEnabledByDefaultenabled.- Parameters:
thingClazz- theThingHandlerclass.timeout- the discovery timeout in seconds after which the discovery service automatically stops its forced discovery process (>= 0).- Throws:
IllegalArgumentException- iftimeout < 0.
-
AbstractThingHandlerDiscoveryService
protected AbstractThingHandlerDiscoveryService(ScheduledExecutorService scheduler, Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes, int timeout, boolean backgroundDiscoveryEnabledByDefault, @Nullable String scanInputLabel, @Nullable String scanInputDescription) throws IllegalArgumentException Creates a new instance of this class with the specified parameters.For use by tests only, allows setting a different
ScheduledExecutorServicelikeSameThreadExecutorServicefor synchronous behavior during testing.- Parameters:
thingClazz- theThingHandlerclass.supportedThingTypes- the list of Thing types which are supported (can benull).timeout- the discovery timeout in seconds after which the discovery service automatically stops its forced discovery process (>= 0).backgroundDiscoveryEnabledByDefault- defines, whether the default for this discovery service is to enable background discovery or not.scanInputLabel- the label of the optional input parameter to start the discovery or null if no input parameter supported.scanInputDescription- the description of the optional input parameter to start the discovery or null if no input parameter supported.- Throws:
IllegalArgumentException- iftimeout < 0.
-
-
Method Details
-
startScan
protected abstract void startScan()Description copied from class:AbstractDiscoveryServiceThis method is called by theAbstractDiscoveryService.startScan(ScanListener)implementation of theAbstractDiscoveryService. The abstract class schedules a call ofAbstractDiscoveryService.stopScan()afterAbstractDiscoveryService.getScanTimeout()seconds. If this behavior is not appropriate, theAbstractDiscoveryService.startScan(ScanListener)method should be overridden.- Specified by:
startScanin classAbstractDiscoveryService
-
setThingHandler
Description copied from interface:ThingHandlerServiceSets the ThingHandler on which the actions (methods) should be called- Specified by:
setThingHandlerin interfaceThingHandlerService- Parameters:
handler- theThingHandler
-
getThingHandler
Description copied from interface:ThingHandlerServiceGets the ThingHandler on which the actions (methods) should be called- Specified by:
getThingHandlerin interfaceThingHandlerService- Returns:
- the
ThingHandler
-
activate
Description copied from class:AbstractDiscoveryServiceCalled on component activation, if the implementation of this class is an OSGi declarative service and does not override the method. The method implementation callsAbstractDiscoveryService.startBackgroundDiscovery()if background discovery is enabled by default and not overridden by the configuration.- Overrides:
activatein classAbstractDiscoveryService- Parameters:
config- configuration properties
-
modified
Description copied from class:AbstractDiscoveryServiceCalled when the configuration for the discovery service is changed. If background discovery should be enabled and is currently disabled, the methodAbstractDiscoveryService.startBackgroundDiscovery()is called. If background discovery should be disabled and is currently enabled, the methodAbstractDiscoveryService.stopBackgroundDiscovery()is called. In all other cases, nothing happens.- Overrides:
modifiedin classAbstractDiscoveryService- Parameters:
config- configuration properties
-
deactivate
public void deactivate()Description copied from class:AbstractDiscoveryServiceCalled on component deactivation, if the implementation of this class is an OSGi declarative service and does not override the method. The method implementation callsAbstractDiscoveryService.stopBackgroundDiscovery()if background discovery is enabled at the time of component deactivation.- Specified by:
deactivatein interfaceThingHandlerService- Overrides:
deactivatein classAbstractDiscoveryService
-
initialize
public void initialize()Description copied from interface:ThingHandlerServiceThis method is used by the framework during activation of the service. It is called AFTER the component is fully activated and thing handler has been set. Implementations should override this method to add additional initialization code. This method should callsuper.initialize()to ensure background discovery is properly handled. SeeThingHandlerService.activate(),ThingHandlerService.dispose()- Specified by:
initializein interfaceThingHandlerService
-
dispose
public void dispose()Description copied from interface:ThingHandlerServiceThis method is used by the framework during de-activation of the service. It is called while the component is still activated. Code depending on an activated service should go here. This method should callsuper.dispose()to ensure background discovery is properly handled. SeeThingHandlerService.deactivate(),ThingHandlerService.initialize()- Specified by:
disposein interfaceThingHandlerService
-