use of org.eclipse.smarthome.model.rule.rules.GroupMemberUpdateEventTrigger in project smarthome by eclipse.
the class RuleTriggerManager method addRule.
/**
* Adds a given rule to the mapping tables
*
* @param rule the rule to add
*/
public synchronized void addRule(Rule rule) {
for (EventTrigger t : rule.getEventtrigger()) {
// add the rule to the lookup map for the trigger kind
if (t instanceof SystemOnStartupTrigger) {
systemStartupTriggeredRules.add(rule);
} else if (t instanceof SystemOnShutdownTrigger) {
systemShutdownTriggeredRules.add(rule);
} else if (t instanceof CommandEventTrigger) {
CommandEventTrigger ceTrigger = (CommandEventTrigger) t;
Set<Rule> rules = commandEventTriggeredRules.get(ceTrigger.getItem());
if (rules == null) {
rules = new HashSet<Rule>();
commandEventTriggeredRules.put(ceTrigger.getItem(), rules);
}
rules.add(rule);
} else if (t instanceof GroupMemberCommandEventTrigger) {
GroupMemberCommandEventTrigger gmceTrigger = (GroupMemberCommandEventTrigger) t;
Set<Rule> rules = commandEventTriggeredRules.get(GROUP_NAME_PREFIX + gmceTrigger.getGroup());
if (rules == null) {
rules = new HashSet<Rule>();
commandEventTriggeredRules.put(GROUP_NAME_PREFIX + gmceTrigger.getGroup(), rules);
}
rules.add(rule);
} else if (t instanceof UpdateEventTrigger) {
UpdateEventTrigger ueTrigger = (UpdateEventTrigger) t;
Set<Rule> rules = updateEventTriggeredRules.get(ueTrigger.getItem());
if (rules == null) {
rules = new HashSet<Rule>();
updateEventTriggeredRules.put(ueTrigger.getItem(), rules);
}
rules.add(rule);
} else if (t instanceof GroupMemberUpdateEventTrigger) {
GroupMemberUpdateEventTrigger gmueTrigger = (GroupMemberUpdateEventTrigger) t;
Set<Rule> rules = updateEventTriggeredRules.get(GROUP_NAME_PREFIX + gmueTrigger.getGroup());
if (rules == null) {
rules = new HashSet<Rule>();
updateEventTriggeredRules.put(GROUP_NAME_PREFIX + gmueTrigger.getGroup(), rules);
}
rules.add(rule);
} else if (t instanceof ChangedEventTrigger) {
ChangedEventTrigger ceTrigger = (ChangedEventTrigger) t;
Set<Rule> rules = changedEventTriggeredRules.get(ceTrigger.getItem());
if (rules == null) {
rules = new HashSet<Rule>();
changedEventTriggeredRules.put(ceTrigger.getItem(), rules);
}
rules.add(rule);
} else if (t instanceof GroupMemberChangedEventTrigger) {
GroupMemberChangedEventTrigger gmceTrigger = (GroupMemberChangedEventTrigger) t;
Set<Rule> rules = changedEventTriggeredRules.get(GROUP_NAME_PREFIX + gmceTrigger.getGroup());
if (rules == null) {
rules = new HashSet<Rule>();
changedEventTriggeredRules.put(GROUP_NAME_PREFIX + gmceTrigger.getGroup(), rules);
}
rules.add(rule);
} else if (t instanceof TimerTrigger) {
try {
createTimer(rule, (TimerTrigger) t);
timerEventTriggeredRules.add(rule);
} catch (SchedulerException e) {
logger.error("Cannot create timer for rule '{}': {}", rule.getName(), e.getMessage());
}
} else if (t instanceof EventEmittedTrigger) {
EventEmittedTrigger eeTrigger = (EventEmittedTrigger) t;
Set<Rule> rules = triggerEventTriggeredRules.get(eeTrigger.getChannel());
if (rules == null) {
rules = new HashSet<Rule>();
triggerEventTriggeredRules.put(eeTrigger.getChannel(), rules);
}
rules.add(rule);
} else if (t instanceof ThingStateUpdateEventTrigger) {
ThingStateUpdateEventTrigger tsuTrigger = (ThingStateUpdateEventTrigger) t;
Set<Rule> rules = thingUpdateEventTriggeredRules.get(tsuTrigger.getThing());
if (rules == null) {
rules = new HashSet<Rule>();
thingUpdateEventTriggeredRules.put(tsuTrigger.getThing(), rules);
}
rules.add(rule);
} else if (t instanceof ThingStateChangedEventTrigger) {
ThingStateChangedEventTrigger tscTrigger = (ThingStateChangedEventTrigger) t;
Set<Rule> rules = thingChangedEventTriggeredRules.get(tscTrigger.getThing());
if (rules == null) {
rules = new HashSet<Rule>();
thingChangedEventTriggeredRules.put(tscTrigger.getThing(), rules);
}
rules.add(rule);
}
}
}
use of org.eclipse.smarthome.model.rule.rules.GroupMemberUpdateEventTrigger in project smarthome by eclipse.
the class RuleTriggerManager method internalGetUpdateRules.
private void internalGetUpdateRules(String name, Boolean isGroup, List<Class<? extends State>> acceptedDataTypes, State state, List<Rule> result) {
final String mapName = (isGroup) ? GROUP_NAME_PREFIX + name : name;
for (Rule rule : getAllRules(UPDATE, mapName)) {
for (EventTrigger t : rule.getEventtrigger()) {
String triggerStateString = null;
if ((!isGroup) && (t instanceof UpdateEventTrigger)) {
final UpdateEventTrigger ut = (UpdateEventTrigger) t;
if (ut.getItem().equals(name)) {
triggerStateString = ut.getState();
} else {
continue;
}
} else if ((isGroup) && (t instanceof GroupMemberUpdateEventTrigger)) {
final GroupMemberUpdateEventTrigger gmut = (GroupMemberUpdateEventTrigger) t;
if (gmut.getGroup().equals(name)) {
triggerStateString = gmut.getState();
} else {
continue;
}
} else {
continue;
}
if (triggerStateString != null) {
final State triggerState = TypeParser.parseState(acceptedDataTypes, triggerStateString);
if (!state.equals(triggerState)) {
continue;
}
}
result.add(rule);
}
}
}
Aggregations