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');
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);

View File

@@ -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),
() => {