diff --git a/src/rules/rules.js b/src/rules/rules.js index 94ac8acaf..984fcd9c5 100644 --- a/src/rules/rules.js +++ b/src/rules/rules.js @@ -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) @@ -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(); diff --git a/types/rules/rules.d.ts b/types/rules/rules.d.ts index 36a09ce01..e305302ed 100644 --- a/types/rules/rules.d.ts +++ b/types/rules/rules.d.ts @@ -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 */ diff --git a/types/rules/rules.d.ts.map b/types/rules/rules.d.ts.map index fada6e538..bf697b965 100644 --- a/types/rules/rules.d.ts.map +++ b/types/rules/rules.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/rules/rules.js"],"names":[],"mappings":";;;;;;;;;;;cAec,MAAM;;;;cACN,MAAM;;;;mBACN,MAAM;;;;qBACN,MAAM;;;;cACN,MAAM;;;;eACN,MAAM;;;;mBACN,MAAM;;;;gBACN,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;YACN,MAAM;;;;cACN,MAAM;;;;oBACN,MAAM;;;;UACN,MAAM;;;;eACN,MAAM;;;;iBACN,MAAM;;;;gBACN,MAAM;;;;YACN,MAAM;;;;;;;;;;;;;mCAOT,WAAW;;;;;;;;UAKR,MAAM;;;;kBACN,MAAM;;;;cACN,cAAY,aAAa;;;;aACzB,YAAY;;;;SACZ,MAAM;;;;WACN,MAAM,EAAE;;;;gBACR,MAAM;;;;gBACN,OAAO;;;;qBACP,MAAM;;AAkFpB;;;;;;;IAOI;AACJ,gCAHY,MAAM,GACJ,OAAO,CAUpB;AAED;;;;;;;;;IASI;AACJ,6BALY,MAAM,SACN,MAAM,SACN,OAAO,QAalB;AAED;;;;;;;;IAQI;AACJ,+BAJY,MAAM,GACJ,OAAO,CAQpB;AAED;;;;;;;IAOI;AACJ,gCAJY,MAAM,aACN,OAAO,QAQlB;AAED;;;;;;;;;;;;;;;;;IAiBI;AACJ,mCAJY,UAAU,YAiErB;AAED;;;;;;;;;GASG;AACH,6CAJW,UAAU,YA8CpB"} \ No newline at end of file +{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/rules/rules.js"],"names":[],"mappings":";;;;;;;;;;;cAec,MAAM;;;;cACN,MAAM;;;;mBACN,MAAM;;;;qBACN,MAAM;;;;cACN,MAAM;;;;eACN,MAAM;;;;mBACN,MAAM;;;;gBACN,MAAM;;;;eACN,MAAM;;;;eACN,MAAM;;;;YACN,MAAM;;;;cACN,MAAM;;;;oBACN,MAAM;;;;UACN,MAAM;;;;eACN,MAAM;;;;iBACN,MAAM;;;;gBACN,MAAM;;;;YACN,MAAM;;;;;;;;;;;;;mCAOT,WAAW;;;;;;;;UAKR,MAAM;;;;kBACN,MAAM;;;;eACN,cAAY,aAAa;;;;aACzB,YAAY;;;;SACZ,MAAM;;;;WACN,MAAM,EAAE;;;;gBACR,MAAM;;;;gBACN,OAAO;;;;qBACP,MAAM;;AAkFpB;;;;;;;IAOI;AACJ,gCAHY,MAAM,GACJ,OAAO,CAUpB;AAED;;;;;;;;;IASI;AACJ,6BALY,MAAM,SACN,MAAM,SACN,OAAO,QAalB;AAED;;;;;;;;IAQI;AACJ,+BAJY,MAAM,GACJ,OAAO,CAQpB;AAED;;;;;;;IAOI;AACJ,gCAJY,MAAM,aACN,OAAO,QAQlB;AAED;;;;;;;;;;;;;;;;;IAiBI;AACJ,mCAJY,UAAU,YAiErB;AAED;;;;;;;;;GASG;AACH,6CAJW,UAAU,YA8CpB"} \ No newline at end of file