Class NumberItem

  • All Implemented Interfaces:
    Identifiable<String>, ActiveItem, Item

    @NonNullByDefault
    public class NumberItem
    extends GenericItem
    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
    • Constructor Detail

      • NumberItem

        public NumberItem​(String name)
      • NumberItem

        public NumberItem​(String type,
                          String name)
    • Method Detail

      • 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.

        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

        Returns:
        a list of all command types that can be used for this item
      • 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
      • 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()
        Derive the unit for this item by the following priority:
        • the unit parsed from the state description
        • 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 a DecimalType into a new QuantityType. 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 source DecimalType.
        dimension - the dimension to which the new QuantityType should adhere.
        Returns:
        the new QuantityType from the given originalType, null if a unit could not be calculated.