Skip to content

Commit

Permalink
[rules] JSRule: Support rules without triggers (#372)
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Aug 14, 2024
1 parent feb90e1 commit cadda4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/rules/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @typedef {object} RuleConfig configuration for {@link rules.JSRule}
* @property {string} name name of the rule (used in UI)
* @property {string} [description] description of the rule (used in UI)
* @property {HostTrigger|HostTrigger[]} triggers which will fire the rule
* @property {HostTrigger|HostTrigger[]} [triggers] which will fire the rule
* @property {RuleCallback} execute callback to run when the rule fires
* @property {string} [id] UID of the rule, if not provided, one is generated
* @property {string[]} [tags] tags for the rule (used in UI)
Expand Down Expand Up @@ -267,14 +267,14 @@ function JSRule (ruleConfig) {
rule.setTags(jsArrayToJavaSet(ruleConfig.tags));
}

// Register rule here
if (ruleConfig.triggers) {
if (!Array.isArray(ruleConfig.triggers)) ruleConfig.triggers = [ruleConfig.triggers];
rule.setTriggers(ruleConfig.triggers);
rule = automationManager.addRule(rule);
} else {
throw new Error(`Triggers are missing for rule "${ruleConfig.name ? ruleConfig.name : ruleUID}"!`);
log.info(`Rule "${ruleConfig.name ? ruleConfig.name : ruleUID}" has no triggers and will only run when manually triggered.`);
}
// Register rule here
rule = automationManager.addRule(rule);

// Add config to the action so that MainUI can show the script
const actionConfiguration = rule.actions.get(0).getConfiguration();
Expand Down
2 changes: 1 addition & 1 deletion types/rules/rules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export type RuleConfig = {
/**
* which will fire the rule
*/
triggers: HostTrigger | HostTrigger[];
triggers?: HostTrigger | HostTrigger[];
/**
* callback to run when the rule fires
*/
Expand Down
2 changes: 1 addition & 1 deletion types/rules/rules.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cadda4d

Please sign in to comment.