use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.
the class UrtsiBinding method sendToUrtsi.
/**
* The method determines the appropriate
* {@link org.openhab.core.binding.BindingProvider} and uses it to get the
* corresponding URTSI device and channel. Bases on the given type a command
* is send to the device.
*
* @param itemName
* name of the item
* @param type
* Type of the command or status update
* @return Returns true, if the command has been executed successfully.
* Returns false otherwise.
* @throws BindingConfigParseException
*/
private boolean sendToUrtsi(String itemName, Type type) {
UrtsiBindingProvider provider = null;
if (!providers.isEmpty()) {
provider = providers.iterator().next();
}
if (provider == null) {
logger.error("doesn't find matching binding provider [itemName={}, type={}]", itemName, type);
return false;
}
String urtsiDeviceId = provider.getDeviceId(itemName);
UrtsiDevice urtsiDevice = idToDeviceMap.get(urtsiDeviceId);
if (urtsiDevice == null) {
logger.error("No serial port has been configured for urtsi device id '{}'", urtsiDeviceId);
return false;
}
int channel = provider.getChannel(itemName);
int address = provider.getAddress(itemName);
logger.debug("Send to URTSI for item: {}; Type: {}", itemName, type);
String actionKey = null;
if (type instanceof UpDownType) {
switch((UpDownType) type) {
case UP:
actionKey = COMMAND_UP;
break;
case DOWN:
actionKey = COMMAND_DOWN;
break;
}
} else if (type instanceof StopMoveType) {
switch((StopMoveType) type) {
case STOP:
actionKey = COMMAND_STOP;
break;
default:
break;
}
}
logger.debug("Action key: {}", actionKey);
if (actionKey != null) {
String channelString = String.format("%02d", channel);
String addressString = String.format("%02d", address);
String command = addressString + channelString + actionKey;
boolean executedSuccessfully = urtsiDevice.writeString(command);
if (!executedSuccessfully) {
logger.warn("Command has not been processed [itemName={}, command={}]", itemName, command);
}
return executedSuccessfully;
}
return false;
}
use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.
the class ZWaveMultiLevelSwitchConverter method receiveCommand.
/**
* {@inheritDoc}
*/
@Override
public void receiveCommand(Item item, Command command, ZWaveNode node, ZWaveMultiLevelSwitchCommandClass commandClass, int endpointId, Map<String, String> arguments) {
SerialMessage serialMessage = null;
String restoreLastValue = null;
if (command instanceof StopMoveType && (StopMoveType) command == StopMoveType.STOP) {
// special handling for the STOP command
serialMessage = commandClass.stopLevelChangeMessage();
} else {
ZWaveCommandConverter<?, ?> converter = null;
if (command instanceof OnOffType) {
restoreLastValue = arguments.get("restore_last_value");
if ("true".equalsIgnoreCase(restoreLastValue)) {
converter = this.restoreValueOnOffConverter;
} else {
converter = this.normalOnOffConverter;
}
} else {
converter = this.getCommandConverter(command.getClass());
}
if (converter == null) {
logger.warn("NODE {}: No converter found for item = {}, endpoint = {}, ignoring command.", node.getNodeId(), item.getName(), endpointId);
return;
}
// Allow inversion of roller shutter UP/DOWN
if (converter instanceof MultiLevelUpDownCommandConverter) {
logger.debug("Multilevel Switch MultiLevelUpDownCommandConverter");
if ("true".equalsIgnoreCase(arguments.get("invert_state"))) {
logger.trace("Multilevel Switch MultiLevelUpDownCommandConverter - invert");
if (command == UpDownType.UP) {
command = UpDownType.DOWN;
} else {
command = UpDownType.UP;
}
logger.trace("Multilevel Switch MultiLevelUpDownCommandConverter - inverted: {}", command);
}
}
// Allow inversion of roller shutter PERCENT value
if (converter instanceof MultiLevelPercentCommandConverter) {
logger.debug("Multilevel Switch MultiLevelPercentCommandConverter");
if ("true".equalsIgnoreCase(arguments.get("invert_percent"))) {
logger.trace("Multilevel Switch MultiLevelPercentCommandConverter - invert");
command = new PercentType(100 - ((DecimalType) command).intValue());
logger.trace("Multilevel Switch MultiLevelPercentCommandConverter - inverted: {}", command);
}
}
Integer value = (Integer) converter.convertFromCommandToValue(item, command);
logger.trace("NODE {}: Converted command '{}' to value {} for item = {}, endpoint = {}.", node.getNodeId(), command.toString(), value, item.getName(), endpointId);
serialMessage = commandClass.setValueMessage(value);
}
// encapsulate the message in case this is a multi-instance node
serialMessage = node.encapsulate(serialMessage, commandClass, endpointId);
if (serialMessage == null) {
logger.warn("Generating message failed for command class = {}, node = {}, endpoint = {}", commandClass.getCommandClass().getLabel(), node.getNodeId(), endpointId);
return;
}
this.getController().sendData(serialMessage);
// update the bus in case of normal dimming. schedule refresh in case of restore to last value dimming.
if (!"true".equalsIgnoreCase(restoreLastValue) && command instanceof OnOffType && (OnOffType) command == OnOffType.ON) {
executeRefresh(node, commandClass, endpointId, arguments);
} else if (command instanceof State) {
this.getEventPublisher().postUpdate(item.getName(), (State) command);
}
}
use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.
the class FibaroFGRM222Converter method receiveCommand.
@Override
void receiveCommand(final Item item, final Command command, final ZWaveNode node, final FibaroFGRM222CommandClass commandClass, final int endpointId, final Map<String, String> arguments) {
logger.debug("NODE {}: receiveCommand()", node.getNodeId());
Command internalCommand = command;
SerialMessage serialMessage = null;
if (internalCommand instanceof StopMoveType && (StopMoveType) internalCommand == StopMoveType.STOP) {
// special handling for the STOP command
serialMessage = commandClass.stopLevelChangeMessage(arguments.get("type"));
} else {
ZWaveCommandConverter<?, ?> converter = this.getCommandConverter(command.getClass());
if (converter == null) {
logger.warn("NODE {}: No converter found for item = {}, endpoint = {}, ignoring command.", node.getNodeId(), item.getName(), endpointId);
return;
}
if (converter instanceof MultiLevelPercentCommandConverter) {
internalCommand = new PercentType(100 - ((DecimalType) command).intValue());
}
Integer value = (Integer) converter.convertFromCommandToValue(item, internalCommand);
if (value == 0) {
value = 1;
}
logger.trace("NODE {}: Converted command '{}' to value {} for item = {}, endpoint = {}.", node.getNodeId(), internalCommand.toString(), value, item.getName(), endpointId);
serialMessage = commandClass.setValueMessage(value, arguments.get("type"));
}
// encapsulate the message in case this is a multi-instance node
serialMessage = node.encapsulate(serialMessage, commandClass, endpointId);
if (serialMessage == null) {
logger.warn("NODE {}: Generating message failed for command class = {}, node = {}, endpoint = {}", node.getNodeId(), commandClass.getCommandClass().getLabel(), endpointId);
return;
}
this.getController().sendData(serialMessage);
if (command instanceof State) {
this.getEventPublisher().postUpdate(item.getName(), (State) command);
}
}
use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.
the class InsteonHubBinding method internalReceiveCommand.
@Override
protected void internalReceiveCommand(String itemName, Command command) {
// get configuration for this item
InsteonHubBindingConfig config = InsteonHubBindingConfigUtil.getConfigForItem(providers, itemName);
if (config == null) {
logger.error(BINDING_NAME + " received command for unknown item '" + itemName + "'");
return;
}
// parse info from config
BindingType type = config.getBindingType();
String hubId = config.getDeviceInfo().getHubId();
String deviceId = config.getDeviceInfo().getDeviceId();
// lookup proxy from this configuration
InsteonHubProxy proxy = proxies.get(hubId);
if (proxy == null) {
logger.error(BINDING_NAME + " received command for unknown hub id '" + hubId + "'");
return;
}
if (logger.isDebugEnabled()) {
logger.debug(BINDING_NAME + " processing command '" + command + "' of type '" + command.getClass().getSimpleName() + "' for item '" + itemName + "'");
}
try {
// process according to type
if (type == BindingType.SWITCH) {
// set value on or off
if (command instanceof OnOffType) {
proxy.setDevicePower(deviceId, command == OnOffType.ON);
}
} else if (type == BindingType.DIMMER) {
// INSTEON Dimmer supports Dimmer and RollerShutter types
if (command instanceof OnOffType) {
// ON or OFF => Set level to 255 or 0
int level = command == OnOffType.ON ? 255 : 0;
proxy.setDeviceLevel(deviceId, level);
} else if (command instanceof IncreaseDecreaseType) {
// Increase/Decrease => Incremental Brighten/Dim
InsteonHubAdjustmentType adjustmentType;
if (command == IncreaseDecreaseType.INCREASE) {
adjustmentType = InsteonHubAdjustmentType.BRIGHTEN;
} else {
adjustmentType = InsteonHubAdjustmentType.DIM;
}
if (setDimTimeout(itemName)) {
proxy.startDeviceAdjustment(deviceId, adjustmentType);
}
} else if (command instanceof UpDownType) {
// Up/Down => Start Brighten/Dim
InsteonHubAdjustmentType adjustmentType;
if (command == UpDownType.UP) {
adjustmentType = InsteonHubAdjustmentType.BRIGHTEN;
} else {
adjustmentType = InsteonHubAdjustmentType.DIM;
}
proxy.startDeviceAdjustment(deviceId, adjustmentType);
} else if (command instanceof StopMoveType) {
// Stop => Stop Brighten/Dim
if (command == StopMoveType.STOP) {
proxy.stopDeviceAdjustment(deviceId);
}
} else {
// set level from 0 to 100 percent value
byte percentByte = Byte.parseByte(command.toString());
float percent = percentByte * .01f;
int level = (int) (255 * percent);
proxy.setDeviceLevel(deviceId, level);
}
}
} catch (Throwable t) {
logger.error("Error processing command '" + command + "' for item '" + itemName + "'", t);
}
}
use of org.openhab.core.library.types.StopMoveType in project openhab1-addons by openhab.
the class KNXCoreTypeMapper method toDPTValue.
/*
* (non-Javadoc)
*
* @see org.openhab.binding.knx.config.KNXTypeMapper#toDPTValue(org.openhab.core.types.Type, java.lang.String)
*/
@Override
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);
} else {
return "activate " + intVal;
}
default:
return type.toString();
}
} else if (type instanceof StringType) {
return type.toString();
} else if (type instanceof DateTimeType) {
return formatDateTime((DateTimeType) type, dptID);
}
logger.debug("toDPTValue: Couldn't get value for {} dpt id {} (no mapping).", type, dptID);
return null;
}
Aggregations