Search in sources :

Example 1 with TimeBasedTriggerHandler

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;
}
Also used : SchedulerTemporalAdjuster(org.openhab.core.scheduler.SchedulerTemporalAdjuster) Trigger(org.openhab.core.automation.Trigger) RuleExecution(org.openhab.core.automation.RuleExecution) TriggerHandler(org.openhab.core.automation.handler.TriggerHandler) TimeBasedTriggerHandler(org.openhab.core.automation.handler.TimeBasedTriggerHandler) ArrayList(java.util.ArrayList) TimeBasedTriggerHandler(org.openhab.core.automation.handler.TimeBasedTriggerHandler)

Aggregations

ArrayList (java.util.ArrayList)1 RuleExecution (org.openhab.core.automation.RuleExecution)1 Trigger (org.openhab.core.automation.Trigger)1 TimeBasedTriggerHandler (org.openhab.core.automation.handler.TimeBasedTriggerHandler)1 TriggerHandler (org.openhab.core.automation.handler.TriggerHandler)1 SchedulerTemporalAdjuster (org.openhab.core.scheduler.SchedulerTemporalAdjuster)1