Search in sources :

Example 16 with Condition

use of org.eclipse.smarthome.automation.Condition in project smarthome by eclipse.

the class ModuleTypeResourceBundleProvider method createLocalizedConditionType.

/**
 * Utility method for localization of ConditionTypes.
 *
 * @param ct is a ConditionType for localization.
 * @param bundle the bundle providing localization resources.
 * @param moduleTypeUID is a ConditionType uid.
 * @param locale represents a specific geographical, political, or cultural region.
 * @param lconfigDescriptions are ConditionType localized config descriptions.
 * @param llabel is a ConditionType localized label.
 * @param ldescription is a ConditionType localized description.
 * @return localized ConditionType.
 */
private ConditionType createLocalizedConditionType(ConditionType ct, Bundle bundle, String moduleTypeUID, Locale locale, List<ConfigDescriptionParameter> lconfigDescriptions, String llabel, String ldescription) {
    List<Input> inputs = ModuleTypeI18nUtil.getLocalizedInputs(i18nProvider, ct.getInputs(), bundle, moduleTypeUID, locale);
    ConditionType lct = null;
    if (ct instanceof CompositeConditionType) {
        List<Condition> modules = ModuleI18nUtil.getLocalizedModules(i18nProvider, ((CompositeConditionType) ct).getChildren(), bundle, moduleTypeUID, ModuleTypeI18nUtil.MODULE_TYPE, locale);
        lct = new CompositeConditionType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, ct.getTags(), ct.getVisibility(), inputs, modules);
    } else {
        lct = new ConditionType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, ct.getTags(), ct.getVisibility(), inputs);
    }
    return lct;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Input(org.eclipse.smarthome.automation.type.Input) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) CompositeConditionType(org.eclipse.smarthome.automation.type.CompositeConditionType) ConditionType(org.eclipse.smarthome.automation.type.ConditionType)

Example 17 with Condition

use of org.eclipse.smarthome.automation.Condition in project smarthome by eclipse.

the class TemplateResourceBundleProvider method getPerLocale.

/**
 * This method is used to localize the {@link Template}s.
 *
 * @param element is the {@link Template} that must be localized.
 * @param locale represents a specific geographical, political, or cultural region.
 * @return the localized {@link Template}.
 */
private RuleTemplate getPerLocale(RuleTemplate defTemplate, Locale locale) {
    if (locale == null || defTemplate == null || i18nProvider == null) {
        return defTemplate;
    }
    String uid = defTemplate.getUID();
    Bundle bundle = getBundle(uid);
    if (defTemplate instanceof RuleTemplate) {
        String llabel = RuleTemplateI18nUtil.getLocalizedRuleTemplateLabel(i18nProvider, bundle, uid, defTemplate.getLabel(), locale);
        String ldescription = RuleTemplateI18nUtil.getLocalizedRuleTemplateDescription(i18nProvider, bundle, uid, defTemplate.getDescription(), locale);
        List<ConfigDescriptionParameter> lconfigDescriptions = getLocalizedConfigurationDescription(i18nProvider, defTemplate.getConfigurationDescriptions(), bundle, uid, RuleTemplateI18nUtil.RULE_TEMPLATE, locale);
        List<Action> lactions = ModuleI18nUtil.getLocalizedModules(i18nProvider, defTemplate.getActions(), bundle, uid, RuleTemplateI18nUtil.RULE_TEMPLATE, locale);
        List<Condition> lconditions = ModuleI18nUtil.getLocalizedModules(i18nProvider, defTemplate.getConditions(), bundle, uid, RuleTemplateI18nUtil.RULE_TEMPLATE, locale);
        List<Trigger> ltriggers = ModuleI18nUtil.getLocalizedModules(i18nProvider, defTemplate.getTriggers(), bundle, uid, RuleTemplateI18nUtil.RULE_TEMPLATE, locale);
        return new RuleTemplate(uid, llabel, ldescription, defTemplate.getTags(), ltriggers, lconditions, lactions, lconfigDescriptions, defTemplate.getVisibility());
    }
    return null;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Action(org.eclipse.smarthome.automation.Action) Trigger(org.eclipse.smarthome.automation.Trigger) Bundle(org.osgi.framework.Bundle) RuleTemplate(org.eclipse.smarthome.automation.template.RuleTemplate) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Example 18 with Condition

use of org.eclipse.smarthome.automation.Condition in project smarthome by eclipse.

the class RuleUtils method getConditionsCopy.

/**
 * This method creates deep copy of list of conditions
 *
 * @param conditions list of conditions
 * @return deep copy of list of conditions or empty list when the parameter is null.
 */
public static List<Condition> getConditionsCopy(List<Condition> conditions) {
    List<Condition> res = new ArrayList<Condition>();
    if (conditions != null) {
        for (Condition c : conditions) {
            Condition condition = new Condition(c.getId(), c.getTypeUID(), new Configuration(c.getConfiguration().getProperties()), new HashMap<String, String>(c.getInputs()));
            condition.setLabel(c.getLabel());
            condition.setDescription(c.getDescription());
            res.add(condition);
        }
    }
    return res;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Configuration(org.eclipse.smarthome.config.core.Configuration) ArrayList(java.util.ArrayList)

Example 19 with Condition

use of org.eclipse.smarthome.automation.Condition in project smarthome by eclipse.

the class TimerModuleHandlerFactory method internalCreate.

@Override
protected ModuleHandler internalCreate(Module module, String ruleUID) {
    logger.trace("create {} -> {}", module.getId(), module.getTypeUID());
    String moduleTypeUID = module.getTypeUID();
    if (GenericCronTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Trigger) {
        return new GenericCronTriggerHandler((Trigger) module);
    } else if (TimeOfDayTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Trigger) {
        return new TimeOfDayTriggerHandler((Trigger) module);
    } else if (DayOfWeekConditionHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Condition) {
        return new DayOfWeekConditionHandler((Condition) module);
    } else {
        logger.error("The module handler type '{}' is not supported.", moduleTypeUID);
    }
    return null;
}
Also used : GenericCronTriggerHandler(org.eclipse.smarthome.automation.module.timer.handler.GenericCronTriggerHandler) Condition(org.eclipse.smarthome.automation.Condition) Trigger(org.eclipse.smarthome.automation.Trigger) DayOfWeekConditionHandler(org.eclipse.smarthome.automation.module.timer.handler.DayOfWeekConditionHandler) TimeOfDayTriggerHandler(org.eclipse.smarthome.automation.module.timer.handler.TimeOfDayTriggerHandler)

Example 20 with Condition

use of org.eclipse.smarthome.automation.Condition in project smarthome by eclipse.

the class ScriptModuleHandlerFactory method internalCreate.

@Override
protected ModuleHandler internalCreate(Module module, String ruleUID) {
    logger.trace("create {} -> {}", module.getId(), module.getTypeUID());
    String moduleTypeUID = module.getTypeUID();
    if (moduleTypeUID != null) {
        if (ScriptConditionHandler.SCRIPT_CONDITION.equals(moduleTypeUID) && module instanceof Condition) {
            ScriptConditionHandler handler = new ScriptConditionHandler((Condition) module, ruleUID, scriptEngineManager);
            return handler;
        } else if (ScriptActionHandler.SCRIPT_ACTION_ID.equals(moduleTypeUID) && module instanceof Action) {
            ScriptActionHandler handler = new ScriptActionHandler((Action) module, ruleUID, scriptEngineManager);
            return handler;
        } else {
            logger.error("The ModuleHandler is not supported: {}", moduleTypeUID);
        }
    } else {
        logger.error("ModuleType is not registered: {}", moduleTypeUID);
    }
    return null;
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) ScriptConditionHandler(org.eclipse.smarthome.automation.module.script.internal.handler.ScriptConditionHandler) ScriptActionHandler(org.eclipse.smarthome.automation.module.script.internal.handler.ScriptActionHandler) Action(org.eclipse.smarthome.automation.Action)

Aggregations

Condition (org.eclipse.smarthome.automation.Condition)21 Action (org.eclipse.smarthome.automation.Action)10 Configuration (org.eclipse.smarthome.config.core.Configuration)10 Trigger (org.eclipse.smarthome.automation.Trigger)9 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)4 Rule (org.eclipse.smarthome.automation.Rule)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)3 Set (java.util.Set)2 Module (org.eclipse.smarthome.automation.Module)2 RuleStatus (org.eclipse.smarthome.automation.RuleStatus)2 ConditionHandler (org.eclipse.smarthome.automation.handler.ConditionHandler)2 CompareConditionHandler (org.eclipse.smarthome.automation.module.core.handler.CompareConditionHandler)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1