use of org.openhab.binding.tinkerforge.internal.model.PercentTypeActor in project openhab1-addons by openhab.
the class TinkerforgeBinding method internalReceiveCommand.
/**
* {@inheritDoc}
*
* Searches the item with the given {@code itemName} in the {@link TinkerforgeBindingProvider}
* collection and gets the uid and subid of the device. The appropriate device is searched in the
* ecosystem and the command is executed on the device.
*
* {@code OnOffType} commands are executed on {@link MInSwitchActor} objects. {@code StringType}
* commands are executed on {@link MTextActor} objects.
*
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
logger.debug("received command {} for item {}", command, itemName);
for (TinkerforgeBindingProvider provider : providers) {
for (String itemNameP : provider.getItemNames()) {
if (itemNameP.equals(itemName)) {
String deviceUid = provider.getUid(itemName);
String deviceSubId = provider.getSubId(itemName);
String deviceName = provider.getName(itemName);
if (deviceName != null) {
String[] ids = getDeviceIdsForDeviceName(deviceName);
deviceUid = ids[0];
deviceSubId = ids[1];
}
logger.trace("{} found item for command: uid: {}, subid: {}", LoggerConstants.COMMAND, deviceUid, deviceSubId);
MBaseDevice mDevice = tinkerforgeEcosystem.getDevice(deviceUid, deviceSubId);
if (mDevice != null && mDevice.getEnabledA().get()) {
if (command instanceof OnOffType) {
logger.trace("{} found onoff command", LoggerConstants.COMMAND);
OnOffType cmd = (OnOffType) command;
if (mDevice instanceof MSwitchActor) {
OnOffValue state = cmd == OnOffType.OFF ? OnOffValue.OFF : OnOffValue.ON;
((MSwitchActor) mDevice).turnSwitch(state);
} else if (mDevice instanceof DigitalActor) {
HighLowValue state = cmd == OnOffType.OFF ? HighLowValue.LOW : HighLowValue.HIGH;
((DigitalActor) mDevice).turnDigital(state);
} else if (mDevice instanceof ProgrammableSwitchActor) {
OnOffValue state = cmd == OnOffType.OFF ? OnOffValue.OFF : OnOffValue.ON;
((ProgrammableSwitchActor) mDevice).turnSwitch(state, provider.getDeviceOptions(itemName));
} else {
logger.error("{} received OnOff command for non-SwitchActor", LoggerConstants.COMMAND);
}
} else if (command instanceof StringType) {
logger.trace("{} found string command", LoggerConstants.COMMAND);
if (mDevice instanceof MTextActor) {
((MTextActor) mDevice).write(command.toString());
}
} else if (command instanceof DecimalType) {
logger.debug("{} found number command", LoggerConstants.COMMAND);
if (command instanceof HSBType) {
logger.debug("{} found HSBType command", LoggerConstants.COMMAND);
if (mDevice instanceof ProgrammableColorActor) {
logger.debug("{} found ProgrammableColorActor {}", itemName);
((ProgrammableColorActor) mDevice).setSelectedColor((HSBType) command, provider.getDeviceOptions(itemName));
} else if (mDevice instanceof SimpleColorActor) {
logger.debug("{} found SimpleColorActor {}", itemName);
((SimpleColorActor) mDevice).setSelectedColor((HSBType) command);
}
} else if (command instanceof PercentType) {
if (mDevice instanceof SetPointActor) {
((SetPointActor<?>) mDevice).setValue(((PercentType) command), provider.getDeviceOptions(itemName));
logger.debug("found SetpointActor");
} else if (mDevice instanceof PercentTypeActor) {
((PercentTypeActor) mDevice).setValue(((PercentType) command), provider.getDeviceOptions(itemName));
logger.debug("found PercentType actor");
} else {
logger.error("found no percenttype actor");
}
} else {
if (mDevice instanceof NumberActor) {
((NumberActor) mDevice).setNumber(((DecimalType) command).toBigDecimal());
} else if (mDevice instanceof SetPointActor) {
((SetPointActor<?>) mDevice).setValue(((DecimalType) command).toBigDecimal(), provider.getDeviceOptions(itemName));
} else {
logger.error("found no number actor");
}
}
} else if (command instanceof UpDownType) {
UpDownType cmd = (UpDownType) command;
logger.debug("{} UpDownType command {}", itemName, cmd);
if (mDevice instanceof MoveActor) {
((MoveActor) mDevice).move((UpDownType) command, provider.getDeviceOptions(itemName));
}
} else if (command instanceof StopMoveType) {
StopMoveType cmd = (StopMoveType) command;
if (mDevice instanceof MoveActor) {
if (cmd == StopMoveType.STOP) {
((MoveActor) mDevice).stop();
} else {
((MoveActor) mDevice).moveon(provider.getDeviceOptions(itemName));
}
}
logger.debug("{} StopMoveType command {}", itemName, cmd);
} else if (command instanceof IncreaseDecreaseType) {
IncreaseDecreaseType cmd = (IncreaseDecreaseType) command;
if (mDevice instanceof DimmableActor) {
((DimmableActor<?>) mDevice).dimm((IncreaseDecreaseType) command, provider.getDeviceOptions(itemName));
}
logger.debug("{} IncreaseDecreaseType command {}", itemName, cmd);
} else {
logger.error("{} got unknown command type: {}", LoggerConstants.COMMAND, command.toString());
}
} else {
logger.error("{} no tinkerforge device found for command for item uid: {} subId: {}", LoggerConstants.COMMAND, deviceUid, deviceSubId);
}
}
}
}
}
Aggregations