Search in sources :

Example 11 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class RuleEngine method normalizeModuleConfigurations.

private <T extends Module> void normalizeModuleConfigurations(List<@NonNull T> modules) {
    for (Module module : modules) {
        Configuration config = module.getConfiguration();
        if (config != null) {
            String type = module.getTypeUID();
            ModuleType mt = mtRegistry.get(type);
            if (mt != null) {
                List<ConfigDescriptionParameter> configDescriptions = mt.getConfigurationDescriptions();
                Map<String, ConfigDescriptionParameter> mapConfigDescriptions = getConfigDescriptionMap(configDescriptions);
                normalizeConfiguration(config, mapConfigDescriptions);
            }
        }
    }
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) Configuration(org.eclipse.smarthome.config.core.Configuration) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) Module(org.eclipse.smarthome.automation.Module)

Example 12 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class AutomationCommandList method listModuleTypes.

/**
 * This method is responsible for execution of command {@link AutomationCommands#LIST_MODULE_TYPES}.
 *
 * @return a string representing understandable for the user message containing information on the outcome of the
 *         command {@link AutomationCommands#LIST_MODULE_TYPES}.
 */
private String listModuleTypes() {
    Map<String, ModuleType> moduleTypes = new Hashtable<String, ModuleType>();
    Collection<? extends ModuleType> collection = autoCommands.getTriggers(locale);
    addCollection(collection, moduleTypes);
    collection = autoCommands.getConditions(locale);
    addCollection(collection, moduleTypes);
    collection = autoCommands.getActions(locale);
    addCollection(collection, moduleTypes);
    Map<String, String> listModuleTypes = null;
    if (!moduleTypes.isEmpty()) {
        String[] uids = new String[moduleTypes.size()];
        Utils.quickSort(moduleTypes.keySet().toArray(uids), 0, moduleTypes.size());
        listModuleTypes = Utils.putInHastable(uids);
    }
    if (listModuleTypes != null && !listModuleTypes.isEmpty()) {
        if (id != null) {
            collection = getModuleTypeByFilter(listModuleTypes);
            if (collection.size() == 1) {
                ModuleType mt = (ModuleType) collection.toArray()[0];
                if (mt != null) {
                    return Printer.printModuleType(mt);
                } else {
                    return String.format("Nonexistent ID: %s", id);
                }
            } else if (collection.isEmpty()) {
                return String.format("Nonexistent ID: %s", id);
            } else {
                if (!moduleTypes.isEmpty()) {
                    moduleTypes.clear();
                }
                addCollection(collection, moduleTypes);
                listModuleTypes = Utils.filterList(moduleTypes, listModuleTypes);
            }
        }
        return Printer.printModuleTypes(listModuleTypes);
    }
    return "There are no Module Types available!";
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) Hashtable(java.util.Hashtable)

Example 13 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class AutomationCommandList method getModuleTypeByFilter.

/**
 * This method reduces the list of {@link ModuleType}s so that their unique identifier or part of it to match the
 * {@link #id} or
 * the index in the <tt>list</tt> to match the {@link #id}.
 *
 * @param list is the list of {@link ModuleType}s for reducing.
 * @return a collection of {@link ModuleType}s that match the filter.
 */
private Collection<ModuleType> getModuleTypeByFilter(Map<String, String> list) {
    Collection<ModuleType> moduleTypes = new ArrayList<ModuleType>();
    if (!list.isEmpty()) {
        ModuleType mt = null;
        String uid = list.get(id);
        if (uid != null) {
            mt = autoCommands.getModuleType(uid, locale);
            if (mt != null) {
                moduleTypes.add(mt);
                return moduleTypes;
            }
        } else {
            mt = autoCommands.getModuleType(id, locale);
            if (mt != null) {
                moduleTypes.add(mt);
                return moduleTypes;
            } else {
                for (String typeUID : list.values()) {
                    if (typeUID.indexOf(id) != -1) {
                        moduleTypes.add(autoCommands.getModuleType(typeUID, locale));
                    }
                }
            }
        }
    }
    return moduleTypes;
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ArrayList(java.util.ArrayList)

Example 14 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class CommandlineModuleTypeProvider method importData.

@Override
protected Set<ModuleType> importData(URL url, Parser<ModuleType> parser, InputStreamReader inputStreamReader) throws ParsingException {
    Set<ModuleType> providedObjects = parser.parse(inputStreamReader);
    if (providedObjects != null && !providedObjects.isEmpty()) {
        String uid = null;
        List<String> portfolio = new ArrayList<String>();
        synchronized (providerPortfolio) {
            providerPortfolio.put(url, portfolio);
        }
        List<ParsingNestedException> importDataExceptions = new ArrayList<ParsingNestedException>();
        for (ModuleType providedObject : providedObjects) {
            List<ParsingNestedException> exceptions = new ArrayList<ParsingNestedException>();
            uid = providedObject.getUID();
            checkExistence(uid, exceptions);
            if (exceptions.isEmpty()) {
                portfolio.add(uid);
                synchronized (providedObjectsHolder) {
                    notifyListeners(providedObjectsHolder.put(uid, providedObject), providedObject);
                }
            } else {
                importDataExceptions.addAll(exceptions);
            }
        }
        if (!importDataExceptions.isEmpty()) {
            throw new ParsingException(importDataExceptions);
        }
    }
    return providedObjects;
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ParsingException(org.eclipse.smarthome.automation.parser.ParsingException) ArrayList(java.util.ArrayList) ParsingNestedException(org.eclipse.smarthome.automation.parser.ParsingNestedException)

Example 15 with ModuleType

use of org.eclipse.smarthome.automation.type.ModuleType in project smarthome by eclipse.

the class ModuleTypeRegistryImpl method getByTag.

@Override
@SuppressWarnings("unchecked")
public <T extends ModuleType> Collection<T> getByTag(String moduleTypeTag, Locale locale) {
    Collection<T> result = new ArrayList<T>(20);
    for (Provider<ModuleType> provider : elementMap.keySet()) {
        for (ModuleType mType : elementMap.get(provider)) {
            ModuleType mt = locale == null ? mType : ((ModuleTypeProvider) provider).getModuleType(mType.getUID(), locale);
            Collection<String> tags = mt.getTags();
            if (moduleTypeTag == null) {
                result.add((T) createCopy(mt));
            } else if (tags != null && tags.contains(moduleTypeTag)) {
                result.add((T) createCopy(mt));
            }
        }
    }
    return result;
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ArrayList(java.util.ArrayList)

Aggregations

ModuleType (org.eclipse.smarthome.automation.type.ModuleType)18 ArrayList (java.util.ArrayList)11 CompositeActionType (org.eclipse.smarthome.automation.type.CompositeActionType)5 CompositeConditionType (org.eclipse.smarthome.automation.type.CompositeConditionType)5 CompositeTriggerType (org.eclipse.smarthome.automation.type.CompositeTriggerType)5 ActionType (org.eclipse.smarthome.automation.type.ActionType)4 ConditionType (org.eclipse.smarthome.automation.type.ConditionType)4 TriggerType (org.eclipse.smarthome.automation.type.TriggerType)4 ParsingException (org.eclipse.smarthome.automation.parser.ParsingException)3 ParsingNestedException (org.eclipse.smarthome.automation.parser.ParsingNestedException)3 List (java.util.List)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1