Search in sources :

Example 1 with ConfigAdminBindingProvider

use of org.openhab.binding.configadmin.ConfigAdminBindingProvider in project openhab1-addons by openhab.

the class ConfigAdminBinding method initializeBus.

/**
     * Publishes the items with the configuration values.
     */
private void initializeBus() {
    delayedExecutor.cancel();
    delayedExecutor.schedule(new TimerTask() {

        @Override
        public void run() {
            for (ConfigAdminBindingProvider provider : providers) {
                for (String itemName : provider.getItemNames()) {
                    ConfigAdminBindingConfig bindingConfig = provider.getBindingConfig(itemName);
                    Configuration config = getConfiguration(bindingConfig);
                    postUpdate(config, bindingConfig);
                }
            }
        }
    }, 3000);
}
Also used : TimerTask(java.util.TimerTask) ConfigAdminBindingConfig(org.openhab.binding.configadmin.internal.ConfigAdminGenericBindingProvider.ConfigAdminBindingConfig) Configuration(org.osgi.service.cm.Configuration) ConfigAdminBindingProvider(org.openhab.binding.configadmin.ConfigAdminBindingProvider)

Example 2 with ConfigAdminBindingProvider

use of org.openhab.binding.configadmin.ConfigAdminBindingProvider in project openhab1-addons by openhab.

the class ConfigAdminBinding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    if (configAdmin != null) {
        for (ConfigAdminBindingProvider provider : this.providers) {
            ConfigAdminBindingConfig bindingConfig = provider.getBindingConfig(itemName);
            Configuration config = getConfiguration(bindingConfig);
            if (config != null) {
                Dictionary props = config.getProperties();
                props.put(bindingConfig.configParameter, command.toString());
                try {
                    config.update(props);
                } catch (IOException ioe) {
                    logger.error("updating Configuration '{}' with '{}' failed", bindingConfig.normalizedPid, command.toString());
                }
                logger.debug("successfully updated configuration (pid={}, value={})", bindingConfig.normalizedPid, command.toString());
            } else {
                logger.info("There is no configuration found for pid '{}'", bindingConfig.normalizedPid);
            }
        }
    }
}
Also used : Dictionary(java.util.Dictionary) ConfigAdminBindingConfig(org.openhab.binding.configadmin.internal.ConfigAdminGenericBindingProvider.ConfigAdminBindingConfig) Configuration(org.osgi.service.cm.Configuration) ConfigAdminBindingProvider(org.openhab.binding.configadmin.ConfigAdminBindingProvider) IOException(java.io.IOException)

Aggregations

ConfigAdminBindingProvider (org.openhab.binding.configadmin.ConfigAdminBindingProvider)2 ConfigAdminBindingConfig (org.openhab.binding.configadmin.internal.ConfigAdminGenericBindingProvider.ConfigAdminBindingConfig)2 Configuration (org.osgi.service.cm.Configuration)2 IOException (java.io.IOException)1 Dictionary (java.util.Dictionary)1 TimerTask (java.util.TimerTask)1