Class Channels

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

@NonNullByDefault public class Channels extends Object
Channels provides DSL access to channel manipulation.
Author:
Ravi Nadahar - Initial contribution
  • Constructor Details

    • Channels

      public Channels()
  • Method Details

    • getLinks

      public static Set<ItemChannelLink> getLinks(@Nullable String itemName)
      Get the ItemChannelLinks that are linked to the specified item.
      Parameters:
      itemName - the name of the item.
      Returns:
      The Set of ItemChannelLinks.
    • getLinks

      public static Set<ItemChannelLink> getLinks(@Nullable Item item)
      Get the ItemChannelLinks that are linked to the specified item.
      Parameters:
      item - the Item.
      Returns:
      The Set of ItemChannelLinks.
    • getChannelLinks

      public static Set<ItemChannelLink> getChannelLinks(@Nullable String channelUid)
      Get the ItemChannelLinks that are linked to the specified channel.
      Parameters:
      channelUid - the UID of the channel.
      Returns:
      The Set of ItemChannelLinks.
    • getChannelLinks

      public static Set<ItemChannelLink> getChannelLinks(@Nullable ChannelUID channelUid)
      Get the ItemChannelLinks that are linked to the specified channel.
      Parameters:
      channelUid - the ChannelUID of the channel.
      Returns:
      The Set of ItemChannelLinks.
    • getBoundChannels

      public static Set<ChannelUID> getBoundChannels(@Nullable String itemName)
      Get the ChannelUIDs of the channels that are bound to the specified Item.
      Parameters:
      itemName - the name of the item.
      Returns:
      The Set of ChannelUIDs of the bound channels.
    • getBoundChannels

      @NonNullByDefault({}) public static @NonNull Set<@NonNull ChannelUID> getBoundChannels(Item item)
      Get the ChannelUIDs of the channels that are bound to the specified Item.
      Parameters:
      item - the Item.
      Returns:
      The Set of ChannelUIDs of the bound channels.
      Throws:
      IllegalArgumentException - If item is null.
    • getBoundThings

      public static Set<Thing> getBoundThings(@Nullable String itemName)
      Get the Things that are bound to the specified Item.
      Parameters:
      itemName - the name of the item.
      Returns:
      The Set of bound Things.
    • getBoundThings

      @NonNullByDefault({}) public static @NonNull Set<@NonNull Thing> getBoundThings(Item item)
      Get the Things that are bound to the specified Item.
      Parameters:
      item - the Item.
      Returns:
      The Set of bound Things.
      Throws:
      IllegalArgumentException - If item is null.
    • getLinkedItemNames

      public static Set<String> getLinkedItemNames(@Nullable String channelUid)
      Get the names of all the items that are linked to a specific channel.
      Parameters:
      channelUid - the UID of the channel.
      Returns:
      The Set of names of the linked items.
    • getLinkedItemNames

      @NonNullByDefault({}) public static @NonNull Set<@NonNull String> getLinkedItemNames(ChannelUID channelUid)
      Get the names of all the items that are linked to a specific channel.
      Parameters:
      channelUid - the ChannelUID of the channel.
      Returns:
      The Set of names of the linked items.
      Throws:
      IllegalArgumentException - If channelUid is null.
    • getLinkedItems

      public static Set<Item> getLinkedItems(@Nullable String channelUid)
      Get all Items that are linked to a specific channel.
      Parameters:
      channelUid - the UID of the channel.
      Returns:
      The Set of linked Items.
    • getLinkedItems

      @NonNullByDefault({}) public static @NonNull Set<@NonNull Item> getLinkedItems(ChannelUID channelUid)
      Get all Items that are linked to a specific channel.
      Parameters:
      channelUid - the ChannelUID of the channel.
      Returns:
      The Set of linked Items.
      Throws:
      IllegalArgumentException - If channelUid is null.
    • isLinked

      public static boolean isLinked(@Nullable String itemName)
      Check if the specified item has at least one link.
      Parameters:
      itemName - the name of the item to check.
      Returns:
      true if a link exists, false otherwise.
    • isLinked

      public static boolean isLinked(@Nullable Item item)
      Check if the specified item has at least one link.
      Parameters:
      item - the Item to check.
      Returns:
      true if a link exists, false otherwise.
    • isLinked

      public static boolean isLinked(@Nullable String itemName, @Nullable String channelUid)
      Check if the specified item and channel are linked.
      Parameters:
      itemName - the name of the item to check.
      channelUid - the UID of the channel to check.
      Returns:
      true if a link exists, false otherwise.
    • isLinked

      public static boolean isLinked(@Nullable Item item, @Nullable String channelUid)
      Check if the specified item and channel are linked.
      Parameters:
      item - the Item to check.
      channelUid - the UID of the channel to check.
      Returns:
      true if a link exists, false otherwise.
    • isLinked

      public static boolean isLinked(@Nullable Item item, @Nullable ChannelUID channelUid)
      Check if the specified item and channel are linked.
      Parameters:
      item - the Item to check.
      channelUid - the ChannelUID of the channel to check.
      Returns:
      true if a link exists, false otherwise.
    • isChannelLinked

      public static boolean isChannelLinked(@Nullable String channelUid)
      Check if the specified channel has at least one link.
      Parameters:
      channelUid - the UID of the channel to check.
      Returns:
      true if a link exists, false otherwise.
    • isChannelLinked

      public static boolean isChannelLinked(@Nullable ChannelUID channelUid)
      Check if the specified channel has at least one link.
      Parameters:
      channelUid - the ChannelUID of the channel to check.
      Returns:
      true if a link exists, false otherwise.
    • getLink

      @NonNullByDefault({}) public static @Nullable ItemChannelLink getLink(Item item, ChannelUID channelUid)
      Get an existing ItemChannelLink for the specified item and channel.
      Parameters:
      item - the Item.
      channelUid - the ChannelUID of the channel.
      Returns:
      The ItemChannelLink or null if none were found.
      Throws:
      IllegalArgumentException - If item or channelUid is null.
    • getLink

      @NonNullByDefault({}) public static @Nullable ItemChannelLink getLink(Item item, @Nullable String channelUid)
      Get an existing ItemChannelLink for the specified item and channel.
      Parameters:
      item - the Item.
      channelUid - the UID of the channel.
      Returns:
      The ItemChannelLink or null if none were found.
      Throws:
      IllegalArgumentException - If item is null.
    • getLink

      public static @Nullable ItemChannelLink getLink(@Nullable String itemName, @Nullable String channelUid)
      Get an existing ItemChannelLink for the specified item and channel.
      Parameters:
      itemName - the name of the item.
      channelUid - the UID of the channel.
      Returns:
      The ItemChannelLink or null if none were found.
    • addItemChannelLink

      @NonNullByDefault({}) public static ItemChannelLink addItemChannelLink(Item item, String channelUid)
      Add a new ItemChannelLink between an existing Item and a Channel.
      Parameters:
      item - the Item to link.
      channelUid - the UID of the channel to link.
      Returns:
      The newly created ItemChannelLink.
      Throws:
      IllegalArgumentException - If item is null, the ItemChannelLink already exists, or channelUid is invalid.
      IllegalStateException - If a ManagedProvider isn't available.
    • addItemChannelLink

      public static ItemChannelLink addItemChannelLink(Item item, String channelUid, Object... configProperties)
      Add a new ItemChannelLink between an existing Item and a Channel.
      Parameters:
      item - the Item to link.
      channelUid - the UID of the channel to link.
      configProperties - the pairs of Strings and Objects 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 - If item is null, channelUid is invalid, the ItemChannelLink already exists, or if there is an odd number of configProperties, or if any of the keys aren't Strings.
      IllegalStateException - If a ManagedProvider isn't available.
    • addItemChannelLink

      @NonNullByDefault({}) public static ItemChannelLink addItemChannelLink(Item item, String channelUid, @Nullable Map<@NonNull String,@Nullable Object> configProperties)
      Add a new ItemChannelLink between an existing Item and a Channel.
      Parameters:
      item - the Item to 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 - If item is null, the ItemChannelLink already exists, or channelUid is invalid.
      IllegalStateException - If a ManagedProvider isn't available.
    • replaceItemChannelLink

      @NonNullByDefault({}) public static @Nullable ItemChannelLink replaceItemChannelLink(Item item, String channelUid)
      Add or replace a ItemChannelLink between an existing Item and a Channel.
      Parameters:
      item - the Item to link.
      channelUid - the UID of the channel to link.
      Returns:
      The old ItemChannelLink if one existed, or null.
      Throws:
      IllegalArgumentException - If item is null or channelUid is invalid.
      IllegalStateException - If a ManagedProvider isn't available.
    • replaceItemChannelLink

      public static @Nullable ItemChannelLink replaceItemChannelLink(Item item, String channelUid, Object... configProperties)
      Add or replace a ItemChannelLink between an existing Item and a Channel.
      Parameters:
      item - the Item to link.
      channelUid - the UID of the channel to link.
      configProperties - the pairs of Strings and Objects 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 ItemChannelLink if one existed, or null.
      Throws:
      IllegalArgumentException - If item is null, channelUid is invalid, or if there is an odd number of configProperties, or if any of the keys aren't Strings.
      IllegalStateException - If a ManagedProvider isn't available.
    • replaceItemChannelLink

      @NonNullByDefault({}) public static @Nullable ItemChannelLink replaceItemChannelLink(Item item, String channelUid, @Nullable Map<@NonNull String,@Nullable Object> configProperties)
      Add or replace a ItemChannelLink between an existing Item and a Channel.
      Parameters:
      item - the Item to link.
      channelUid - the UID of the channel to link.
      configProperties - the map of configuration properties for the link.
      Returns:
      The old ItemChannelLink if one existed, or null.
      Throws:
      IllegalArgumentException - If item is null, or channelUid is invalid.
      IllegalStateException - If a ManagedProvider isn't available.
    • removeItemChannelLink

      @NonNullByDefault({}) public static @Nullable ItemChannelLink removeItemChannelLink(Item item, ChannelUID channelUid)
      Remove a ItemChannelLink between an existing Item and a Channel.
      Parameters:
      item - the Item of the link to remove.
      channelUid - the UID of the channel of the link to remove.
      Returns:
      The removed ItemChannelLink or null if none existed.
      Throws:
      IllegalArgumentException - If item or channelUid is null.
      IllegalStateException - If a ManagedProvider isn't available.
    • removeItemChannelLink

      @NonNullByDefault({}) public static @Nullable ItemChannelLink removeItemChannelLink(Item item, @Nullable String channelUid)
      Remove a ItemChannelLink between an existing Item and a Channel.
      Parameters:
      item - the Item of the link to remove.
      channelUid - the UID of the channel of the link to remove.
      Returns:
      The removed ItemChannelLink or null if none existed.
      Throws:
      IllegalArgumentException - If item is null.
      IllegalStateException - If a ManagedProvider isn't available.
    • removeItemChannelLink

      public static @Nullable ItemChannelLink removeItemChannelLink(@Nullable String itemName, @Nullable String channelUid)
      Remove a ItemChannelLink between an existing Item and a Channel.
      Parameters:
      itemName - the name of the item of the link to remove.
      channelUid - the UID of the channel of the link to remove.
      Returns:
      The removed ItemChannelLink or null if none existed.
      Throws:
      IllegalStateException - If a ManagedProvider isn't available.
    • removeLinksForItem

      public static int removeLinksForItem(@Nullable String itemName)
      Remove all managed links related to the specified item.
      Parameters:
      itemName - the name of the item.
      Returns:
      The number of removed links.
    • removeLinksForItem

      public static int removeLinksForItem(@Nullable Item item)
      Remove all managed links related to the specified item.
      Parameters:
      item - the Item.
      Returns:
      The number of removed links.
    • removeOrphanedItemChannelLinks

      public static int removeOrphanedItemChannelLinks()
      Remove all orphaned (item or channel missing) managed links.
      Returns:
      The number of removed links.