use of org.openhab.binding.autelis.AutelisBindingProvider in project openhab1-addons by openhab.
the class AutelisBinding method internalReceiveCommand.
/**
* @{inheritDoc}
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
logger.trace("internalReceiveCommand({},{}) is called!", itemName, command);
for (AutelisBindingProvider provider : providers) {
Item item = provider.getItem(itemName);
String config = provider.getAutelisBindingConfigString(itemName);
Matcher m = commandPattern.matcher(config);
if (m.find() && m.groupCount() > 1) {
String type = m.group(1);
String name = m.group(2);
if (type.equals(AUTELIS_TYPES_EQUIP)) {
String cmd = AUTELIS_CMD_VALUE;
int value;
if (command == OnOffType.OFF) {
value = 0;
} else if (command == OnOffType.ON) {
value = 1;
} else if (command instanceof DecimalType) {
value = ((DecimalType) item.getStateAs(DecimalType.class)).intValue();
if (value >= 3) {
// this is a dim type. not sure what 2 does
cmd = AUTELIS_CMD_DIM;
}
} else {
logger.error("Equipment commands must be of Decimal type not {}", command);
break;
}
String response = HttpUtil.executeUrl("GET", baseURL + "/set.cgi?name=" + name + "&" + cmd + "=" + value, TIMEOUT);
logger.trace("equipment set {} {} {} : result {}", name, cmd, value, response);
} else if (type.equals(AUTELIS_TYPES_TEMP)) {
String value;
if (command == IncreaseDecreaseType.INCREASE) {
value = AUTELIS_CMD_UP;
} else if (command == IncreaseDecreaseType.DECREASE) {
value = AUTELIS_CMD_DOWN;
} else {
value = command.toString();
}
String cmd;
// name ending in sp are setpoints, ht are heat types?
if (name.endsWith(AUTELIS_SETPOINT)) {
cmd = AUTELIS_TYPES_TEMP;
} else if (name.endsWith(AUTELIS_HEATTYPE)) {
cmd = AUTELIS_CMD_HEAT;
} else {
logger.error("Unknown temp type {}", name);
break;
}
String response = HttpUtil.executeUrl("GET", baseURL + "/set.cgi?wait=1&name=" + name + "&" + cmd + "=" + value, TIMEOUT);
logger.trace("temp set {} {} : result {}", cmd, value, response);
}
} else if (config.equals(AUTELIS_TYPES_LIGHTS)) {
/*
* lighting command
* possible values, but we will let anything through.
* alloff, allon, csync, cset, cswim, party, romance, caribbean, american,
* sunset, royalty, blue, green, red, white, magenta, hold, recall
*/
String response = HttpUtil.executeUrl("GET", baseURL + "lights.cgi?val=" + command.toString(), TIMEOUT);
logger.trace("lights set {} : result {}", command.toString(), response);
} else {
logger.error("Unsupported set config {}", config);
}
}
scheduleClearTime(UPDATE_CLEARTIME);
}
use of org.openhab.binding.autelis.AutelisBindingProvider in project openhab1-addons by openhab.
the class AutelisBinding method execute.
/**
* @{inheritDoc}
*/
@Override
protected void execute() {
logger.trace("Connecting to {}" + baseURL);
clearState();
String xmlDoc = fetchStateFromController();
if (xmlDoc == null) {
return;
}
for (AutelisBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
Item item = provider.getItem(itemName);
String config = provider.getAutelisBindingConfigString(itemName);
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
try {
InputSource is = new InputSource(new StringReader(xmlDoc));
String value = xpath.evaluate("response/" + config.replace('.', '/'), is);
State state = toState(item.getClass(), value);
State oldState = stateMap.put(itemName, state);
if (!state.equals(oldState)) {
logger.debug("updating item {} with state {}", itemName, state);
eventPublisher.postUpdate(itemName, state);
}
} catch (XPathExpressionException e) {
logger.warn("could not parse xml", e);
}
}
}
}
Aggregations