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.
 - 
  
    
      #links  ⇒ ItemChannelLinks 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns all of the item's links (channels and link configurations).
 - 
  
    
      #metadata  ⇒ Metadata::NamespaceHash 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Access to the item's metadata.
 - 
  
    
      #name  ⇒ String 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The item's name.
 - 
  
    
      #provider  ⇒ org.openhab.core.common.registry.Provider? 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the provider for this item.
 - 
  
    
      #thing  ⇒ Thing 
    
    
      (also: #linked_thing)
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Return the item's thing if this item is linked with a thing.
 - 
  
    
      #things  ⇒ Array<Thing> 
    
    
      (also: #all_linked_things)
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns all of the item's linked things.
 
Instance Method Summary collapse
- 
  
    
      #color_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a color item.
 - 
  
    
      #contact_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a contact item.
 - 
  
    
      #date_time_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a date_time item.
 - 
  
    
      #dimmer_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a dimmer item.
 - 
  
    
      #group_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a group item.
 - 
  
    
      #image_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a image item.
 - #inspect ⇒ String
 - 
  
    
      #link(channel, config = {})  ⇒ Things::ItemChannelLink 
    
    
  
  
  
  
  
  
  
  
  
    
Links the item to a channel.
 - 
  
    
      #location_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a location item.
 - 
  
    
      #member_of?(*groups)  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Checks if this item is a member of at least one of the given groups.
 - 
  
    
      #number_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a number item.
 - 
  
    
      #player_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a player item.
 - 
  
    
      #rollershutter_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a rollershutter item.
 - 
  
    
      #string_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a string item.
 - 
  
    
      #switch_item?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the item is a switch item.
 - 
  
    
      #tagged?(*tags)  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Checks if this item has at least one of the given tags.
 - #to_s ⇒ String
 - 
  
    
      #unlink(channel)  ⇒ Things::ItemChannelLink? 
    
    
  
  
  
  
  
  
  
  
  
    
Removes a link to a channel from managed link providers.
 
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 43
     | 
  
#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 46
     | 
  
#all_groups ⇒ Array<GroupItem> (readonly)
Returns all groups that this item is a part of, as well as those groups' groups, recursively
      92 93 94 95 96 97 98 99 100 101 102 103 104  | 
    
      # File 'lib/openhab/core/items/item.rb', line 92 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
      65 66 67  | 
    
      # File 'lib/openhab/core/items/item.rb', line 65 def groups group_names.map { |name| EntityLookup.lookup_item(name) }.compact end  | 
  
#links ⇒ ItemChannelLinks (readonly)
Returns all of the item's links (channels and link configurations).
      288 289 290  | 
    
      # File 'lib/openhab/core/items/item.rb', line 288 def links ItemChannelLinks.new(self, Things::Links::Provider.registry.get_links(name)) 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
  
      223 224 225  | 
    
      # File 'lib/openhab/core/items/item.rb', line 223 def metadata @metadata ||= Metadata::NamespaceHash.new(name) end  | 
  
#name ⇒ String (readonly)
The item's name.
| 
       | 
    
      # File 'lib/openhab/core/items/item.rb', line 39
     | 
  
#provider ⇒ org.openhab.core.common.registry.Provider? (readonly)
Returns the provider for this item.
      362 363 364  | 
    
      # File 'lib/openhab/core/items/item.rb', line 362 def provider Provider.registry.provider_for(self) end  | 
  
#thing ⇒ Thing (readonly) 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.
      259 260 261  | 
    
      # File 'lib/openhab/core/items/item.rb', line 259 def thing all_linked_things.first end  | 
  
#things ⇒ Array<Thing> (readonly) Also known as: all_linked_things
Returns all of the item's linked things.
      268 269 270  | 
    
      # File 'lib/openhab/core/items/item.rb', line 268 def things Things::Links::Provider.registry.get_bound_things(name).map { |thing| Things::Proxy.new(thing) } end  | 
  
Instance Method Details
#color_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a color item.
Check if the item is a color item.
      383  | 
    
      # File 'lib/openhab/core/items/item.rb', line 383 def_type_predicate(:color)  | 
  
#contact_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a contact item.
Check if the item is a contact item.
      384  | 
    
      # File 'lib/openhab/core/items/item.rb', line 384 def_type_predicate(:contact)  | 
  
#date_time_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a date_time item.
Check if the item is a date_time item.
      385  | 
    
      # File 'lib/openhab/core/items/item.rb', line 385 def_type_predicate(:date_time)  | 
  
#dimmer_item? ⇒ true, false
Color items are also considered dimmer items.
If the item is a group item, it will also return true if the base item is a dimmer item.
Check if the item is a dimmer item.
      387  | 
    
      # File 'lib/openhab/core/items/item.rb', line 387 def_type_predicate(:dimmer)  | 
  
#group_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a group item.
Check if the item is a group item.
      388  | 
    
      # File 'lib/openhab/core/items/item.rb', line 388 def_type_predicate(:group)  | 
  
#image_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a image item.
Check if the item is a image item.
      389  | 
    
      # File 'lib/openhab/core/items/item.rb', line 389 def_type_predicate(:image)  | 
  
#inspect ⇒ String
      350 351 352 353 354 355 356 357 358  | 
    
      # File 'lib/openhab/core/items/item.rb', line 350 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  | 
  
#link(channel, config = {}) ⇒ Things::ItemChannelLink
Links the item to a channel.
      316 317 318 319 320 321 322 323 324 325  | 
    
      # File 'lib/openhab/core/items/item.rb', line 316 def link(channel, config = {}) Core::Things::Links::Provider.create_link(self, channel, config).tap do |new_link| provider = Core::Things::Links::Provider.current if !(current_link = provider.get(new_link.uid)) provider.add(new_link) elsif current_link.configuration != config provider.update(new_link) end end end  | 
  
#location_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a location item.
Check if the item is a location item.
      390  | 
    
      # File 'lib/openhab/core/items/item.rb', line 390 def_type_predicate(:location)  | 
  
#member_of?(*groups) ⇒ true, false
Checks if this item is a member of at least one of the given groups.
      78 79 80 81 82 83  | 
    
      # File 'lib/openhab/core/items/item.rb', line 78 def member_of?(*groups) groups.map! do |group| group.is_a?(GroupItem) ? group.name : group end !(group_names & groups).empty? end  | 
  
#number_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a number item.
Check if the item is a number item.
      391  | 
    
      # File 'lib/openhab/core/items/item.rb', line 391 def_type_predicate(:number)  | 
  
#player_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a player item.
Check if the item is a player item.
      392  | 
    
      # File 'lib/openhab/core/items/item.rb', line 392 def_type_predicate(:player)  | 
  
#rollershutter_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a rollershutter item.
Check if the item is a rollershutter item.
      393  | 
    
      # File 'lib/openhab/core/items/item.rb', line 393 def_type_predicate(:rollershutter)  | 
  
#string_item? ⇒ true, false
If the item is a group item, it will also return true if the base item is a string item.
Check if the item is a string item.
      394  | 
    
      # File 'lib/openhab/core/items/item.rb', line 394 def_type_predicate(:string)  | 
  
#switch_item? ⇒ true, false
Color and dimmer items are also considered switch items.
If the item is a group item, it will also return true if the base item is a switch item.
Check if the item is a switch item.
      396  | 
    
      # File 'lib/openhab/core/items/item.rb', line 396 def_type_predicate(:switch)  | 
  
#tagged?(*tags) ⇒ true, false
Checks if this item has at least one of the given tags.
      240 241 242 243 244 245 246 247 248 249 250 251 252  | 
    
      # File 'lib/openhab/core/items/item.rb', line 240 def tagged?(*tags) tags.map! do |tag| # @deprecated OH3.4 if tag.is_a?(Module) tag.simple_name elsif defined?(Semantics::SemanticTag) && tag.is_a?(Semantics::SemanticTag) tag.name else tag end end !(self.tags.to_a & tags).empty? end  | 
  
#to_s ⇒ String
      54 55 56  | 
    
      # File 'lib/openhab/core/items/item.rb', line 54 def to_s label || name end  | 
  
#unlink(channel) ⇒ Things::ItemChannelLink?
Removes a link to a channel from managed link providers.
      338 339 340 341 342 343 344 345 346 347  | 
    
      # File 'lib/openhab/core/items/item.rb', line 338 def unlink(channel) link_to_delete = Things::Links::Provider.create_link(self, channel, {}) provider = Things::Links::Provider.registry.provider_for(link_to_delete.uid) unless provider.is_a?(ManagedProvider) raise FrozenError, "Cannot remove the link #{link_to_delete.uid} from non-managed provider #{provider.inspect}" end provider.remove(link_to_delete.uid) end  |