Search in sources :

Example 1 with ModuleInformation

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;
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ModuleInformation(org.eclipse.smarthome.automation.module.core.provider.ModuleInformation) Bundle(org.osgi.framework.Bundle)

Example 2 with ModuleInformation

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);
                }
            }
        }
    }
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ModuleInformation(org.eclipse.smarthome.automation.module.core.provider.ModuleInformation)

Example 3 with ModuleInformation

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);
                    }
                }
            }
        }
    }
}
Also used : ThingActionsScope(org.eclipse.smarthome.core.thing.binding.ThingActionsScope) ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ModuleInformation(org.eclipse.smarthome.automation.module.core.provider.ModuleInformation) Reference(org.osgi.service.component.annotations.Reference)

Example 4 with ModuleInformation

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);
                }
            }
        }
    }
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ModuleInformation(org.eclipse.smarthome.automation.module.core.provider.ModuleInformation)

Example 5 with ModuleInformation

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;
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ModuleInformation(org.eclipse.smarthome.automation.module.core.provider.ModuleInformation) Bundle(org.osgi.framework.Bundle)

Aggregations

ModuleInformation (org.eclipse.smarthome.automation.module.core.provider.ModuleInformation)6 ModuleType (org.eclipse.smarthome.automation.type.ModuleType)6 Bundle (org.osgi.framework.Bundle)2 Reference (org.osgi.service.component.annotations.Reference)2 ThingActionsScope (org.eclipse.smarthome.core.thing.binding.ThingActionsScope)1