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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations