Package org.openhab.core.items
Class GenericItem
java.lang.Object
org.openhab.core.items.GenericItem
- All Implemented Interfaces:
 Identifiable<String>,ActiveItem,Item
- Direct Known Subclasses:
 CallItem,ContactItem,DateTimeItem,GroupItem,ImageItem,LocationItem,NumberItem,PlayerItem,RollershutterItem,StringItem,SwitchItem
The abstract base class for all items. It provides all relevant logic
 for the infrastructure, such as publishing updates to the event bus
 or notifying listeners.
- Author:
 - Kai Kreuzer - Initial contribution, Andre Fuechsel - Added tags, Stefan Bußweiler - Migration to new ESH event concept, Jan N. Klug - Added time series support
 
- 
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable Stringprotected @Nullable EventPublisherprotected @Nullable ItemStateConverterprotected @Nullable Stringprotected Set<StateChangeListener>protected final Stringprotected Stateprotected Set<TimeSeriesListener>protected final String - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionvoidaddGroupName(String groupItemName) Adds a group name to theGenericItem.voidaddGroupNames(String... groupItemNames) Assigns the according item to the given groups.voidaddGroupNames(List<String> groupItemNames) Assigns the according item to the given groups.voidaddStateChangeListener(StateChangeListener listener) voidAdds a tag to the item.voidAdds tags to the item.voidaddTags(Collection<String> tags) Adds tags to the item.voidaddTimeSeriesListener(TimeSeriesListener listener) protected final voidapplyState(State state) Sets new state, notifies listeners and sends events.protected final voidapplyTimeSeries(TimeSeries timeSeries) Sets new time series, notifies listeners and sends events.voiddispose()Disposes this item.boolean@Nullable StringReturns the category of the item or null if no category is set.@Nullable CommandDescriptiongetCommandDescription(@Nullable Locale locale) Returns theCommandDescriptionfor the given locale.Returns a list of the names of the groups this item belongs to.@Nullable StringgetLabel()Returns the label of the item or null if no label is set.getName()returns the name of the itemgetState()returns the current state of the item<T extends State>
@Nullable TgetStateAs(Class<T> typeClass) returns the current state of the item as a specific type@Nullable StateDescriptionReturns the first provided state description (uses the default locale).@Nullable StateDescriptiongetStateDescription(@Nullable Locale locale) Returns the first provided state description for a given locale.getTags()Returns a set of tags.getType()returns the item type as defined byItemFactorysgetUID()Get the unique identifier.inthashCode()booleanReturns true if the item's tags contains the specific tag, otherwise false.protected voidinternalSend(Command command) booleanisAcceptedState(List<Class<? extends State>> acceptedDataTypes, State state) Tests if state is within acceptedDataTypes list or a subclass of one of themprotected voidlogSetTypeError(State state) protected voidlogSetTypeError(TimeSeries timeSeries) protected voidnotifyListeners(State oldState, State newState) voidClears all tags of this item.voidremoveGroupName(String groupItemName) Removes a group item name from theGenericItem.voidremoveStateChangeListener(StateChangeListener listener) voidRemoves a tag from the item.voidremoveTimeSeriesListener(TimeSeriesListener listener) voidsend(RefreshType command) voidsetCategory(@Nullable String category) Sets the category of the item (can be null)voidsetCommandDescriptionService(@Nullable CommandDescriptionService commandDescriptionService) voidsetEventPublisher(@Nullable EventPublisher eventPublisher) voidsetItemStateConverter(@Nullable ItemStateConverter itemStateConverter) voidSets the label of an itemvoidSet a new state.voidsetStateDescriptionService(@Nullable StateDescriptionService stateDescriptionService) voidsetTimeSeries(TimeSeries timeSeries) Set a new time series.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.openhab.core.items.Item
getAcceptedCommandTypes, getAcceptedDataTypes, getCommandDescription 
- 
Field Details
- 
eventPublisher
 - 
listeners
 - 
timeSeriesListeners
 - 
groupNames
 - 
tags
 - 
name
 - 
type
 - 
state
 - 
label
 - 
category
 - 
itemStateConverter
 
 - 
 - 
Constructor Details
- 
GenericItem
 
 - 
 - 
Method Details
- 
getState
Description copied from interface:Itemreturns the current state of the item - 
getStateAs
Description copied from interface:Itemreturns the current state of the item as a specific type- Specified by:
 getStateAsin interfaceItem- Returns:
 - the current state in the requested type or null, if state cannot be provided as the requested type
 
 - 
getUID
Description copied from interface:IdentifiableGet the unique identifier.- Specified by:
 getUIDin interfaceIdentifiable<String>- Returns:
 - the unique identifier
 
 - 
getName
Description copied from interface:Itemreturns the name of the item - 
getType
Description copied from interface:Itemreturns the item type as defined byItemFactorys - 
getGroupNames
Description copied from interface:ItemReturns a list of the names of the groups this item belongs to.- Specified by:
 getGroupNamesin interfaceItem- Returns:
 - list of item group names
 
 - 
addGroupName
Adds a group name to theGenericItem.- Specified by:
 addGroupNamein interfaceActiveItem- Parameters:
 groupItemName- group item name to add- Throws:
 IllegalArgumentException- if groupItemName isnull
 - 
addGroupNames
Description copied from interface:ActiveItemAssigns the according item to the given groups.- Specified by:
 addGroupNamesin interfaceActiveItem- Parameters:
 groupItemNames- names of the groups (must not be null)
 - 
addGroupNames
Description copied from interface:ActiveItemAssigns the according item to the given groups.- Specified by:
 addGroupNamesin interfaceActiveItem- Parameters:
 groupItemNames- names of the groups (must not be null)
 - 
removeGroupName
Removes a group item name from theGenericItem.- Specified by:
 removeGroupNamein interfaceActiveItem- Parameters:
 groupItemName- group item name to remove- Throws:
 IllegalArgumentException- if groupItemName isnull
 - 
dispose
public void dispose()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. - 
setEventPublisher
 - 
setStateDescriptionService
 - 
setCommandDescriptionService
public void setCommandDescriptionService(@Nullable CommandDescriptionService commandDescriptionService)  - 
setItemStateConverter
 - 
internalSend
 - 
setState
Set a new state. Subclasses may override this method in order to do necessary conversions upfront. Afterwards,applyState(State)should be called by classes overriding this method.- Parameters:
 state- new state of this item
 - 
applyState
Sets new state, notifies listeners and sends events. Classes overriding thesetState(State)method should call this method in order to actually set the state, inform listeners and send the event.- Parameters:
 state- new state of this item
 - 
setTimeSeries
Set a new time series. Subclasses may override this method in order to do necessary conversions upfront. Afterwards,applyTimeSeries(TimeSeries)should be called by classes overriding this method. A time series may only contain events that are compatible with the item's internal state.- Parameters:
 timeSeries- new time series of this item
 - 
applyTimeSeries
Sets new time series, notifies listeners and sends events. Classes overriding thesetTimeSeries(TimeSeries)method should call this method in order to actually set the time series, inform listeners and send the event. A time series may only contain events that are compatible with the item's internal state.- Parameters:
 timeSeries- new time series of this item
 - 
send
 - 
notifyListeners
 - 
toString
 - 
addStateChangeListener
 - 
removeStateChangeListener
 - 
addTimeSeriesListener
 - 
removeTimeSeriesListener
 - 
hashCode
public int hashCode() - 
equals
 - 
getTags
Description copied from interface:ItemReturns a set of tags. If the item is not tagged, an empty set is returned. - 
hasTag
Description copied from interface:ItemReturns true if the item's tags contains the specific tag, otherwise false. - 
addTag
Description copied from interface:ActiveItemAdds a tag to the item.- Specified by:
 addTagin interfaceActiveItem- Parameters:
 tag- a tag that is to be added to item's tags.
 - 
addTags
Description copied from interface:ActiveItemAdds tags to the item.- Specified by:
 addTagsin interfaceActiveItem- Parameters:
 tags- tags that are to be added to item's tags.
 - 
addTags
Description copied from interface:ActiveItemAdds tags to the item.- Specified by:
 addTagsin interfaceActiveItem- Parameters:
 tags- tags that are to be added to item's tags.
 - 
removeTag
Description copied from interface:ActiveItemRemoves a tag from the item.- Specified by:
 removeTagin interfaceActiveItem- Parameters:
 tag- a tag that is to be removed from item's tags.
 - 
removeAllTags
public void removeAllTags()Description copied from interface:ActiveItemClears all tags of this item.- Specified by:
 removeAllTagsin interfaceActiveItem
 - 
getLabel
Description copied from interface:ItemReturns the label of the item or null if no label is set. - 
setLabel
Description copied from interface:ActiveItemSets the label of an item- Specified by:
 setLabelin interfaceActiveItem- Parameters:
 label- label (can be null)
 - 
getCategory
Description copied from interface:ItemReturns the category of the item or null if no category is set.- Specified by:
 getCategoryin interfaceItem- Returns:
 - category or null
 
 - 
setCategory
Description copied from interface:ActiveItemSets the category of the item (can be null)- Specified by:
 setCategoryin interfaceActiveItem- Parameters:
 category- category
 - 
getStateDescription
Description copied from interface:ItemReturns the first provided state description (uses the default locale). If options are defined on the channel, they are included in the returned state description.- Specified by:
 getStateDescriptionin interfaceItem- Returns:
 - state description (can be null)
 
 - 
getStateDescription
Description copied from interface:ItemReturns the first provided state description for a given locale. If options are defined on the channel, they are included in the returned state description.- Specified by:
 getStateDescriptionin interfaceItem- Parameters:
 locale- locale (can be null)- Returns:
 - state description (can be null)
 
 - 
getCommandDescription
Description copied from interface:ItemReturns theCommandDescriptionfor the given locale. In case no dedicatedCommandDescriptionis provided theStateOptions from theStateDescriptionwill be served as validCommandOptions.- Specified by:
 getCommandDescriptionin interfaceItem- Parameters:
 locale- locale (can be null)- Returns:
 - command description (can be null)
 
 - 
isAcceptedState
Tests if state is within acceptedDataTypes list or a subclass of one of them- Parameters:
 acceptedDataTypes- list of datatypes this items accepts as a statestate- to be tested- Returns:
 - true if state is an acceptedDataType or subclass thereof
 
 - 
logSetTypeError
 - 
logSetTypeError
 
 -