use of org.openhab.core.automation.handler.TimeBasedTriggerHandler in project openhab-core by openhab.
the class RuleExecutionSimulator method simulateExecutionsForRule.
/**
* Simulates the next executions for the given {@link Rule} until the given {@link Date}.
*
* @param rule {@link Rule} to be simulated.
* @param from {@link ZonedDateTime} earliest time to be contained in the rule simulation.
* @param until {@link ZonedDateTime} latest time to be contained in the rule simulation.
* @return List of expected {@link RuleExecution}.
*/
private List<RuleExecution> simulateExecutionsForRule(Rule rule, ZonedDateTime from, ZonedDateTime until) {
final List<RuleExecution> executions = new ArrayList<>();
for (Trigger trigger : rule.getTriggers()) {
TriggerHandler triggerHandler = (TriggerHandler) this.ruleEngine.getModuleHandler(trigger, rule.getUID());
// Only triggers that are time-based will be considered within the simulation
if (triggerHandler instanceof TimeBasedTriggerHandler) {
SchedulerTemporalAdjuster temporalAdjuster = ((TimeBasedTriggerHandler) triggerHandler).getTemporalAdjuster();
if (temporalAdjuster != null) {
executions.addAll(simulateExecutionsForCronBasedRule(rule, from, until, temporalAdjuster));
}
}
}
logger.debug("Created {} rule simulations for rule {}.", executions.size(), rule.getName());
return executions;
}
Aggregations