Search in sources :

Example 16 with ModuleType

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

the class ModuleTypeRegistryImpl method getActions.

@Override
public Collection<ActionType> getActions(String... tags) {
    Collection<ModuleType> moduleTypes = getByTags(tags);
    Collection<ActionType> actionTypes = new ArrayList<ActionType>();
    for (ModuleType mt : moduleTypes) {
        if (mt instanceof ActionType) {
            actionTypes.add((ActionType) mt);
        }
    }
    return actionTypes;
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ActionType(org.eclipse.smarthome.automation.type.ActionType) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType) ArrayList(java.util.ArrayList)

Example 17 with ModuleType

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

the class CompositeModuleHandlerFactory method internalCreate.

@Override
public ModuleHandler internalCreate(Module module, String ruleUID) {
    ModuleHandler handler = null;
    if (module != null) {
        String moduleType = module.getTypeUID();
        ModuleType mt = mtRegistry.get(moduleType);
        if (mt instanceof CompositeTriggerType) {
            List<Trigger> childModules = ((CompositeTriggerType) mt).getChildren();
            LinkedHashMap<Trigger, TriggerHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
            if (mapModuleToHandler != null) {
                handler = new CompositeTriggerHandler((Trigger) module, (CompositeTriggerType) mt, mapModuleToHandler, ruleUID);
            }
        } else if (mt instanceof CompositeConditionType) {
            List<Condition> childModules = ((CompositeConditionType) mt).getChildren();
            LinkedHashMap<Condition, ConditionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
            if (mapModuleToHandler != null) {
                handler = new CompositeConditionHandler((Condition) module, (CompositeConditionType) mt, mapModuleToHandler, ruleUID);
            }
        } else if (mt instanceof CompositeActionType) {
            List<Action> childModules = ((CompositeActionType) mt).getChildren();
            LinkedHashMap<Action, ActionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
            if (mapModuleToHandler != null) {
                handler = new CompositeActionHandler((Action) module, (CompositeActionType) mt, mapModuleToHandler, ruleUID);
            }
        }
        if (handler != null) {
            logger.debug("Set module handler: {}  -> {} of rule {}.", module.getId(), handler.getClass().getSimpleName() + "(" + moduleType + ")", ruleUID);
        } else {
            logger.debug("Not found module handler {} for moduleType {} of rule {}.", module.getId(), moduleType, ruleUID);
        }
    }
    return handler;
}
Also used : Action(org.eclipse.smarthome.automation.Action) TriggerHandler(org.eclipse.smarthome.automation.handler.TriggerHandler) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) LinkedHashMap(java.util.LinkedHashMap) ModuleHandler(org.eclipse.smarthome.automation.handler.ModuleHandler) CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) ModuleType(org.eclipse.smarthome.automation.type.ModuleType) Trigger(org.eclipse.smarthome.automation.Trigger) List(java.util.List) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType) ActionHandler(org.eclipse.smarthome.automation.handler.ActionHandler)

Example 18 with ModuleType

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

the class ModuleTypeGSONParser method createMapByType.

private Map<String, List<? extends ModuleType>> createMapByType(Set<ModuleType> dataObjects) {
    Map<String, List<? extends ModuleType>> map = new HashMap<String, List<? extends ModuleType>>();
    List<TriggerType> triggers = new ArrayList<TriggerType>();
    List<ConditionType> conditions = new ArrayList<ConditionType>();
    List<ActionType> actions = new ArrayList<ActionType>();
    for (ModuleType moduleType : dataObjects) {
        if (moduleType instanceof TriggerType) {
            triggers.add((TriggerType) moduleType);
        } else if (moduleType instanceof ConditionType) {
            conditions.add((ConditionType) moduleType);
        } else if (moduleType instanceof ActionType) {
            actions.add((ActionType) moduleType);
        }
    }
    map.put("triggers", triggers);
    map.put("conditions", conditions);
    map.put("actions", actions);
    return map;
}
Also used : CompositeTriggerType(org.eclipse.smarthome.automation.type.CompositeTriggerType) TriggerType(org.eclipse.smarthome.automation.type.TriggerType) ModuleType(org.eclipse.smarthome.automation.type.ModuleType) ActionType(org.eclipse.smarthome.automation.type.ActionType) CompositeActionType(org.eclipse.smarthome.automation.type.CompositeActionType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) ConditionType(org.eclipse.smarthome.automation.type.ConditionType)

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