Search in sources :

Example 1 with BindingProvider

use of org.openhab.core.binding.BindingProvider in project openhab1-addons by openhab.

the class DmxGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    if (dmxService == null) {
        logger.error("DMX Service unavailable. Cannot process item configuration for {}", item.getName());
        return;
    }
    super.processBindingConfiguration(context, item, bindingConfig);
    String config = (bindingConfig == null) ? "" : bindingConfig.replaceAll(" ", "").toUpperCase();
    logger.trace("Binding item: {} with configuration {}", item.getName(), config);
    DmxItem itemBinding = null;
    if (item instanceof ColorItem) {
        itemBinding = new DmxColorItem(item.getName(), config, this);
    } else if (item instanceof DimmerItem) {
        itemBinding = new DmxDimmerItem(item.getName(), config, this);
    } else if (item instanceof SwitchItem) {
        itemBinding = new DmxSwitchItem(item.getName(), config, this);
    } else {
        throw new BindingConfigParseException("Unsupported item type " + item.getClass().getSimpleName());
    }
    if (itemBinding.isStatusListener()) {
        final DmxStatusUpdateListener dmxStatusListener = itemBinding;
        final String itemName = item.getName();
        logger.trace("Registering status listener for item {} ", item.getName());
        dmxService.registerStatusListener(dmxStatusListener);
        // add binding change listener to clean up status listeners on item
        // removal
        addBindingChangeListener(new BindingChangeListener() {

            @Override
            public void bindingChanged(BindingProvider provider, String changedItemName) {
                if (itemName.equals(changedItemName) && !provider.providesBindingFor(itemName)) {
                    logger.trace("Removing status listener for item {}", itemName);
                    dmxService.unregisterStatusListener(dmxStatusListener);
                }
            }

            @Override
            public void allBindingsChanged(BindingProvider provider) {
                if (!provider.providesBindingFor(itemName)) {
                    logger.trace("Removing status listener for item {}", itemName);
                    dmxService.unregisterStatusListener(dmxStatusListener);
                }
            }
        });
    }
    addBindingConfig(item, itemBinding);
}
Also used : DmxStatusUpdateListener(org.openhab.binding.dmx.DmxStatusUpdateListener) DmxItem(org.openhab.binding.dmx.internal.config.DmxItem) DmxSwitchItem(org.openhab.binding.dmx.internal.config.DmxSwitchItem) DmxColorItem(org.openhab.binding.dmx.internal.config.DmxColorItem) ColorItem(org.openhab.core.library.items.ColorItem) BindingChangeListener(org.openhab.core.binding.BindingChangeListener) DmxBindingProvider(org.openhab.binding.dmx.DmxBindingProvider) AbstractGenericBindingProvider(org.openhab.model.item.binding.AbstractGenericBindingProvider) BindingProvider(org.openhab.core.binding.BindingProvider) DmxDimmerItem(org.openhab.binding.dmx.internal.config.DmxDimmerItem) DimmerItem(org.openhab.core.library.items.DimmerItem) DmxDimmerItem(org.openhab.binding.dmx.internal.config.DmxDimmerItem) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) DmxColorItem(org.openhab.binding.dmx.internal.config.DmxColorItem) DmxSwitchItem(org.openhab.binding.dmx.internal.config.DmxSwitchItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 2 with BindingProvider

use of org.openhab.core.binding.BindingProvider in project openhab1-addons by openhab.

the class MiosBinding method invokeMiosAction.

/**
     * {@inheritDoc}
     */
@Override
public boolean invokeMiosAction(String itemName, String actionName, List<Entry<String, Object>> params) {
    try {
        logger.debug("invokeMiosAction item {}, action {}, params {}", new Object[] { itemName, actionName, Integer.valueOf((params == null) ? 0 : params.size()) });
        boolean sent = false;
        // Lookup the MiOS Unit name and property for this item
        String unitName = getMiosUnitName(itemName);
        MiosUnitConnector connector = getMiosConnector(unitName);
        if (connector == null) {
            logger.warn("invokeMiosAction: Action call for item '{}' but no connector found for MiOS Unit '{}', ignoring", itemName, unitName);
            return false;
        }
        if (!connector.isConnected()) {
            logger.warn("invokeMiosAction: Action call for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", itemName, unitName);
            return false;
        }
        for (BindingProvider provider : providers) {
            if (provider instanceof MiosBindingProvider) {
                MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
                MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
                if ((config != null) && (config instanceof DeviceBindingConfig)) {
                    connector.invokeAction((DeviceBindingConfig) config, actionName, params);
                    sent = true;
                } else {
                    logger.error("invokeMiosAction: Missing BindingConfig for item '{}', or not bound to a MiOS Device.", itemName);
                }
            }
        }
        return sent;
    } catch (Exception e) {
        logger.error("invokeMiosScene: Error handling command", e);
        return false;
    }
}
Also used : MiosBindingConfig(org.openhab.binding.mios.internal.config.MiosBindingConfig) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) BindingProvider(org.openhab.core.binding.BindingProvider) DeviceBindingConfig(org.openhab.binding.mios.internal.config.DeviceBindingConfig) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 3 with BindingProvider

use of org.openhab.core.binding.BindingProvider in project openhab1-addons by openhab.

the class MaxCulGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    final String itemName = item.getName();
    logger.debug("Processing item " + itemName);
    final MaxCulBindingConfig config = new MaxCulBindingConfig(bindingConfig);
    addBindingConfig(item, config);
    addBindingChangeListener(new BindingChangeListener() {

        @Override
        public void bindingChanged(BindingProvider provider, String itemName) {
            /* binding changed so update the association map */
            associationsMapBuilt = false;
        // TODO check if config temperatures are set and flag that they
        // should be sent the device because they might have changed?
        }

        @Override
        public void allBindingsChanged(BindingProvider provider) {
            if (!provider.providesBindingFor(itemName)) {
            // TODO get serial number of itemName
            // then check if we still interact with that device, if not
            // then
            // deassociate and send a reset to it
            }
        }
    });
}
Also used : BindingChangeListener(org.openhab.core.binding.BindingChangeListener) AbstractGenericBindingProvider(org.openhab.model.item.binding.AbstractGenericBindingProvider) BindingProvider(org.openhab.core.binding.BindingProvider) MaxCulBindingProvider(org.openhab.binding.maxcul.MaxCulBindingProvider)

Example 4 with BindingProvider

use of org.openhab.core.binding.BindingProvider in project openhab1-addons by openhab.

the class MqttGenericBindingProvider method processBindingConfiguration.

@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    final String itemName = item.getName();
    logger.trace("Starting to load MQTT config for item {}", itemName);
    if (StringUtils.isEmpty(bindingConfig)) {
        throw new BindingConfigParseException("Missing mqtt binding configuration for item " + itemName);
    }
    final MqttItemConfig itemConfig = new MqttItemConfig(item, bindingConfig);
    // register all message consumers
    for (MqttMessageSubscriber subscriber : itemConfig.getMessageSubscribers()) {
        subscriber.setItemName(item.getName());
        mqttService.registerMessageConsumer(subscriber.getBroker(), subscriber);
    }
    // add binding change listener to clean up message consumers on item removal
    addBindingChangeListener(new BindingChangeListener() {

        @Override
        public void bindingChanged(BindingProvider provider, String changedItemName) {
            if (itemName.equals(changedItemName) && !provider.providesBindingFor(itemName)) {
                logger.debug("Removing message consumers for item {}", itemName);
                for (MqttMessageSubscriber subscriber : itemConfig.getMessageSubscribers()) {
                    mqttService.unregisterMessageConsumer(subscriber.getBroker(), subscriber);
                }
                removeBindingChangeListener(this);
            }
        }

        @Override
        public void allBindingsChanged(BindingProvider provider) {
            if (!provider.providesBindingFor(itemName)) {
                logger.debug("Removing message consumers for item {}", itemName);
                for (MqttMessageSubscriber subscriber : itemConfig.getMessageSubscribers()) {
                    mqttService.unregisterMessageConsumer(subscriber.getBroker(), subscriber);
                }
                removeBindingChangeListener(this);
            }
        }
    });
    // register all message producers
    for (MqttMessagePublisher publisher : itemConfig.getMessagePublishers()) {
        publisher.setItemName(item.getName());
        mqttService.registerMessageProducer(publisher.getBroker(), publisher);
    }
    // add binding change listener to clean up message publishers on item
    // removal
    addBindingChangeListener(new BindingChangeListener() {

        @Override
        public void bindingChanged(BindingProvider provider, String changedItemName) {
            if (itemName.equals(changedItemName) && !provider.providesBindingFor(itemName)) {
                logger.debug("Removing message publishers for item {}", itemName);
                for (MqttMessagePublisher publisher : itemConfig.getMessagePublishers()) {
                    mqttService.unregisterMessageProducer(publisher.getBroker(), publisher);
                }
                removeBindingChangeListener(this);
            }
        }

        @Override
        public void allBindingsChanged(BindingProvider provider) {
            if (!provider.providesBindingFor(itemName)) {
                logger.debug("Removing message publishers for item {}", itemName);
                for (MqttMessagePublisher publisher : itemConfig.getMessagePublishers()) {
                    mqttService.unregisterMessageProducer(publisher.getBroker(), publisher);
                }
                removeBindingChangeListener(this);
            }
        }
    });
    addBindingConfig(item, itemConfig);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) BindingChangeListener(org.openhab.core.binding.BindingChangeListener) BindingProvider(org.openhab.core.binding.BindingProvider) MqttBindingProvider(org.openhab.binding.mqtt.MqttBindingProvider) AbstractGenericBindingProvider(org.openhab.model.item.binding.AbstractGenericBindingProvider)

Example 5 with BindingProvider

use of org.openhab.core.binding.BindingProvider in project openhab1-addons by openhab.

the class MiosBinding method invokeMiosScene.

/**
     * {@inheritDoc}
     */
@Override
public boolean invokeMiosScene(String itemName) {
    try {
        logger.debug("invokeMiosScene item {}", itemName);
        boolean sent = false;
        // Lookup the MiOS Unit name and property for this item
        String unitName = getMiosUnitName(itemName);
        MiosUnitConnector connector = getMiosConnector(unitName);
        if (connector == null) {
            logger.warn("invokeMiosScene: Scene call for item '{}' but no connector found for MiOS Unit '{}', ignoring", itemName, unitName);
            return false;
        }
        if (!connector.isConnected()) {
            logger.warn("invokeMiosScene: Scene call for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", itemName, unitName);
            return false;
        }
        for (BindingProvider provider : providers) {
            if (provider instanceof MiosBindingProvider) {
                MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
                MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
                if ((config != null) && (config instanceof SceneBindingConfig)) {
                    connector.invokeScene((SceneBindingConfig) config);
                    sent = true;
                } else {
                    logger.error("invokeMiosScene: Missing BindingConfig for item '{}', or not bound to a MiOS Scene.", itemName);
                }
            }
        }
        return sent;
    } catch (Exception e) {
        logger.error("invokeMiosScene: Error handling command", e);
        return false;
    }
}
Also used : MiosBindingConfig(org.openhab.binding.mios.internal.config.MiosBindingConfig) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) MiosBindingProvider(org.openhab.binding.mios.MiosBindingProvider) BindingProvider(org.openhab.core.binding.BindingProvider) ConfigurationException(org.osgi.service.cm.ConfigurationException) SceneBindingConfig(org.openhab.binding.mios.internal.config.SceneBindingConfig)

Aggregations

BindingProvider (org.openhab.core.binding.BindingProvider)8 MiosBindingProvider (org.openhab.binding.mios.MiosBindingProvider)5 MiosBindingConfig (org.openhab.binding.mios.internal.config.MiosBindingConfig)4 ConfigurationException (org.osgi.service.cm.ConfigurationException)4 BindingChangeListener (org.openhab.core.binding.BindingChangeListener)3 AbstractGenericBindingProvider (org.openhab.model.item.binding.AbstractGenericBindingProvider)3 ItemRegistry (org.openhab.core.items.ItemRegistry)2 State (org.openhab.core.types.State)2 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)2 HashMap (java.util.HashMap)1 DmxBindingProvider (org.openhab.binding.dmx.DmxBindingProvider)1 DmxStatusUpdateListener (org.openhab.binding.dmx.DmxStatusUpdateListener)1 DmxColorItem (org.openhab.binding.dmx.internal.config.DmxColorItem)1 DmxDimmerItem (org.openhab.binding.dmx.internal.config.DmxDimmerItem)1 DmxItem (org.openhab.binding.dmx.internal.config.DmxItem)1 DmxSwitchItem (org.openhab.binding.dmx.internal.config.DmxSwitchItem)1 MaxCulBindingProvider (org.openhab.binding.maxcul.MaxCulBindingProvider)1 DeviceBindingConfig (org.openhab.binding.mios.internal.config.DeviceBindingConfig)1 SceneBindingConfig (org.openhab.binding.mios.internal.config.SceneBindingConfig)1 MqttBindingProvider (org.openhab.binding.mqtt.MqttBindingProvider)1