Class ProviderThingRegistryDelegate

java.lang.Object
org.openhab.core.automation.module.script.providersupport.shared.ProviderThingRegistryDelegate
All Implemented Interfaces:
org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry, Registry<Thing,ThingUID>, ThingRegistry

@NonNullByDefault public class ProviderThingRegistryDelegate extends Object implements ThingRegistry, org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry
The ProviderThingRegistryDelegate is wrapping a ThingRegistry to provide a comfortable way to provide Things from scripts without worrying about the need to remove Things again when the script is unloaded. Nonetheless, using the addPermanent(Thing) method it is still possible to add Things permanently.

Use a new instance of this class for each ScriptEngine.

Author:
Florian Hotze - Initial contribution
  • Constructor Details

  • Method Details

    • addRegistryChangeListener

      public void addRegistryChangeListener(RegistryChangeListener<Thing> listener)
      Description copied from interface: Registry
      Adds a RegistryChangeListener to the registry.
      Specified by:
      addRegistryChangeListener in interface Registry<Thing,ThingUID>
      Parameters:
      listener - registry change listener
    • getAll

      public Collection<Thing> getAll()
      Description copied from interface: Registry
      Returns a collection of all elements in the registry.
      Specified by:
      getAll in interface Registry<Thing,ThingUID>
      Returns:
      collection of all elements in the registry
    • stream

      public Stream<Thing> stream()
      Description copied from interface: Registry
      Returns a stream of all elements in the registry.
      Specified by:
      stream in interface Registry<Thing,ThingUID>
      Returns:
      stream of all elements in the registry
    • removeRegistryChangeListener

      public void removeRegistryChangeListener(RegistryChangeListener<Thing> listener)
      Description copied from interface: Registry
      Removes a RegistryChangeListener from the registry.
      Specified by:
      removeRegistryChangeListener in interface Registry<Thing,ThingUID>
      Parameters:
      listener - registry change listener
    • add

      public Thing add(Thing element)
      Description copied from interface: Registry
      Adds the given element to the according ManagedProvider.
      Specified by:
      add in interface Registry<Thing,ThingUID>
      Parameters:
      element - element to be added (must not be null)
      Returns:
      the added element or newly created object of the same type
    • addPermanent

      public Thing addPermanent(Thing element)
      Add a Thing permanently to the registry. This Thing will be kept in the registry even if the script is unloaded.
      Parameters:
      element - the Thing to be added (must not be null)
      Returns:
      the added Thing
    • update

      public @Nullable Thing update(Thing element)
      Description copied from interface: Registry
      Updates the given element at the according ManagedProvider.
      Specified by:
      update in interface Registry<Thing,ThingUID>
      Parameters:
      element - element to be updated (must not be null)
      Returns:
      returns the old element or null if no element with the same key exists
    • get

      public @Nullable Thing get(ThingUID uid)
      Description copied from interface: ThingRegistry
      Returns a thing for a given UID or null if no thing was found.
      Specified by:
      get in interface Registry<Thing,ThingUID>
      Specified by:
      get in interface ThingRegistry
      Parameters:
      uid - thing UID
      Returns:
      thing for a given UID or null if no thing was found
    • getChannel

      public @Nullable Channel getChannel(ChannelUID channelUID)
      Description copied from interface: ThingRegistry
      Returns a channel for the given channel UID or null if no channel was found
      Specified by:
      getChannel in interface ThingRegistry
      Parameters:
      channelUID - channel UID
      Returns:
      channel for the given channel UID or null of no channel was found
    • updateConfiguration

      public void updateConfiguration(ThingUID thingUID, Map<String,Object> configurationParameters)
      Description copied from interface: ThingRegistry
      Updates the configuration of a thing for the given UID.
      Specified by:
      updateConfiguration in interface ThingRegistry
      Parameters:
      thingUID - thing UID
      configurationParameters - configuration parameters
    • remove

      public @Nullable Thing remove(ThingUID thingUID)
      Description copied from interface: ThingRegistry
      Initiates the removal process for the Thing specified by the given ThingUID. Unlike in other Registrys, Things don't get removed immediately. Instead, the corresponding ThingHandler is given the chance to perform any required removal handling before it actually gets removed.

      If for any reasons the Thing should be removed immediately without any prior processing, use ThingRegistry.forceRemove(ThingUID) instead.

      Specified by:
      remove in interface Registry<Thing,ThingUID>
      Specified by:
      remove in interface ThingRegistry
      Parameters:
      thingUID - Identificator of the Thing to be removed
      Returns:
      the Thing that was removed, or null if no Thing with the given ThingUID exists
    • removeAllAddedByScript

      public void removeAllAddedByScript()
      Description copied from interface: org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry
      Removes all elements that are provided by the script the ProviderRegistry instance is bound to. To be called when the script is unloaded or reloaded.
      Specified by:
      removeAllAddedByScript in interface org.openhab.core.automation.module.script.providersupport.internal.ProviderRegistry
    • forceRemove

      public @Nullable Thing forceRemove(ThingUID thingUID)
      Description copied from interface: ThingRegistry
      Removes the Thing specified by the given ThingUID. If the corresponding ThingHandler should be given the chance to perform any removal operations, use ThingRegistry.remove(ThingUID) instead.
      Specified by:
      forceRemove in interface ThingRegistry
      Parameters:
      thingUID - Identificator of the Thing to be removed
      Returns:
      the Thing that was removed, or null if no Thing with the given ThingUID exists
    • createThingOfType

      public @Nullable Thing createThingOfType(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID, @Nullable String label, Configuration configuration)
      Description copied from interface: ThingRegistry
      Creates a thing based on the given configuration properties
      Specified by:
      createThingOfType in interface ThingRegistry
      Parameters:
      thingTypeUID - thing type unique id
      thingUID - thing unique id which should be created. This id might be null.
      bridgeUID - the thing's bridge. Null if there is no bridge or if the thing is a bridge by itself.
      configuration - the configuration
      Returns:
      the created thing