Class: OpenHAB::Core::Items::GroupItem
- Inherits:
-
GenericItem
- Object
- GenericItem
- OpenHAB::Core::Items::GroupItem
- Includes:
- DSL::Items::TimedCommand
- Defined in:
- lib/openhab/core/items/group_item.rb,
lib/openhab/core/items/semantics.rb
Overview
A group behaves like a regular item, but also has #members which are nested items that can be enumerated.
If the group has a particular type, the methods from that type are directly available.
The examples all assume the following items exist.
Group House
// Location perspective
Group GroundFloor (House)
Group Livingroom (GroundFloor)
// Functional perspective
Group Sensors (House)
Group Temperatures (Sensors)
Number Livingroom_Temperature "Living Room temperature" (Livingroom, Temperatures)
Number Bedroom_Temp "Bedroom temperature" (GroundFloor, Temperatures)
Number Den_Temp "Den temperature" (GroundFloor, Temperatures)
Defined Under Namespace
Classes: Members
Constant Summary
Constants included from Semantics
Semantics::Equipment, Semantics::Location, Semantics::Point, Semantics::Property, Semantics::Tag
Constants included from Persistence
Instance Attribute Summary collapse
-
#all_members ⇒ Array
readonly
Get all non-group members of the group recursively.
-
#base_item ⇒ Item?
readonly
A typed item if the group has a particular type.
-
#equipments ⇒ Array<Item>
readonly
Calls members.equipments.
-
#function ⇒ GroupFunction
readonly
Returns the function of this GroupItem.
-
#locations ⇒ Array<Item>
readonly
Calls members.locations.
-
#members ⇒ Members
readonly
Get an Array-like object representing the members of the group.
Attributes inherited from GenericItem
#category, #formatted_state, #label, #name, #raw_state, #state, #tags
Attributes included from Semantics
#equipment, #equipment_type, #location, #location_type, #point_type, #property_type, #semantic_type
Attributes included from Item
#accepted_command_types, #accepted_data_types, #all_groups, #channel, #channel_uid, #channel_uids, #channels, #groups, #links, #metadata, #name, #provider, #thing, #things
Method Summary
Methods included from DSL::Items::TimedCommand
Methods inherited from GenericItem
#command, #modify, #null?, #refresh, #state?, #time_series=, #undef?, #update
Methods included from Semantics
add, #equipment?, #location?, lookup, #point?, #points, remove, #semantic?, tags
Methods included from Item
#call_item?, #color_item?, #contact_item?, #date_time_item?, #dimmer_item?, #group_item?, #image_item?, #inspect, #link, #location_item?, #member_of?, #number_item?, #player_item?, #rollershutter_item?, #string_item?, #switch_item?, #tagged?, #to_s, #unlink
Methods included from Persistence
#all_states_between, #all_states_since, #all_states_until, #average_between, #average_since, #average_until, #changed_between?, #changed_since?, #changed_until?, #count_between, #count_since, #count_state_changes_between, #count_state_changes_since, #count_state_changes_until, #count_until, #delta_between, #delta_since, #delta_until, #deviation_between, #deviation_since, #deviation_until, #evolution_rate, #evolution_rate_between, #evolution_rate_since, #evolution_rate_until, #historic_state, #last_change, #last_update, #maximum_between, #maximum_since, #maximum_until, #median_between, #median_since, #median_until, #minimum_between, #minimum_since, #minimum_until, #next_change, #next_state, #next_update, #persist, #persisted_state, #previous_state, #remove_all_states_between, #remove_all_states_since, #remove_all_states_until, #sum_between, #sum_since, #sum_until, #updated_between?, #updated_since?, #updated_until?, #variance_between, #variance_since, #variance_until
Methods included from DSL::Items::Ensure::Ensurable
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
Delegate missing methods to #base_item if possible
202 203 204 205 206 |
# File 'lib/openhab/core/items/group_item.rb', line 202 def method_missing(method, *args, &block) return base_item.__send__(method, *args, &block) if base_item&.respond_to?(method) # rubocop:disable Lint/RedundantSafeNavigation nil responds to :to_a super end |
Instance Attribute Details
#all_members ⇒ Array (readonly)
Returns Get all non-group members of the group recursively.
157 158 159 |
# File 'lib/openhab/core/items/group_item.rb', line 157 def all_members getAllMembers.map { |m| Proxy.new(m) } end |
#base_item ⇒ Item? (readonly)
Returns A typed item if the group has a particular type.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/openhab/core/items/group_item.rb', line 71 class GroupItem < GenericItem # # Class for indicating to triggers that a group trigger should be used # class Members include LazyArray # @return [GroupItem] attr_reader :group # @!visibility private def initialize(group_item) @group = group_item end # # Adds a member to the group # # @param [Item, String] member The item to add to the group # @return [Members] self # def add(member) if member.is_a?(String) member = items[member] raise ArgumentError, "Item not found: #{member}" if member.nil? end member = member.__getobj__ if member.is_a?(Proxy) raise ArgumentError, "Member must be an Item" unless member.is_a?(Item) group.add_member(member) self end alias_method :<<, :add # Explicit conversion to Array # # @return [Array] def to_a group.get_members.map { |i| Proxy.new(i) } end # Name of the group # # @return [String] def name group.name end # @return [String] def inspect r = "#<OpenHAB::Core::Items::GroupItems::Members #{name}" r += " #{map(&:name).inspect}>" unless @group.__getobj__.nil? "#{r}>" end alias_method :to_s, :inspect end # @!attribute [r] function # @return [GroupFunction] Returns the function of this GroupItem # Override because we want to send them to the base item if possible %i[command update].each do |method| define_method(method) do |command, **kwargs| return base_item.__send__(method, command, **kwargs) if base_item super(command, **kwargs) end end # # @!attribute [r] members # @return [Members] Get an Array-like object representing the members of the group # # @see Enumerable # def members Members.new(Proxy.new(self)) end # # @!attribute [r] all_members # @return [Array] Get all non-group members of the group recursively. # # @see Enumerable # def all_members getAllMembers.map { |m| Proxy.new(m) } end # give the base item type a chance to format commands # @!visibility private def format_type(command) return super unless base_item base_item.format_type(command) end %w[call color contact date_time dimmer image location number player rollershutter string switch].each do |type| type_class = type.gsub(/(^[a-z]|_[a-z])/) { |letter| letter[-1].upcase } class_eval <<~RUBY, __FILE__, __LINE__ + 1 def #{type}_item? # def date_time_item? base_item&.is_a?(#{type_class}Item) # base_item&.is_a?(DateTimeItem) end # end RUBY end # # Compares all attributes of the item with another item. # # @param other [Item] The item to compare with # @return [true,false] true if all attributes are equal, false otherwise # # @!visibility private def config_eql?(other) return false unless super base_item&.type == other.base_item&.type && function&.inspect == other.function&.inspect end private # Add base type and function details def type_details r = "" r += ":#{base_item.type}#{base_item.__send__(:type_details)}" if base_item r += ":#{function.inspect}" if function && function.to_s != "EQUALITY" r end # Delegate missing methods to {base_item} if possible def method_missing(method, *args, &block) return base_item.__send__(method, *args, &block) if base_item&.respond_to?(method) # rubocop:disable Lint/RedundantSafeNavigation nil responds to :to_a super end def respond_to_missing?(method, include_private = false) return true if base_item&.respond_to?(method) # rubocop:disable Lint/RedundantSafeNavigation super end end |
#equipments ⇒ Array<Item> (readonly)
Calls members.equipments.
11 |
# File 'lib/openhab/core/items/semantics.rb', line 11 def equipments; end |
#function ⇒ GroupFunction (readonly)
Returns the function of this GroupItem
|
# File 'lib/openhab/core/items/group_item.rb', line 129
|
#locations ⇒ Array<Item> (readonly)
Calls members.locations.
22 |
# File 'lib/openhab/core/items/semantics.rb', line 22 def locations; end |
#members ⇒ Members (readonly)
Returns Get an Array-like object representing the members of the group.
147 148 149 |
# File 'lib/openhab/core/items/group_item.rb', line 147 def members Members.new(Proxy.new(self)) end |