From aec90ead0cc2ce3ae3325c95a4add3164882a886 Mon Sep 17 00:00:00 2001 From: Christian Weimann Date: Sun, 7 Jan 2024 08:16:23 +0100 Subject: [PATCH] Minor improvements --- utils/lib.js | 9 +++++---- utils/watch.js | 15 ++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/utils/lib.js b/utils/lib.js index 5e3aef9..37e8d81 100644 --- a/utils/lib.js +++ b/utils/lib.js @@ -1,12 +1,13 @@ -const log = Java.type('org.slf4j.LoggerFactory').getLogger('js.lib'); -log.info('Load lib module'); +const log = Java.type('org.slf4j.LoggerFactory').getLogger('js.utils.lib'); +log.info('Load utils.lib module'); function compare(a, b, operator) { // Hint: a = currentState, b = targetState let logMsg = ''; let returnValue = undefined; + try { - logMsg = `Quantity comparison of ${a}, ${b} with operator ${operator}`; + logMsg = `Quantity comparison of ${a} and ${b} with operator ${operator}`; switch (operator) { case '==': returnValue = a.equal(b); @@ -31,7 +32,7 @@ function compare(a, b, operator) { return; } } catch(e) { - logMsg = `Standard comparison of ${a}, ${b} with operator ${operator}`; + logMsg = `Standard comparison of ${a} and ${b} with operator ${operator}`; switch (operator) { case '==': returnValue = (a == b); diff --git a/utils/watch.js b/utils/watch.js index 56a11d0..c8911a5 100644 --- a/utils/watch.js +++ b/utils/watch.js @@ -151,11 +151,13 @@ class Watch { #createWatchRule(item) { // Create openHAB rule log.info(`Create openHAB watch rule for item ${item}`); + let watchRuleID = String(utils.randomUUID()); rules.JSRule({ id: watchRuleID, - name: 'Watch rule for ' + item, + name: item + ' watch rule', triggers: [triggers.ItemStateChangeTrigger(item)], + tags: ['Watch'], execute: (event) => { this.#processItemEvent(event) }, }); this.#watchItems[item] = watchRuleID; @@ -199,7 +201,10 @@ class Watch { } #startAlert(watchUUID) { - log.info(`Initial alert for watchObject ${watchUUID} triggered`); + // Get itemName + let watchItemName = this.#watchObjects[watchUUID].item; + + log.info(`Initial alert for watchObject ${watchUUID} (${watchItemName}) triggered`); // Set alertFunc as inital alert function if no initialAlertFunc is set let initialAlertFunc = this.#watchObjects[watchUUID].alertFunc; @@ -216,10 +221,10 @@ class Watch { // Execute initial alert function or create timer to run initial alert rule if required if (alertDelay == '') { - log.info(`Run initial alert function for watchObject ${watchUUID}`); + log.info(`Run initial alert function for watchObject ${watchUUID} (${watchItemName})`); initialAlertFunc(); } else { - log.info(`Shedule initial alert function for watchObject ${watchUUID} with delay setting ${alertDelay}`); + log.info(`Shedule initial alert function for watchObject ${watchUUID} (${watchItemName}) with delay setting ${alertDelay}`); let alertDelayZDT = time.toZDT(alertDelay); alertDelayAbsolute = (alertDelayZDT.getMillisFromNow() / 1000); @@ -235,7 +240,7 @@ class Watch { // Create timer to run repeat alert rule if required if (alertRepeat != '') { - log.info(`Shedule repeat alert function for watchObject ${watchUUID} with repeat setting ${alertRepeat}`); + log.info(`Shedule repeat alert function for watchObject ${watchUUID} (${watchItemName}) with repeat setting ${alertRepeat}`); this.#timers.create('repeatAlarm ' + watchUUID, time.toZDT(alertRepeat).plusSeconds(alertDelayAbsolute), () => {