Class: OpenHAB::Core::Items::GroupItem
- Inherits:
-
GenericItem
- Object
- GenericItem
- OpenHAB::Core::Items::GroupItem
- 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. “‘xtend 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
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 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
#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 DSL::Items::TimedCommand
Methods included from Persistence
#average_between, #average_since, #changed_between?, #changed_since?, #count_between, #count_since, #count_state_changes_between, #count_state_changes_since, #delta_between, #delta_since, #deviation_between, #deviation_since, #evolution_rate, #historic_state, #last_update, #maximum_between, #maximum_since, #minimum_between, #minimum_since, #persist, #previous_state, #sum_between, #sum_since, #updated_between?, #updated_since?, #variance_between, #variance_since
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
182 183 184 185 186 |
# File 'lib/openhab/core/items/group_item.rb', line 182 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.
137 138 139 |
# File 'lib/openhab/core/items/group_item.rb', line 137 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 |
# 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 # 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| return base_item.__send__(method, command) if base_item super(command) 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[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 109
|
#locations ⇒ Array<Item> (readonly)
Calls members.locations.
22 |
# File 'lib/openhab/core/items/semantics.rb', line 22 def locations; end |