if (percent != -1) {
if (percent > -1 && percent < 101) {
if (device.getOutputMode().equals(OutputModeEnum.SLAT)) {
DigitalSTROMBindingConfig confItem = getConfigForItemName(itemName);
if (confItem != null) {
if (confItem.context != null
&& confItem.context
.equals(ContextConfig.slat)) {
int old = device.getSlatPosition();
device.setSlatPosition(fromPercentToValue(
percent,
device.getMaxSlatPosition()));
boolean transmitted = digitalSTROM
.setDeviceOutputValue(
getSessionToken(),
device.getDSID(),
null,
DeviceConstants.DEVICE_SENSOR_SLAT_OUTPUT,
fromPercentToValue(
percent,
device.getMaxSlatPosition()));
if (!transmitted) {
device.setSlatPosition(old);
logger.error("could NOT successfully set new value for slats ..."
+ cm.toString());
}
} else {
int old = device.getOutputValue();
device.setOutputValue(fromPercentToValue(
percent, device.getMaxOutPutValue()));
boolean transmitted = digitalSTROM
.setDeviceValue(
getSessionToken(),
device.getDSID(),
null,
fromPercentToValue(
percent,
device.getMaxOutPutValue()));
if (!transmitted) {
device.setOutputValue(old);
logger.error("could NOT successfully set new value ..."
+ cm.toString());
}
}
}
} else {
int old = device.getOutputValue();
device.setOutputValue(fromPercentToValue(percent,
device.getMaxOutPutValue()));
boolean transmitted = digitalSTROM.setDeviceValue(
getSessionToken(),
device.getDSID(),
null,
fromPercentToValue(percent,
device.getMaxOutPutValue()));
if (!transmitted) {
device.setOutputValue(old);
logger.error("could NOT successfully set new value ..."
+ cm.toString());
}
}
}
}
} else if (cm instanceof org.openhab.core.library.types.StopMoveType) {
if (device.getOutputMode().equals(OutputModeEnum.SLAT)) {
DigitalSTROMBindingConfig confItem = getConfigForItemName(itemName);
if (confItem != null) {
if (confItem.context != null
&& confItem.context.equals(ContextConfig.slat)) {
logger.warn("stop and move command NOT possible for slats, use PercentType command or up and down please");
} else {
handleStopMoveForRollershutter(device, cm);
}
}
} else if (device.getOutputMode()
.equals(OutputModeEnum.UP_DOWN)) {
handleStopMoveForRollershutter(device, cm);
}
} else if (cm instanceof org.openhab.core.library.types.UpDownType) {
if (device.getOutputMode().equals(OutputModeEnum.SLAT)) {
// 255 is max open, 0 is closed
DigitalSTROMBindingConfig confItem = getConfigForItemName(itemName);
if (confItem != null) {
if (confItem.context != null
&& confItem.context.equals(ContextConfig.slat)) {
if (((org.openhab.core.library.types.UpDownType) cm)
.equals(UpDownType.UP)) {
int slatPosition = device.getSlatPosition();
int newPosition = slatPosition
+ DeviceConstants.MOVE_STEP_SLAT;
if (newPosition > device.getMaxSlatPosition()) {
newPosition = device.getMaxSlatPosition();
}
boolean transmitted = digitalSTROM
.setDeviceOutputValue(
getSessionToken(),
device.getDSID(),
null,
DeviceConstants.DEVICE_SENSOR_SLAT_OUTPUT,
newPosition);
if (transmitted) {
device.setSlatPosition(newPosition);
}
} else if (((org.openhab.core.library.types.UpDownType) cm)
.equals(UpDownType.DOWN)) {
int slatPosition = device.getSlatPosition();
int newPosition = slatPosition
- DeviceConstants.MOVE_STEP_SLAT;
if (newPosition < device.getMinSlatPosition()) {
newPosition = device.getMinSlatPosition();
}
boolean transmitted = digitalSTROM
.setDeviceOutputValue(
getSessionToken(),
device.getDSID(),
null,
DeviceConstants.DEVICE_SENSOR_SLAT_OUTPUT,
newPosition);
if (transmitted) {
device.setSlatPosition(newPosition);
}
}
} else {
handleUpDownForRollershutter(device, cm);
}
}
} else if (device.getOutputMode()
.equals(OutputModeEnum.UP_DOWN)) {
handleUpDownForRollershutter(device, cm);
} else {
logger.warn("Wrong item configuration ... this hardware is not a rollershutter: "
+ itemName);
}
}
} else {
// this item is not mapped to real hardware, it is to make scene
// calls (as they are known in digitalSTROM)
if (cm instanceof DecimalType) {
DigitalSTROMBindingConfig confItem = getConfigForItemName(itemName);
if (confItem != null && confItem.context != null) {
if (confItem.context.equals(ContextConfig.apartment)) {
digitalSTROM.callApartmentScene(getSessionToken(),
confItem.groupID, null, ApartmentSceneEnum
.getApartmentScene(((DecimalType) cm)
.intValue()), false);
} else if (confItem.context.equals(ContextConfig.zone)) {
digitalSTROM.callZoneScene(getSessionToken(),
confItem.zoneID, null, confItem.groupID, null,
ZoneSceneEnum.getZoneScene(((DecimalType) cm)
.intValue()), false);
}
}
} else if (cm instanceof StringType) {
DigitalSTROMBindingConfig confItem = getConfigForItemName(itemName);
if (confItem != null && confItem.context != null) {
int scene = -1;
try {
scene = Integer.parseInt(cm.toString());
} catch (java.lang.NumberFormatException e) {