1
0

Delete watchRule if no more watchObjects are present

This commit is contained in:
2023-08-19 05:51:11 +02:00
parent ca1213d204
commit 7b8229a047

View File

@@ -71,6 +71,12 @@ class Watch {
}
delete this.#watchObjects[watchUUID];
// Delete watchRule if no more watchObjects are present
if (Object.keys(this.#watchObjects).length == 0) {
console.debug(`Remove openHAB watch rule for item ${this.#watchItemName}`);
rules.removeRule(this.watchRuleID);
}
}
deleteAll() {
@@ -135,7 +141,9 @@ class Watch {
#createWatchRule() {
// Create openHAB rule
console.log(`Create openHAB watch rule for item ${this.#watchItemName}`);
let ruleID = rules.JSRule({
this.watchRuleID = String(utils.randomUUID());
rules.JSRule({
id: this.watchRuleID,
name: 'Watch rule for ' + this.#watchItemName,
triggers: [triggers.ItemStateUpdateTrigger(this.#watchItemName)],
execute: (event) => { this.#processItemEvent(event) },