use of org.openhab.binding.tellstick.TellstickBindingConfig in project openhab1-addons by openhab.
the class TellstickGenericBindingProvider method getDevice.
@Override
public TellstickDevice getDevice(String itemName) {
TellstickDevice res = null;
TellstickBindingConfig conf = getTellstickBindingConfig(itemName);
if (conf != null) {
for (TellstickDevice device : getAllDevices()) {
if (device.getId() == conf.getId()) {
res = device;
break;
}
}
} else {
logger.warn("Could not find conf for " + itemName);
}
return res;
}
use of org.openhab.binding.tellstick.TellstickBindingConfig in project openhab1-addons by openhab.
the class TellstickBinding method internalReceiveCommand.
/**
* @{inheritDoc
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
// the code being executed when a command was sent on the openHAB
// event bus goes here. This method is only called if one of the
// BindingProviders provide a binding for the given 'itemName'.
logger.debug("internalReceiveCommand() is called! for " + itemName + " with " + command);
TellstickBindingConfig config = findTellstickBindingConfig(itemName);
if (config != null) {
if (!controllerThread.isAlive()) {
controllerThread.start();
}
TellstickDevice dev = findDevice(config);
Long eventTime = System.currentTimeMillis();
synchronized (messageQue) {
messageQue.put(dev, new TellstickSendEvent(config, dev, command, eventTime));
messageQue.notify();
}
}
}
use of org.openhab.binding.tellstick.TellstickBindingConfig in project openhab1-addons by openhab.
the class TellstickGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
TellstickBindingConfig config = new TellstickBindingConfig();
config.setItemName(item.getName());
String[] configParts = bindingConfig.trim().split(":");
if (configParts.length < 1) {
throw new BindingConfigParseException("Tellstick binding must contain two parts separated by ':'");
}
TellstickDevice device;
try {
device = findDevice(configParts[0].trim());
} catch (SupportedMethodsException e) {
throw new BindingConfigParseException(e.getMessage());
}
validateBinding(item, configParts, device);
if (device == null) {
config.setId(Integer.valueOf(configParts[0].trim()));
} else {
config.setId(device.getId());
}
config.setValueSelector(TellstickValueSelector.getValueSelector(configParts[1].trim()));
if (configParts.length > 2 && configParts[2].trim().length() > 0) {
config.setUsageSelector(TellstickValueSelector.getValueSelector(configParts[2].trim()));
}
if (configParts.length > 3) {
if (isIntegerRegex(configParts[3])) {
config.setResend(Integer.parseInt(configParts[3]));
} else if (configParts[3].matches("^([0-9]+)/([0-9]+)$")) {
// Parse ie '3/300' into resend=3 and resendInterval=300
String[] resendParts = configParts[3].split("/");
config.setResend(Integer.parseInt(resendParts[0]));
config.setResendInterval(Long.parseLong(resendParts[1]));
} else {
config.setProtocol(configParts[3]);
}
}
logger.debug("Context:" + context + " Item " + item + " Conf:" + config);
addBindingConfig(item, config);
}
use of org.openhab.binding.tellstick.TellstickBindingConfig in project openhab1-addons by openhab.
the class TellstickBinding method handleDeviceEvent.
private void handleDeviceEvent(TellstickDeviceEvent event) {
TellstickDevice device = event.getDevice();
controller.setLastSend(System.currentTimeMillis());
logger.debug("Got deviceEvent for " + device + " name:" + device + " method " + event.getMethod());
if (device != null) {
State cmd = resolveCommand(event.getMethod(), event.getData());
TellstickBindingConfig conf = findTellstickBindingConfig(device.getId(), null, null);
if (conf != null) {
sendToOpenHab(conf.getItemName(), cmd);
} else {
logger.info("Could not find config for " + device);
}
}
}
Aggregations