1
0

Improve logging

This commit is contained in:
2023-08-15 08:20:44 +02:00
parent 946c7fe337
commit 949eb8e9a6

View File

@@ -8,12 +8,12 @@ class Watch {
#watchObjects = new Object();
constructor(itemName) {
console.log('Create new Watch instance for ' + itemName);
console.log(`Create new Watch instance for ${itemName}`);
// Check if item to watch is existing
this.#item = items.getItem(itemName, true);
if (this.#item == null) {
throw('Item ' + itemName + ' not existing');
throw(`Item ${itemName} not existing`);
}
this.#watchItemName = itemName;
@@ -27,7 +27,7 @@ class Watch {
// Validate config for watchObject
if (!this.validateWatchConfig(params)) {
console.warn('Failed to add watch object for ' + this.#watchItemName + ' because no valid config was provided');
console.warn(`Failed to add watch object for ${this.#watchItemName} because no valid config was provided`);
return;
}
@@ -35,7 +35,7 @@ class Watch {
let operator = (params['operator'] !== undefined) ? params['operator'] : '==';
// Create watch object and return UUID
console.log('Add watch object for item ' + this.#watchItemName + ' with state ' + params['targetState'] + ' and operator ' + operator + ' with UUID ' + watchUUID);
console.log(`Add watch object for item ${this.#watchItemName} with state ${params['targetState']} and operator ${operator} with UUID ${watchUUID}`);
this.#watchObjects[watchUUID] = {
targetState: params['targetState'],
operator: operator,
@@ -56,7 +56,7 @@ class Watch {
}
delete(watchUUID) {
console.log('Delete watch object for item ' + this.#watchItemName + ' with watchUUID ' + watchUUID);
console.log(`Delete watch object for item ${this.#watchItemName} with watchUUID ${watchUUID}`);
// End repeatAlertTimer if existing
if (this.#watchObjects[watchUUID].hasOwnProperty('repeatAlertTimer') && this.#watchObjects[watchUUID].repeatAlertTimer.isActive()) {
@@ -95,7 +95,7 @@ class Watch {
}
#applyHysteresis(currentState, targetState, hysteresis) {
console.log('Applying hysteresis with: ' + currentState + ', ' + targetState + ', ' + hysteresis);
console.log(`Applying hysteresis with: ${currentState}, ${targetState}, ${hysteresis}`);
let delta = Math.abs(targetState - currentState);
console.log(delta);
@@ -111,7 +111,7 @@ class Watch {
// Do comparison
if (lib.compare(currentState, this.#watchObjects[watchUUID].targetState, this.#watchObjects[watchUUID].operator)) { // Comparison successful
console.log('State ' + currentState + ' is ' + this.#watchObjects[watchUUID].operator + ' ' + this.#watchObjects[watchUUID].targetState + ' triggered by ' + watchUUID);
console.log(`State ${currentState} is ${this.#watchObjects[watchUUID].operator} ${this.#watchObjects[watchUUID].targetState} triggered by ${watchUUID}`);
if (this.#watchObjects[watchUUID].alert == true) { // Comparison successful and alert is already active
this.#rescheduleAlert(watchUUID);
} else { // Comparison successful and alert is not active
@@ -131,7 +131,7 @@ class Watch {
#createWatchRule() {
// 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({
name: 'Watch rule for ' + this.#watchItemName,
triggers: [triggers.ItemStateChangeTrigger(this.#watchItemName)],
@@ -140,12 +140,12 @@ class Watch {
}
#endAlert(watchUUID) {
console.log('End alert for watchObject ' + watchUUID + ' triggered');
console.log(`End alert for watchObject ${watchUUID} triggered`);
this.#watchObjects[watchUUID].alert = false;
// Run end alert function if existing
if (this.#watchObjects[watchUUID].endAlertFunc != '') {
console.log('Run end alert function for watchObject ' + watchUUID);
console.log(`Run end alert function for watchObject ${watchUUID}`);
this.#watchObjects[watchUUID].endAlertFunc();
}
@@ -165,11 +165,11 @@ class Watch {
#processStateChange(event) {
// Skip if function is triggered without openHAB event
if (event === undefined || event.eventType === undefined) {
console.warn('ProcessStateChange triggered without openHAB event');
console.warn(`ProcessStateChange for ${this.#watchItemName} triggered without openHAB event`);
return;
}
console.log('Processing state ' + this.#item.state + ' for ' + this.#watchItemName);
console.log(`Processing state ${this.#item.state} for ${this.#watchItemName}`);
// Iterate through watchObjetcs // todo: rework to only fetch UUID
for (let [watchUUID, watchObject] of Object.entries(this.#watchObjects)) {
@@ -178,11 +178,11 @@ class Watch {
}
#rescheduleAlert(watchUUID) {
console.log('Subsequent alert for ' + watchUUID);
console.log(`Subsequent alert for ${watchUUID}`);
}
#startAlert(watchUUID) {
console.log('Initial alert for watchObject ' + watchUUID + ' triggered');
console.log(`Initial alert for watchObject ${watchUUID} triggered`);
// Set alertFunc as inital alert function if no initialAlertFunc is set
let initialAlertFunc = this.#watchObjects[watchUUID].alertFunc;
@@ -195,10 +195,10 @@ class Watch {
// Execute initial alert function or create timer to run initial alert rule if required
if (this.#watchObjects[watchUUID].alertDelay == '') {
console.log('Run initial alert function for watchObject ' + watchUUID);
console.log(`Run initial alert function for watchObject ${watchUUID}`);
initialAlertFunc();
} else {
console.log('Run initial alert function for watchObject ' + watchUUID + ' with delay setting ' + this.#watchObjects[watchUUID].alertDelay);
console.log(`Run initial alert function for watchObject ${watchUUID} with delay setting ${this.#watchObjects[watchUUID].alertDelay}`);
this.#watchObjects[watchUUID].startAlertTimer = actions.ScriptExecution.createTimer('startAlert ' + watchUUID,
time.toZDT(this.#watchObjects[watchUUID].alertDelay),
() => {