Search in sources :

Example 1 with ModuleHandler

use of org.eclipse.smarthome.automation.handler.ModuleHandler in project smarthome by eclipse.

the class RuleEngine method setModuleHandlers.

/**
 * This method links modules to corresponding module handlers.
 *
 * @param rUID id of rule containing these modules
 * @param modules list of modules
 * @return null when all modules are connected or list of RuleErrors for missing handlers.
 */
private <T extends Module> String setModuleHandlers(String rUID, List<T> modules) {
    StringBuffer sb = null;
    if (modules != null) {
        for (T m : modules) {
            try {
                ModuleHandler moduleHandler = getModuleHandler(m, rUID);
                if (moduleHandler != null) {
                    if (m instanceof RuntimeAction) {
                        ((RuntimeAction) m).setModuleHandler((ActionHandler) moduleHandler);
                    } else if (m instanceof RuntimeCondition) {
                        ((RuntimeCondition) m).setModuleHandler((ConditionHandler) moduleHandler);
                    } else if (m instanceof RuntimeTrigger) {
                        ((RuntimeTrigger) m).setModuleHandler((TriggerHandler) moduleHandler);
                    }
                } else {
                    if (sb == null) {
                        sb = new StringBuffer();
                    }
                    String message = "Missing handler '" + m.getTypeUID() + "' for module '" + m.getId() + "'";
                    sb.append(message).append("\n");
                    logger.trace(message);
                }
            } catch (Throwable t) {
                if (sb == null) {
                    sb = new StringBuffer();
                }
                String message = "Getting handler '" + m.getTypeUID() + "' for module '" + m.getId() + "' failed: " + t.getMessage();
                sb.append(message).append("\n");
                logger.trace(message);
            }
        }
    }
    return sb != null ? sb.toString() : null;
}
Also used : ModuleHandler(org.eclipse.smarthome.automation.handler.ModuleHandler) ConditionHandler(org.eclipse.smarthome.automation.handler.ConditionHandler)

Example 2 with ModuleHandler

use of org.eclipse.smarthome.automation.handler.ModuleHandler in project smarthome by eclipse.

the class AbstractCompositeModuleHandler method dispose.

@Override
public void dispose() {
    List<M> children = getChildren();
    for (M child : children) {
        ModuleHandler childHandler = moduleHandlerMap.remove(child);
        if (childHandler != null) {
            childHandler.dispose();
        }
    }
    moduleHandlerMap = null;
}
Also used : ModuleHandler(org.eclipse.smarthome.automation.handler.ModuleHandler)

Example 3 with ModuleHandler

use of org.eclipse.smarthome.automation.handler.ModuleHandler in project smarthome by eclipse.

the class ScriptedPrivateModuleHandlerFactory method internalCreate.

@Override
protected ModuleHandler internalCreate(Module module, String ruleUID) {
    ModuleHandler moduleHandler = null;
    ScriptedHandler scriptedHandler = null;
    try {
        scriptedHandler = privateTypes.get(module.getConfiguration().get(PRIV_ID));
    } catch (Exception e) {
        logger.warn("ScriptedHandler {} for ruleUID {} not found", module.getConfiguration().get(PRIV_ID), ruleUID);
    }
    if (scriptedHandler != null) {
        moduleHandler = getModuleHandler(module, scriptedHandler);
    }
    return moduleHandler;
}
Also used : ModuleHandler(org.eclipse.smarthome.automation.handler.ModuleHandler) ScriptedHandler(org.eclipse.smarthome.automation.module.script.rulesupport.shared.ScriptedHandler)

Example 4 with ModuleHandler

use of org.eclipse.smarthome.automation.handler.ModuleHandler in project smarthome by eclipse.

the class SampleHandlerFactory method internalCreate.

@Override
protected ModuleHandler internalCreate(Module module, String ruleUID) {
    ModuleHandler moduleHandler = null;
    if (SUPPORTED_TRIGGER.equals(module.getTypeUID())) {
        moduleHandler = new SampleTriggerHandler((Trigger) module, ruleUID);
        createdTriggerHandler.add((TriggerHandler) moduleHandler);
    } else if (SUPPORTED_CONDITION.equals(module.getTypeUID())) {
        moduleHandler = new SampleConditionHandler((Condition) module);
    } else if (SUPPORTED_ACTION.equals(module.getTypeUID())) {
        moduleHandler = new SampleActionHandler((Action) module);
    } else {
        logger.error(MODULE_HANDLER_FACTORY_NAME + "Not supported moduleHandler: {}", module.getTypeUID());
    }
    return moduleHandler;
}
Also used : ModuleHandler(org.eclipse.smarthome.automation.handler.ModuleHandler) Action(org.eclipse.smarthome.automation.Action) Trigger(org.eclipse.smarthome.automation.Trigger)

Example 5 with ModuleHandler

use of org.eclipse.smarthome.automation.handler.ModuleHandler 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)

Aggregations

ModuleHandler (org.eclipse.smarthome.automation.handler.ModuleHandler)6 Action (org.eclipse.smarthome.automation.Action)2 Trigger (org.eclipse.smarthome.automation.Trigger)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Module (org.eclipse.smarthome.automation.Module)1 ActionHandler (org.eclipse.smarthome.automation.handler.ActionHandler)1 BaseModuleHandlerFactory (org.eclipse.smarthome.automation.handler.BaseModuleHandlerFactory)1 ConditionHandler (org.eclipse.smarthome.automation.handler.ConditionHandler)1 ModuleHandlerFactory (org.eclipse.smarthome.automation.handler.ModuleHandlerFactory)1 TriggerHandler (org.eclipse.smarthome.automation.handler.TriggerHandler)1 ScriptedHandler (org.eclipse.smarthome.automation.module.script.rulesupport.shared.ScriptedHandler)1 CompositeActionType (org.eclipse.smarthome.automation.type.CompositeActionType)1 CompositeConditionType (org.eclipse.smarthome.automation.type.CompositeConditionType)1 CompositeTriggerType (org.eclipse.smarthome.automation.type.CompositeTriggerType)1 ModuleType (org.eclipse.smarthome.automation.type.ModuleType)1