Class Items

java.lang.Object
org.openhab.core.model.script.lib.Items

@NonNullByDefault public class Items extends Object
Items provides DSL access to item and metadata manipulation.
Author:
Ravi Nadahar - Initial contribution
  • Constructor Details

    • Items

      public Items()
  • Method Details

    • exists

      public static boolean exists(String itemName)
      Check whether a named item exists.
      Parameters:
      itemName - the item name.
      Returns:
      true if the item exists, false if it doesn't.
    • get

      public static @Nullable Item get(String itemName)
      Get an item by name.
      Parameters:
      itemName - the item name.
      Returns:
      The Item or null if it doesn't exist.
    • getAll

      public static Collection<Item> getAll()
      Get all items.
      Returns:
      The Collection of Items.
    • getByPattern

      public static Collection<Item> getByPattern(String pattern)
      Get all items that match a pattern using ? and *.
      Parameters:
      pattern - the pattern.
      Returns:
      The Collection of matching Items.
    • getByTag

      public static Collection<Item> getByTag(String... tags)
      Get all items that have all the specified tags.
      Parameters:
      tags - the tags.
      Returns:
      The Collection of matching Items.
    • getOfType

      public static Collection<Item> getOfType(String type)
      Get all items of the specified type.

      Types includes: Call, Color, Contact, DateTime, Dimmer, Image, Location, Number, Player, Rollershutter, String and Switch.

      Parameters:
      type - the type.
      Returns:
      The Collection of matching Items.
    • getByTagAndType

      public static Collection<Item> getByTagAndType(String type, String... tags)
      Get all items of the specified type that also have all the specified tags.

      Types includes: Call, Color, Contact, DateTime, Dimmer, Image, Location, Number, Player, Rollershutter, String and Switch.

      Parameters:
      type - the type.
      tags - the tags.
      Returns:
      The Collection of matching Items.
    • getMetadata

      @NonNullByDefault({}) public static @Nullable Metadata getMetadata(String itemName, String namespace)
      Get item metadata for the specified namespace.
      Parameters:
      itemName - the item name.
      namespace - the metadata namespace.
      Returns:
      The matching Metadata or null.
    • addMetadata

      public static void addMetadata(String itemName, String namespace, String value)
      Add metadata to an item.
      Parameters:
      itemName - the item name.
      namespace - the metadata namespace.
      value - the metadata value.
      Throws:
      IllegalArgumentException - If value is null, namespace is null, or itemName is invalid.
      UnsupportedOperationException - If the metadata namespace has a reserved MetadataProvider that is not a ManagedProvider.
      IllegalStateException - If no ManagedProvider is available.
    • addMetadata

      public static void addMetadata(String itemName, String namespace, String value, Object... configProperties)
      Add metadata to an item.
      Parameters:
      itemName - the item name.
      namespace - the metadata namespace.
      value - the metadata value.
      configProperties - the pairs of Strings and Objects that constitutes the configuration.
      Throws:
      IllegalArgumentException - If namespace, itemName or value is null, if namespace or itemName is invalid, or if there is an odd number of configProperties, or if any of the keys aren't Strings.
      UnsupportedOperationException - If the metadata namespace has a reserved MetadataProvider that is not a ManagedProvider.
      IllegalStateException - If no ManagedProvider is available.
    • addMetadata

      @NonNullByDefault({}) public static void addMetadata(String itemName, String namespace, String value, @Nullable Map<@NonNull String,@NonNull Object> configuration)
      Add metadata to an item.
      Parameters:
      itemName - the item name.
      namespace - the metadata namespace.
      value - the metadata value.
      configuration - the Map of configuration properties that make up the configuration.
      Throws:
      IllegalArgumentException - If namespace, itemName or value is null, or if namespace or itemName is invalid.
      UnsupportedOperationException - If the metadata namespace has a reserved MetadataProvider that is not a ManagedProvider.
      IllegalStateException - If no ManagedProvider is available.
    • removeMetadata

      @NonNullByDefault({}) public static @Nullable Metadata removeMetadata(String itemName, String namespace)
      Remove metadata from an item for the specified namespace.
      Parameters:
      itemName - the item name.
      namespace - the metadata namespace.
      Returns:
      The removed Metadata or null if no such metadata existed.
    • updateMetadata

      public static @Nullable Metadata updateMetadata(String itemName, String namespace, String value)
      Update item metadata for the specified namespace.
      Parameters:
      itemName - the item name.
      namespace - the metadata namespace.
      value - the new metadata value.
      Returns:
      The old Metadata or null if no previous metadata existed.
      Throws:
      IllegalArgumentException - If namespace, itemName or value is null, or if namespace or itemName is invalid.
      UnsupportedOperationException - If the metadata namespace has a reserved MetadataProvider that is not a ManagedProvider.
      IllegalStateException - If no ManagedProvider is available.
    • updateMetadata

      public static @Nullable Metadata updateMetadata(String itemName, String namespace, String value, Object... configProperties)
      Update item metadata for the specified namespace.
      Parameters:
      itemName - the item name.
      namespace - the metadata namespace.
      value - the new metadata value.
      configProperties - the pairs of Strings and Objects that constitutes the configuration.
      Returns:
      The old Metadata or null if no previous metadata existed.
      Throws:
      IllegalArgumentException - If namespace, itemName or value is null, if namespace or itemName is invalid, or if there is an odd number of configProperties, or if any of the keys aren't Strings.
      UnsupportedOperationException - If the metadata namespace has a reserved MetadataProvider that is not a ManagedProvider.
      IllegalStateException - If no ManagedProvider is available.
    • updateMetadata

      @NonNullByDefault({}) public static @Nullable Metadata updateMetadata(String itemName, String namespace, String value, @Nullable Map<@NonNull String,@NonNull Object> configuration)
      Update item metadata for the specified namespace.
      Parameters:
      itemName - the item name.
      namespace - the metadata namespace.
      value - the new metadata value.
      configuration - the Map of configuration properties that make up the configuration.
      Returns:
      The old Metadata or null if no previous metadata existed.
      Throws:
      IllegalArgumentException - If namespace, itemName or value is null, or if namespace or itemName is invalid.
      UnsupportedOperationException - If the metadata namespace has a reserved MetadataProvider that is not a ManagedProvider.
      IllegalStateException - If no ManagedProvider is available.