Search in sources :

Example 1 with ThingActionsScope

use of org.eclipse.smarthome.core.thing.binding.ThingActionsScope 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)

Aggregations

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