Package org.openhab.core.transform.util
Class ItemDisplayStateUtil
java.lang.Object
org.openhab.core.transform.util.ItemDisplayStateUtil
Utility class for getting the display state of an Item from its
StateDescription.- Author:
- Florian Hotze - Initial contribution (extracted from SseItemStatesEventBuilder)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternRegEx to extract and parse a transformation function call, e.g.,MAP(en.map):%s -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable StringformatState(String itemName, @Nullable String pattern, List<StateOption> options, State state, ZoneId zoneId) Format a state with the provided pattern.static @Nullable StringgetDisplayState(Item item, @Nullable Locale locale, ZoneId zoneId) Get the display state of an item.static @Nullable StringgetDisplayState(Item item, State state, @Nullable Locale locale, ZoneId zoneId) Get the display state of an item for a given state.static @Nullable StringTransform an arbitrary value with a transformation servicestatic @Nullable StringTransform an Item state with a transformation service
-
Field Details
-
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 servicefunction- the name of the transformation functionvalue- 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 servicefunction- the name of the transformation functionformat- the format to apply to the state before applying the transformation functionstate- 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
Get the display state of an item.- Parameters:
item- the itemlocale- the localezoneId- 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 itemstate- the statelocale- the localezoneId- 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 formatstate- the statezoneId- the timezone id- Returns:
- the display state
-