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
Modifier and TypeFieldDescriptionprotected final @Nullable Item
protected @Nullable GroupFunction
protected final CopyOnWriteArrayList<Item>
static final String
Fields inherited from class org.openhab.core.items.GenericItem
category, eventPublisher, groupNames, itemStateConverter, label, listeners, name, state, tags, timeSeriesListeners, type
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addedMetadata
(Metadata metadata) Can be implemented by subclasses to be informed about added metadatavoid
Adds the given item to the members of this group item.void
dispose()
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 Item
Returns the base item of thisGroupItem
.@Nullable GroupFunction
Returns 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 void
internalSend
(Command command) void
Removes all items from the members of this group item.void
removedMetadata
(Metadata metadata) Can be implemented by subclasses to be informed about removed metadatavoid
removeMember
(Item item) Removes the given item from the members of this group item.void
replaceMember
(Item oldItem, Item newItem) void
void
setCommandDescriptionService
(@Nullable CommandDescriptionService commandDescriptionService) void
Set a new state.void
setStateDescriptionService
(@Nullable StateDescriptionService stateDescriptionService) void
stateChanged
(Item item, State oldState, State newState) This method is called, if a state has changed.void
stateUpdated
(Item item, State state) This method is called, if a state was updated, but has not changedtoString()
void
updatedMetadata
(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, getName, getState, getStateDescription, getStateDescription, getTags, getType, getUID, hashCode, hasTag, isAcceptedState, logSetTypeError, logSetTypeError, notifyListeners, removeAllTags, removeGroupName, removeStateChangeListener, removeTag, removeTimeSeriesListener, send, setCategory, setEventPublisher, setItemStateConverter, setLabel, setTimeSeries
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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: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 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 thisGroupItem
and recursively all members of the potentially containedGroupItem
s as well. TheGroupItem
s itself aren't contained. The returned items are unique.- Returns:
- all members of this and all contained
GroupItem
s
-
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:
getAcceptedDataTypes
in 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:
getAcceptedCommandTypes
in interfaceItem
- Returns:
- the accepted command types of this group item
-
send
-
internalSend
- Overrides:
internalSend
in classGenericItem
-
getStateAs
Description copied from interface:Item
returns the current state of the item as a specific type- Specified by:
getStateAs
in interfaceItem
- Overrides:
getStateAs
in classGenericItem
- Returns:
- the current state in the requested type or null, if state cannot be provided as the requested type
-
toString
- Overrides:
toString
in classGenericItem
-
stateChanged
Description copied from interface:StateChangeListener
This method is called, if a state has changed.- Specified by:
stateChanged
in interfaceStateChangeListener
- Parameters:
item
- the item whose state has changedoldState
- the previous statenewState
- the new state
-
stateUpdated
Description copied from interface:StateChangeListener
This method is called, if a state was updated, but has not changed- Specified by:
stateUpdated
in interfaceStateChangeListener
- Parameters:
item
- the item whose state was updatedstate
- the current state, same before and after the update
-
setState
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 classGenericItem
- Parameters:
state
- new state of this item
-
setStateDescriptionService
- Overrides:
setStateDescriptionService
in classGenericItem
-
setCommandDescriptionService
public void setCommandDescriptionService(@Nullable CommandDescriptionService commandDescriptionService) - Overrides:
setCommandDescriptionService
in classGenericItem
-
addedMetadata
Description copied from interface:MetadataAwareItem
Can be implemented by subclasses to be informed about added metadata- Specified by:
addedMetadata
in interfaceMetadataAwareItem
- Parameters:
metadata
- the addedMetadata
object for thisItem
-
updatedMetadata
Description copied from interface:MetadataAwareItem
Can be implemented by subclasses to be informed about updated metadata- Specified by:
updatedMetadata
in interfaceMetadataAwareItem
- Parameters:
oldMetadata
- the oldMetadata
object for thisItem
newMetadata
- the newMetadata
object for thisItem
-
removedMetadata
Description copied from interface:MetadataAwareItem
Can be implemented by subclasses to be informed about removed metadata- Specified by:
removedMetadata
in interfaceMetadataAwareItem
- Parameters:
metadata
- the removedMetadata
object for thisItem
-