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);
}
}
}
}
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!";
}
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;
}
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;
}
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;
}
Aggregations