Class: OpenHAB::Core::Items::ItemChannelLinks

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/openhab/core/items/item_channel_links.rb

Overview

A wrapper for OpenHAB::Core::Items::Item#links delegated to Set<orgorg.openhaborg.openhab.coreorg.openhab.core.thingorg.openhab.core.thing.linkorg.openhab.core.thing.link.ItemChannelLink>.

Adds methods for clearing item’s links to channels.

Instance Method Summary collapse

Instance Method Details

#clearself

Removes all links to channels from managed link providers.

Returns:

  • (self)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/openhab/core/items/item_channel_links.rb', line 28

def clear
  Things::Links::Provider.registry.all.each do |link|
    if @owner.is_a?(String)
      next unless link.item_name == @owner
    else
      next unless link.linked_uid == @owner
    end

    provider = Things::Links::Provider.registry.provider_for(link.uid)
    if provider.is_a?(ManagedProvider)
      provider.remove(link.uid)
    else
      logger.warn("Cannot remove the link #{link.uid} from non-managed provider #{provider.inspect}")
    end
  end
  self
end