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 SummaryFieldsFields inherited from class org.openhab.core.config.discovery.AbstractDiscoveryServicei18nProvider, localeProvider, scanListener, schedulerFields inherited from interface org.openhab.core.config.discovery.DiscoveryServiceCONFIG_PROPERTY_BACKGROUND_DISCOVERY
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedAbstractThingHandlerDiscoveryService(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 SummaryModifier 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.AbstractDiscoveryServiceabortScan, 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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openhab.core.thing.binding.ThingHandlerServiceactivate
- 
Field Details- 
thingHandler
 
- 
- 
Constructor Details- 
AbstractThingHandlerDiscoveryServiceprotected 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- the- ThingHandlerclass.
- supportedThingTypes- the list of Thing types which are supported (can be- null).
- 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- if- timeout < 0.
 
- 
AbstractThingHandlerDiscoveryServiceprotected 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- the- ThingHandlerclass.
- supportedThingTypes- the list of Thing types which are supported (can be- null).
- 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- if- timeout < 0.
 
- 
AbstractThingHandlerDiscoveryServiceprotected 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- the- ThingHandlerclass.
- supportedThingTypes- the list of Thing types which are supported (can be- null).
- timeout- the discovery timeout in seconds after which the discovery service automatically stops its forced discovery process (>= 0).
- Throws:
- IllegalArgumentException- if- timeout < 0.
 
- 
AbstractThingHandlerDiscoveryServiceprotected 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- the- ThingHandlerclass.
- timeout- the discovery timeout in seconds after which the discovery service automatically stops its forced discovery process (>= 0).
- Throws:
- IllegalArgumentException- if- timeout < 0.
 
- 
AbstractThingHandlerDiscoveryServiceprotected 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- the- ThingHandlerclass.
- supportedThingTypes- the list of Thing types which are supported (can be- null).
- 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- if- timeout < 0.
 
 
- 
- 
Method Details- 
startScanprotected 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 class- AbstractDiscoveryService
 
- 
setThingHandlerDescription copied from interface:ThingHandlerServiceSets the ThingHandler on which the actions (methods) should be called- Specified by:
- setThingHandlerin interface- ThingHandlerService
- Parameters:
- handler- the- ThingHandler
 
- 
getThingHandlerDescription copied from interface:ThingHandlerServiceGets the ThingHandler on which the actions (methods) should be called- Specified by:
- getThingHandlerin interface- ThingHandlerService
- Returns:
- the ThingHandler
 
- 
activateDescription 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 class- AbstractDiscoveryService
- Parameters:
- config- configuration properties
 
- 
modifiedDescription 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 class- AbstractDiscoveryService
- Parameters:
- config- configuration properties
 
- 
deactivatepublic 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 interface- ThingHandlerService
- Overrides:
- deactivatein class- AbstractDiscoveryService
 
- 
initializepublic 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 interface- ThingHandlerService
 
- 
disposepublic 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 interface- ThingHandlerService
 
 
-