Class NumberItem
- All Implemented Interfaces:
Identifiable<String>
,ActiveItem
,Item
- Author:
- Kai Kreuzer - Initial contribution
-
Field Summary
Fields inherited from class org.openhab.core.items.GenericItem
category, eventPublisher, groupNames, itemStateConverter, label, listeners, name, state, tags, type, unitProvider
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThis method provides a list of all command types that can be used for this itemThis method provides a list of all data types that can be used to update the item state@Nullable Class<? extends javax.measure.Quantity<?>>
Returns theDimension
associated with thisNumberItem
, may be null.@Nullable StateDescription
getStateDescription
(@Nullable Locale locale) Returns the first provided state description for a given locale.@Nullable javax.measure.Unit<? extends javax.measure.Quantity<?>>
getUnit()
Derive the unit for this item by the following priority: the unit parsed from the state description no unit if state description contains%unit%
the default system unit from the item's dimension@Nullable String
Returns the optional unit symbol for thisNumberItem
.void
send
(DecimalType command) void
send
(QuantityType<?> command) void
Set a new state.@Nullable QuantityType<?>
toQuantityType
(DecimalType originalType, @Nullable Class<? extends javax.measure.Quantity<?>> dimension) Try to convert aDecimalType
into a newQuantityType
.Methods inherited from class org.openhab.core.items.GenericItem
addGroupName, addGroupNames, addGroupNames, addStateChangeListener, addTag, addTags, addTags, applyState, dispose, equals, getCategory, getCommandDescription, getGroupNames, getLabel, getName, getState, getStateAs, getStateDescription, getTags, getType, getUID, hashCode, hasTag, internalSend, isAcceptedState, logSetTypeError, notifyListeners, removeAllTags, removeGroupName, removeStateChangeListener, removeTag, send, setCategory, setCommandDescriptionService, setEventPublisher, setItemStateConverter, setLabel, setStateDescriptionService, setUnitProvider, 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
getCommandDescription
-
Constructor Details
-
NumberItem
-
NumberItem
-
-
Method Details
-
getAcceptedDataTypes
Description copied from interface:Item
This method provides a list of all data types that can be used to update the item state
Imagine e.g. a dimmer device: It's status could be 0%, 10%, 50%, 100%, but also OFF or ON and maybe UNDEFINED. So the accepted data types would be in this case
PercentType
,OnOffType
andUnDefType
The order of data types denotes the order of preference. So in case a state needs to be converted in order to be accepted, it will be attempted to convert it to a type from top to bottom. Therefore the type with the least information loss should be on top of the list - in the example above the
PercentType
carries more information than theOnOffType
, hence it is listed first.- Returns:
- a list of data types that can be used to update the item state
-
getAcceptedCommandTypes
Description copied from interface:Item
This method provides a list of all command types that can be used for this item
Imagine e.g. a dimmer device: You could ask it to dim to 0%, 10%, 50%, 100%, but also to turn OFF or ON. So the accepted command types would be in this case
PercentType
,OnOffType
- Returns:
- a list of all command types that can be used for this item
-
send
-
send
-
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
- Overrides:
getStateDescription
in classGenericItem
- Parameters:
locale
- locale (can be null)- Returns:
- state description (can be null)
-
getDimension
Returns theDimension
associated with thisNumberItem
, may be null.- Returns:
- the
Dimension
associated with thisNumberItem
, may be null.
-
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
-
getUnitSymbol
Returns the optional unit symbol for thisNumberItem
.- Returns:
- the optional unit symbol for this
NumberItem
.
-
getUnit
public @Nullable javax.measure.Unit<? extends javax.measure.Quantity<?>> getUnit()Derive the unit for this item by the following priority:- the unit parsed from the state description
- no unit if state description contains
%unit%
- the default system unit from the item's dimension
- Returns:
- the
Unit
for this item if available,null
otherwise.
-
toQuantityType
public @Nullable QuantityType<?> toQuantityType(DecimalType originalType, @Nullable Class<? extends javax.measure.Quantity<?>> dimension) Try to convert aDecimalType
into a newQuantityType
. The unit for the new type is derived either from the state description (which might also give a hint on items w/o dimension) or from the system default unit of the given dimension.- Parameters:
originalType
- the sourceDecimalType
.dimension
- the dimension to which the newQuantityType
should adhere.- Returns:
- the new
QuantityType
from the given originalType,null
if a unit could not be calculated.
-