Skip to content

Commit

Permalink
Include StartLevelEvent in start level triggers (openhab#4093)
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng authored Feb 18, 2024
1 parent e628f75 commit b64e972
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.openhab.core.common.registry.RegistryChangeListener;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventPublisher;
import org.openhab.core.events.system.SystemEventFactory;
import org.openhab.core.service.ReadyMarker;
import org.openhab.core.service.ReadyMarkerFilter;
import org.openhab.core.service.ReadyService;
Expand Down Expand Up @@ -854,8 +855,8 @@ private boolean activateRule(final WrappedRule rule) {
if (slTriggers.stream()
.anyMatch(t -> ((BigDecimal) t.getConfiguration().get(SystemTriggerHandler.CFG_STARTLEVEL))
.intValue() <= startLevelService.getStartLevel())) {
runNow(rule.getUID(), true,
Map.of(SystemTriggerHandler.OUT_STARTLEVEL, StartLevelService.STARTLEVEL_RULES));
runNow(rule.getUID(), true, Map.of(SystemTriggerHandler.OUT_STARTLEVEL, StartLevelService.STARTLEVEL_RULES,
"event", SystemEventFactory.createStartlevelEvent(StartLevelService.STARTLEVEL_RULES)));
}

return true;
Expand Down Expand Up @@ -1447,7 +1448,8 @@ private void executeRulesWithStartLevel() {
ruleRegistry.getAll().stream() //
.filter(this::mustTrigger) //
.forEach(r -> runNow(r.getUID(), true,
Map.of(SystemTriggerHandler.OUT_STARTLEVEL, StartLevelService.STARTLEVEL_RULES)));
Map.of(SystemTriggerHandler.OUT_STARTLEVEL, StartLevelService.STARTLEVEL_RULES, "event",
SystemEventFactory.createStartlevelEvent(StartLevelService.STARTLEVEL_RULES))));
started = true;
readyService.markReady(MARKER);
logger.info("Rule engine started.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.openhab.core.automation.internal.module.handler;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -87,7 +86,7 @@ public void receive(Event event) {
if (startlevel <= sl && startlevel > StartLevelService.STARTLEVEL_RULEENGINE) {
// only execute rules if their start level is higher than the rule engine activation level, since
// otherwise the rule engine takes care of the execution already
trigger();
trigger(event);
}
}
}
Expand All @@ -101,15 +100,14 @@ public void dispose() {
super.dispose();
}

public void trigger() {
private void trigger(Event event) {
final ModuleHandlerCallback callback = this.callback;
if (!(callback instanceof TriggerHandlerCallback)) {
return;
}

TriggerHandlerCallback thCallback = (TriggerHandlerCallback) callback;
Map<String, Object> values = new HashMap<>();
values.put(OUT_STARTLEVEL, startlevel);
Map<String, Object> values = Map.of(OUT_STARTLEVEL, startlevel, "event", event);
thCallback.triggered(module, values);
triggered = true;
}
Expand Down

0 comments on commit b64e972

Please sign in to comment.