use of org.openhab.binding.horizon.internal.control.HorizonBox in project openhab1-addons by openhab.
the class HorizonBinding method updateConfiguration.
private void updateConfiguration(final Map<String, Object> configuration) throws ConfigurationException {
Set<String> keys = configuration.keySet();
Iterator<String> keysIt = keys.iterator();
while (keysIt.hasNext()) {
String key = keysIt.next();
if ("service.pid".equals(key)) {
continue;
}
Matcher matcher = EXTRACT_HORIZON_CONFIG_PATTERN.matcher(key);
if (!matcher.matches()) {
logger.debug("given config key '" + key + "' does not follow the expected pattern '<id>.<host>'");
continue;
}
matcher.reset();
matcher.find();
String deviceId = matcher.group(1);
String host = null;
String configKey = matcher.group(2);
String value = (String) configuration.get(key);
if ("host".equals(configKey)) {
host = value;
} else {
throw new ConfigurationException("The given configKey '" + configKey + "' is unknown");
}
HorizonBox horizonBox = new HorizonBox(host, DEFAULT_HORIZON_PORT);
deviceConfigCache.put(deviceId, horizonBox);
}
}
use of org.openhab.binding.horizon.internal.control.HorizonBox in project openhab1-addons by openhab.
the class HorizonBinding method internalReceiveCommand.
/**
* {@inheritDoc}
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
logger.debug("internalReceiveCommand({},{}) is called!", itemName, command);
HorizonBindingProvider horizonBindingProvider = findFirstMatchingBindingProvider(itemName, command);
String horizonKeyWithHorizonId = horizonBindingProvider.getHorizonCommand(itemName, command.toString());
String[] horizonKeyWithHorizonIdSplit = horizonKeyWithHorizonId.split(":");
String horizonId = horizonKeyWithHorizonIdSplit[0];
String horizonKey = horizonKeyWithHorizonIdSplit[1];
HorizonBox horizonBox = deviceConfigCache.get(horizonId);
if (horizonBox != null) {
try {
horizonBox.sendKey(Integer.valueOf(horizonKey));
} catch (Exception e) {
logger.error("Error sending key to device with device id '{}'", horizonId, e);
}
} else {
logger.warn("Cannot find connection details for device id '{}'", horizonId);
}
}
Aggregations