Module: RSpec::OpenHAB::Items

Defined in:
lib/rspec/openhab/items.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.populate_items_from_api(api) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspec/openhab/items.rb', line 8

def populate_items_from_api(api)
  all_items = api.items

  gfh = org.openhab.core.internal.items.GroupFunctionHelper.new

  all_items.each do |item_json|
    type, _dimension = item_json["type"].split(":")
    if type == "Group"
      if item_json["groupType"]
        type, _dimension = item_json["groupType"].split(":")
        klass = ::OpenHAB::DSL::Items.const_get(:"#{type}Item")
        base_item = klass.new(item_json["name"])
      end
      if item_json["function"]
        dto = org.openhab.core.items.dto.GroupFunctionDTO.new
        dto.name = item_json.dig("function", "name")
        dto.params = item_json.dig("function", "params")
        function = gfh.create_group_function(dto, base_item)
      end
      item = GroupItem.new(item_json["name"], base_item, function)
    else
      klass = ::OpenHAB::DSL::Items.const_get(:"#{type}Item")
      item = klass.new(item_json["name"])
    end

    item.label = item_json["label"]
    item_json["tags"].each do |tag|
      item.add_tag(tag)
    end
    item_json["metadata"]&.each do |key, config|
      item.meta[key] = config["value"], config["config"]
    end

    $ir.add(item)
  end
  all_items.each do |item_json| # rubocop:disable Style/CombinableLoops
    item_json["groupNames"].each do |group_name|
      next unless (group = $ir.get(group_name))

      group.add_member($ir.get(item_json["name"]))
    end
  end
end

Instance Method Details

#autoupdate_all_itemsObject



53
54
55
56
57
58
# File 'lib/rspec/openhab/items.rb', line 53

def autoupdate_all_items
  @autoupdated_items ||= {}
  $ir.for_each do |_provider, item|
    @autoupdated_items[item] = item.meta.delete("autoupdate") if item.meta.key?("autoupdate")
  end
end