Class StringItem

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

@NonNullByDefault public class StringItem extends GenericItem
A StringItem can be used for any kind of string to either send or receive from a device.
Author:
Kai Kreuzer - Initial contribution
  • Constructor Details

    • StringItem

      public StringItem(String name)
  • Method Details

    • send

      public void send(StringType command)
    • 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
    • getStateAs

      public <T extends State> @Nullable T getStateAs(Class<T> typeClass)
      Description copied from interface: Item
      returns the current state of the item as a specific type
      Specified by:
      getStateAs in interface Item
      Overrides:
      getStateAs in class GenericItem
      Returns:
      the current state in the requested type or null, if state cannot be provided as the requested type
    • 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