Class Items
java.lang.Object
org.openhab.core.model.script.lib.Items
Items provides DSL access to item and metadata manipulation.- Author:
- Ravi Nadahar - Initial contribution
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddMetadata(String itemName, String namespace, String value) Add metadata to an item.static voidaddMetadata(String itemName, String namespace, String value, Object... configProperties) Add metadata to an item.static voidaddMetadata(String itemName, String namespace, String value, @Nullable Map<@NonNull String, @NonNull Object> configuration) Add metadata to an item.static booleanCheck whether a named item exists.static @Nullable ItemGet an item by name.static Collection<Item> getAll()Get all items.static Collection<Item> getByPattern(String pattern) Get all items that match a pattern using?and*.static Collection<Item> Get all items that have all the specified tags.static Collection<Item> getByTagAndType(String type, String... tags) Get all items of the specified type that also have all the specified tags.static @Nullable MetadatagetMetadata(String itemName, String namespace) Get item metadata for the specified namespace.static Collection<Item> Get all items of the specified type.static @Nullable MetadataremoveMetadata(String itemName, String namespace) Remove metadata from an item for the specified namespace.static @Nullable MetadataupdateMetadata(String itemName, String namespace, String value) Update item metadata for the specified namespace.static @Nullable MetadataupdateMetadata(String itemName, String namespace, String value, Object... configProperties) Update item metadata for the specified namespace.static @Nullable MetadataupdateMetadata(String itemName, String namespace, String value, @Nullable Map<@NonNull String, @NonNull Object> configuration) Update item metadata for the specified namespace.
-
Constructor Details
-
Items
public Items()
-
-
Method Details
-
exists
Check whether a named item exists.- Parameters:
itemName- the item name.- Returns:
trueif the item exists,falseif it doesn't.
-
get
Get an item by name.- Parameters:
itemName- the item name.- Returns:
- The
Itemornullif it doesn't exist.
-
getAll
Get all items.- Returns:
- The
CollectionofItems.
-
getByPattern
Get all items that match a pattern using?and*.- Parameters:
pattern- the pattern.- Returns:
- The
Collectionof matchingItems.
-
getByTag
Get all items that have all the specified tags.- Parameters:
tags- the tags.- Returns:
- The
Collectionof matchingItems.
-
getOfType
Get all items of the specified type.Types includes:
Call,Color,Contact,DateTime,Dimmer,Image,Location,Number,Player,Rollershutter,StringandSwitch.- Parameters:
type- the type.- Returns:
- The
Collectionof matchingItems.
-
getByTagAndType
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,StringandSwitch.- Parameters:
type- the type.tags- the tags.- Returns:
- The
Collectionof matchingItems.
-
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
Metadataornull.
-
addMetadata
Add metadata to an item.- Parameters:
itemName- the item name.namespace- the metadata namespace.value- the metadata value.- Throws:
IllegalArgumentException- Ifvalueisnull,namespaceisnull, oritemNameis invalid.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris 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 ofStrings andObjects that constitutes the configuration.- Throws:
IllegalArgumentException- Ifnamespace,itemNameorvalueisnull, ifnamespaceoritemNameis invalid, or if there is an odd number ofconfigProperties, or if any of the keys aren'tStrings.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris 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- theMapof configuration properties that make up the configuration.- Throws:
IllegalArgumentException- Ifnamespace,itemNameorvalueisnull, or ifnamespaceoritemNameis invalid.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris 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
Metadataornullif no such metadata existed.
-
updateMetadata
Update item metadata for the specified namespace.- Parameters:
itemName- the item name.namespace- the metadata namespace.value- the new metadata value.- Returns:
- The old
Metadataornullif no previous metadata existed. - Throws:
IllegalArgumentException- Ifnamespace,itemNameorvalueisnull, or ifnamespaceoritemNameis invalid.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris 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 ofStrings andObjects that constitutes the configuration.- Returns:
- The old
Metadataornullif no previous metadata existed. - Throws:
IllegalArgumentException- Ifnamespace,itemNameorvalueisnull, ifnamespaceoritemNameis invalid, or if there is an odd number ofconfigProperties, or if any of the keys aren'tStrings.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris 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- theMapof configuration properties that make up the configuration.- Returns:
- The old
Metadataornullif no previous metadata existed. - Throws:
IllegalArgumentException- Ifnamespace,itemNameorvalueisnull, or ifnamespaceoritemNameis invalid.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris available.
-