}
return null;
}
private void deviceCall(String itemName, Command cm) {
Device device = deviceMap.get(itemName);
if (device != null) {
if (cm instanceof org.openhab.core.library.types.OnOffType) {
if (((org.openhab.core.library.types.OnOffType) cm)
.equals(OnOffType.ON)) {
boolean transmitted = digitalSTROM.turnDeviceOn(
getSessionToken(), device.getDSID(), null);
if (transmitted) {
device.setOutputValue(device.getMaxOutPutValue());
addEcho(device.getDSID().getValue(),
(short) ZoneSceneEnum.MAXIMUM.getSceneNumber());
}
} else if (((org.openhab.core.library.types.OnOffType) cm)
.equals(OnOffType.OFF)) {
boolean transmitted = digitalSTROM.turnDeviceOff(
getSessionToken(), device.getDSID(), null);
if (transmitted) {
device.setOutputValue(0);
addEcho(device.getDSID().getValue(),
(short) ZoneSceneEnum.MINIMUM.getSceneNumber());
}
}
} else if (cm instanceof org.openhab.core.library.types.IncreaseDecreaseType) {
if (!device.isDimmable()) {
logger.warn("device is not in dimm mode: " + itemName
+ " outputMode: "
+ device.getOutputMode().getMode());
return;
}
if (((org.openhab.core.library.types.IncreaseDecreaseType) cm)
.equals(IncreaseDecreaseType.INCREASE)) {
boolean transmitted = digitalSTROM.callDeviceScene(
getSessionToken(), device.getDSID(), null,
ZoneSceneEnum.INCREMENT, false);
if (transmitted) {
addEcho(device.getDSID().getValue(),
(short) ZoneSceneEnum.INCREMENT
.getSceneNumber());
if (device.getOutputValue() == 0) {
initDeviceOutputValue(device,
DeviceConstants.DEVICE_SENSOR_OUTPUT);
} else {
device.increase();
}
} else {
logger.error("transmitting increase command FAILED "
+ itemName);
}
} else if (((org.openhab.core.library.types.IncreaseDecreaseType) cm)
.equals(IncreaseDecreaseType.DECREASE)) {
boolean transmitted = digitalSTROM.callDeviceScene(
getSessionToken(), device.getDSID(), null,
ZoneSceneEnum.DECREMENT, false);
if (transmitted) {
addEcho(device.getDSID().getValue(),
(short) ZoneSceneEnum.DECREMENT
.getSceneNumber());
device.decrease();
} else {
logger.error("transmitting decrease command FAILED "
+ itemName);
}
}
} else if (cm instanceof org.openhab.core.library.types.PercentType) {
int percent = -1;
try {
percent = (int) Float.parseFloat(cm.toString());
} catch (java.lang.NumberFormatException e) {
logger.error("NumberFormatException on a PercentType with command: "
+ cm.toString());
}
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);