node-red-contrib-knx-ultimate 2.1.7 → 2.1.8
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 +4 -0
- package/nodes/utils/hueUtils.js +85 -67
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/nodes/utils/hueUtils.js
CHANGED
|
@@ -3,14 +3,8 @@
|
|
|
3
3
|
// const hueApi = require('node-hue-api')
|
|
4
4
|
const hueApiV2 = require('node-hue')
|
|
5
5
|
const { EventEmitter } = require('events')
|
|
6
|
-
|
|
7
|
-
|
|
8
6
|
const https = require('https');
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
8
|
class classHUE extends EventEmitter {
|
|
15
9
|
constructor(_hueBridgeIP, _username, _clientkey, _bridgeid) {
|
|
16
10
|
super()
|
|
@@ -25,70 +19,96 @@ class classHUE extends EventEmitter {
|
|
|
25
19
|
this.commandQueue = []
|
|
26
20
|
this.closePushEventStream = false
|
|
27
21
|
this.timerwriteQueueAdd = setTimeout(this.handleQueue, 3000) // First start
|
|
28
|
-
|
|
22
|
+
//this.run()
|
|
29
23
|
// start the SSE Stream Receiver
|
|
30
24
|
// #############################################
|
|
31
|
-
const options = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
// const options = {
|
|
26
|
+
// host: _hueBridgeIP, // Indirizzo IP del tuo bridge Philips Hue
|
|
27
|
+
// path: '/eventstream/clip/v2', // Il percorso dell'API per gli eventi
|
|
28
|
+
// method: 'GET',
|
|
29
|
+
// headers: {
|
|
30
|
+
// 'Connection': 'keep-alive',
|
|
31
|
+
// 'hue-application-key': _username
|
|
32
|
+
// //'Accept': 'text/event-stream'
|
|
33
|
+
// },
|
|
34
|
+
// rejectUnauthorized: false
|
|
35
|
+
// }
|
|
36
|
+
|
|
37
|
+
// // Funzione per la gestione della risposta
|
|
38
|
+
// const handleResponse = (response) => {
|
|
39
|
+
// let data = '';
|
|
40
|
+
|
|
41
|
+
// response.on('data', (chunk) => {
|
|
42
|
+
// data += chunk;
|
|
43
|
+
// });
|
|
44
|
+
|
|
45
|
+
// response.on('end', () => {
|
|
46
|
+
// try {
|
|
47
|
+
// const events = JSON.parse(data)
|
|
48
|
+
// // An array event "Container", can have multiple events.
|
|
49
|
+
// // for..loop is more efficent. We need speed.
|
|
50
|
+
// for (let index = 0; index < events.length; index++) {
|
|
51
|
+
// const oEvento = events[index]
|
|
52
|
+
// if (oEvento.type === 'update') {
|
|
53
|
+
// for (let i = 0; i < oEvento.data.length; i++) {
|
|
54
|
+
// const element = oEvento.data[i]
|
|
55
|
+
// this.emit('event', element)
|
|
56
|
+
// }
|
|
57
|
+
// }
|
|
58
|
+
// }
|
|
59
|
+
// } catch (error) {
|
|
60
|
+
// console.log('KNXUltimateHUEConfig: classHUE: response.on(end): ' + error.message)
|
|
61
|
+
// }
|
|
62
|
+
// req();
|
|
63
|
+
// });
|
|
64
|
+
// };
|
|
65
|
+
// // Funzione per richiedere gli eventi
|
|
66
|
+
// const req = () => {
|
|
67
|
+
// if (this.closePushEventStream) return // I'm destroying the class
|
|
68
|
+
// const request = https.request(options, handleResponse);
|
|
69
|
+
// request.on('error', (error) => {
|
|
70
|
+
// console.log('KNXUltimateHUEConfig: classHUE: request.on(error): ' + error.message)
|
|
71
|
+
// // Restart the connection
|
|
72
|
+
// setTimeout(() => {
|
|
73
|
+
// this.commandQueue = []
|
|
74
|
+
// req();
|
|
75
|
+
// }, 2000);
|
|
76
|
+
// });
|
|
77
|
+
// request.end();
|
|
78
|
+
// };
|
|
79
|
+
|
|
80
|
+
// // Starts the connection for the first time
|
|
81
|
+
// req();
|
|
82
|
+
|
|
83
|
+
// Eventstream Reader using hueApiV2
|
|
84
|
+
const runStreamReader = async () => {
|
|
85
|
+
try {
|
|
86
|
+
const listener = (event) => {
|
|
87
|
+
//console.log(event)
|
|
88
|
+
event.data.forEach(element => {
|
|
89
|
+
if (event.type === 'update') this.emit('event', element)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const hueEventStream = hueApiV2.connect({
|
|
93
|
+
host: this.hueBridgeIP,
|
|
94
|
+
key: this.username,
|
|
95
|
+
eventListener: listener
|
|
96
|
+
})
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.log('KNXUltimateHUEConfig: classHUE: const run = async: ' + error.message)
|
|
99
|
+
}
|
|
41
100
|
}
|
|
101
|
+
runStreamReader()
|
|
42
102
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
response.on('data', (chunk) => {
|
|
48
|
-
data += chunk;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
response.on('end', () => {
|
|
52
|
-
try {
|
|
53
|
-
const events = JSON.parse(data)
|
|
54
|
-
// An array event "Container", can have multiple events.
|
|
55
|
-
// for..loop is more efficent. We need speed.
|
|
56
|
-
for (let index = 0; index < events.length; index++) {
|
|
57
|
-
const oEvento = events[index]
|
|
58
|
-
if (oEvento.type === 'update') {
|
|
59
|
-
for (let i = 0; i < oEvento.data.length; i++) {
|
|
60
|
-
const element = oEvento.data[i]
|
|
61
|
-
this.emit('event', element)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.log('KNXUltimateHUEConfig: classHUE: response.on(end): ' + error.message)
|
|
67
|
-
}
|
|
68
|
-
req();
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
// Funzione per richiedere gli eventi
|
|
72
|
-
const req = () => {
|
|
73
|
-
if (this.closePushEventStream) return // I'm destroying the class
|
|
74
|
-
const request = https.request(options, handleResponse);
|
|
75
|
-
request.on('error', (error) => {
|
|
76
|
-
console.log('KNXUltimateHUEConfig: classHUE: request.on(error): ' + error.message)
|
|
77
|
-
// Restart the connection
|
|
78
|
-
setTimeout(() => {
|
|
79
|
-
this.commandQueue = []
|
|
80
|
-
req();
|
|
81
|
-
}, 2000);
|
|
82
|
-
});
|
|
83
|
-
request.end();
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// Starts the connection for the first time
|
|
87
|
-
req();
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// #############################################
|
|
88
106
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
92
112
|
// Handle the send queue
|
|
93
113
|
// ######################################
|
|
94
114
|
handleQueue = async () => {
|
|
@@ -172,8 +192,6 @@ class classHUE extends EventEmitter {
|
|
|
172
192
|
}
|
|
173
193
|
|
|
174
194
|
|
|
175
|
-
|
|
176
|
-
|
|
177
195
|
close = async () => {
|
|
178
196
|
return new Promise((resolve, reject) => {
|
|
179
197
|
try {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"engines": {
|
|
4
4
|
"node": ">=14.0.0"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.1.
|
|
6
|
+
"version": "2.1.8",
|
|
7
7
|
"description": "Control your KNX intallation via Node-Red! Single Node KNX IN/OUT with optional ETS group address importer. Easy to use and highly configurable. With integrated Philips HUE devices handling.",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"mkdirp": "1.0.4",
|