Class NumberItem

java.lang.Object
org.openhab.core.items.GenericItem
org.openhab.core.library.items.NumberItem
All Implemented Interfaces:
Identifiable<String>, ActiveItem, Item, MetadataAwareItem

@NonNullByDefault public class NumberItem extends GenericItem implements MetadataAwareItem
A NumberItem has a decimal value and is usually used for all kinds of sensors, like temperature, brightness, wind, etc. It can also be used as a counter or as any other thing that can be expressed as a number.
Author:
Kai Kreuzer - Initial contribution
  • Field Details

  • Constructor Details

  • Method Details

    • getAcceptedDataTypes

      public List<Class<? extends State>> 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 and UnDefType

      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 the OnOffType, hence it is listed first.

      Specified by:
      getAcceptedDataTypes in interface Item
      Returns:
      a list of data types that can be used to update the item state
    • getAcceptedCommandTypes

      public List<Class<? extends Command>> 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

      Specified by:
      getAcceptedCommandTypes in interface Item
      Returns:
      a list of all command types that can be used for this item
    • send

      public void send(DecimalType command)
    • send

      public void send(QuantityType<?> command)
    • getStateDescription

      public @Nullable StateDescription getStateDescription(@Nullable Locale locale)
      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 interface Item
      Overrides:
      getStateDescription in class GenericItem
      Parameters:
      locale - locale (can be null)
      Returns:
      state description (can be null)
    • getDimension

      public @Nullable Class<? extends javax.measure.Quantity<?>> getDimension()
      Returns the Dimension associated with this NumberItem, may be null.
      Returns:
      the Dimension associated with this NumberItem, may be null.
    • setState

      public void setState(State state)
      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 class GenericItem
      Parameters:
      state - new state of this item
    • setTimeSeries

      public void setTimeSeries(TimeSeries timeSeries)
      Description copied from class: GenericItem
      Set a new time series.

      Subclasses may override this method in order to do necessary conversions upfront. Afterwards, GenericItem.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.

      Overrides:
      setTimeSeries in class GenericItem
      Parameters:
      timeSeries - new time series of this item
    • getUnitSymbol

      public @Nullable String getUnitSymbol()
      Returns the optional unit symbol for this NumberItem.
      Returns:
      the optional unit symbol for this NumberItem.
    • getUnit

      public @Nullable javax.measure.Unit<? extends javax.measure.Quantity<?>> getUnit()
      Get the unit for this item, either:
      • the unit retrieved from the unit namespace in the item's metadata
      • the default system unit for the item's dimension
      Returns:
      the Unit for this item if available, null otherwise.
    • addedMetadata

      public void addedMetadata(Metadata metadata)
      Description copied from interface: MetadataAwareItem
      Can be implemented by subclasses to be informed about added metadata
      Specified by:
      addedMetadata in interface MetadataAwareItem
      Parameters:
      metadata - the added Metadata object for this Item
    • updatedMetadata

      public void updatedMetadata(Metadata oldMetadata, Metadata newMetadata)
      Description copied from interface: MetadataAwareItem
      Can be implemented by subclasses to be informed about updated metadata
      Specified by:
      updatedMetadata in interface MetadataAwareItem
      Parameters:
      oldMetadata - the old Metadata object for this Item
      newMetadata - the new Metadata object for this Item
    • removedMetadata

      public void removedMetadata(Metadata metadata)
      Description copied from interface: MetadataAwareItem
      Can be implemented by subclasses to be informed about removed metadata
      Specified by:
      removedMetadata in interface MetadataAwareItem
      Parameters:
      metadata - the removed Metadata object for this Item