Search in sources :

Example 1 with DmxItem

use of org.openhab.binding.dmx.internal.config.DmxItem in project openhab1-addons by openhab.

the class DmxBinding method receiveCommand.

/**
     * {@inheritDoc}
     */
@Override
public void receiveCommand(String itemName, Command command) {
    if (dmxService == null) {
        logger.warn("No DMX Service available.");
        return;
    }
    // get the item's corresponding dmx binding
    DmxItem itemBinding = null;
    for (DmxBindingProvider provider : providers) {
        if (provider.providesBindingFor(itemName)) {
            itemBinding = provider.getBindingConfig(itemName);
            break;
        }
    }
    if (itemBinding == null) {
        return;
    }
    dmxService.suspend(true);
    itemBinding.processCommand(dmxService, command);
    dmxService.suspend(false);
}
Also used : DmxBindingProvider(org.openhab.binding.dmx.DmxBindingProvider) DmxItem(org.openhab.binding.dmx.internal.config.DmxItem)

Example 2 with DmxItem

use of org.openhab.binding.dmx.internal.config.DmxItem 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)

Aggregations

DmxBindingProvider (org.openhab.binding.dmx.DmxBindingProvider)2 DmxItem (org.openhab.binding.dmx.internal.config.DmxItem)2 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 DmxSwitchItem (org.openhab.binding.dmx.internal.config.DmxSwitchItem)1 BindingChangeListener (org.openhab.core.binding.BindingChangeListener)1 BindingProvider (org.openhab.core.binding.BindingProvider)1 ColorItem (org.openhab.core.library.items.ColorItem)1 DimmerItem (org.openhab.core.library.items.DimmerItem)1 SwitchItem (org.openhab.core.library.items.SwitchItem)1 AbstractGenericBindingProvider (org.openhab.model.item.binding.AbstractGenericBindingProvider)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1