@nightspark77/node-red-charlie-home-assistant 1.0.2 → 1.0.5
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.html +6 -9
- package/device.js +6 -10
- package/package.json +1 -1
package/device.html
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
color: '#fff',
|
|
6
6
|
defaults: {
|
|
7
7
|
name: { value: '', required: true },
|
|
8
|
-
deviceId: { value: '', required: true },
|
|
9
8
|
deviceType: { value: 'light', required: true },
|
|
10
9
|
externalId: { value: '', required: true },
|
|
10
|
+
roomId: { value: '', required: false },
|
|
11
11
|
outputs: { value: 2 },
|
|
12
12
|
},
|
|
13
13
|
inputs: 1,
|
|
@@ -31,18 +31,13 @@
|
|
|
31
31
|
|
|
32
32
|
<script type="text/x-red" data-template-name="charlie-device">
|
|
33
33
|
<form id="dialog-form" class="form-horizontal" autocomplete="off">
|
|
34
|
-
<div class="form-row">
|
|
35
|
-
<label for="node-input-deviceId">Id</label>
|
|
36
|
-
<input id="node-input-deviceId" />
|
|
37
|
-
</div>
|
|
38
|
-
|
|
39
34
|
<div class="form-row">
|
|
40
35
|
<label for="node-input-name">Name</label>
|
|
41
36
|
<input id="node-input-name" />
|
|
42
37
|
</div>
|
|
43
38
|
|
|
44
39
|
<div class="form-row">
|
|
45
|
-
<label for="node-input-externalId">
|
|
40
|
+
<label for="node-input-externalId">Unique ID</label>
|
|
46
41
|
<input id="node-input-externalId" />
|
|
47
42
|
</div>
|
|
48
43
|
|
|
@@ -53,6 +48,9 @@
|
|
|
53
48
|
<option value="switch">Interupteur</option>
|
|
54
49
|
<option value="shutter">Volet</option>
|
|
55
50
|
<option value="sprinkler">Arrosage</option>
|
|
51
|
+
<option value="sensor">Capteur</option>
|
|
52
|
+
<option value="button">Bouton</option>
|
|
53
|
+
<option value="unknown">Inconnu</option>
|
|
56
54
|
</select>
|
|
57
55
|
</div>
|
|
58
56
|
</form>
|
|
@@ -121,9 +119,8 @@
|
|
|
121
119
|
|
|
122
120
|
<h3>Properties</h3>
|
|
123
121
|
<ul>
|
|
124
|
-
<li><b>ID</b> – Unique identifier for this device within Charlie.</li>
|
|
125
122
|
<li><b>Name</b> – Display name shown in the Node‑RED editor.</li>
|
|
126
|
-
<li><b>
|
|
123
|
+
<li><b>Unique ID</b> – Identifier used by the Charlie backend.</li>
|
|
127
124
|
<li><b>Type</b> – Device category:
|
|
128
125
|
<ul>
|
|
129
126
|
<li><b>Lum</b> – Light</li>
|
package/device.js
CHANGED
|
@@ -9,12 +9,7 @@ module.exports = function (RED) {
|
|
|
9
9
|
let client = null;
|
|
10
10
|
|
|
11
11
|
(async () => {
|
|
12
|
-
if (
|
|
13
|
-
!config.deviceId ||
|
|
14
|
-
!config.name ||
|
|
15
|
-
!config.externalId ||
|
|
16
|
-
!config.deviceType
|
|
17
|
-
)
|
|
12
|
+
if (!config.name || !config.externalId || !config.deviceType)
|
|
18
13
|
return;
|
|
19
14
|
|
|
20
15
|
await isReady();
|
|
@@ -26,7 +21,6 @@ module.exports = function (RED) {
|
|
|
26
21
|
'Content-Type': 'application/json',
|
|
27
22
|
},
|
|
28
23
|
body: JSON.stringify({
|
|
29
|
-
_id: config.deviceId,
|
|
30
24
|
name: config.name,
|
|
31
25
|
externalId: config.externalId,
|
|
32
26
|
provider: conf.provider.id,
|
|
@@ -37,7 +31,7 @@ module.exports = function (RED) {
|
|
|
37
31
|
client = mqtt.connect(mqttHost());
|
|
38
32
|
|
|
39
33
|
client.on('connect', () => {
|
|
40
|
-
client.subscribe(`device/${config.
|
|
34
|
+
client.subscribe(`device/${config.externalId}/state`);
|
|
41
35
|
});
|
|
42
36
|
|
|
43
37
|
client.on('message', (topic, payload) => {
|
|
@@ -51,7 +45,7 @@ module.exports = function (RED) {
|
|
|
51
45
|
|
|
52
46
|
const outputs = [null, null, null];
|
|
53
47
|
outputs[oi] = {
|
|
54
|
-
topic: config.
|
|
48
|
+
topic: config.externalId,
|
|
55
49
|
payload: { state: res.power, level: res.level },
|
|
56
50
|
};
|
|
57
51
|
|
|
@@ -75,7 +69,7 @@ module.exports = function (RED) {
|
|
|
75
69
|
client.publish(
|
|
76
70
|
`device/state`,
|
|
77
71
|
JSON.stringify({
|
|
78
|
-
|
|
72
|
+
externalId: config.externalId,
|
|
79
73
|
power: payload.state,
|
|
80
74
|
level: payload.level ?? 100,
|
|
81
75
|
}),
|
|
@@ -88,6 +82,8 @@ module.exports = function (RED) {
|
|
|
88
82
|
}
|
|
89
83
|
}
|
|
90
84
|
});
|
|
85
|
+
|
|
86
|
+
node.on('close', () => client?.end(true));
|
|
91
87
|
}
|
|
92
88
|
|
|
93
89
|
RED.nodes.registerType('charlie-device', MyNode);
|