use of org.eclipse.smarthome.automation.type.Output in project smarthome by eclipse.
the class ModuleTypeRegistryMockup method createActionType.
private ActionType createActionType() {
List<Input> inputs = new ArrayList<Input>(3);
// conflict in3 -> out4 or in3 -> out5
inputs.add(createInput("in3", new String[] { "tagD" }));
// in4 -> out5
inputs.add(createInput("in4", new String[] { "tagD", "tagE" }));
// in5 -> out3
inputs.add(createInput("in5", new String[] { "tagA", "tagB", "tagC" }));
// conflict in6 has user defined connection
inputs.add(createInput("in6", new String[] { "tagA", "tagB" }));
List<Output> outputs = new ArrayList<Output>(3);
outputs.add(createOutput("out4", new String[] { "tagD" }));
outputs.add(createOutput("out5", new String[] { "tagD", "tagE" }));
ActionType t = new ActionType(ACTION_TYPE, null, inputs, outputs);
return t;
}
use of org.eclipse.smarthome.automation.type.Output in project smarthome by eclipse.
the class CompositeTriggerHandler method triggered.
/**
* This method is called by the child triggers defined by the {@link CompositeTriggerType} of parent trigger.
* The method goes through the outputs of the parent trigger and fill them base on the ouput's reference value.
* The ouput's reference value can contain more then one references to the child outputs separated by comma. In this
* case the method will try to fill the output value in sequence defined in the reference value. The letter
* reference can be overwritten by the previous ones.
*
* @see org.eclipse.smarthome.automation.handler.RuleEngineCallback#triggered(org.eclipse.smarthome.automation.Trigger,
* java.util.Map)
*/
@Override
public void triggered(Trigger trigger, Map<String, ?> context) {
if (ruleCallback != null) {
List<Output> outputs = moduleType.getOutputs();
Map<String, Object> result = new HashMap<String, Object>(11);
for (Output output : outputs) {
String refs = output.getReference();
if (refs != null) {
String ref;
StringTokenizer st = new StringTokenizer(refs, ",");
while (st.hasMoreTokens()) {
ref = st.nextToken().trim();
int i = ref.indexOf('.');
if (i != -1) {
String childModuleId = ref.substring(0, i);
if (trigger.getId().equals(childModuleId)) {
ref = ref.substring(i + 1);
}
}
Object value = null;
int idx = ReferenceResolverUtil.getNextRefToken(ref, 1);
if (idx < ref.length()) {
String outputId = ref.substring(0, idx);
value = ReferenceResolverUtil.getValue(context.get(outputId), ref.substring(idx + 1));
} else {
value = context.get(ref);
}
if (value != null) {
result.put(output.getName(), value);
}
}
}
}
ruleCallback.triggered(module, result);
}
}
use of org.eclipse.smarthome.automation.type.Output in project smarthome by eclipse.
the class CompositeActionHandler method execute.
/**
* The method calls handlers of child action, collect their outputs and sets the output of the parent action.
*
* @see org.eclipse.smarthome.automation.handler.ActionHandler#execute(java.util.Map)
*/
@Override
public Map<String, Object> execute(Map<String, Object> context) {
final Map<String, Object> result = new HashMap<String, Object>();
final List<Action> children = getChildren();
final Map<String, Object> compositeContext = getCompositeContext(context);
for (Action child : children) {
ActionHandler childHandler = moduleHandlerMap.get(child);
Map<String, Object> childContext = Collections.unmodifiableMap(getChildContext(child, compositeContext));
Map<String, Object> childResults = childHandler.execute(childContext);
if (childResults != null) {
for (Entry<String, Object> childResult : childResults.entrySet()) {
String childOuputName = child.getId() + "." + childResult.getKey();
Output output = compositeOutputs.get(childOuputName);
if (output != null) {
String childOuputRef = output.getReference();
if (childOuputRef != null && childOuputRef.length() > childOuputName.length()) {
childOuputRef = childOuputRef.substring(childOuputName.length());
result.put(output.getName(), ReferenceResolverUtil.getValue(childResult.getValue(), childOuputRef));
} else {
result.put(output.getName(), childResult.getValue());
}
}
}
}
}
return result.size() > 0 ? result : null;
}
use of org.eclipse.smarthome.automation.type.Output in project smarthome by eclipse.
the class CompositeActionHandler method getCompositeOutputMap.
/**
* Create a map of links between child outputs and parent outputs. These links are base on the refecences defined in
* the outputs of parent action.
*
* @param outputs outputs of the parent action. The action of {@link CompositeActionType}
* @return map of links between child action outputs and parent output
*/
protected Map<String, Output> getCompositeOutputMap(List<Output> outputs) {
Map<String, Output> result = new HashMap<String, Output>(11);
if (outputs != null) {
for (Output output : outputs) {
String refs = output.getReference();
if (refs != null) {
String ref;
StringTokenizer st = new StringTokenizer(refs, ",");
while (st.hasMoreTokens()) {
ref = st.nextToken().trim();
int i = ref.indexOf('.');
if (i != -1) {
int j = ReferenceResolverUtil.getNextRefToken(ref, i + 1);
if (j != -1) {
ref = ref.substring(0, j);
}
}
result.put(ref, output);
}
}
}
}
return result;
}
use of org.eclipse.smarthome.automation.type.Output in project smarthome by eclipse.
the class ModuleTypeResourceBundleProvider method createLocalizedTriggerType.
/**
* Utility method for localization of TriggerTypes.
*
* @param ct is a TriggerType for localization.
* @param bundle the bundle providing localization resources.
* @param moduleTypeUID is a TriggerType uid.
* @param locale represents a specific geographical, political, or cultural region.
* @param lconfigDescriptions are TriggerType localized config descriptions.
* @param llabel is a TriggerType localized label.
* @param ldescription is a TriggerType localized description.
* @return localized TriggerType.
*/
private TriggerType createLocalizedTriggerType(TriggerType tt, Bundle bundle, String moduleTypeUID, Locale locale, List<ConfigDescriptionParameter> lconfigDescriptions, String llabel, String ldescription) {
List<Output> outputs = ModuleTypeI18nUtil.getLocalizedOutputs(i18nProvider, tt.getOutputs(), bundle, moduleTypeUID, locale);
TriggerType ltt = null;
if (tt instanceof CompositeTriggerType) {
List<Trigger> modules = ModuleI18nUtil.getLocalizedModules(i18nProvider, ((CompositeTriggerType) tt).getChildren(), bundle, moduleTypeUID, ModuleTypeI18nUtil.MODULE_TYPE, locale);
ltt = new CompositeTriggerType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, tt.getTags(), tt.getVisibility(), outputs, modules);
} else {
ltt = new TriggerType(moduleTypeUID, lconfigDescriptions, llabel, ldescription, tt.getTags(), tt.getVisibility(), outputs);
}
return ltt;
}
Aggregations