Search in sources :

Example 1 with InsteonHubSerialProxy

use of org.openhab.binding.insteonhub.internal.hardware.api.serial.InsteonHubSerialProxy in project openhab1-addons by openhab.

the class InsteonHubProxyFactory method createInstances.

public static Map<String, InsteonHubProxy> createInstances(Dictionary<String, ?> config) {
    Map<String, InsteonHubProxy> proxies = new HashMap<String, InsteonHubProxy>();
    // parse all configured receivers
    // ( insteonhub:<hubid>.host=10.0.0.2 )
    Enumeration<String> keys = config.keys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        if (key.endsWith(CONFIG_KEY_HOST)) {
            // parse host
            String host = (String) config.get(key);
            int separatorIdx = key.indexOf('.');
            String hubId, keyPrefix;
            if (separatorIdx == -1) {
                // no prefix/hubid => one hub => use default hub ID
                hubId = InsteonHubBinding.DEFAULT_HUB_ID;
                keyPrefix = "";
            } else {
                // prefix => use it as the hub ID
                hubId = key.substring(0, separatorIdx);
                keyPrefix = hubId + ".";
            }
            String portStr = (String) config.get(keyPrefix + CONFIG_KEY_PORT);
            int port = StringUtils.isBlank(portStr) ? InsteonHubSerialProxy.DEFAULT_PORT : Integer.parseInt(config.get(keyPrefix + CONFIG_KEY_PORT).toString());
            // Create proxy, and add it to map
            InsteonHubProxy proxy = new InsteonHubSerialProxy(host, port);
            proxies.put(hubId, proxy);
        }
    }
    return proxies;
}
Also used : HashMap(java.util.HashMap) InsteonHubSerialProxy(org.openhab.binding.insteonhub.internal.hardware.api.serial.InsteonHubSerialProxy) InsteonHubProxy(org.openhab.binding.insteonhub.internal.hardware.InsteonHubProxy)

Aggregations

HashMap (java.util.HashMap)1 InsteonHubProxy (org.openhab.binding.insteonhub.internal.hardware.InsteonHubProxy)1 InsteonHubSerialProxy (org.openhab.binding.insteonhub.internal.hardware.api.serial.InsteonHubSerialProxy)1