use of org.openhab.binding.energenie.internal.EnergenieBindingConfig.ChannelTypeDef in project openhab1-addons by openhab.
the class EnergenieGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
try {
if (bindingConfig != null) {
String[] configParts = bindingConfig.split(";");
if (configParts.length < 2 || configParts.length > 2) {
throw new BindingConfigParseException("energenie binding configuration must have 2 parts");
}
String itemType = item.toString();
if (item instanceof SwitchItem) {
if ((configParts[1].equals("1")) || (configParts[1].equals("2")) || (configParts[1].equals("3")) || (configParts[1].equals("4"))) {
BindingConfig energenieBindingConfig = new EnergenieBindingConfig(configParts[0], configParts[1], itemType);
addBindingConfig(item, energenieBindingConfig);
} else {
throw new BindingConfigParseException("Your SwitchItem configuration does not contain channelNumbers");
}
} else if (item instanceof NumberItem) {
ChannelTypeDef channelType = ChannelTypeDef.valueOf(configParts[1].trim());
if (channelType != null) {
BindingConfig energenieBindingConfig = new EnergenieBindingConfig(configParts[0], configParts[1], itemType);
addBindingConfig(item, energenieBindingConfig);
} else {
throw new BindingConfigParseException("Your NumberItem configuration does not contain channelTypes");
}
}
} else {
logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!");
}
} catch (ArrayIndexOutOfBoundsException e) {
logger.warn("bindingConfig is invalid (item=" + item + ") -> processing bindingConfig aborted!");
}
}
use of org.openhab.binding.energenie.internal.EnergenieBindingConfig.ChannelTypeDef in project openhab1-addons by openhab.
the class EnergenieBinding method processNumberItem.
/**
* @{inheritDoc}
*/
private void processNumberItem(EnergenieBindingConfig deviceConfig, String loginResponseString, String pwmChannelType, String itemName) {
String stateResponseSearch = "";
int start = 0, stop = 0, divisor = 1;
double value = 0.0;
ChannelTypeDef channelType = ChannelTypeDef.valueOf(pwmChannelType);
switch(channelType) {
case VOLTAGE:
stateResponseSearch = "var V = ";
start = 9;
stop = 20;
divisor = 10;
break;
case CURRENT:
stateResponseSearch = "var I = ";
start = 9;
stop = 20;
divisor = 100;
break;
case POWER:
stateResponseSearch = "var P=";
start = 6;
stop = 20;
divisor = 466;
break;
case ENERGY:
stateResponseSearch = "var E=";
start = 6;
stop = 20;
divisor = 25600;
break;
case NONE:
break;
default:
break;
}
int findState = loginResponseString.lastIndexOf(stateResponseSearch);
if (findState > 0) {
logger.trace("searchstring {} found at position {}", stateResponseSearch, findState);
String slicedResponseTmp = loginResponseString.substring(findState + start, findState + stop);
logger.trace("transformed state response = {}", slicedResponseTmp);
String[] slicedResponse = slicedResponseTmp.split(";");
logger.trace("transformed state response = {} - {}", slicedResponse[0], slicedResponse[1]);
if (Double.parseDouble(slicedResponse[0]) / 1 == Double.parseDouble(slicedResponse[0])) {
value = Double.parseDouble(slicedResponse[0]) / divisor;
} else {
value = -1.0;
}
logger.trace("transformed state for item {} = {}", itemName, value);
State newState = new DecimalType(value);
eventPublisher.postUpdate(itemName, newState);
} else {
logger.trace("searchstring %s not found", stateResponseSearch);
}
}
Aggregations