Java Code Examples for org.eclipse.smarthome.core.library.types.StringType#toString()

The following examples show how to use org.eclipse.smarthome.core.library.types.StringType#toString() . 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: LightStateConverter.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Transforms the given {@link StringType} into a light state containing the {@link AlertMode} to be triggered.
 *
 * @param alertType {@link StringType} representing the required {@link AlertMode} . <br>
 *            Supported values are:
 *            <ul>
 *            <li>{@value #ALERT_MODE_NONE}.
 *            <li>{@value #ALERT_MODE_SELECT}.
 *            <li>{@value #ALERT_MODE_LONG_SELECT}.
 *            <ul>
 * @return light state containing the {@link AlertMode} or <b><code>null </code></b> if the provided
 *         {@link StringType} represents unsupported mode.
 */
public static @Nullable StateUpdate toAlertState(StringType alertType) {
    AlertMode alertMode;

    switch (alertType.toString()) {
        case ALERT_MODE_NONE:
            alertMode = State.AlertMode.NONE;
            break;
        case ALERT_MODE_SELECT:
            alertMode = State.AlertMode.SELECT;
            break;
        case ALERT_MODE_LONG_SELECT:
            alertMode = State.AlertMode.LSELECT;
            break;
        default:
            return null;
    }
    return new StateUpdate().setAlert(alertMode);
}
 
Example 2
Source File: StringTypeConverter.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Object toBinding(StringType type, HmDatapoint dp) throws ConverterException {
    if (dp.isStringType()) {
        return type.toString();
    } else {
        int idx = dp.getOptionIndex(type.toString());
        if (idx == -1) {
            throw new ConverterException(String.format("Option value '%s' not found in datapoint '%s'",
                    type.toString(), new HmDatapointInfo(dp)));
        }
        return idx;
    }
}