Module: OpenHAB::Core::Items::Item
- Included in:
- GenericItem
- Defined in:
- lib/openhab/core/items/item.rb
Overview
The core features of an openHAB item.
Instance Attribute Summary collapse
-
#accepted_command_types ⇒ Array<Class>
readonly
An array of Commands that can be sent as commands to this item.
-
#accepted_data_types ⇒ Array<Class>
readonly
An array of States that can be sent as commands to this item.
-
#all_groups ⇒ Array<GroupItem>
readonly
Returns all groups that this item is a part of, as well as those groups' groups, recursively.
-
#groups ⇒ Array<GroupItem>
readonly
Returns all groups that this item is part of.
-
#metadata ⇒ Metadata::NamespaceHash
readonly
Access to the item's metadata.
-
#name ⇒ String
readonly
The item's name.
Instance Method Summary collapse
- #inspect ⇒ String
-
#member_of?(*groups) ⇒ true, false
Checks if this item is a member of at least one of the given groups.
- #provider ⇒ org.openhab.core.common.registry.Provider
-
#tagged?(*tags) ⇒ true, false
Checks if this item has at least one of the given tags.
-
#thing ⇒ Thing
(also: #linked_thing)
Return the item's thing if this item is linked with a thing.
-
#things ⇒ Array<Thing>
(also: #all_linked_things)
Returns all of the item's linked things.
- #to_s ⇒ String
Instance Attribute Details
#accepted_command_types ⇒ Array<Class> (readonly)
Returns An array of Commands that can be sent as commands to this item.
|
# File 'lib/openhab/core/items/item.rb', line 27
|
#accepted_data_types ⇒ Array<Class> (readonly)
Returns An array of States that can be sent as commands to this item.
|
# File 'lib/openhab/core/items/item.rb', line 30
|
#all_groups ⇒ Array<GroupItem> (readonly)
Returns all groups that this item is a part of, as well as those groups' groups, recursively
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/openhab/core/items/item.rb', line 76 def all_groups result = [] new_groups = Set.new(groups) until new_groups.empty? result.concat(new_groups.to_a) new_groups.replace(new_groups.flat_map(&:groups)) # remove any groups we already have in the result to avoid loops new_groups.subtract(result) end result end |
#groups ⇒ Array<GroupItem> (readonly)
Returns all groups that this item is part of
49 50 51 |
# File 'lib/openhab/core/items/item.rb', line 49 def groups group_names.map { |name| EntityLookup.lookup_item(name) }.compact end |
#metadata ⇒ Metadata::NamespaceHash (readonly)
Access to the item's metadata.
Both the return value of this method as well as the individual namespaces can be treated as Hashes.
Examples assume the following items:
Switch Item1 { namespace1="value" [ config1="foo", config2="bar" ] }
String StringItem1
207 208 209 |
# File 'lib/openhab/core/items/item.rb', line 207 def metadata @metadata ||= Metadata::NamespaceHash.new(name) end |
#name ⇒ String (readonly)
The item's name.
|
# File 'lib/openhab/core/items/item.rb', line 23
|
Instance Method Details
#inspect ⇒ String
248 249 250 251 252 253 254 255 256 |
# File 'lib/openhab/core/items/item.rb', line 248 def inspect s = "#<OpenHAB::Core::Items::#{type}Item#{type_details} #{name} #{label.inspect} state=#{raw_state.inspect}" s += " category=#{category.inspect}" if category s += " tags=#{tags.to_a.inspect}" unless tags.empty? s += " groups=#{group_names}" unless group_names.empty? meta = metadata.to_h s += " metadata=#{meta.inspect}" unless meta.empty? "#{s}>" end |
#member_of?(*groups) ⇒ true, false
Checks if this item is a member of at least one of the given groups.
62 63 64 65 66 67 |
# File 'lib/openhab/core/items/item.rb', line 62 def member_of?(*groups) groups.map! do |group| group.is_a?(GroupItem) ? group.name : group end !(group_names & groups).empty? end |
#provider ⇒ org.openhab.core.common.registry.Provider
259 260 261 |
# File 'lib/openhab/core/items/item.rb', line 259 def provider Provider.registry.provider_for(self) end |
#tagged?(*tags) ⇒ true, false
Checks if this item has at least one of the given tags.
221 222 223 224 225 226 |
# File 'lib/openhab/core/items/item.rb', line 221 def tagged?(*tags) tags.map! do |tag| tag.is_a?(Module) ? tag.simple_name : tag end !(self.tags.to_a & tags).empty? end |
#thing ⇒ Thing Also known as: linked_thing
Return the item's thing if this item is linked with a thing. If an item is linked to more than one thing, this method only returns the first thing.
232 233 234 |
# File 'lib/openhab/core/items/item.rb', line 232 def thing all_linked_things.first end |
#things ⇒ Array<Thing> Also known as: all_linked_things
Returns all of the item's linked things.
240 241 242 243 244 |
# File 'lib/openhab/core/items/item.rb', line 240 def things registry = Things::Links::Provider.registry channels = registry.get_bound_channels(name).to_a channels.map(&:thing_uid).uniq.map { |tuid| EntityLookup.lookup_thing(tuid) }.compact end |