Search in sources :

Example 1 with HmValueType

use of org.eclipse.smarthome.binding.homematic.internal.model.HmValueType in project smarthome by eclipse.

the class CommonRpcParser method assembleDatapoint.

/**
 * Assembles a datapoint with the given parameters.
 */
protected HmDatapoint assembleDatapoint(String name, String unit, String type, String[] options, Object min, Object max, Integer operations, Object defaultValue, HmParamsetType paramsetType, boolean isHmIpDevice) throws IOException {
    HmDatapoint dp = new HmDatapoint();
    dp.setName(name);
    dp.setDescription(name);
    dp.setUnit(StringUtils.replace(StringUtils.trimToNull(unit), "\ufffd", "°"));
    if (dp.getUnit() == null && StringUtils.startsWith(dp.getName(), "RSSI_")) {
        dp.setUnit("dBm");
    }
    HmValueType valueType = HmValueType.parse(type);
    if (valueType == null || valueType == HmValueType.UNKNOWN) {
        throw new IOException("Unknown datapoint type: " + type);
    }
    dp.setType(valueType);
    dp.setOptions(options);
    if (dp.isNumberType() || dp.isEnumType()) {
        if (isHmIpDevice && dp.isEnumType()) {
            dp.setMinValue(dp.getOptionIndex(toString(min)));
            dp.setMaxValue(dp.getOptionIndex(toString(max)));
        } else {
            dp.setMinValue(toNumber(min));
            dp.setMaxValue(toNumber(max));
        }
    }
    dp.setReadOnly((operations & 2) != 2);
    dp.setReadable((operations & 1) == 1);
    dp.setParamsetType(paramsetType);
    if (isHmIpDevice && dp.isEnumType()) {
        dp.setDefaultValue(dp.getOptionIndex(toString(defaultValue)));
    } else {
        dp.setDefaultValue(convertToType(dp, defaultValue));
    }
    dp.setValue(dp.getDefaultValue());
    return dp;
}
Also used : HmValueType(org.eclipse.smarthome.binding.homematic.internal.model.HmValueType) IOException(java.io.IOException) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)

Aggregations

IOException (java.io.IOException)1 HmDatapoint (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)1 HmValueType (org.eclipse.smarthome.binding.homematic.internal.model.HmValueType)1