Search in sources :

Example 1 with CompositeActionType

use of org.openhab.core.automation.type.CompositeActionType in project openhab-core by openhab.

the class CompositeModuleHandlerFactory method internalCreate.

@Override
@Nullable
public ModuleHandler internalCreate(Module module, String ruleUID) {
    ModuleHandler handler = null;
    String moduleType = module.getTypeUID();
    ModuleType mt = mtRegistry.get(moduleType);
    if (mt instanceof CompositeTriggerType) {
        List<Trigger> childModules = ((CompositeTriggerType) mt).getChildren();
        LinkedHashMap<Trigger, @Nullable 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, @Nullable 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, @Nullable 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.openhab.core.automation.Action) TriggerHandler(org.openhab.core.automation.handler.TriggerHandler) CompositeConditionType(org.openhab.core.automation.type.CompositeConditionType) LinkedHashMap(java.util.LinkedHashMap) ModuleHandler(org.openhab.core.automation.handler.ModuleHandler) CompositeTriggerType(org.openhab.core.automation.type.CompositeTriggerType) ModuleType(org.openhab.core.automation.type.ModuleType) Trigger(org.openhab.core.automation.Trigger) ArrayList(java.util.ArrayList) List(java.util.List) CompositeActionType(org.openhab.core.automation.type.CompositeActionType) ActionHandler(org.openhab.core.automation.handler.ActionHandler) Nullable(org.eclipse.jdt.annotation.Nullable) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with CompositeActionType

use of org.openhab.core.automation.type.CompositeActionType in project openhab-core by openhab.

the class ModuleTypeI18nServiceImpl method createLocalizedActionType.

/**
 * Utility method for localization of ActionTypes.
 *
 * @param at is an ActionType for localization.
 * @param bundle the bundle providing localization resources.
 * @param moduleTypeUID is an ActionType uid.
 * @param locale represents a specific geographical, political, or cultural region.
 * @param lconfigDescriptions are ActionType localized config descriptions.
 * @param llabel is an ActionType localized label.
 * @param ldescription is an ActionType localized description.
 * @return localized ActionType.
 */
@Nullable
private ActionType createLocalizedActionType(ActionType at, Bundle bundle, String moduleTypeUID, @Nullable Locale locale, @Nullable List<ConfigDescriptionParameter> lconfigDescriptions, @Nullable String llabel, @Nullable String ldescription) {
    List<Input> inputs = moduleTypeI18nUtil.getLocalizedInputs(at.getInputs(), bundle, moduleTypeUID, locale);
    List<Output> outputs = moduleTypeI18nUtil.getLocalizedOutputs(at.getOutputs(), bundle, moduleTypeUID, locale);
    ActionType lat = null;
    if (at instanceof CompositeActionType) {
        List<Action> modules = moduleI18nUtil.getLocalizedModules(((CompositeActionType) at).getChildren(), bundle, moduleTypeUID, ModuleTypeI18nUtil.MODULE_TYPE, locale);
        lat = new CompositeActionType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, at.getTags(), at.getVisibility(), inputs, outputs, modules);
    } else {
        lat = new ActionType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, at.getTags(), at.getVisibility(), inputs, outputs);
    }
    return lat;
}
Also used : Input(org.openhab.core.automation.type.Input) Action(org.openhab.core.automation.Action) ActionType(org.openhab.core.automation.type.ActionType) CompositeActionType(org.openhab.core.automation.type.CompositeActionType) Output(org.openhab.core.automation.type.Output) CompositeActionType(org.openhab.core.automation.type.CompositeActionType) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with CompositeActionType

use of org.openhab.core.automation.type.CompositeActionType in project openhab-core by openhab.

the class ModuleTypeRegistryImpl method createCopy.

@Nullable
private ModuleType createCopy(@Nullable ModuleType mType) {
    if (mType == null) {
        return null;
    }
    ModuleType result;
    if (mType instanceof CompositeTriggerType) {
        CompositeTriggerType m = (CompositeTriggerType) mType;
        result = new CompositeTriggerType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getOutputs(), new ArrayList<>(m.getChildren()));
    } else if (mType instanceof TriggerType) {
        TriggerType m = (TriggerType) mType;
        result = new TriggerType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getOutputs());
    } else if (mType instanceof CompositeConditionType) {
        CompositeConditionType m = (CompositeConditionType) mType;
        result = new CompositeConditionType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getInputs(), new ArrayList<>(m.getChildren()));
    } else if (mType instanceof ConditionType) {
        ConditionType m = (ConditionType) mType;
        result = new ConditionType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getInputs());
    } else if (mType instanceof CompositeActionType) {
        CompositeActionType m = (CompositeActionType) mType;
        result = new CompositeActionType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getInputs(), m.getOutputs(), new ArrayList<>(m.getChildren()));
    } else if (mType instanceof ActionType) {
        ActionType m = (ActionType) mType;
        result = new ActionType(mType.getUID(), mType.getConfigurationDescriptions(), mType.getLabel(), mType.getDescription(), mType.getTags(), mType.getVisibility(), m.getInputs(), m.getOutputs());
    } else {
        throw new IllegalArgumentException("Invalid template type:" + mType);
    }
    return result;
}
Also used : CompositeTriggerType(org.openhab.core.automation.type.CompositeTriggerType) TriggerType(org.openhab.core.automation.type.TriggerType) CompositeTriggerType(org.openhab.core.automation.type.CompositeTriggerType) ModuleType(org.openhab.core.automation.type.ModuleType) ActionType(org.openhab.core.automation.type.ActionType) CompositeActionType(org.openhab.core.automation.type.CompositeActionType) ArrayList(java.util.ArrayList) CompositeConditionType(org.openhab.core.automation.type.CompositeConditionType) CompositeConditionType(org.openhab.core.automation.type.CompositeConditionType) ConditionType(org.openhab.core.automation.type.ConditionType) CompositeActionType(org.openhab.core.automation.type.CompositeActionType) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

Nullable (org.eclipse.jdt.annotation.Nullable)3 CompositeActionType (org.openhab.core.automation.type.CompositeActionType)3 ArrayList (java.util.ArrayList)2 Action (org.openhab.core.automation.Action)2 ActionType (org.openhab.core.automation.type.ActionType)2 CompositeConditionType (org.openhab.core.automation.type.CompositeConditionType)2 CompositeTriggerType (org.openhab.core.automation.type.CompositeTriggerType)2 ModuleType (org.openhab.core.automation.type.ModuleType)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Trigger (org.openhab.core.automation.Trigger)1 ActionHandler (org.openhab.core.automation.handler.ActionHandler)1 ModuleHandler (org.openhab.core.automation.handler.ModuleHandler)1 TriggerHandler (org.openhab.core.automation.handler.TriggerHandler)1 ConditionType (org.openhab.core.automation.type.ConditionType)1 Input (org.openhab.core.automation.type.Input)1 Output (org.openhab.core.automation.type.Output)1 TriggerType (org.openhab.core.automation.type.TriggerType)1