Module: Enumerable
- Defined in:
 - lib/openhab/core/items/semantics/enumerable.rb,
lib/openhab/core/items/semantics.rb 
Overview
Additions to Enumerable to allow easily filtering groups of items based on the semantic model
Filtering Methods collapse
- 
  
    
      #all_groups  ⇒ Array<GroupItem> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns all groups all elements are a part of, recursively.
 - 
  
    
      #all_members  ⇒ Array<Item> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns all non-group members of all group elements, recursively.
 - 
  
    
      #equipments(type = nil)  ⇒ Array<Item> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a new array of items that are a semantics equipment (optionally of the given type).
 - 
  
    
      #groups  ⇒ Array<GroupItem> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the groups of all elements.
 - 
  
    
      #locations(type = nil)  ⇒ Array<Item> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a new array of items that are a semantics Location (optionally of the given type).
 - 
  
    
      #member_of(*groups)  ⇒ Array<Item> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a new array of items that are a member of at least one of the given groups.
 - 
  
    
      #members  ⇒ Array<Item> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the group members of all group elements.
 - 
  
    
      #not_member_of(*groups)  ⇒ Array<Item> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a new array of items that are not a member of any of the given groups.
 - 
  
    
      #not_tagged(*tags)  ⇒ Array<Item> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a new array of items that do not have any of the given tags.
 - 
  
    
      #points(*point_or_property_types)  ⇒ Array<Item> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a new array of items that are semantics points (optionally of a given type).
 - 
  
    
      #tagged(*tags)  ⇒ Array<Item> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a new array of items that have at least one of the given tags.
 
Items State and Command Methods collapse
- 
  
    
      #command(command)  ⇒ self? 
    
    
  
  
  
  
  
  
  
  
  
    
Send a command to every item in the collection.
 - 
  
    
      #command!(command)  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send a command to every item in the collection, even when ensure_states! is in effect.
 - 
  
    
      #decrease  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the DECREASE command to every item in the collection.
 - 
  
    
      #down  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the DOWN command to every item in the collection.
 - 
  
    
      #fast_forward  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the FASTFORWARD command to every item in the collection.
 - 
  
    
      #increase  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the INCREASE command to every item in the collection.
 - 
  
    
      #move  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the MOVE command to every item in the collection.
 - 
  
    
      #next  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the NEXT command to every item in the collection.
 - 
  
    
      #off  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the OFF command to every item in the collection.
 - 
  
    
      #on  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the ON command to every item in the collection.
 - 
  
    
      #pause  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the PAUSE command to every item in the collection.
 - 
  
    
      #play  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the PLAY command to every item in the collection.
 - 
  
    
      #previous  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the PREVIOUS command to every item in the collection.
 - 
  
    
      #refresh  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the REFRESH command to every item in the collection.
 - 
  
    
      #rewind  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the REWIND command to every item in the collection.
 - 
  
    
      #stop  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the STOP command to every item in the collection.
 - 
  
    
      #up  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Send the UP command to every item in the collection.
 - 
  
    
      #update(state)  ⇒ self? 
    
    
  
  
  
  
  
  
  
  
  
    
Update the state of every item in the collection.
 - 
  
    
      #update!(state)  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Update the state of every item in the collection, even when ensure_states! is in effect.
 
Instance Method Details
#all_groups ⇒ Array<GroupItem>
Returns all groups all elements are a part of, recursively
      91 92 93  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 91 def all_groups flat_map(&:all_groups).uniq end  | 
  
#all_members ⇒ Array<Item>
Returns all non-group members of all group elements, recursively
      79 80 81  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 79 def all_members grep(OpenHAB::Core::Items::GroupItem).flat_map(&:all_members).uniq end  | 
  
#command(command) ⇒ self?
Send a command to every item in the collection
      100 101 102  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 100 def command(command) self if count { |i| i.command(command) }.positive? end  | 
  
#command!(command) ⇒ self
Send a command to every item in the collection, even when ensure_states! is in effect.
      106 107 108 109 110 111  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 106 def command!(command) # We cannot alias this to #command above, otherwise it will call # DSL::Items::Ensure::Item#command which checks for ensure_states each { |i| i.command!(command) } self end  | 
  
#decrease ⇒ self
Send the DECREASE command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 162
     | 
  
#down ⇒ self
Send the DOWN command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 146
     | 
  
#equipments(type = nil) ⇒ Array<Item>
As equipments are usually GroupItems, this method therefore returns an array of GroupItems. In order to get the points that belong to the equipments, use #members before calling #points. See the example with #points.
Returns a new array of items that are a semantics equipment (optionally of the given type)
      637 638 639 640 641 642 643 644 645 646 647 648  | 
    
      # File 'lib/openhab/core/items/semantics.rb', line 637 def equipments(type = nil) begin raise ArgumentError if type && !(type < Semantics::Equipment) rescue ArgumentError, TypeError raise ArgumentError, "type must be a subclass of Equipment" end result = select(&:equipment?) result.select! { |i| i.equipment_type <= type } if type result end  | 
  
#fast_forward ⇒ self
Send the FASTFORWARD command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 178
     | 
  
#groups ⇒ Array<GroupItem>
Returns the groups of all elements
      85 86 87  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 85 def groups flat_map(&:groups).uniq end  | 
  
#increase ⇒ self
Send the INCREASE command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 158
     | 
  
#locations(type = nil) ⇒ Array<Item>
Returns a new array of items that are a semantics Location (optionally of the given type)
      612 613 614 615 616 617 618 619 620 621 622 623  | 
    
      # File 'lib/openhab/core/items/semantics.rb', line 612 def locations(type = nil) begin raise ArgumentError if type && !(type < Semantics::Location) rescue ArgumentError, TypeError raise ArgumentError, "type must be a subclass of Location" end result = select(&:location?) result.select! { |i| i.location_type <= type } if type result end  | 
  
#member_of(*groups) ⇒ Array<Item>
Returns a new array of items that are a member of at least one of the given groups
      60 61 62  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 60 def member_of(*groups) select { |i| i.member_of?(*groups) } end  | 
  
#members ⇒ Array<Item>
Returns the group members of all group elements
      73 74 75  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 73 def members grep(OpenHAB::Core::Items::GroupItem).flat_map(&:members).uniq end  | 
  
#move ⇒ self
Send the MOVE command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 154
     | 
  
#next ⇒ self
Send the NEXT command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 182
     | 
  
#not_member_of(*groups) ⇒ Array<Item>
Returns a new array of items that are not a member of any of the given groups
      67 68 69  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 67 def not_member_of(*groups) reject { |i| i.member_of?(*groups) } end  | 
  
#not_tagged(*tags) ⇒ Array<Item>
Returns a new array of items that do not have any of the given tags
      53 54 55  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 53 def not_tagged(*tags) reject { |i| i.tagged?(*tags) } end  | 
  
#off ⇒ self
Send the OFF command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 138
     | 
  
#on ⇒ self
Send the ON command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 134
     | 
  
#pause ⇒ self
Send the PAUSE command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 170
     | 
  
#play ⇒ self
Send the PLAY command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 166
     | 
  
#points(*point_or_property_types) ⇒ Array<Item>
Returns a new array of items that are semantics points (optionally of a given type)
      659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683  | 
    
      # File 'lib/openhab/core/items/semantics.rb', line 659 def points(*point_or_property_types) unless (0..2).cover?(point_or_property_types.length) raise ArgumentError, "wrong number of arguments (given #{point_or_property_types.length}, expected 0..2)" end begin raise ArgumentError unless point_or_property_types.all? do |tag| (tag < Semantics::Point || tag < Semantics::Property) end rescue ArgumentError, TypeError raise ArgumentError, "point_or_property_types must all be a subclass of Point or Property" end if point_or_property_types.count { |tag| tag < Semantics::Point } > 1 || point_or_property_types.count { |tag| tag < Semantics::Property } > 1 raise ArgumentError, "point_or_property_types cannot both be a subclass of Point or Property" end select do |point| point.point? && point_or_property_types.all? do |tag| (tag < Semantics::Point && point.point_type&.<=(tag)) || (tag < Semantics::Property && point.property_type&.<=(tag)) end end end  | 
  
#previous ⇒ self
Send the PREVIOUS command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 186
     | 
  
#refresh ⇒ self
Send the REFRESH command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 130
     | 
  
#rewind ⇒ self
Send the REWIND command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 174
     | 
  
#stop ⇒ self
Send the STOP command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 150
     | 
  
#tagged(*tags) ⇒ Array<Item>
Returns a new array of items that have at least one of the given tags
      46 47 48  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 46 def tagged(*tags) select { |i| i.tagged?(*tags) } end  | 
  
#up ⇒ self
Send the UP command to every item in the collection
| 
       | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 142
     | 
  
#update(state) ⇒ self?
Update the state of every item in the collection
      116 117 118  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 116 def update(state) self if count { |i| i.update(state) }.positive? end  | 
  
#update!(state) ⇒ self
Update the state of every item in the collection, even when ensure_states! is in effect.
      123 124 125 126 127 128  | 
    
      # File 'lib/openhab/core/items/semantics/enumerable.rb', line 123 def update!(state) # We cannot alias this to #update above, otherwise it will call # DSL::Items::Ensure::Item#update which checks for ensure_states each { |i| i.update!(state) } self end  |