Class ItemDisplayStateUtil

java.lang.Object
org.openhab.core.transform.util.ItemDisplayStateUtil

@NonNullByDefault public class ItemDisplayStateUtil extends Object
Utility class for getting the display state of an Item from its StateDescription.
Author:
Florian Hotze - Initial contribution (extracted from SseItemStatesEventBuilder)
  • Field Details

    • EXTRACT_TRANSFORM_FUNCTION_PATTERN

      public static final Pattern EXTRACT_TRANSFORM_FUNCTION_PATTERN
      RegEx to extract and parse a transformation function call, e.g., MAP(en.map):%s
  • Constructor Details

    • ItemDisplayStateUtil

      public ItemDisplayStateUtil()
  • Method Details

    • transform

      public static @Nullable String transform(String serviceName, String function, String value) throws TransformationException
      Transform an arbitrary value with a transformation service
      Parameters:
      serviceName - the name of the transformation service
      function - the name of the transformation function
      value - the value to transform
      Returns:
      the transformed state, can be null if the transformation function returns null
      Throws:
      TransformationException - when state formatting failed, the transformation service is unavailable, or the transformation failed
    • transform

      public static @Nullable String transform(String serviceName, String function, String format, State state, ZoneId zoneId) throws TransformationException
      Transform an Item state with a transformation service
      Parameters:
      serviceName - the name of the transformation service
      function - the name of the transformation function
      format - the format to apply to the state before applying the transformation function
      state - the state to transform
      Returns:
      the transformed state, can be null if the transformation function returns null
      Throws:
      TransformationException - when state formatting failed, the transformation service is unavailable, or the transformation failed
    • getDisplayState

      public static @Nullable String getDisplayState(Item item, @Nullable Locale locale, ZoneId zoneId)
      Get the display state of an item.
      Parameters:
      item - the item
      locale - the locale
      zoneId - the timezone id
      Returns:
      the display state
    • getDisplayState

      public static @Nullable String getDisplayState(Item item, State state, @Nullable Locale locale, ZoneId zoneId)
      Get the display state of an item for a given state.
      Parameters:
      item - the item
      state - the state
      locale - the locale
      zoneId - the timezone id
      Returns:
      the display state
    • formatState

      public static @Nullable String formatState(String itemName, @Nullable String pattern, List<StateOption> options, State state, ZoneId zoneId)
      Format a state with the provided pattern.
      Parameters:
      pattern - the pattern to format
      state - the state
      zoneId - the timezone id
      Returns:
      the display state