Package org.openhab.core.items
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final @Nullable Itemprotected @Nullable GroupFunctionprotected final CopyOnWriteArrayList<Item> static final StringFields inherited from class org.openhab.core.items.GenericItem
category, eventPublisher, groupNames, itemStateConverter, label, lastState, lastStateChange, lastStateUpdate, listeners, name, state, tags, timeSeriesListeners, type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddedMetadata(Metadata metadata) Can be implemented by subclasses to be informed about added metadatavoidAdds the given item to the members of this group item.voiddispose()Disposes this item.The accepted command types of a group item is the same as of the underlying base item.The accepted data types of a group item is the same as of the underlying base item.@Nullable ItemReturns the base item of thisGroupItem.@Nullable GroupFunctionReturns the function of thisGroupItem.getMembers(Predicate<Item> filterItem) Retrieves ALL members of this group and filters it with the given Predicate<T extends State>
@Nullable TgetStateAs(Class<T> typeClass) returns the current state of the item as a specific typeprotected voidinternalSend(Command command, @Nullable String source) voidRemoves all items from the members of this group item.voidremovedMetadata(Metadata metadata) Can be implemented by subclasses to be informed about removed metadatavoidremoveMember(Item item) Removes the given item from the members of this group item.voidreplaceMember(Item oldItem, Item newItem) voidSend a command to the each member of the group.voidSend a command to the each member of the group.voidsetCommandDescriptionService(@Nullable CommandDescriptionService commandDescriptionService) voidSet a new state.voidsetStateDescriptionService(@Nullable StateDescriptionService stateDescriptionService) voidstateChanged(Item item, State oldState, State newState) This method is called, if a state has changed.voidstateUpdated(Item item, State state) This method is called, if a state was updated, but has not changedtoString()voidupdatedMetadata(Metadata oldMetadata, Metadata newMetadata) Can be implemented by subclasses to be informed about updated metadataMethods inherited from class org.openhab.core.items.GenericItem
addGroupName, addGroupNames, addGroupNames, addStateChangeListener, addTag, addTags, addTags, addTimeSeriesListener, applyState, applyTimeSeries, equals, getCategory, getCommandDescription, getCommandOptions, getGroupNames, getLabel, getLastState, getLastStateChange, getLastStateUpdate, getName, getState, getStateDescription, getStateDescription, getTags, getType, getUID, hashCode, hasTag, isAcceptedState, logSetTypeError, logSetTypeError, notifyListeners, removeAllTags, removeGroupName, removeStateChangeListener, removeTag, removeTimeSeriesListener, send, send, setCategory, setEventPublisher, setItemStateConverter, setLabel, setState, setState, setTimeSeriesMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.openhab.core.items.Item
getCommandDescription
-
Field Details
-
TYPE
- See Also:
-
baseItem
-
function
-
members
-
-
Constructor Details
-
GroupItem
Creates a plain GroupItem- Parameters:
name- name of the group
-
GroupItem
-
GroupItem
Creates a GroupItem with function- Parameters:
name- name of the groupbaseItem- type of items in the groupfunction- function to calculate group status out of member status
-
-
Method Details
-
dispose
public void dispose()Description copied from class:GenericItemDisposes 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:
disposein classGenericItem
-
getBaseItem
Returns the base item of thisGroupItem. 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
Returns the function of thisGroupItem.- Returns:
- the function of this GroupItem
-
getMembers
- Returns:
- the direct members of this
GroupItem
-
getAllMembers
Returns the direct members of thisGroupItemand recursively all members of the potentially containedGroupItems as well. TheGroupItems itself aren't contained. The returned items are unique.- Returns:
- all members of this and all contained
GroupItems
-
getAllStateMembers
Returns the direct members of thisGroupItemand recursively all members of the potentially containedGroupItems as well. TheGroupItems itself are contained if they can have a state. The returned items are unique.- Returns:
- all members of this and all contained
GroupItems
-
getMembers
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
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
-
removeMember
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
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:
getAcceptedDataTypesin interfaceItem- Returns:
- the accepted data types of this group item
-
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:
getAcceptedCommandTypesin interfaceItem- Returns:
- the accepted command types of this group item
-
send
Send a command to the each member of the group.- Parameters:
command- the command to be sent
-
send
Send a command to the each member of the group.- Parameters:
command- the command to be sentsource- the source of the command. See https://www.openhab.org/docs/developer/utils/events.html#the-core-events
-
internalSend
- Overrides:
internalSendin classGenericItem
-
getStateAs
Description copied from interface:Itemreturns the current state of the item as a specific type- Specified by:
getStateAsin interfaceItem- Overrides:
getStateAsin classGenericItem- Returns:
- the current state in the requested type or null, if state cannot be provided as the requested type
-
toString
- Overrides:
toStringin classGenericItem
-
stateChanged
Description copied from interface:StateChangeListenerThis method is called, if a state has changed.- Specified by:
stateChangedin interfaceStateChangeListener- Parameters:
item- the item whose state has changedoldState- the previous statenewState- the new state
-
stateUpdated
Description copied from interface:StateChangeListenerThis method is called, if a state was updated, but has not changed- Specified by:
stateUpdatedin interfaceStateChangeListener- Parameters:
item- the item whose state was updatedstate- the current state, same before and after the update
-
setState
Description copied from class:GenericItemSet a new state. Subclasses may override this method in order to do necessary conversions upfront. Afterwards,GenericItem.applyState(State, String)should be called by classes overriding this method.- Overrides:
setStatein classGenericItem- Parameters:
state- new state of this itemsource- the source of the state update. See https://www.openhab.org/docs/developer/utils/events.html#the-core-events
-
setStateDescriptionService
- Overrides:
setStateDescriptionServicein classGenericItem
-
setCommandDescriptionService
public void setCommandDescriptionService(@Nullable CommandDescriptionService commandDescriptionService) - Overrides:
setCommandDescriptionServicein classGenericItem
-
addedMetadata
Description copied from interface:MetadataAwareItemCan be implemented by subclasses to be informed about added metadata- Specified by:
addedMetadatain interfaceMetadataAwareItem- Parameters:
metadata- the addedMetadataobject for thisItem
-
updatedMetadata
Description copied from interface:MetadataAwareItemCan be implemented by subclasses to be informed about updated metadata- Specified by:
updatedMetadatain interfaceMetadataAwareItem- Parameters:
oldMetadata- the oldMetadataobject for thisItemnewMetadata- the newMetadataobject for thisItem
-
removedMetadata
Description copied from interface:MetadataAwareItemCan be implemented by subclasses to be informed about removed metadata- Specified by:
removedMetadatain interfaceMetadataAwareItem- Parameters:
metadata- the removedMetadataobject for thisItem
-