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;
}
Aggregations