use of org.openhab.core.types.Command in project openhab1-addons by openhab.
the class WindowHandleProfile method valueChanged.
@Override
public void valueChanged(ParameterAddress parameterAddress, Value valueObject) {
Command command = null;
if (valueObject.getValue().equals(Positions.DOWN.toString())) {
command = new StringType("CLOSED");
} else if (valueObject.getValue().equals(Positions.MIDDLE.toString())) {
command = new StringType("OPEN");
} else if (valueObject.getValue().equals(Positions.UP.toString())) {
command = new StringType("AJAR");
}
postCommand(command);
}
use of org.openhab.core.types.Command in project openhab1-addons by openhab.
the class KNXBinding method readFromKNX.
/**
* Handles the given {@link ProcessEvent}. After finding the corresponding
* Item (by iterating through all known group addresses) this Item is updated.
* Each item is added to a special list to identify and avoid echo's in
* the <code>receiveUpdate</code> and <code>receiveCommand</code> methods.
*
* @param e the {@link ProcessEvent} to handle.
*/
private void readFromKNX(ProcessEvent e) {
try {
GroupAddress destination = e.getDestination();
byte[] asdu = e.getASDU();
if (asdu.length == 0) {
return;
}
String[] itemList = getItemNames(destination);
if (itemList.length == 0) {
logger.debug("Received telegram for unknown group address {}", destination.toString());
}
for (String itemName : itemList) {
Iterable<Datapoint> datapoints = getDatapoints(itemName, destination);
if (datapoints != null) {
for (Datapoint datapoint : datapoints) {
Type type = getType(datapoint, asdu);
if (type != null) {
if (type instanceof Command && isStartStopEnabled(itemName, destination, datapoint)) {
if (isDimmerThreadRunning(itemName) && type == IncreaseDecreaseType.INCREASE) {
stopDimmerThread(itemName);
} else {
startDimmerThread(destination, itemName, (Command) type);
}
} else {
sendTypeToItemButNotToKnx(destination, itemName, type);
}
} else {
final char[] hexCode = "0123456789ABCDEF".toCharArray();
StringBuilder sb = new StringBuilder(2 + asdu.length * 2);
sb.append("0x");
for (byte b : asdu) {
sb.append(hexCode[(b >> 4) & 0xF]);
sb.append(hexCode[(b & 0xF)]);
}
logger.debug("Ignoring KNX bus data: couldn't transform to an openHAB type (not supported). Destination='{}', datapoint='{}', data='{}'", new Object[] { destination.toString(), datapoint.toString(), sb.toString() });
}
}
}
}
} catch (RuntimeException re) {
logger.error("Error while receiving event from KNX bus: " + re.toString());
}
}
use of org.openhab.core.types.Command in project openhab1-addons by openhab.
the class IRtransGenericBindingProvider method parseBindingConfig.
/**
* Parses the binding config.
*
* @param config the config
* @param item the item
* @param bindingConfig the binding config
* @throws BindingConfigParseException the binding config parse exception
*/
private void parseBindingConfig(IRtransBindingConfig config, Item item, String bindingConfig) throws BindingConfigParseException {
String commandAsString = null;
String host = null;
String port = null;
String led = null;
String remote = null;
String irCommand = null;
Leds ledType = Leds.DEFAULT;
if (bindingConfig != null) {
Matcher actionMatcher = ACTION_CONFIG_PATTERN.matcher(bindingConfig);
Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig);
if ((!actionMatcher.matches() && !statusMatcher.matches())) {
throw new BindingConfigParseException(getBindingType() + " binding configuration must consist of five [config=" + statusMatcher.pattern() + "] or six parts [config=" + actionMatcher.pattern() + "]");
} else {
if (actionMatcher.matches()) {
commandAsString = actionMatcher.group(1);
host = actionMatcher.group(2);
port = actionMatcher.group(3);
led = actionMatcher.group(4);
remote = actionMatcher.group(5);
irCommand = actionMatcher.group(6);
} else if (statusMatcher.matches()) {
host = statusMatcher.group(1);
port = statusMatcher.group(2);
led = statusMatcher.group(3);
remote = statusMatcher.group(4);
irCommand = statusMatcher.group(5);
}
if (led.equals("*")) {
ledType = Leds.ALL;
} else {
ledType = Leds.valueOf(led);
}
IRtransBindingConfigElement newElement = new IRtransBindingConfigElement(host, port, ledType, remote, irCommand, item.getAcceptedDataTypes());
Command command = null;
if (commandAsString == null) {
// for those configuration strings that are not really linked to a openHAB command we
// create a dummy Command to be able to store the configuration information
// I have choosen to do that with NumberItems
NumberItem dummy = new NumberItem(Integer.toString(counter));
command = createCommandFromString(dummy, Integer.toString(counter));
counter++;
config.put(command, newElement);
} else {
command = createCommandFromString(item, commandAsString);
config.put(command, newElement);
}
config.put(command, newElement);
}
} else {
return;
}
}
use of org.openhab.core.types.Command in project openhab1-addons by openhab.
the class ExecGenericBindingProvider method parseLegacyOutBindingConfig.
protected void parseLegacyOutBindingConfig(Item item, String bindingConfig, ExecBindingConfig config) throws BindingConfigParseException {
String command = StringUtils.substringBefore(bindingConfig, ":").trim();
String tmpCommandLine = StringUtils.substringAfter(bindingConfig, ":").trim();
if (StringUtils.isBlank(command) && StringUtils.isBlank(tmpCommandLine)) {
return;
}
String commandLine;
// if commandLine is surrounded by quotes, life is easy ...
if (tmpCommandLine.startsWith("'")) {
commandLine = tmpCommandLine.substring(1).split("(?<!\\\\)'")[0];
// is there another command we have to parse?
String tail = tmpCommandLine.replaceFirst(".*(?<!\\\\)' ?,", "").trim();
if (!tail.isEmpty()) {
parseLegacyOutBindingConfig(item, tail, config);
}
} else {
// if not, we have to search for the next "," (if there are more than
// one commandLines) or for the end of this line.
String[] tmpCommandLineElements = tmpCommandLine.split("(?<!\\\\),");
if (tmpCommandLineElements.length == 0) {
commandLine = tmpCommandLine;
} else {
commandLine = tmpCommandLineElements[0];
String tail = StringUtils.join(tmpCommandLineElements, ", ", 1, tmpCommandLineElements.length);
parseLegacyOutBindingConfig(item, tail, config);
}
}
ExecBindingConfigElement configElement = new ExecBindingConfigElement();
configElement.commandLine = commandLine.replaceAll("(?<!\\\\)\\\\", "");
Command cmd = createCommandFromString(item, command);
config.put(cmd, configElement);
}
use of org.openhab.core.types.Command in project openhab1-addons by openhab.
the class ExecGenericBindingProvider method parseOutBindingConfig.
protected ExecBindingConfig parseOutBindingConfig(Item item, String bindingConfig, ExecBindingConfig config) throws BindingConfigParseException {
Matcher matcher = OUT_BINDING_PATTERN.matcher(bindingConfig);
if (!matcher.matches()) {
throw new BindingConfigParseException("bindingConfig '" + bindingConfig + "' doesn't represent a valid in-binding-configuration.");
}
matcher.reset();
ExecBindingConfigElement configElement;
while (matcher.find()) {
Command command = createCommandFromString(item, matcher.group(1));
configElement = new ExecBindingConfigElement();
configElement.commandLine = matcher.group(2).replaceAll("\\\\\"", "");
config.put(command, configElement);
}
return config;
}
Aggregations