Class GroupItem

java.lang.Object
org.openhab.core.items.GenericItem
org.openhab.core.items.GroupItem
All Implemented Interfaces:
Identifiable<String>, ActiveItem, Item, MetadataAwareItem, StateChangeListener

@NonNullByDefault public class GroupItem extends GenericItem implements StateChangeListener, MetadataAwareItem
Author:
Kai Kreuzer - Initial contribution
  • Field Details

  • Constructor Details

    • GroupItem

      public GroupItem(String name)
      Creates a plain GroupItem
      Parameters:
      name - name of the group
    • GroupItem

      public GroupItem(String name, @Nullable Item baseItem)
    • GroupItem

      public GroupItem(String name, @Nullable Item baseItem, @Nullable GroupFunction function)
      Creates a GroupItem with function
      Parameters:
      name - name of the group
      baseItem - type of items in the group
      function - function to calculate group status out of member status
  • Method Details

    • dispose

      public void dispose()
      Description copied from class: GenericItem
      Disposes this item. Clears all injected services and unregisters all change listeners. This does not remove this item from its groups. Removing from groups should be done externally to retain the member order in case this item is exchanged in a group.
      Overrides:
      dispose in class GenericItem
    • getBaseItem

      public @Nullable Item getBaseItem()
      Returns the base item of this GroupItem. This method is only intended to allow instance checks of the underlying BaseItem. It must not be changed in any way.
      Returns:
      the base item of this GroupItem
    • getFunction

      public @Nullable GroupFunction getFunction()
      Returns the function of this GroupItem.
      Returns:
      the function of this GroupItem
    • getMembers

      public Set<Item> getMembers()
      Returns the direct members of this GroupItem regardless if these members are GroupItems as well.
      Returns:
      the direct members of this GroupItem
    • getAllMembers

      public Set<Item> getAllMembers()
      Returns the direct members of this GroupItem and recursively all members of the potentially contained GroupItems as well. The GroupItems itself aren't contained. The returned items are unique.
      Returns:
      all members of this and all contained GroupItems
    • getMembers

      public Set<Item> getMembers(Predicate<Item> filterItem)
      Retrieves ALL members of this group and filters it with the given Predicate
      Parameters:
      filterItem - Predicate with settings to filter member list
      Returns:
      Set of member items filtered by filterItem
    • addMember

      public void addMember(Item item)
      Adds the given item to the members of this group item.
      Parameters:
      item - the item to be added (must not be null)
      Throws:
      IllegalArgumentException - if the given item is null
    • replaceMember

      public void replaceMember(Item oldItem, Item newItem)
    • removeMember

      public void removeMember(Item item)
      Removes the given item from the members of this group item.
      Parameters:
      item - the item to be removed (must not be null)
      Throws:
      IllegalArgumentException - if the given item is null
    • removeAllMembers

      public void removeAllMembers()
      Removes all items from the members of this group item.
    • getAcceptedDataTypes

      public List<Class<? extends State>> getAcceptedDataTypes()
      The accepted data types of a group item is the same as of the underlying base item. If none is defined, the intersection of all sets of accepted data types of all group members is used instead.
      Specified by:
      getAcceptedDataTypes in interface Item
      Returns:
      the accepted data types of this group item
    • getAcceptedCommandTypes

      public List<Class<? extends Command>> getAcceptedCommandTypes()
      The accepted command types of a group item is the same as of the underlying base item. If none is defined, the intersection of all sets of accepted command types of all group members is used instead.
      Specified by:
      getAcceptedCommandTypes in interface Item
      Returns:
      the accepted command types of this group item
    • send

      public void send(Command command)
    • internalSend

      protected void internalSend(Command command)
      Overrides:
      internalSend in class GenericItem
    • getStateAs

      public <T extends State> @Nullable T getStateAs(Class<T> typeClass)
      Description copied from interface: Item
      returns the current state of the item as a specific type
      Specified by:
      getStateAs in interface Item
      Overrides:
      getStateAs in class GenericItem
      Returns:
      the current state in the requested type or null, if state cannot be provided as the requested type
    • toString

      public String toString()
      Overrides:
      toString in class GenericItem
    • stateChanged

      public void stateChanged(Item item, State oldState, State newState)
      Description copied from interface: StateChangeListener
      This method is called, if a state has changed.
      Specified by:
      stateChanged in interface StateChangeListener
      Parameters:
      item - the item whose state has changed
      oldState - the previous state
      newState - the new state
    • stateUpdated

      public void stateUpdated(Item item, State state)
      Description copied from interface: StateChangeListener
      This method is called, if a state was updated, but has not changed
      Specified by:
      stateUpdated in interface StateChangeListener
      Parameters:
      item - the item whose state was updated
      state - the current state, same before and after the update
    • setState

      public void setState(State state)
      Description copied from class: GenericItem
      Set a new state. Subclasses may override this method in order to do necessary conversions upfront. Afterwards, GenericItem.applyState(State) should be called by classes overriding this method.
      Overrides:
      setState in class GenericItem
      Parameters:
      state - new state of this item
    • setStateDescriptionService

      public void setStateDescriptionService(@Nullable StateDescriptionService stateDescriptionService)
      Overrides:
      setStateDescriptionService in class GenericItem
    • setCommandDescriptionService

      public void setCommandDescriptionService(@Nullable CommandDescriptionService commandDescriptionService)
      Overrides:
      setCommandDescriptionService in class GenericItem
    • addedMetadata

      public void addedMetadata(Metadata metadata)
      Description copied from interface: MetadataAwareItem
      Can be implemented by subclasses to be informed about added metadata
      Specified by:
      addedMetadata in interface MetadataAwareItem
      Parameters:
      metadata - the added Metadata object for this Item
    • updatedMetadata

      public void updatedMetadata(Metadata oldMetadata, Metadata newMetadata)
      Description copied from interface: MetadataAwareItem
      Can be implemented by subclasses to be informed about updated metadata
      Specified by:
      updatedMetadata in interface MetadataAwareItem
      Parameters:
      oldMetadata - the old Metadata object for this Item
      newMetadata - the new Metadata object for this Item
    • removedMetadata

      public void removedMetadata(Metadata metadata)
      Description copied from interface: MetadataAwareItem
      Can be implemented by subclasses to be informed about removed metadata
      Specified by:
      removedMetadata in interface MetadataAwareItem
      Parameters:
      metadata - the removed Metadata object for this Item