@nightspark77/node-red-charlie-home-assistant 1.0.5 → 1.0.6
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/device.js +17 -0
- package/package.json +22 -22
- package/shared.js +2 -2
package/device.js
CHANGED
|
@@ -31,9 +31,26 @@ module.exports = function (RED) {
|
|
|
31
31
|
client = mqtt.connect(mqttHost());
|
|
32
32
|
|
|
33
33
|
client.on('connect', () => {
|
|
34
|
+
node.log(`MQTT connected for device ${config.externalId}`);
|
|
34
35
|
client.subscribe(`device/${config.externalId}/state`);
|
|
35
36
|
});
|
|
36
37
|
|
|
38
|
+
client.on('error', (err) => {
|
|
39
|
+
node.warn(
|
|
40
|
+
`MQTT error for device ${config.externalId}: ${err.message}`
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
client.on('close', () => {
|
|
45
|
+
node.log(
|
|
46
|
+
`MQTT connection closed for device ${config.externalId}`
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
client.on('reconnect', () => {
|
|
51
|
+
node.log(`MQTT reconnecting for device ${config.externalId}`);
|
|
52
|
+
});
|
|
53
|
+
|
|
37
54
|
client.on('message', (topic, payload) => {
|
|
38
55
|
const res = JSON.parse(payload.toString());
|
|
39
56
|
const oi =
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nightspark77/node-red-charlie-home-assistant",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Create and control your own device with Charlie within nodered",
|
|
5
|
-
"license": "ISC",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"node-red"
|
|
8
|
-
],
|
|
9
|
-
"author": "Quentin Vanhauteghem",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
-
},
|
|
13
|
-
"node-red": {
|
|
14
|
-
"nodes": {
|
|
15
|
-
"provider": "provider.js",
|
|
16
|
-
"device": "device.js",
|
|
17
|
-
"ask": "ask.js"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"mqtt": "^5.14.1"
|
|
22
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@nightspark77/node-red-charlie-home-assistant",
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "Create and control your own device with Charlie within nodered",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"node-red"
|
|
8
|
+
],
|
|
9
|
+
"author": "Quentin Vanhauteghem",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"node-red": {
|
|
14
|
+
"nodes": {
|
|
15
|
+
"provider": "provider.js",
|
|
16
|
+
"device": "device.js",
|
|
17
|
+
"ask": "ask.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"mqtt": "^5.14.1"
|
|
22
|
+
}
|
|
23
23
|
}
|
package/shared.js
CHANGED
|
@@ -11,14 +11,14 @@ module.exports = {
|
|
|
11
11
|
apiUrl: () =>
|
|
12
12
|
`http://${conf.provider.charlieHost ?? 'localhost'}:${conf.provider.apiPort ?? '9300'}`,
|
|
13
13
|
mqttHost: () =>
|
|
14
|
-
`mqtt://${conf.provider.charlieHost}:${conf.provider.
|
|
14
|
+
`mqtt://${conf.provider.charlieHost}:${conf.provider.mqttPort ?? '9304'}`,
|
|
15
15
|
isReady: () => {
|
|
16
16
|
return new Promise((res) => {
|
|
17
17
|
const inter = setInterval(() => {
|
|
18
18
|
if (conf.ready) {
|
|
19
|
+
clearInterval(inter);
|
|
19
20
|
res();
|
|
20
21
|
}
|
|
21
|
-
clearInterval(inter);
|
|
22
22
|
}, 500);
|
|
23
23
|
});
|
|
24
24
|
},
|