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, Connor Petty - added osgi service registration for thing handler services.
  • 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 the BaseThingHandlerFactory. If this method is overridden by a sub class, the implementing method must call super.activate(componentContext) first.
      Parameters:
      componentContext - component context (must not be null)
    • deactivate

      protected void deactivate(org.osgi.service.component.ComponentContext componentContext)
      Disposes the BaseThingHandlerFactory. If this method is overridden by a sub class, the implementing method must call super.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

      public ThingHandler registerHandler(Thing thing)
      Description copied from interface: ThingHandlerFactory
      Creates a new ThingHandler instance. In addition, the handler can be registered as a service if it is required, e.g. as FirmwareUpdateHandler, 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 interface ThingHandlerFactory
      Parameters:
      thing - the thing for which a new handler must be registered
      Returns:
      the created thing handler instance, not null
    • createHandler

      protected abstract @Nullable ThingHandler createHandler(Thing thing)
      Creates a ThingHandler for the given thing.
      Parameters:
      thing - the thing
      Returns:
      thing the created handler
    • unregisterHandler

      public void unregisterHandler(Thing thing)
      Description copied from interface: ThingHandlerFactory
      Unregisters a ThingHandler instance.

      The framework expects this method to be non-blocking and return quickly.

      Specified by:
      unregisterHandler in interface ThingHandlerFactory
      Parameters:
      thing - the thing for which the handler must be unregistered
    • removeHandler

      protected void removeHandler(ThingHandler thingHandler)
      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

      public void removeThing(ThingUID thingUID)
      Description copied from interface: ThingHandlerFactory
      A thing with the given Thing UID was removed.
      Specified by:
      removeThing in interface ThingHandlerFactory
      Parameters:
      thingUID - thing UID of the removed object
    • getThingTypeByUID

      protected @Nullable ThingType getThingTypeByUID(ThingTypeUID thingTypeUID)
      Returns the ThingType which is represented by the given ThingTypeUID.
      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 interface ThingHandlerFactory
      Parameters:
      thingTypeUID - thing type uid (must not be null)
      configuration - (must not be null)
      thingUID - thingUID (can be null)
      bridgeUID - (can be null)
      Returns:
      thing (can be null, if thing type is unknown)
    • getConfigDescriptionRegistry

      protected @Nullable ConfigDescriptionRegistry getConfigDescriptionRegistry()