Class ItemExtensions
java.lang.Object
org.openhab.core.model.script.lib.ItemExtensions
ItemExtensions provides DSL Item extensions.- Author:
- Ravi Nadahar - Initial contribution
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ItemChannelLinkaddChannelLink(Item item, String channelUid) static ItemChannelLinkaddChannelLink(Item item, String channelUid, Object... configProperties) static ItemChannelLinkaddChannelLink(Item item, String channelUid, @Nullable Map<String, @Nullable Object> configProperties) static voidaddMetadata(Item item, String namespace, String value) Add metadata to an item.static voidaddMetadata(Item item, String namespace, String value, Object... configProperties) Add metadata to an item.static voidAdd metadata to an item.static Set<ChannelUID> getBoundChannels(Item item) Get theChannelUIDs of the channels that are bound to the specifiedItem.getBoundThings(Item item) static @Nullable ItemChannelLinkgetChannelLink(Item item, @Nullable String channelUid) Get an existingItemChannelLinkfor the specified item and channel.static @Nullable ItemChannelLinkgetChannelLink(Item item, ChannelUID channelUid) Get an existingItemChannelLinkfor the specified item and channel.static Set<ItemChannelLink> getChannelLinks(@Nullable Item item) Get theItemChannelLinks that are linked to the specified item.static @Nullable MetadatagetMetadata(Item item, String namespace) Get item metadata for the specified namespace.static booleanCheck if the specified item has at least one link.static booleanCheck if the specified item and channel are linked.static booleanisLinked(@Nullable Item item, @Nullable ChannelUID channelUid) Check if the specified item and channel are linked.static @Nullable ItemChannelLinkremoveChannelLink(Item item, @Nullable String channelUid) static @Nullable ItemChannelLinkremoveChannelLink(Item item, ChannelUID channelUid) static intremoveChannelLinks(@Nullable Item item) Remove all managed links related to the specified item.static @Nullable MetadataremoveMetadata(Item item, String namespace) Remove metadata from an item for the specified namespace.static @Nullable ItemChannelLinkreplaceChannelLink(Item item, String channelUid) static @Nullable ItemChannelLinkreplaceChannelLink(Item item, String channelUid, Object... configProperties) static @Nullable ItemChannelLinkreplaceChannelLink(Item item, String channelUid, @Nullable Map<String, @Nullable Object> configProperties) static @Nullable MetadataupdateMetadata(Item item, String namespace, String value) Update item metadata for the specified namespace.static @Nullable MetadataupdateMetadata(Item item, String namespace, String value, Object... configuration) Update item metadata for the specified namespace.static @Nullable MetadataupdateMetadata(Item item, String namespace, String value, @Nullable Map<String, Object> configuration) Update item metadata for the specified namespace.
-
Constructor Details
-
ItemExtensions
public ItemExtensions()
-
-
Method Details
-
addMetadata
Add metadata to an item.- Parameters:
item- theItem.namespace- the metadata namespace.value- the metadata value.- Throws:
IllegalArgumentException- Ifnamespaceorvalueisnull, ifnamespaceis invalid.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris available.
-
addMetadata
public static void addMetadata(Item item, String namespace, String value, Object... configProperties) Add metadata to an item.- Parameters:
item- theItem.namespace- the metadata namespace.value- the metadata value.configProperties- the pairs ofStrings andObjects that constitutes the configuration.- Throws:
IllegalArgumentException- Ifnamespaceorvalueisnull, ifnamespaceis 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
public static void addMetadata(Item item, String namespace, String value, @Nullable Map<String, Object> configuration) Add metadata to an item.- Parameters:
item- theItem.namespace- the metadata namespace.value- the metadata value.configuration- theMapof configuration properties that make up the configuration.- Throws:
IllegalArgumentException- Ifnamespaceorvalueisnull, or ifnamespaceis invalid.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris available.
-
getMetadata
Get item metadata for the specified namespace. -
removeMetadata
Remove metadata from an item for the specified namespace. -
updateMetadata
Update item metadata for the specified namespace.- Parameters:
item- theItem.namespace- the metadata namespace.value- the new metadata value.- Returns:
- The old
Metadataornullif no previous metadata existed. - Throws:
IllegalArgumentException- Ifnamespaceorvalueisnull, or ifnamespaceis invalid.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris available.
-
updateMetadata
public static @Nullable Metadata updateMetadata(Item item, String namespace, String value, Object... configuration) Update item metadata for the specified namespace.- Parameters:
item- theItem.namespace- the metadata namespace.value- the new metadata value.- Returns:
- The old
Metadataornullif no previous metadata existed. - Throws:
IllegalArgumentException- Ifnamespaceorvalueisnull, or isnamespaceis invalid.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris available.
-
updateMetadata
public static @Nullable Metadata updateMetadata(Item item, String namespace, String value, @Nullable Map<String, Object> configuration) Update item metadata for the specified namespace.- Parameters:
item- theItem.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- Ifnamespaceorvalueisnull, or ifnamespaceis invalid.UnsupportedOperationException- If the metadata namespace has a reservedMetadataProviderthat is not aManagedProvider.IllegalStateException- If noManagedProvideris available.
-
getChannelLinks
Get theItemChannelLinks that are linked to the specified item.- Parameters:
item- theItem.- Returns:
- The
SetofItemChannelLinks.
-
getBoundChannels
Get theChannelUIDs of the channels that are bound to the specifiedItem.- Parameters:
item- theItem.- Returns:
- The
SetofChannelUIDs of the bound channels.
-
getBoundThings
- Parameters:
item- theItem.- Returns:
- The
Setof boundThings. - Throws:
IllegalArgumentException- Ifitemisnull.
-
isLinked
Check if the specified item has at least one link.- Parameters:
item- theItemto check.- Returns:
trueif a link exists,falseotherwise.
-
isLinked
Check if the specified item and channel are linked.- Parameters:
item- theItemto check.channelUid- the UID of the channel to check.- Returns:
trueif a link exists,falseotherwise.
-
isLinked
Check if the specified item and channel are linked.- Parameters:
item- theItemto check.channelUid- theChannelUIDof the channel to check.- Returns:
trueif a link exists,falseotherwise.
-
getChannelLink
Get an existingItemChannelLinkfor the specified item and channel.- Parameters:
item- theItem.channelUid- theChannelUIDof the channel.- Returns:
- The
ItemChannelLinkornullif none were found. - Throws:
IllegalArgumentException- IfitemorchannelUidisnull.
-
getChannelLink
Get an existingItemChannelLinkfor the specified item and channel.- Parameters:
item- theItem.channelUid- the UID of the channel.- Returns:
- The
ItemChannelLinkornullif none were found. - Throws:
IllegalArgumentException- Ifitemisnull.
-
addChannelLink
- Parameters:
item- theItemto link.channelUid- the UID of the channel to link.- Returns:
- The newly created
ItemChannelLink. - Throws:
IllegalArgumentException- Ifitemisnull, theItemChannelLinkalready exists, orchannelUidis invalid.IllegalStateException- If aManagedProviderisn't available.
-
addChannelLink
public static ItemChannelLink addChannelLink(Item item, String channelUid, Object... configProperties) - Parameters:
item- theItemto link.channelUid- the UID of the channel to link.configProperties- the pairs ofStrings andObjects that constitutes the configuration properties for the link. Must be in pairs, the first is the key, the second is the value.- Returns:
- The newly created
ItemChannelLink. - Throws:
IllegalArgumentException- Ifitemisnull,channelUidis invalid, theItemChannelLinkalready exists, or if there is an odd number ofconfigProperties, or if any of the keys aren'tStrings.IllegalStateException- If aManagedProviderisn't available.
-
addChannelLink
public static ItemChannelLink addChannelLink(Item item, String channelUid, @Nullable Map<String, @Nullable Object> configProperties) - Parameters:
item- theItemto link.channelUid- the UID of the channel to link.configProperties- the map of configuration properties for the link.- Returns:
- The newly created
ItemChannelLink. - Throws:
IllegalArgumentException- Ifitemisnull, theItemChannelLinkalready exists, orchannelUidis invalid.IllegalStateException- If aManagedProviderisn't available.
-
replaceChannelLink
- Parameters:
item- theItemto link.channelUid- the UID of the channel to link.- Returns:
- The old
ItemChannelLinkif one existed, ornull. - Throws:
IllegalArgumentException- IfitemisnullorchannelUidis invalid.IllegalStateException- If aManagedProviderisn't available.
-
replaceChannelLink
public static @Nullable ItemChannelLink replaceChannelLink(Item item, String channelUid, Object... configProperties) - Parameters:
item- theItemto link.channelUid- the UID of the channel to link.configProperties- the pairs ofStrings andObjects that constitutes the configuration properties for the link. Must be in pairs, the first is the key, the second is the value.- Returns:
- The old
ItemChannelLinkif one existed, ornull. - Throws:
IllegalArgumentException- Ifitemisnull,channelUidis invalid, or if there is an odd number ofconfigProperties, or if any of the keys aren'tStrings.IllegalStateException- If aManagedProviderisn't available.
-
replaceChannelLink
public static @Nullable ItemChannelLink replaceChannelLink(Item item, String channelUid, @Nullable Map<String, @Nullable Object> configProperties) - Parameters:
item- theItemto link.channelUid- the UID of the channel to link.configProperties- the map of configuration properties for the link.- Returns:
- The old
ItemChannelLinkif one existed, ornull. - Throws:
IllegalArgumentException- Ifitemisnull, orchannelUidis invalid.IllegalStateException- If aManagedProviderisn't available.
-
removeChannelLink
- Parameters:
item- theItemof the link to remove.channelUid- the UID of the channel of the link to remove.- Returns:
- The removed
ItemChannelLinkornullif none existed. - Throws:
IllegalArgumentException- IfitemorchannelUidisnull.IllegalStateException- If aManagedProviderisn't available.
-
removeChannelLink
- Parameters:
item- theItemof the link to remove.channelUid- the UID of the channel of the link to remove.- Returns:
- The removed
ItemChannelLinkornullif none existed. - Throws:
IllegalArgumentException- Ifitemisnull.IllegalStateException- If aManagedProviderisn't available.
-
removeChannelLinks
Remove all managed links related to the specified item.- Parameters:
item- theItem.- Returns:
- The number of removed links.
-