Package org.openhab.core.thing.binding
Class BaseThingHandlerFactory
java.lang.Object
org.openhab.core.thing.binding.BaseThingHandlerFactory
- All Implemented Interfaces:
ThingHandlerFactory
@NonNullByDefault
public abstract class BaseThingHandlerFactory
extends Object
implements ThingHandlerFactory
The
BaseThingHandlerFactory
provides a base implementation for the ThingHandlerFactory
interface.
It is recommended to extend this abstract base class, because it covers a lot of common logic.
- Author:
- Dennis Nobel - Initial contribution, Benedikt Niehues - fix for Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=445137 considering default values, Thomas Höfer - added config status provider and firmware update handler service registration, Stefan Bußweiler - API changes due to bridge/thing life cycle refactoring, removed OSGi service registration for thing handlers
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
activate
(org.osgi.service.component.ComponentContext componentContext) Initializes theBaseThingHandlerFactory
.protected abstract @Nullable ThingHandler
createHandler
(Thing thing) Creates aThingHandler
for the given thing.@Nullable Thing
createThing
(ThingTypeUID thingTypeUID, Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) Creates a thing based on given thing type uid.protected @Nullable Thing
createThing
(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID) Creates a thing based on given thing type uid.protected void
deactivate
(org.osgi.service.component.ComponentContext componentContext) Disposes theBaseThingHandlerFactory
.protected org.osgi.framework.BundleContext
Get the bundle context.protected @Nullable ConfigDescriptionRegistry
protected @Nullable ThingType
getThingTypeByUID
(ThingTypeUID thingTypeUID) Returns theThingType
which is represented by the givenThingTypeUID
.registerHandler
(Thing thing) Creates a newThingHandler
instance.protected void
removeHandler
(ThingHandler thingHandler) This method is called when a thing handler should be removed.void
removeThing
(ThingUID thingUID) A thing with the givenThing
UID was removed.void
unregisterHandler
(Thing thing) Unregisters aThingHandler
instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.openhab.core.thing.binding.ThingHandlerFactory
supportsThingType
-
Field Details
-
bundleContext
@NonNullByDefault({}) protected org.osgi.framework.BundleContext bundleContext
-
-
Constructor Details
-
BaseThingHandlerFactory
public BaseThingHandlerFactory()
-
-
Method Details
-
activate
protected void activate(org.osgi.service.component.ComponentContext componentContext) Initializes theBaseThingHandlerFactory
. If this method is overridden by a sub class, the implementing method must callsuper.activate(componentContext)
first.- Parameters:
componentContext
- component context (must not be null)
-
deactivate
protected void deactivate(org.osgi.service.component.ComponentContext componentContext) Disposes theBaseThingHandlerFactory
. If this method is overridden by a sub class, the implementing method must callsuper.deactivate(componentContext)
first.- Parameters:
componentContext
- component context (must not be null)
-
getBundleContext
protected org.osgi.framework.BundleContext getBundleContext()Get the bundle context.- Returns:
- the bundle context
- Throws:
IllegalArgumentException
- if the bundle thing handler is not active
-
registerHandler
Description copied from interface:ThingHandlerFactory
Creates a newThingHandler
instance. In addition, the handler can be registered as a service if it is required, e.g. asFirmwareUpdateHandler
,ConfigStatusProvider
.This method is only called if the
ThingHandlerFactory
supports the type of the given thing.The framework expects this method to be non-blocking and return quickly.
- Specified by:
registerHandler
in interfaceThingHandlerFactory
- Parameters:
thing
- the thing for which a new handler must be registered- Returns:
- the created thing handler instance, not null
-
createHandler
Creates aThingHandler
for the given thing.- Parameters:
thing
- the thing- Returns:
- thing the created handler
-
unregisterHandler
Description copied from interface:ThingHandlerFactory
Unregisters aThingHandler
instance.The framework expects this method to be non-blocking and return quickly.
- Specified by:
unregisterHandler
in interfaceThingHandlerFactory
- Parameters:
thing
- the thing for which the handler must be unregistered
-
removeHandler
This method is called when a thing handler should be removed. The implementing caller can override this method to release specific resources.- Parameters:
thingHandler
- thing handler to be removed
-
removeThing
Description copied from interface:ThingHandlerFactory
A thing with the givenThing
UID was removed.- Specified by:
removeThing
in interfaceThingHandlerFactory
- Parameters:
thingUID
- thing UID of the removed object
-
getThingTypeByUID
Returns theThingType
which is represented by the givenThingTypeUID
.- Parameters:
thingTypeUID
- the unique id of the thing type- Returns:
- the thing type represented by the given unique id
-
createThing
protected @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID) Creates a thing based on given thing type uid.- Parameters:
thingTypeUID
- thing type uid (can not be null)configuration
- (can not be null)thingUID
- thingUID (can not be null)- Returns:
- thing (can be null, if thing type is unknown)
-
createThing
public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) Creates a thing based on given thing type uid.- Specified by:
createThing
in interfaceThingHandlerFactory
- Parameters:
thingTypeUID
- thing type uid (must not be null)thingUID
- thingUID (can be null)configuration
- (must not be null)bridgeUID
- (can be null)- Returns:
- thing (can be null, if thing type is unknown)
-
getConfigDescriptionRegistry
-