1
0

Minor improvements

This commit is contained in:
2024-01-07 08:16:23 +01:00
parent 0af0bb0a56
commit aec90ead0c
2 changed files with 15 additions and 9 deletions

View File

@@ -1,12 +1,13 @@
const log = Java.type('org.slf4j.LoggerFactory').getLogger('js.lib'); const log = Java.type('org.slf4j.LoggerFactory').getLogger('js.utils.lib');
log.info('Load lib module'); log.info('Load utils.lib module');
function compare(a, b, operator) { function compare(a, b, operator) {
// Hint: a = currentState, b = targetState // Hint: a = currentState, b = targetState
let logMsg = ''; let logMsg = '';
let returnValue = undefined; let returnValue = undefined;
try { try {
logMsg = `Quantity comparison of ${a}, ${b} with operator ${operator}`; logMsg = `Quantity comparison of ${a} and ${b} with operator ${operator}`;
switch (operator) { switch (operator) {
case '==': case '==':
returnValue = a.equal(b); returnValue = a.equal(b);
@@ -31,7 +32,7 @@ function compare(a, b, operator) {
return; return;
} }
} catch(e) { } catch(e) {
logMsg = `Standard comparison of ${a}, ${b} with operator ${operator}`; logMsg = `Standard comparison of ${a} and ${b} with operator ${operator}`;
switch (operator) { switch (operator) {
case '==': case '==':
returnValue = (a == b); returnValue = (a == b);

View File

@@ -151,11 +151,13 @@ class Watch {
#createWatchRule(item) { #createWatchRule(item) {
// Create openHAB rule // Create openHAB rule
log.info(`Create openHAB watch rule for item ${item}`); log.info(`Create openHAB watch rule for item ${item}`);
let watchRuleID = String(utils.randomUUID()); let watchRuleID = String(utils.randomUUID());
rules.JSRule({ rules.JSRule({
id: watchRuleID, id: watchRuleID,
name: 'Watch rule for ' + item, name: item + ' watch rule',
triggers: [triggers.ItemStateChangeTrigger(item)], triggers: [triggers.ItemStateChangeTrigger(item)],
tags: ['Watch'],
execute: (event) => { this.#processItemEvent(event) }, execute: (event) => { this.#processItemEvent(event) },
}); });
this.#watchItems[item] = watchRuleID; this.#watchItems[item] = watchRuleID;
@@ -199,7 +201,10 @@ class Watch {
} }
#startAlert(watchUUID) { #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 // Set alertFunc as inital alert function if no initialAlertFunc is set
let initialAlertFunc = this.#watchObjects[watchUUID].alertFunc; 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 // Execute initial alert function or create timer to run initial alert rule if required
if (alertDelay == '') { if (alertDelay == '') {
log.info(`Run initial alert function for watchObject ${watchUUID}`); log.info(`Run initial alert function for watchObject ${watchUUID} (${watchItemName})`);
initialAlertFunc(); initialAlertFunc();
} else { } 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); let alertDelayZDT = time.toZDT(alertDelay);
alertDelayAbsolute = (alertDelayZDT.getMillisFromNow() / 1000); alertDelayAbsolute = (alertDelayZDT.getMillisFromNow() / 1000);
@@ -235,7 +240,7 @@ class Watch {
// Create timer to run repeat alert rule if required // Create timer to run repeat alert rule if required
if (alertRepeat != '') { 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, this.#timers.create('repeatAlarm ' + watchUUID,
time.toZDT(alertRepeat).plusSeconds(alertDelayAbsolute), time.toZDT(alertRepeat).plusSeconds(alertDelayAbsolute),
() => { () => {