Search in sources :

Example 1 with OpenWebIfConfig

use of org.openhab.action.openwebif.internal.impl.config.OpenWebIfConfig in project openhab1-addons by openhab.

the class OpenWebIfActionService method updated.

/**
     * {@inheritDoc}
     */
@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    if (properties != null) {
        Enumeration<String> keys = properties.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            String value = StringUtils.trimToNull((String) properties.get(key));
            if (StringUtils.startsWithIgnoreCase(key, "receiver")) {
                parseConfig(key, value);
            }
        }
        for (OpenWebIfConfig config : OpenWebIf.getConfigs().values()) {
            if (!config.isValid()) {
                throw new ConfigurationException("openwebif", "Invalid OpenWebIf receiver configuration: " + config.toString());
            }
            logger.info("{}", config.toString());
        }
    }
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) OpenWebIfConfig(org.openhab.action.openwebif.internal.impl.config.OpenWebIfConfig)

Example 2 with OpenWebIfConfig

use of org.openhab.action.openwebif.internal.impl.config.OpenWebIfConfig in project openhab1-addons by openhab.

the class OpenWebIfActionService method parseConfig.

/**
     * Parses the properties for a OpenWebIfConfig.
     */
private void parseConfig(String key, String value) throws ConfigurationException {
    if (value == null) {
        throw new ConfigurationException("openwebif", "Empty property '" + key + "', please check your openhab.cfg!");
    }
    String receiverName = StringUtils.substringBetween(key, ".");
    if (receiverName == null) {
        throw new ConfigurationException("openwebif", "Malformed receiver property '" + key + "', please check your openhab.cfg!");
    }
    OpenWebIfConfig rc = OpenWebIf.getConfigs().get(receiverName);
    if (rc == null) {
        rc = new OpenWebIfConfig();
        rc.setName(receiverName);
        OpenWebIf.getConfigs().put(receiverName, rc);
    }
    String keyId = StringUtils.substringAfterLast(key, ".");
    if (StringUtils.equalsIgnoreCase(keyId, "host")) {
        rc.setHost(value);
    } else if (StringUtils.equalsIgnoreCase(keyId, "port")) {
        rc.setPort(parseNumber(key, value).intValue());
    } else if (StringUtils.equalsIgnoreCase(keyId, "user")) {
        rc.setUser(value);
    } else if (StringUtils.equalsIgnoreCase(keyId, "password")) {
        rc.setPassword(value);
    } else if (StringUtils.equalsIgnoreCase(keyId, "https")) {
        rc.setHttps(Boolean.parseBoolean(value));
    } else {
        throw new ConfigurationException("openwebif", "Unknown configuration key '" + key + "', please check your openhab.cfg!");
    }
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) OpenWebIfConfig(org.openhab.action.openwebif.internal.impl.config.OpenWebIfConfig)

Aggregations

OpenWebIfConfig (org.openhab.action.openwebif.internal.impl.config.OpenWebIfConfig)2 ConfigurationException (org.osgi.service.cm.ConfigurationException)2