node-red-contrib-knx-ultimate 3.3.24 → 3.3.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,9 @@
6
6
 
7
7
  # CHANGELOG
8
8
 
9
+ **Version 3.3.25** - April 2025<br/>
10
+ - HUE: fixed a saltuary bug preventing reconnection after HUE bridge has been restarted and there is no KNX Gateway configured.<br/>
11
+
9
12
  **Version 3.3.24** - April 2025<br/>
10
13
  - NEW: Added Datapoint 14.1200<br/>
11
14
 
@@ -43,13 +43,10 @@ module.exports = (RED) => {
43
43
 
44
44
  // Connect to Bridge and get the resources
45
45
  node.initHUEConnection = async () => {
46
+ await node.closeConnection();
46
47
  try {
47
- if (node.hueManager !== undefined) node.hueManager.close();
48
+ if (node.hueManager !== undefined) await node.hueManager.close();
48
49
  } catch (error) { /* empty */ }
49
- try {
50
- if (node.hueManager !== undefined) node.hueManager.removeAllListeners();
51
- } catch (error) { /* empty */ }
52
- // Handle events
53
50
  try {
54
51
  // Init HUE Utility
55
52
  node.hueManager = new HueClass(node.host, node.credentials.username, node.credentials.clientkey, config.bridgeid, node.sysLogger);
@@ -87,11 +84,11 @@ module.exports = (RED) => {
87
84
  text: "HUE",
88
85
  payload: error.message,
89
86
  });
90
- }, 1000);
87
+ }, 200);
91
88
  });
92
89
  }
93
90
  })();
94
- }, 6000); // 17/02/2020 Do initial read of all nodes requesting initial read
91
+ }, 10000); // 17/02/2020 Do initial read of all nodes requesting initial read
95
92
  }
96
93
  });
97
94
 
@@ -106,12 +103,12 @@ module.exports = (RED) => {
106
103
  });
107
104
  });
108
105
  try {
109
- node.hueManager.Connect();
106
+ await node.hueManager.Connect();
110
107
  } catch (error) { }
111
108
 
112
109
  };
113
110
 
114
- node.startWatchdogTimer = () => {
111
+ node.startWatchdogTimer = async () => {
115
112
  if (node.timerHUEConfigCheckState !== null) clearTimeout(node.timerHUEConfigCheckState);
116
113
  node.timerHUEConfigCheckState = setTimeout(() => {
117
114
  (async () => {
@@ -123,12 +120,14 @@ module.exports = (RED) => {
123
120
  node.sysLogger?.error(`Errore hue-config: node.startWatchdogTimer: ${error.message}`);
124
121
  }
125
122
  }
126
- node.startWatchdogTimer();
123
+ await node.startWatchdogTimer();
127
124
  })();
128
- }, 10000);
125
+ }, 20000);
129
126
  };
130
- node.startWatchdogTimer();
131
127
 
128
+ (async () => {
129
+ await node.startWatchdogTimer();
130
+ })();
132
131
 
133
132
  // Functions called from the nodes ----------------------------------------------------------------
134
133
  // Query the HUE Bridge to return the resources
@@ -480,11 +479,16 @@ module.exports = (RED) => {
480
479
  }
481
480
  };
482
481
 
482
+ node.closeConnection = async () => {
483
+ node.hueManager?.removeAllListeners();
484
+ node.linkStatus === "disconnected";
485
+ }
486
+
483
487
  node.on("close", (done) => {
484
488
  try {
485
- if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger = null;
489
+ node.sysLogger = null;
486
490
  node.nodeClients = [];
487
- if (node.hueManager !== undefined && node.hueManager !== null) node.hueManager.removeAllListeners();
491
+ node.closeConnection();
488
492
  (async () => {
489
493
  try {
490
494
  await node.hueManager.close();
@@ -19,9 +19,9 @@ class classHUE extends EventEmitter {
19
19
  this.bridgeid = _bridgeid;
20
20
  this.commandQueue = [];
21
21
  // eslint-disable-next-line max-len
22
- setTimeout(this.handleQueue, 10000); // First start. Allow the KNX to connect
23
22
  this.sysLogger = _sysLogger;
24
23
  this.timerCheckConnected = null;
24
+ this.handleQueue();
25
25
  }
26
26
 
27
27
  Connect = () => {
@@ -59,7 +59,7 @@ class classHUE extends EventEmitter {
59
59
  try {
60
60
  this.es = new EventSource(`https://${this.hueBridgeIP}/eventstream/clip/v2`, options);
61
61
  } catch (error) {
62
- console.log("hue-config: ew EventSource:" + error.message);
62
+ if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.error(`hueEngine: ew EventSource: ${error.message}`);
63
63
  }
64
64
 
65
65
 
@@ -91,37 +91,41 @@ class classHUE extends EventEmitter {
91
91
  this.timerCheckConnected = setInterval(() => {
92
92
  (async () => {
93
93
  try {
94
- if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.debug(`KNXUltimatehueEngine: classHUE: processQueueItem: Pinging...`);
94
+ if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.debug(`KNXUltimatehueEngine: classHUE: Pinging...`);
95
95
  const jReturn = await this.hueApiV2.get('/resource/bridge');
96
96
  if (!Array.isArray(jReturn) || jReturn.length < 1) throw new Error("jReturn: not an array or array empty")
97
97
  this.HUEBridgeConnectionStatus = "connected";
98
- if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.debug(`KNXUltimatehueEngine: classHUE: processQueueItem: Ping OK`);
98
+ if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.debug(`KNXUltimatehueEngine: classHUE: Ping OK`);
99
99
  } catch (error) {
100
- if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.error(`KNXUltimatehueEngine: classHUE: processQueueItem: Ping ERROR: ${error.message}`);
100
+ if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.error(`KNXUltimatehueEngine: classHUE: Ping ERROR: ${error.message}`);
101
101
  if (this.timerCheckConnected !== null) clearInterval(this.timerCheckConnected);
102
102
  this.commandQueue = [];
103
- this.emit("disconnected");
104
103
  try {
105
- this.close();
104
+ await this.close();
106
105
  } catch (error) { }
106
+ this.emit("disconnected");
107
107
  }
108
108
  })();
109
- }, 20000);
109
+ }, 60000);
110
110
  };
111
111
 
112
112
  this.es.onerror = (error) => {
113
- if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.error(`KNXUltimatehueEngine: classHUE: this.es.onopen: ${error.status || ''} ${error.message}`);
113
+ if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.error(`KNXUltimatehueEngine: classHUE: this.es.onopen: ${error.message}`);
114
+ (async () => {
115
+ await this.close();
116
+ if (this.HUEBridgeConnectionStatus === 'connected') this.emit('disconnected');
117
+ })();
118
+
119
+ // 29/08/2023 NON riattivare, perchè alla disconnessione, va in loop e consuma tutto il pool di risorse.
120
+ // try {
121
+ // this.es.close();
122
+ // this.es = null;
123
+ // if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.error(`KNXUltimatehueEngine: classHUE: request.on(error): ${error.message}`);
124
+ // } catch (err) { /* empty */ }
125
+ // this.Connect();
126
+ // // this.emit('error', error)
127
+ // };
114
128
  };
115
- // 29/08/2023 NON riattivare, perchè alla disconnessione, va in loop e consuma tutto il pool di risorse.
116
- // try {
117
- // this.es.close();
118
- // this.es = null;
119
- // if (this.sysLogger !== undefined && this.sysLogger !== null) this.sysLogger.error(`KNXUltimatehueEngine: classHUE: request.on(error): ${error.message}`);
120
- // } catch (err) { /* empty */ }
121
- // this.Connect();
122
- // // this.emit('error', error)
123
- // };
124
-
125
129
  };
126
130
 
127
131
  // Process single item in the queue
@@ -201,6 +205,7 @@ class classHUE extends EventEmitter {
201
205
  //console.log("\x1b[42m End processing commandQueue \x1b[0m " + new Date().toTimeString(), this.commandQueue.length);
202
206
  };
203
207
 
208
+
204
209
  writeHueQueueAdd = async (_lightID, _state, _operation) => {
205
210
  // Add the new item
206
211
  this.commandQueue.unshift({ _lightID, _state, _operation });
@@ -226,6 +231,7 @@ class classHUE extends EventEmitter {
226
231
  setTimeout(() => {
227
232
  try {
228
233
  if (this.es !== null && this.es !== undefined) this.es.close();
234
+ if (this.es !== null && this.es !== undefined) this.es.removeEventListener();
229
235
  } catch (error) { }
230
236
  this.es = null;
231
237
  resolve(true);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "engines": {
4
4
  "node": ">=16.0.0"
5
5
  },
6
- "version": "3.3.24",
6
+ "version": "3.3.25",
7
7
  "description": "Control your KNX intallation via Node-Red! A bunch of KNX nodes, with integrated Philips HUE control and ETS group address importer. Easy to use and highly configurable.",
8
8
  "dependencies": {
9
9
  "binary-parser": "2.2.1",