Delete watchRule if no more watchObjects are present
This commit is contained in:
@@ -71,6 +71,12 @@ class Watch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete this.#watchObjects[watchUUID];
|
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() {
|
deleteAll() {
|
||||||
@@ -135,7 +141,9 @@ class Watch {
|
|||||||
#createWatchRule() {
|
#createWatchRule() {
|
||||||
// Create openHAB rule
|
// Create openHAB rule
|
||||||
console.log(`Create openHAB watch rule for item ${this.#watchItemName}`);
|
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,
|
name: 'Watch rule for ' + this.#watchItemName,
|
||||||
triggers: [triggers.ItemStateUpdateTrigger(this.#watchItemName)],
|
triggers: [triggers.ItemStateUpdateTrigger(this.#watchItemName)],
|
||||||
execute: (event) => { this.#processItemEvent(event) },
|
execute: (event) => { this.#processItemEvent(event) },
|
||||||
|
|||||||
Reference in New Issue
Block a user