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 more...
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
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.
-
#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, #groups, #metadata, #name
Method Summary
Methods inherited from GenericItem
#command, #modify, #null?, #refresh, #state?, #undef?, #update
Methods included from Semantics
#equipment?, #location?, #point?, #points, #semantic?
Methods included from Item
#inspect, #member_of?, #provider, #tagged?, #thing, #things, #to_s
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
160 161 162 163 164 |
# File 'lib/openhab/core/items/group_item.rb', line 160 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.
134 135 136 |
# File 'lib/openhab/core/items/group_item.rb', line 134 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 |
# 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 # 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 private # Add base type and function details def type_details r = "" r += ":#{base_item.type}#{base_item.__send__(:type_details)}" if base_item if function && (fn = function.class.java_class.simple_name.upcase) != "EQUALITY" r += ":#{fn}" r += "(#{function.parameters.map(&:inspect).join(",")})" unless function.parameters.empty? end 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 |
#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.
124 125 126 |
# File 'lib/openhab/core/items/group_item.rb', line 124 def members Members.new(Proxy.new(self)) end |