use of org.eclipse.smarthome.automation.module.core.provider.ModuleInformation in project smarthome by eclipse.
the class AnnotatedThingActionModuleTypeProvider method localizeModuleType.
private ModuleType localizeModuleType(String uid, Locale locale) {
Set<ModuleInformation> mis = moduleInformation.get(uid);
if (mis != null && !mis.isEmpty()) {
ModuleInformation mi = mis.iterator().next();
Bundle bundle = FrameworkUtil.getBundle(mi.getActionProvider().getClass());
ModuleType mt = helper.buildModuleType(uid, moduleInformation);
ModuleType localizedModuleType = moduleTypeI18nService.getModuleTypePerLocale(mt, locale, bundle);
return localizedModuleType;
}
return null;
}
use of org.eclipse.smarthome.automation.module.core.provider.ModuleInformation in project smarthome by eclipse.
the class AnnotatedThingActionModuleTypeProvider method removeAnnotatedThingActions.
public void removeAnnotatedThingActions(ThingActions annotatedThingActions, Map<String, Object> properties) {
Collection<ModuleInformation> moduleInformations = helper.parseAnnotations(annotatedThingActions);
String thingUID = annotatedThingActions.getThingHandler().getThing().getUID().getAsString();
for (ModuleInformation mi : moduleInformations) {
mi.setThingUID(thingUID);
ModuleType oldType = null;
Set<ModuleInformation> availableModuleConfigs = this.moduleInformation.get(mi.getUID());
if (availableModuleConfigs != null) {
if (availableModuleConfigs.size() > 1) {
oldType = helper.buildModuleType(mi.getUID(), this.moduleInformation);
availableModuleConfigs.remove(mi);
} else {
this.moduleInformation.remove(mi.getUID());
}
ModuleType mt = helper.buildModuleType(mi.getUID(), this.moduleInformation);
// localize moduletype -> remove from map
for (ProviderChangeListener<ModuleType> l : changeListeners) {
if (oldType != null) {
l.updated(this, oldType, mt);
} else {
l.removed(this, mt);
}
}
}
}
}
use of org.eclipse.smarthome.automation.module.core.provider.ModuleInformation in project smarthome by eclipse.
the class AnnotatedThingActionModuleTypeProvider method addAnnotatedThingActions.
@Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE)
public void addAnnotatedThingActions(ThingActions annotatedThingActions) {
if (annotatedThingActions.getClass().isAnnotationPresent(ThingActionsScope.class)) {
ThingActionsScope scope = annotatedThingActions.getClass().getAnnotation(ThingActionsScope.class);
Collection<ModuleInformation> moduleInformations = helper.parseAnnotations(scope.name(), annotatedThingActions);
String thingUID = annotatedThingActions.getThingHandler().getThing().getUID().getAsString();
for (ModuleInformation mi : moduleInformations) {
mi.setThingUID(thingUID);
ModuleType oldType = null;
if (this.moduleInformation.containsKey(mi.getUID())) {
oldType = helper.buildModuleType(mi.getUID(), this.moduleInformation);
Set<ModuleInformation> availableModuleConfigs = this.moduleInformation.get(mi.getUID());
availableModuleConfigs.add(mi);
} else {
Set<ModuleInformation> configs = ConcurrentHashMap.newKeySet();
configs.add(mi);
this.moduleInformation.put(mi.getUID(), configs);
}
ModuleType mt = helper.buildModuleType(mi.getUID(), this.moduleInformation);
if (mt != null) {
for (ProviderChangeListener<ModuleType> l : changeListeners) {
if (oldType != null) {
l.updated(this, oldType, mt);
} else {
l.added(this, mt);
}
}
}
}
}
}
use of org.eclipse.smarthome.automation.module.core.provider.ModuleInformation in project smarthome by eclipse.
the class AnnotatedActionModuleTypeProvider method removeActionProvider.
public void removeActionProvider(AnnotatedActions actionProvider, Map<String, Object> properties) {
Collection<ModuleInformation> moduleInformations = helper.parseAnnotations(actionProvider);
String configName = getConfigNameFromService(properties);
for (ModuleInformation mi : moduleInformations) {
mi.setConfigName(configName);
ModuleType oldType = null;
Set<ModuleInformation> availableModuleConfigs = this.moduleInformation.get(mi.getUID());
if (availableModuleConfigs != null) {
if (availableModuleConfigs.size() > 1) {
oldType = helper.buildModuleType(mi.getUID(), this.moduleInformation);
availableModuleConfigs.remove(mi);
} else {
this.moduleInformation.remove(mi.getUID());
}
ModuleType mt = helper.buildModuleType(mi.getUID(), this.moduleInformation);
for (ProviderChangeListener<ModuleType> l : changeListeners) {
if (oldType != null) {
l.updated(this, oldType, mt);
} else {
l.removed(this, mt);
}
}
}
}
}
use of org.eclipse.smarthome.automation.module.core.provider.ModuleInformation in project smarthome by eclipse.
the class AnnotatedActionModuleTypeProvider method localizeModuleType.
private ModuleType localizeModuleType(String uid, Locale locale) {
Set<ModuleInformation> mis = moduleInformation.get(uid);
if (mis != null && !mis.isEmpty()) {
ModuleInformation mi = mis.iterator().next();
Bundle bundle = FrameworkUtil.getBundle(mi.getActionProvider().getClass());
ModuleType mt = helper.buildModuleType(uid, moduleInformation);
ModuleType localizedModuleType = moduleTypeI18nService.getModuleTypePerLocale(mt, locale, bundle);
return localizedModuleType;
}
return null;
}
Aggregations