Class: OpenHAB::Core::Things::Links::Provider

Inherits:
Provider show all
Defined in:
lib/openhab/core/things/links/provider.rb

Overview

Provides items linked to channels in Ruby to openHAB.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Provider

#[], #all, current, #inspect

Methods included from Enumerable

#all_groups, #all_members, #command, #command!, #decrease, #down, #equipments, #fast_forward, #groups, #increase, #locations, #member_of, #members, #move, #next, #not_member_of, #not_tagged, #off, #on, #pause, #play, #points, #previous, #refresh, #rewind, #stop, #tagged, #toggle, #up, #update, #update!

Class Method Details

.registryorg.openhab.core.thing.link.ItemChannelLinkRegistry

The ItemChannelLink registry



22
23
24
# File 'lib/openhab/core/things/links/provider.rb', line 22

def registry
  @registry ||= OSGi.service("org.openhab.core.thing.link.ItemChannelLinkRegistry")
end

Instance Method Details

Removes all links to a given item.

Parameters:

  • item_name (String)

Returns:

  • (Integer)

    how many links were removed



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/openhab/core/things/links/provider.rb', line 42

def remove_links_for_item(item_name)
  count = 0
  @elements.delete_if do |_k, v|
    next unless v.item_name == item_name

    count += 1
    notify_listeners_about_removed_element(v)
    true
  end
  count
end

Removes all links to a given thing.

Parameters:

Returns:

  • (Integer)

    how many links were removed



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/openhab/core/things/links/provider.rb', line 61

def remove_links_for_thing(thing_uid)
  count = 0
  @elements.delete_if do |_k, v|
    next unless v.linked_uid.thing_uid == thing_uid

    count += 1
    notify_listeners_about_removed_element(v)
    true
  end
  count
end