Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/add-startup-level-trigger' into …
Browse files Browse the repository at this point in the history
…add-startup-level-trigger

# Conflicts:
#	src/main/java/org/openhab/automation/jrule/internal/engine/JRuleBuilder.java
#	src/main/java/org/openhab/automation/jrule/internal/engine/JRuleEngine.java
#	src/main/java/org/openhab/automation/jrule/internal/module/JRuleModuleEntry.java
#	src/main/java/org/openhab/automation/jrule/internal/module/JRuleModuleHandlerFactory.java
#	src/main/java/org/openhab/automation/jrule/internal/module/JRuleModuleTypeProvider.java
#	src/main/java/org/openhab/automation/jrule/rules/JRuleWhenStartup.java
#	src/test/java/org/openhab/automation/jrule/rules/integration_test/ITJRule.java
#	src/test/java/org/openhab/automation/jrule/rules/user/TestRules.java
  • Loading branch information
querdenker2k committed Jan 6, 2025
2 parents 48a4d3b + 828f11b commit d0b0ee5
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.automation.jrule.internal.engine.excutioncontext.*;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleChannelExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleItemChangeExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleItemExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleItemReceivedCommandExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleItemReceivedUpdateExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRulePreconditionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleStartupExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleThingExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleTimeTimerExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleTimedCronExecutionContext;
import org.openhab.automation.jrule.internal.module.JRuleModuleEntry;
import org.openhab.automation.jrule.rules.JRuleMemberOf;
import org.openhab.automation.jrule.things.JRuleThingStatus;
Expand All @@ -46,16 +55,16 @@ public class JRuleBuilder {
private Duration timedLock = null;
private Duration delayed = null;

final private List<PreCondition> preConditions = new ArrayList<>();
private final List<PreCondition> preConditions = new ArrayList<>();

final private List<WhenStartupTrigger> whenStartupTriggers = new ArrayList<>();
final private List<WhenThingTrigger> whenThingTriggers = new ArrayList<>();
final private List<WhenChannelTrigger> whenChannelTriggers = new ArrayList<>();
final private List<WhenItemReceivedCommand> whenItemReceivedCommandTriggers = new ArrayList<>();
final private List<WhenItemChanged> whenItemChangedTriggers = new ArrayList<>();
final private List<WhenItemReceivedUpdate> whenItemReceivedUpdateTriggers = new ArrayList<>();
final private List<WhenCronTrigger> whenCronTriggers = new ArrayList<>();
final private List<WhenTimeTrigger> whenTimeTriggers = new ArrayList<>();
private final List<WhenStartupTrigger> whenStartupTriggers = new ArrayList<>();
private final List<WhenThingTrigger> whenThingTriggers = new ArrayList<>();
private final List<WhenChannelTrigger> whenChannelTriggers = new ArrayList<>();
private final List<WhenItemReceivedCommand> whenItemReceivedCommandTriggers = new ArrayList<>();
private final List<WhenItemChanged> whenItemChangedTriggers = new ArrayList<>();
private final List<WhenItemReceivedUpdate> whenItemReceivedUpdateTriggers = new ArrayList<>();
private final List<WhenCronTrigger> whenCronTriggers = new ArrayList<>();
private final List<WhenTimeTrigger> whenTimeTriggers = new ArrayList<>();

JRuleBuilder(JRuleEngine jRuleEngine, String ruleName, JRuleInvocationCallback invocationCallback) {
this.jRuleEngine = jRuleEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,34 @@
import org.openhab.automation.jrule.exception.JRuleRuntimeException;
import org.openhab.automation.jrule.internal.JRuleConfig;
import org.openhab.automation.jrule.internal.JRuleLog;
import org.openhab.automation.jrule.internal.engine.excutioncontext.*;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleChannelExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleItemExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleStartupExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleThingExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleTimedExecutionContext;
import org.openhab.automation.jrule.internal.engine.timer.JRuleTimerExecutor;
import org.openhab.automation.jrule.internal.events.JRuleEventSubscriber;
import org.openhab.automation.jrule.internal.handler.JRuleTimerHandler;
import org.openhab.automation.jrule.internal.module.JRuleModuleEntry;
import org.openhab.automation.jrule.internal.module.JRuleRuleProvider;
import org.openhab.automation.jrule.rules.*;
import org.openhab.automation.jrule.rules.JRule;
import org.openhab.automation.jrule.rules.JRuleCondition;
import org.openhab.automation.jrule.rules.JRuleDebounce;
import org.openhab.automation.jrule.rules.JRuleDelayed;
import org.openhab.automation.jrule.rules.JRuleLogName;
import org.openhab.automation.jrule.rules.JRuleMemberOf;
import org.openhab.automation.jrule.rules.JRuleName;
import org.openhab.automation.jrule.rules.JRulePrecondition;
import org.openhab.automation.jrule.rules.JRuleTag;
import org.openhab.automation.jrule.rules.JRuleWhenChannelTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenCronTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenItemChange;
import org.openhab.automation.jrule.rules.JRuleWhenItemReceivedCommand;
import org.openhab.automation.jrule.rules.JRuleWhenItemReceivedUpdate;
import org.openhab.automation.jrule.rules.JRuleWhenStartup;
import org.openhab.automation.jrule.rules.JRuleWhenThingTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenTimeTrigger;
import org.openhab.automation.jrule.rules.event.JRuleEvent;
import org.openhab.automation.jrule.things.JRuleThingStatus;
import org.openhab.core.events.AbstractEvent;
Expand Down Expand Up @@ -204,7 +225,6 @@ private void add(Method method, JRule jRule, boolean enableRule) {
.orElse(null),
Optional.of(jRuleWhen.from()).filter(s -> s != JRuleThingStatus.THING_UNKNOWN).orElse(null),
Optional.of(jRuleWhen.to()).filter(s -> s != JRuleThingStatus.THING_UNKNOWN).orElse(null)));

Arrays.stream(method.getAnnotationsByType(JRuleWhenStartup.class))
.forEach(jRuleWhen -> jRuleBuilder.whenStartupTrigger(jRuleWhen.level()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
*/
package org.openhab.automation.jrule.internal.handler;

import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.NonNull;
Expand All @@ -24,12 +32,47 @@
import org.openhab.automation.jrule.items.JRuleItem;
import org.openhab.automation.jrule.items.JRuleItemRegistry;
import org.openhab.automation.jrule.rules.JRule;
import org.openhab.automation.jrule.rules.value.*;
import org.openhab.automation.jrule.rules.value.JRuleDateTimeValue;
import org.openhab.automation.jrule.rules.value.JRuleDecimalValue;
import org.openhab.automation.jrule.rules.value.JRuleHsbValue;
import org.openhab.automation.jrule.rules.value.JRuleNextPreviousValue;
import org.openhab.automation.jrule.rules.value.JRuleOnOffValue;
import org.openhab.automation.jrule.rules.value.JRuleOpenClosedValue;
import org.openhab.automation.jrule.rules.value.JRulePercentValue;
import org.openhab.automation.jrule.rules.value.JRulePlayPauseValue;
import org.openhab.automation.jrule.rules.value.JRulePointValue;
import org.openhab.automation.jrule.rules.value.JRuleQuantityValue;
import org.openhab.automation.jrule.rules.value.JRuleRawValue;
import org.openhab.automation.jrule.rules.value.JRuleRewindFastforwardValue;
import org.openhab.automation.jrule.rules.value.JRuleStopMoveValue;
import org.openhab.automation.jrule.rules.value.JRuleStringListValue;
import org.openhab.automation.jrule.rules.value.JRuleStringValue;
import org.openhab.automation.jrule.rules.value.JRuleUpDownValue;
import org.openhab.automation.jrule.rules.value.JRuleValue;
import org.openhab.core.events.EventPublisher;
import org.openhab.core.items.*;
import org.openhab.core.items.GenericItem;
import org.openhab.core.items.GroupItem;
import org.openhab.core.items.Item;
import org.openhab.core.items.ItemNotFoundException;
import org.openhab.core.items.ItemRegistry;
import org.openhab.core.items.events.ItemEvent;
import org.openhab.core.items.events.ItemEventFactory;
import org.openhab.core.library.types.*;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.NextPreviousType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.PlayPauseType;
import org.openhab.core.library.types.PointType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.RawType;
import org.openhab.core.library.types.RewindFastforwardType;
import org.openhab.core.library.types.StopMoveType;
import org.openhab.core.library.types.StringListType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.types.UpDownType;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
import org.openhab.automation.jrule.internal.engine.JRuleEngine;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleExecutionContext;
import org.openhab.automation.jrule.internal.engine.excutioncontext.JRuleStartupExecutionContext;
import org.openhab.automation.jrule.rules.*;
import org.openhab.automation.jrule.rules.JRule;
import org.openhab.automation.jrule.rules.JRuleWhenChannelTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenCronTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenItemChange;
import org.openhab.automation.jrule.rules.JRuleWhenItemReceivedCommand;
import org.openhab.automation.jrule.rules.JRuleWhenItemReceivedUpdate;
import org.openhab.automation.jrule.rules.JRuleWhenStartup;
import org.openhab.automation.jrule.rules.JRuleWhenThingTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenTimeTrigger;
import org.openhab.core.automation.Action;
import org.openhab.core.automation.Trigger;
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.automation.jrule.rules.*;
import org.openhab.automation.jrule.rules.JRuleWhenChannelTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenCronTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenItemChange;
import org.openhab.automation.jrule.rules.JRuleWhenItemReceivedCommand;
import org.openhab.automation.jrule.rules.JRuleWhenItemReceivedUpdate;
import org.openhab.automation.jrule.rules.JRuleWhenStartup;
import org.openhab.automation.jrule.rules.JRuleWhenThingTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenTimeTrigger;
import org.openhab.core.automation.Module;
import org.openhab.core.automation.Trigger;
import org.openhab.core.automation.handler.BaseModuleHandlerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.automation.jrule.rules.*;
import org.openhab.automation.jrule.rules.JRuleWhenChannelTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenCronTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenItemChange;
import org.openhab.automation.jrule.rules.JRuleWhenItemReceivedCommand;
import org.openhab.automation.jrule.rules.JRuleWhenItemReceivedUpdate;
import org.openhab.automation.jrule.rules.JRuleWhenStartup;
import org.openhab.automation.jrule.rules.JRuleWhenThingTrigger;
import org.openhab.automation.jrule.rules.JRuleWhenTimeTrigger;
import org.openhab.core.automation.type.ModuleType;
import org.openhab.core.automation.type.ModuleTypeProvider;
import org.openhab.core.common.registry.ProviderChangeListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.openhab.automation.jrule.internal.JRuleUtil;
import org.openhab.automation.jrule.internal.handler.JRuleEventHandler;
import org.openhab.automation.jrule.internal.items.JRuleInternalColorItem;
import org.openhab.automation.jrule.rules.value.*;
import org.openhab.automation.jrule.rules.value.JRuleHsbValue;

/**
* The {@link JRuleColorItem} JRule Item
Expand All @@ -36,7 +36,7 @@ static Optional<JRuleColorItem> forNameOptional(String itemName) {

/**
* Sends a hsb command
*
*
* @param command command to send.
*/
default void sendCommand(JRuleHsbValue command) {
Expand All @@ -45,7 +45,7 @@ default void sendCommand(JRuleHsbValue command) {

/**
* Sends a hsb update
*
*
* @param state update to send
*/
default void postUpdate(JRuleHsbValue state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
package org.openhab.automation.jrule.items;

import java.time.ZonedDateTime;
import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.automation.jrule.exception.JRuleItemNotFoundException;
Expand Down Expand Up @@ -56,7 +60,7 @@ static Optional<JRuleItem> forNameOptional(String itemName) {

/**
* Returns all GroupItems, which this item belongs to -> this item is a member of the returning result
*
*
* @return GroupItems which this items belongs to
*/
default Set<JRuleGroupItem<? extends JRuleItem>> getGroupItems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import org.openhab.automation.jrule.internal.JRuleUtil;
import org.openhab.automation.jrule.internal.handler.JRuleEventHandler;
import org.openhab.automation.jrule.internal.items.JRuleInternalPlayerItem;
import org.openhab.automation.jrule.rules.value.*;
import org.openhab.automation.jrule.rules.value.JRuleNextPreviousValue;
import org.openhab.automation.jrule.rules.value.JRulePlayPauseValue;
import org.openhab.automation.jrule.rules.value.JRuleRewindFastforwardValue;

/**
* The {@link JRulePlayerItem} JRule Item
Expand All @@ -43,7 +45,7 @@ static Optional<JRulePlayerItem> forNameOptional(String itemName) {

/**
* Sends a play/pause command
*
*
* @param command command to send.
*/
default void sendCommand(JRulePlayPauseValue command) {
Expand All @@ -52,7 +54,7 @@ default void sendCommand(JRulePlayPauseValue command) {

/**
* Sends a play/pause update
*
*
* @param state update to send
*/
default void postUpdate(JRulePlayPauseValue state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import org.openhab.automation.jrule.internal.JRuleUtil;
import org.openhab.automation.jrule.internal.handler.JRuleEventHandler;
import org.openhab.automation.jrule.internal.items.JRuleInternalRollershutterItem;
import org.openhab.automation.jrule.rules.value.*;
import org.openhab.automation.jrule.rules.value.JRulePercentValue;
import org.openhab.automation.jrule.rules.value.JRuleStopMoveValue;
import org.openhab.automation.jrule.rules.value.JRuleUpDownValue;

/**
* The {@link JRuleRollershutterItem} JRule Item
Expand All @@ -42,7 +44,7 @@ static Optional<JRuleRollershutterItem> forNameOptional(String itemName) {

/**
* Sends a percent command
*
*
* @param command command to send.
*/
default void sendCommand(JRulePercentValue command) {
Expand All @@ -51,7 +53,7 @@ default void sendCommand(JRulePercentValue command) {

/**
* Sends a percent update
*
*
* @param state update to send
*/
default void postUpdate(JRulePercentValue state) {
Expand All @@ -60,7 +62,7 @@ default void postUpdate(JRulePercentValue state) {

/**
* Sends a percent command.
*
*
* @param command as number via JRulePercentValue will be send.
*/
default void sendCommand(int command) {
Expand Down Expand Up @@ -96,7 +98,7 @@ default void sendCommand(JRuleStopMoveValue command) {

/**
* Sends a percent update.
*
*
* @param state as number via JRulePercentValue will be send.
*/
default void postUpdate(int state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
*/
package org.openhab.automation.jrule.rules;

import java.lang.annotation.*;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The {@link JRuleWhenStartup}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
*/
package org.openhab.automation.jrule.items;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void triggerOnGroupStateChange() throws IOException {
@Test
public void startupTriggered() throws IOException {
verifyRuleWasExecuted(TestRules.NAME_STARTUP_TRIGGERED);
verifyLogEntry("startup level 50 triggered: true");
verifyLogEntry("Startup Event: '50'");
verifyNoError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
import org.awaitility.Awaitility;
import org.eclipse.paho.client.mqttv3.*;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;
import org.openhab.automation.jrule.items.JRuleSwitchItem;
import org.openhab.automation.jrule.rules.user.TestRules;
import org.slf4j.Logger;
Expand Down
Loading

0 comments on commit d0b0ee5

Please sign in to comment.