Java Code Examples for org.eclipse.smarthome.core.types.State#format()
The following examples show how to use
org.eclipse.smarthome.core.types.State#format() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistoryLastChangesSkill.java From org.openhab.ui.habot with Eclipse Public License 1.0 | 6 votes |
private String formatState(Item item, State state) { if (item.getStateDescription() != null) { StateDescription stateDescription = item.getStateDescription(); if (stateDescription != null && stateDescription.getPattern() != null) { try { String transformedState = TransformationHelper.transform( FrameworkUtil.getBundle(HistoryLastChangesSkill.class).getBundleContext(), stateDescription.getPattern(), state.toString()); if (transformedState != null && transformedState.equals(state.toString())) { return state.format(stateDescription.getPattern()); } else { return transformedState; } } catch (NoClassDefFoundError | TransformationException ex) { // TransformationHelper is optional dependency, so ignore if class not found // return state as it is without transformation return state.toString(); } } else { return state.toString(); } } else { return state.toString(); } }
Example 2
Source File: CardBuilder.java From org.openhab.ui.habot with Eclipse Public License 1.0 | 5 votes |
private String formatState(Item item, State state) throws TransformationException { if (item.getStateDescription() != null) { try { StateDescription stateDescription = item.getStateDescription(); if (stateDescription != null && stateDescription.getPattern() != null) { String transformedState = TransformationHelper.transform( FrameworkUtil.getBundle(CardBuilder.class).getBundleContext(), stateDescription.getPattern(), state.toString()); if (transformedState == null) { return state.toString(); } if (transformedState.equals(state.toString())) { return state.format(stateDescription.getPattern()); } else { return transformedState; } } else { return state.toString(); } } catch (IllegalFormatConversionException e) { return state.toString(); } } else { return state.toString(); } }