/* (non-Javadoc)
* @see org.openhab.binding.knx.config.KNXTypeMapper#toDPTValue(org.openhab.core.types.Type, java.lang.String)
*/
public String toDPTValue(Type type, String dptID) {
DPT dpt;
int mainNumber = getMainNumber(dptID);
if (mainNumber == -1) {
logger.error("toDPTValue couldn't identify mainnumber in dptID: {}",dptID);
return null;
}
try {
DPTXlator translator = TranslatorTypes.createTranslator(mainNumber, dptID);
dpt=translator.getType();
} catch (KNXException e) {
e.printStackTrace();
return null;
}
//check for HSBType first, because it extends PercentType as well
if(type instanceof HSBType) {
Color color = ((HSBType)type).toColor();
return "r:" + Integer.toString(color.getRed()) + " g:" + Integer.toString(color.getGreen()) + " b:" + Integer.toString(color.getBlue());
} else if(type instanceof OnOffType) {
return type.equals(OnOffType.OFF)?dpt.getLowerValue():dpt.getUpperValue();
} else if(type instanceof UpDownType) {
return type.equals(UpDownType.UP)?dpt.getLowerValue():dpt.getUpperValue();
} else if(type instanceof IncreaseDecreaseType) {
DPT valueDPT = ((DPTXlator3BitControlled.DPT3BitControlled) dpt).getControlDPT();
return type.equals(IncreaseDecreaseType.DECREASE)?valueDPT.getLowerValue()+" 5":valueDPT.getUpperValue()+" 5";
} else if(type instanceof OpenClosedType) {
return type.equals(OpenClosedType.CLOSED)?dpt.getLowerValue():dpt.getUpperValue();
} else if(type instanceof StopMoveType) {
return type.equals(StopMoveType.STOP)?dpt.getLowerValue():dpt.getUpperValue();
} else if(type instanceof PercentType) {
return type.toString();
} else if(type instanceof DecimalType) {
switch (mainNumber) {
case 2:
DPT valueDPT = ((DPTXlator1BitControlled.DPT1BitControlled) dpt).getValueDPT();
switch (((DecimalType) type).intValue()) {
case 0: return "0 "+valueDPT.getLowerValue();
case 1: return "0 "+valueDPT.getUpperValue();
case 2: return "1 "+valueDPT.getLowerValue();
default:
return "1 "+valueDPT.getUpperValue();
}
case 18:
int intVal=((DecimalType) type).intValue();
if (intVal > 63) {
return "learn "+(intVal-0x80);