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
Modifier and TypeFieldDescriptionprotected @Nullable String
protected @Nullable EventPublisher
protected @Nullable ItemStateConverter
protected @Nullable String
protected Set<StateChangeListener>
protected final String
protected State
protected Set<TimeSeriesListener>
protected final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addGroupName
(String groupItemName) Adds a group name to theGenericItem
.void
addGroupNames
(String... groupItemNames) Assigns the according item to the given groups.void
addGroupNames
(List<String> groupItemNames) Assigns the according item to the given groups.void
addStateChangeListener
(StateChangeListener listener) void
Adds a tag to the item.void
Adds tags to the item.void
addTags
(Collection<String> tags) Adds tags to the item.void
addTimeSeriesListener
(TimeSeriesListener listener) protected final void
applyState
(State state) Sets new state, notifies listeners and sends events.protected final void
applyTimeSeries
(TimeSeries timeSeries) Sets new time series, notifies listeners and sends events.void
dispose()
Disposes this item.boolean
@Nullable String
Returns the category of the item or null if no category is set.@Nullable CommandDescription
getCommandDescription
(@Nullable Locale locale) Returns theCommandDescription
for the given locale.Returns a list of the names of the groups this item belongs to.@Nullable String
getLabel()
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 StateDescription
Returns the first provided state description (uses the default locale).@Nullable StateDescription
getStateDescription
(@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 byItemFactory
sgetUID()
Get the unique identifier.int
hashCode()
boolean
Returns true if the item's tags contains the specific tag, otherwise false.protected void
internalSend
(Command command) boolean
isAcceptedState
(List<Class<? extends State>> acceptedDataTypes, State state) Tests if state is within acceptedDataTypes list or a subclass of one of themprotected void
logSetTypeError
(State state) protected void
logSetTypeError
(TimeSeries timeSeries) protected void
notifyListeners
(State oldState, State newState) void
Clears all tags of this item.void
removeGroupName
(String groupItemName) Removes a group item name from theGenericItem
.void
removeStateChangeListener
(StateChangeListener listener) void
Removes a tag from the item.void
removeTimeSeriesListener
(TimeSeriesListener listener) void
send
(RefreshType command) void
setCategory
(@Nullable String category) Sets the category of the item (can be null)void
setCommandDescriptionService
(@Nullable CommandDescriptionService commandDescriptionService) void
setEventPublisher
(@Nullable EventPublisher eventPublisher) void
setItemStateConverter
(@Nullable ItemStateConverter itemStateConverter) void
Sets the label of an itemvoid
Set a new state.void
setStateDescriptionService
(@Nullable StateDescriptionService stateDescriptionService) void
setTimeSeries
(TimeSeries timeSeries) Set a new time series.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:Item
returns the current state of the item -
getStateAs
Description copied from interface:Item
returns the current state of the item as a specific type- Specified by:
getStateAs
in 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:Identifiable
Get the unique identifier.- Specified by:
getUID
in interfaceIdentifiable<String>
- Returns:
- the unique identifier
-
getName
Description copied from interface:Item
returns the name of the item -
getType
Description copied from interface:Item
returns the item type as defined byItemFactory
s -
getGroupNames
Description copied from interface:Item
Returns a list of the names of the groups this item belongs to.- Specified by:
getGroupNames
in interfaceItem
- Returns:
- list of item group names
-
addGroupName
Adds a group name to theGenericItem
.- Specified by:
addGroupName
in interfaceActiveItem
- Parameters:
groupItemName
- group item name to add- Throws:
IllegalArgumentException
- if groupItemName isnull
-
addGroupNames
Description copied from interface:ActiveItem
Assigns the according item to the given groups.- Specified by:
addGroupNames
in interfaceActiveItem
- Parameters:
groupItemNames
- names of the groups (must not be null)
-
addGroupNames
Description copied from interface:ActiveItem
Assigns the according item to the given groups.- Specified by:
addGroupNames
in interfaceActiveItem
- Parameters:
groupItemNames
- names of the groups (must not be null)
-
removeGroupName
Removes a group item name from theGenericItem
.- Specified by:
removeGroupName
in 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:Item
Returns a set of tags. If the item is not tagged, an empty set is returned. -
hasTag
Description copied from interface:Item
Returns true if the item's tags contains the specific tag, otherwise false. -
addTag
Description copied from interface:ActiveItem
Adds a tag to the item.- Specified by:
addTag
in interfaceActiveItem
- Parameters:
tag
- a tag that is to be added to item's tags.
-
addTags
Description copied from interface:ActiveItem
Adds tags to the item.- Specified by:
addTags
in interfaceActiveItem
- Parameters:
tags
- tags that are to be added to item's tags.
-
addTags
Description copied from interface:ActiveItem
Adds tags to the item.- Specified by:
addTags
in interfaceActiveItem
- Parameters:
tags
- tags that are to be added to item's tags.
-
removeTag
Description copied from interface:ActiveItem
Removes a tag from the item.- Specified by:
removeTag
in interfaceActiveItem
- Parameters:
tag
- a tag that is to be removed from item's tags.
-
removeAllTags
public void removeAllTags()Description copied from interface:ActiveItem
Clears all tags of this item.- Specified by:
removeAllTags
in interfaceActiveItem
-
getLabel
Description copied from interface:Item
Returns the label of the item or null if no label is set. -
setLabel
Description copied from interface:ActiveItem
Sets the label of an item- Specified by:
setLabel
in interfaceActiveItem
- Parameters:
label
- label (can be null)
-
getCategory
Description copied from interface:Item
Returns the category of the item or null if no category is set.- Specified by:
getCategory
in interfaceItem
- Returns:
- category or null
-
setCategory
Description copied from interface:ActiveItem
Sets the category of the item (can be null)- Specified by:
setCategory
in interfaceActiveItem
- Parameters:
category
- category
-
getStateDescription
Description copied from interface:Item
Returns 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:
getStateDescription
in interfaceItem
- Returns:
- state description (can be null)
-
getStateDescription
Description copied from interface:Item
Returns 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:
getStateDescription
in interfaceItem
- Parameters:
locale
- locale (can be null)- Returns:
- state description (can be null)
-
getCommandDescription
Description copied from interface:Item
Returns theCommandDescription
for the given locale. In case no dedicatedCommandDescription
is provided theStateOption
s from theStateDescription
will be served as validCommandOption
s.- Specified by:
getCommandDescription
in 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
-