Search in sources :

Example 1 with BindingConfig

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

the class DavisGenericBindingProvider method getConfiguredKeys.

/**
     * @{inheritDoc
     */
public List<String> getConfiguredKeys() {
    Set<String> eventTypes = new HashSet<String>();
    Iterator<BindingConfig> it = bindingConfigs.values().iterator();
    while (it.hasNext()) {
        BindingConfig config = it.next();
        eventTypes.add(((DavisBindingConfig) config).key);
    }
    return new ArrayList<String>(eventTypes);
}
Also used : BindingConfig(org.openhab.core.binding.BindingConfig) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 2 with BindingConfig

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

the class MaxCulGenericBindingProvider method buildAssociationMap.

/**
     * Loop over all bindings finding their associated devices and create
     * entries for each one. So end up with something like (psuedo binding
     * code): Binding 1: dev A { assoc=B,C } result: A -> B,C Binding 2: dev B {
     * assoc=C } result: A -> B,C B -> C Binding 3: dev B { assoc=D } result: A
     * -> B,C B -> C,D
     */
private void buildAssociationMap() {
    // TODO refactor into its own class e.g. AssociationMap extends HashMap
    if (super.bindingConfigs.values().isEmpty() == false) {
        logger.debug("Found " + super.bindingConfigs.values().size() + " binding configs to process in association map");
        for (BindingConfig c : super.bindingConfigs.values()) {
            MaxCulBindingConfig config = (MaxCulBindingConfig) c;
            logger.debug("Processing " + config.getSerialNumber() + " with " + config.getAssociatedSerialNum().size() + " associations");
            if (associationMap.containsKey(config.getSerialNumber()) && config.getAssociatedSerialNum().isEmpty() == false) {
                /*
                     * serial number already exists in the map so check if we
                     * need to add any devices to the association
                     */
                HashSet<MaxCulBindingConfig> set = associationMap.get(config.getSerialNumber());
                logger.debug("Found " + config.getSerialNumber() + " in map already with " + set.size() + " entrys");
                for (String serial : config.getAssociatedSerialNum()) {
                    MaxCulBindingConfig bc = getConfigForSerialNumber(serial);
                    if (bc != null) {
                        boolean deviceInSet = false;
                        for (MaxCulBindingConfig bcInSet : set) {
                            if (bcInSet.getSerialNumber().equalsIgnoreCase(bc.getSerialNumber())) {
                                deviceInSet |= true;
                            }
                        }
                        if (!deviceInSet) {
                            logger.debug("Adding " + serial + " to set for " + config.getSerialNumber());
                            set.add(bc);
                        }
                    }
                }
            } else if (config.getAssociatedSerialNum().isEmpty() == false) {
                /* new serial number, add it and its associations */
                HashSet<MaxCulBindingConfig> set = new HashSet<MaxCulBindingConfig>();
                for (String serial : config.getAssociatedSerialNum()) {
                    /*
                         * add first config for this serial number. This is
                         * enough to give us device type and destination address
                         * which is all we need.
                         */
                    MaxCulBindingConfig bc = getConfigForSerialNumber(serial);
                    if (bc != null) {
                        boolean deviceInSet = false;
                        for (MaxCulBindingConfig bcInSet : set) {
                            if (bcInSet.getSerialNumber().equalsIgnoreCase(bc.getSerialNumber())) {
                                deviceInSet |= true;
                            }
                        }
                        if (!deviceInSet) {
                            logger.debug("Adding " + serial + " to set for " + config.getSerialNumber());
                            set.add(bc);
                        }
                    }
                }
                /* only add if it has entries */
                if (!set.isEmpty()) {
                    associationMap.put(config.getSerialNumber(), set);
                }
            }
        }
        associationsMapBuilt = true;
        /* debug print of association map */
        if (!associationMap.isEmpty()) {
            for (String serialKey : associationMap.keySet()) {
                if (serialKey != null) {
                    logger.debug("Device " + serialKey + " associated with:");
                    for (MaxCulBindingConfig bc : associationMap.get(serialKey)) {
                        logger.debug("\t=> " + bc.getSerialNumber());
                    }
                }
            }
        }
    }
}
Also used : BindingConfig(org.openhab.core.binding.BindingConfig) HashSet(java.util.HashSet)

Example 3 with BindingConfig

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

the class ComfoAirGenericBindingProvider method getConfiguredKeys.

/**
     * @{inheritDoc
     */
@Override
public List<String> getConfiguredKeys() {
    Set<String> eventTypes = new HashSet<String>();
    Iterator<BindingConfig> it = bindingConfigs.values().iterator();
    while (it.hasNext()) {
        BindingConfig config = it.next();
        eventTypes.add(((ComfoAirBindingConfig) config).key);
    }
    return new ArrayList<String>(eventTypes);
}
Also used : BindingConfig(org.openhab.core.binding.BindingConfig) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 4 with BindingConfig

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

the class KNXGenericBindingProvider method autoUpdate.

/*
     * (non-Javadoc)
     * 
     * @see org.openhab.core.autoupdate.AutoUpdateBindingProvider#autoUpdate(java.lang.String)
     */
@Override
public Boolean autoUpdate(String itemName) {
    BindingConfig config = bindingConfigs.get(itemName);
    if (config instanceof KNXBindingConfig) {
        KNXBindingConfig knxConfig = (KNXBindingConfig) config;
        Iterator<KNXBindingConfigItem> it = knxConfig.iterator();
        while (it.hasNext()) {
            KNXBindingConfigItem item = it.next();
            if (item.allDataPoints.getDatapoints().size() > 1) {
                // will come from KNX.
                return false;
            }
        }
    }
    return null;
}
Also used : BindingConfig(org.openhab.core.binding.BindingConfig)

Example 5 with BindingConfig

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

the class EnergenieGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    try {
        if (bindingConfig != null) {
            String[] configParts = bindingConfig.split(";");
            if (configParts.length < 2 || configParts.length > 2) {
                throw new BindingConfigParseException("energenie binding configuration must have 2 parts");
            }
            String itemType = item.toString();
            if (item instanceof SwitchItem) {
                if ((configParts[1].equals("1")) || (configParts[1].equals("2")) || (configParts[1].equals("3")) || (configParts[1].equals("4"))) {
                    BindingConfig energenieBindingConfig = new EnergenieBindingConfig(configParts[0], configParts[1], itemType);
                    addBindingConfig(item, energenieBindingConfig);
                } else {
                    throw new BindingConfigParseException("Your SwitchItem configuration does not contain channelNumbers");
                }
            } else if (item instanceof NumberItem) {
                ChannelTypeDef channelType = ChannelTypeDef.valueOf(configParts[1].trim());
                if (channelType != null) {
                    BindingConfig energenieBindingConfig = new EnergenieBindingConfig(configParts[0], configParts[1], itemType);
                    addBindingConfig(item, energenieBindingConfig);
                } else {
                    throw new BindingConfigParseException("Your NumberItem configuration does not contain channelTypes");
                }
            }
        } else {
            logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!");
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        logger.warn("bindingConfig is invalid (item=" + item + ") -> processing bindingConfig aborted!");
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) BindingConfig(org.openhab.core.binding.BindingConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SwitchItem(org.openhab.core.library.items.SwitchItem) ChannelTypeDef(org.openhab.binding.energenie.internal.EnergenieBindingConfig.ChannelTypeDef)

Aggregations

BindingConfig (org.openhab.core.binding.BindingConfig)10 HashSet (java.util.HashSet)3 SwitchItem (org.openhab.core.library.items.SwitchItem)3 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)3 ArrayList (java.util.ArrayList)2 ColorItem (org.openhab.core.library.items.ColorItem)2 DimmerItem (org.openhab.core.library.items.DimmerItem)2 ChannelTypeDef (org.openhab.binding.energenie.internal.EnergenieBindingConfig.ChannelTypeDef)1 OneWireBindingProvider (org.openhab.binding.onewire.OneWireBindingProvider)1 AbstractOneWireControlBindingConfig (org.openhab.binding.onewire.internal.control.AbstractOneWireControlBindingConfig)1 AbstractOneWireDevicePropertyBindingConfig (org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig)1 AbstractOneWireDevicePropertyWritableBindingConfig (org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyWritableBindingConfig)1 OneWireDevicePropertyExecutableBindingConfig (org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyExecutableBindingConfig)1 NumberItem (org.openhab.core.library.items.NumberItem)1