node-red-contrib-esphome 0.1.1 → 0.2.0
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/README.md +8 -1
- package/build/nodes/device.html +22 -4
- package/build/nodes/device.js +27 -22
- package/build/nodes/device.js.map +1 -1
- package/build/nodes/in.html +27 -13
- package/build/nodes/in.js +22 -3
- package/build/nodes/in.js.map +1 -1
- package/build/nodes/out.html +14 -12
- package/build/nodes/out.js +19 -11
- package/build/nodes/out.js.map +1 -1
- package/package.json +7 -7
- package/readme/device.png +0 -0
- package/readme/flow.png +0 -0
- package/src/nodes/device.ts +35 -17
- package/src/nodes/in.ts +30 -3
- package/src/nodes/out.ts +21 -11
package/README.md
CHANGED
|
@@ -21,9 +21,12 @@ Node-RED nodes to ESPhome devices
|
|
|
21
21
|
|
|
22
22
|
## Changelog
|
|
23
23
|
|
|
24
|
+
#### 0.2.0
|
|
25
|
+
- support MediaPlayer
|
|
26
|
+
- support BLE Advertisements (thx @richardhopton)
|
|
27
|
+
- support Encryption Key (thx @richardhopton)
|
|
24
28
|
#### 0.1.1
|
|
25
29
|
- fix logs
|
|
26
|
-
|
|
27
30
|
#### 0.1.0
|
|
28
31
|
- support logs in node
|
|
29
32
|
- allow empty password
|
|
@@ -76,6 +79,10 @@ $ npm i node-red-contrib-esphome
|
|
|
76
79
|
#### Lock
|
|
77
80
|
- `command` - REQUIRED. 0 - UNLOCK, 1 - LOCK, 2 - OPEN
|
|
78
81
|
- `code` - optional. string. See `requiresCode` attr in config
|
|
82
|
+
#### MediaPlayer
|
|
83
|
+
- `command` - REQUIRED. 0 - MEDIA_PLAYER_COMMAND_PLAY, 1 - MEDIA_PLAYER_COMMAND_PAUSE, 2 - MEDIA_PLAYER_COMMAND_STOP, 3 - MEDIA_PLAYER_COMMAND_MUTE, 4 - MEDIA_PLAYER_COMMAND_UNMUTE
|
|
84
|
+
- `volume` - optional. float
|
|
85
|
+
- `mediaUrl` - optional. string
|
|
79
86
|
#### Number
|
|
80
87
|
- `state` - REQUIRED. float. See `minValue`, `maxValue`, and `step` attrs in config
|
|
81
88
|
#### Select
|
package/build/nodes/device.html
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
host: {value: ''},
|
|
7
7
|
port: {value: 6053, validate: RED.validators.number()},
|
|
8
8
|
loglevel: {value: '0'},
|
|
9
|
-
logdump: {value: false}
|
|
9
|
+
logdump: {value: false},
|
|
10
|
+
ble: {value: false}
|
|
10
11
|
},
|
|
11
12
|
paletteLabel: 'device',
|
|
12
13
|
credentials: {
|
|
14
|
+
encryptionkey: {type: 'password'},
|
|
13
15
|
password: {type: 'password'}
|
|
14
16
|
},
|
|
15
17
|
label: function () {
|
|
@@ -125,9 +127,14 @@
|
|
|
125
127
|
<input type="text" id="node-config-input-port" placeholder="Port" />
|
|
126
128
|
</div>
|
|
127
129
|
|
|
130
|
+
<div class="form-row">
|
|
131
|
+
<label for="node-config-input-encryptionkey"><i class="fa fa-key"></i> Encryption</label>
|
|
132
|
+
<input type="password" id="node-config-input-encryptionkey" placeholder="Encryption Key" />
|
|
133
|
+
</div>
|
|
134
|
+
|
|
128
135
|
<div class="form-row">
|
|
129
136
|
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
|
|
130
|
-
<input type="password" id="node-config-input-password" placeholder="
|
|
137
|
+
<input type="password" id="node-config-input-password" placeholder="Deprecated" />
|
|
131
138
|
</div>
|
|
132
139
|
|
|
133
140
|
<div class="form-row">
|
|
@@ -145,10 +152,17 @@
|
|
|
145
152
|
</div>
|
|
146
153
|
|
|
147
154
|
<div class="form-row">
|
|
148
|
-
<label for="node-config-input-logdump"
|
|
155
|
+
<label for="node-config-input-logdump"> </label>
|
|
149
156
|
<label for="node-config-input-logdump" style="width:70%">
|
|
150
157
|
<input type="checkbox" id="node-config-input-logdump" style="display:inline-block; width:22px; vertical-align:top;" autocomplete="off"><span>dump config</span>
|
|
151
|
-
|
|
158
|
+
</label>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<div class="form-row">
|
|
162
|
+
<label for="node-config-input-ble"><i class="fa fa-bluetooth"></i> <span>BLE</span></label>
|
|
163
|
+
<label for="node-config-input-ble" style="width:70%">
|
|
164
|
+
<input type="checkbox" id="node-config-input-ble" style="display:inline-block; width:22px; vertical-align:top;" autocomplete="off"><span>Advertisements</span>
|
|
165
|
+
</label>
|
|
152
166
|
</div>
|
|
153
167
|
|
|
154
168
|
<div class="form-row">
|
|
@@ -164,11 +178,15 @@
|
|
|
164
178
|
<dd>host or ip address</dd>
|
|
165
179
|
<dt class="required">Port<span class="property-type">number</span></dt>
|
|
166
180
|
<dd>port</dd>
|
|
181
|
+
<dt class="required">Encryption Key<span class="property-type">password</span></dt>
|
|
182
|
+
<dd>encryption key for API</dd>
|
|
167
183
|
<dt class="required">Password<span class="property-type">password</span></dt>
|
|
168
184
|
<dd>password for API</dd>
|
|
169
185
|
<dt class="required">Log Level<span class="property-type">number</span></dt>
|
|
170
186
|
<dd>possible log levels</dd>
|
|
171
187
|
<dt class="required">Dump Config<span class="property-type">true|false</span></dt>
|
|
172
188
|
<dd>dump config</dd>
|
|
189
|
+
<dt class="required">BLE<span class="property-type">true|false</span></dt>
|
|
190
|
+
<dd>ble advertising</dd>
|
|
173
191
|
</dl>
|
|
174
192
|
</script>
|
package/build/nodes/device.js
CHANGED
|
@@ -16,6 +16,7 @@ module.exports = (RED) => {
|
|
|
16
16
|
self.entities = [];
|
|
17
17
|
self.current_status = 'disconnected';
|
|
18
18
|
self.logger = parseInt(config === null || config === void 0 ? void 0 : config.loglevel);
|
|
19
|
+
self.ble = Boolean(config === null || config === void 0 ? void 0 : config.ble);
|
|
19
20
|
if (!(config === null || config === void 0 ? void 0 : config.host) || !(config === null || config === void 0 ? void 0 : config.port)) {
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
@@ -26,19 +27,28 @@ module.exports = (RED) => {
|
|
|
26
27
|
self.onState = function (object) {
|
|
27
28
|
self.emit('onState', object);
|
|
28
29
|
};
|
|
30
|
+
self.onBle = function (object) {
|
|
31
|
+
self.emit('onBle', object);
|
|
32
|
+
};
|
|
29
33
|
let options = {
|
|
30
34
|
host: config.host,
|
|
31
35
|
port: config.port,
|
|
32
|
-
password: self.credentials.password,
|
|
33
36
|
clientInfo: Package.name + ' ' + Package.version,
|
|
34
37
|
initializeDeviceInfo: true,
|
|
35
38
|
initializeListEntities: true,
|
|
36
39
|
initializeSubscribeStates: true,
|
|
37
40
|
reconnect: true,
|
|
38
41
|
reconnectInterval: 15 * 1000,
|
|
39
|
-
pingInterval: 15 * 1000
|
|
42
|
+
pingInterval: 15 * 1000,
|
|
43
|
+
initializeSubscribeBLEAdvertisements: self.ble
|
|
40
44
|
};
|
|
41
|
-
if (
|
|
45
|
+
if (self.credentials.encryptionkey) {
|
|
46
|
+
options = Object.assign(Object.assign({}, options), { encryptionKey: self.credentials.encryptionkey });
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
options = Object.assign(Object.assign({}, options), { password: self.credentials.password });
|
|
50
|
+
}
|
|
51
|
+
if (self.logger) {
|
|
42
52
|
options = Object.assign(Object.assign({}, options), { initializeSubscribeLogs: {
|
|
43
53
|
level: config.loglevel,
|
|
44
54
|
dumpConfig: config.logdump
|
|
@@ -54,24 +64,6 @@ module.exports = (RED) => {
|
|
|
54
64
|
return;
|
|
55
65
|
}
|
|
56
66
|
self.client.on('error', (e) => {
|
|
57
|
-
if (e.message.includes('EHOSTUNREACH')) {
|
|
58
|
-
/* empty */
|
|
59
|
-
}
|
|
60
|
-
else if (e.message.includes('Invalid password')) {
|
|
61
|
-
/* empty */
|
|
62
|
-
}
|
|
63
|
-
else if (e.message.includes('ECONNRESET')) {
|
|
64
|
-
/* empty */
|
|
65
|
-
}
|
|
66
|
-
else if (e.message.includes('TIMEOUT')) {
|
|
67
|
-
/* empty */
|
|
68
|
-
}
|
|
69
|
-
else if (e.message.includes('write after end')) {
|
|
70
|
-
/* empty */
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// copy this error to issues ...
|
|
74
|
-
}
|
|
75
67
|
self.error(e.message);
|
|
76
68
|
self.onStatus('error');
|
|
77
69
|
});
|
|
@@ -82,7 +74,7 @@ module.exports = (RED) => {
|
|
|
82
74
|
// clear entities
|
|
83
75
|
self.entities = [];
|
|
84
76
|
// logs to entities
|
|
85
|
-
if (
|
|
77
|
+
if (self.logger) {
|
|
86
78
|
self.entities.push({
|
|
87
79
|
key: 'logs',
|
|
88
80
|
type: 'Systems',
|
|
@@ -92,6 +84,14 @@ module.exports = (RED) => {
|
|
|
92
84
|
}
|
|
93
85
|
});
|
|
94
86
|
}
|
|
87
|
+
// ble to entities
|
|
88
|
+
if (self.ble) {
|
|
89
|
+
self.entities.push({
|
|
90
|
+
key: 'ble',
|
|
91
|
+
type: 'Systems',
|
|
92
|
+
name: 'BLE'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
95
|
self.onStatus('connecting');
|
|
96
96
|
});
|
|
97
97
|
self.client.on('initialized', () => {
|
|
@@ -119,11 +119,16 @@ module.exports = (RED) => {
|
|
|
119
119
|
self.client.on('logs', (payload) => {
|
|
120
120
|
self.onState(Object.assign({ key: 'logs' }, payload));
|
|
121
121
|
});
|
|
122
|
+
// ble
|
|
123
|
+
self.client.on('ble', (payload) => {
|
|
124
|
+
self.onBle(Object.assign({ key: 'ble' }, payload));
|
|
125
|
+
});
|
|
122
126
|
self.on('close', () => {
|
|
123
127
|
self.client.disconnect();
|
|
124
128
|
});
|
|
125
129
|
}, {
|
|
126
130
|
credentials: {
|
|
131
|
+
encryptionkey: { type: 'password' },
|
|
127
132
|
password: { type: 'password' }
|
|
128
133
|
}
|
|
129
134
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../src/nodes/device.ts"],"names":[],"mappings":";;AACA,8DAA8D;AAC9D,MAAM,EAAC,MAAM,EAAC,GAAG,OAAO,CAAC,6BAA6B,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E;gBAChC,IAAI,CAAC,OAAO,mBAAK,KAAK,EAAE,CAAC;YAC3B,CAAC,CAAC,CAAC;YAEH,6DAA6D;YAC7D,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAQ,EAAE,EAAE;gBAC9B,WAAW;YACb,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO;QACP,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,OAAY,EAAE,EAAE;YACtC,IAAI,CAAC,OAAO,iBAAE,GAAG,EAAE,MAAM,IAAK,OAAO,EAAE,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,MAAM;QACN,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,OAAY,EAAE,EAAE;YACrC,IAAI,CAAC,KAAK,iBAAE,GAAG,EAAE,KAAK,IAAK,OAAO,EAAE,CAAC;QACvC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACpB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC,EACD;QACE,WAAW,EAAE;YACX,aAAa,EAAE,EAAC,IAAI,EAAE,UAAU,EAAC;YACjC,QAAQ,EAAE,EAAC,IAAI,EAAE,UAAU,EAAC;SAC7B;KACF,CACF,CAAC;AACJ,CAAC,CAAC"}
|
package/build/nodes/in.html
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
defaults: {
|
|
7
7
|
name: {},
|
|
8
8
|
device: {value: '', type: 'esphome-device'},
|
|
9
|
-
entity: {value: ''}
|
|
9
|
+
entity: {value: ''},
|
|
10
|
+
bleaddress: {value: ''}
|
|
10
11
|
},
|
|
11
12
|
outputs: 1,
|
|
12
13
|
icon: 'esphome.svg',
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
|
|
23
24
|
if ($device && $device != '_ADD_') {
|
|
24
25
|
let entity = $('#node-input-entity');
|
|
25
|
-
let $val =
|
|
26
|
+
let $val = entity.val() || node.entity;
|
|
26
27
|
|
|
27
28
|
$.post('esphome/entities', {
|
|
28
29
|
deviceNode: $device
|
|
@@ -48,18 +49,20 @@
|
|
|
48
49
|
|
|
49
50
|
// TODO: join -> split ...
|
|
50
51
|
let label = '';
|
|
51
|
-
if (d.config
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
if (d.config) {
|
|
53
|
+
if (d.config.deviceClass || d.config.unitOfMeasurement) {
|
|
54
|
+
label += '(';
|
|
55
|
+
if (d.config.deviceClass) {
|
|
56
|
+
label += d.config.deviceClass;
|
|
57
|
+
}
|
|
58
|
+
if (d.config.deviceClass && d.config.unitOfMeasurement) {
|
|
59
|
+
label += ', ';
|
|
60
|
+
}
|
|
61
|
+
if (d.config.unitOfMeasurement) {
|
|
62
|
+
label += d.config.unitOfMeasurement;
|
|
63
|
+
}
|
|
64
|
+
label += ')';
|
|
55
65
|
}
|
|
56
|
-
if (d.config.deviceClass && d.config.unitOfMeasurement) {
|
|
57
|
-
label += ', ';
|
|
58
|
-
}
|
|
59
|
-
if (d.config.unitOfMeasurement) {
|
|
60
|
-
label += d.config.unitOfMeasurement;
|
|
61
|
-
}
|
|
62
|
-
label += ')';
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
$('<option/>')
|
|
@@ -82,6 +85,10 @@
|
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
$('#node-input-device').on('change', selectEntity);
|
|
88
|
+
$('#node-input-entity').on('change', function() {
|
|
89
|
+
let $val = $(this).val() || node.entity;
|
|
90
|
+
$val == 'ble' ? $('#ble-show').show() : $('#ble-show').hide();
|
|
91
|
+
});
|
|
85
92
|
},
|
|
86
93
|
oneditsave: function () {
|
|
87
94
|
let $elm = $('#node-input-entity option:selected');
|
|
@@ -107,6 +114,13 @@
|
|
|
107
114
|
<label for="node-input-entity"><i class="fa fa-globe"></i> Entity</label>
|
|
108
115
|
<select id="node-input-entity" style="width: 70%;" disabled></select>
|
|
109
116
|
</div>
|
|
117
|
+
|
|
118
|
+
<div id="ble-show" style="display: none;">
|
|
119
|
+
<div class="form-row">
|
|
120
|
+
<label for="node-input-bleaddress"><i class="fa fa-bluetooth"></i> Address</label>
|
|
121
|
+
<input type="text" id="node-input-bleaddress" placeholder="00:AB:CD:EF:11:22" />
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
110
124
|
</script>
|
|
111
125
|
|
|
112
126
|
<script type="text/html" data-help-name="esphome-in">
|
package/build/nodes/in.js
CHANGED
|
@@ -9,12 +9,12 @@ module.exports = (RED) => {
|
|
|
9
9
|
self.config = config;
|
|
10
10
|
RED.nodes.createNode(this, config);
|
|
11
11
|
try {
|
|
12
|
-
self.deviceNode = RED.nodes.getNode(
|
|
12
|
+
self.deviceNode = RED.nodes.getNode(config.device);
|
|
13
13
|
}
|
|
14
14
|
catch (_) {
|
|
15
15
|
/* empty */
|
|
16
16
|
}
|
|
17
|
-
if (!self.deviceNode || !
|
|
17
|
+
if (!self.deviceNode || !config.entity) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
self.current_status = self.deviceNode.current_status;
|
|
@@ -49,7 +49,23 @@ module.exports = (RED) => {
|
|
|
49
49
|
self.send({
|
|
50
50
|
payload: payload,
|
|
51
51
|
device: self.deviceNode.device,
|
|
52
|
-
|
|
52
|
+
entity: entity
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const onBle = (data) => {
|
|
56
|
+
let address = config.bleaddress;
|
|
57
|
+
const payload = Object.assign({}, data);
|
|
58
|
+
address = address.toLowerCase().replace(/[^a-f0-9]/g, '');
|
|
59
|
+
payload.address = payload.address.toString(16);
|
|
60
|
+
if (payload.address != address) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
delete payload.key;
|
|
64
|
+
setStatus({ fill: 'blue', shape: 'dot', text: 'ble' }, 3000);
|
|
65
|
+
const entity = self.deviceNode.entities.find((e) => e.key == config.entity);
|
|
66
|
+
self.send({
|
|
67
|
+
payload: payload,
|
|
68
|
+
device: self.deviceNode.device,
|
|
53
69
|
entity: entity
|
|
54
70
|
});
|
|
55
71
|
};
|
|
@@ -59,10 +75,13 @@ module.exports = (RED) => {
|
|
|
59
75
|
};
|
|
60
76
|
self.onState = (state) => onState(state);
|
|
61
77
|
self.deviceNode.on('onState', self.onState);
|
|
78
|
+
self.onBle = (data) => onBle(data);
|
|
79
|
+
self.deviceNode.on('onBle', self.onBle);
|
|
62
80
|
self.onStatus = (status) => onStatus(status);
|
|
63
81
|
self.deviceNode.on('onStatus', self.onStatus);
|
|
64
82
|
self.on('close', (_, done) => {
|
|
65
83
|
self.deviceNode.removeListener('onState', self.onState);
|
|
84
|
+
self.deviceNode.removeListener('onBle', self.onBle);
|
|
66
85
|
self.deviceNode.removeListener('onStatus', self.onStatus);
|
|
67
86
|
done();
|
|
68
87
|
});
|
package/build/nodes/in.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in.js","sourceRoot":"","sources":["../../src/nodes/in.ts"],"names":[],"mappings":";;AACA,wCAAoC;AACpC,+BAA6B;AAE7B,MAAM,CAAC,OAAO,GAAG,CAAC,GAAY,EAAE,EAAE;IAChC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,UAAqB,MAAW;QACnE,4DAA4D;QAC5D,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAEnC,IAAI;YACF,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"in.js","sourceRoot":"","sources":["../../src/nodes/in.ts"],"names":[],"mappings":";;AACA,wCAAoC;AACpC,+BAA6B;AAE7B,MAAM,CAAC,OAAO,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AC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAM,EAAE,IAAe,EAAE,EAAE;YAC3C,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACxD,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;YACpD,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1D,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/build/nodes/out.html
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
if ($device && $device != '_ADD_') {
|
|
24
24
|
let entity = $('#node-input-entity');
|
|
25
|
-
let $val =
|
|
25
|
+
let $val = entity.val() || node.entity;
|
|
26
26
|
|
|
27
27
|
$.post('esphome/entities', {
|
|
28
28
|
deviceNode: $device
|
|
@@ -48,18 +48,20 @@
|
|
|
48
48
|
|
|
49
49
|
// TODO: join -> split ...
|
|
50
50
|
let label = '';
|
|
51
|
-
if (d.config
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
if (d.config) {
|
|
52
|
+
if (d.config.deviceClass || d.config.unitOfMeasurement) {
|
|
53
|
+
label += '(';
|
|
54
|
+
if (d.config.deviceClass) {
|
|
55
|
+
label += d.config.deviceClass;
|
|
56
|
+
}
|
|
57
|
+
if (d.config.deviceClass && d.config.unitOfMeasurement) {
|
|
58
|
+
label += ', ';
|
|
59
|
+
}
|
|
60
|
+
if (d.config.unitOfMeasurement) {
|
|
61
|
+
label += d.config.unitOfMeasurement;
|
|
62
|
+
}
|
|
63
|
+
label += ')';
|
|
55
64
|
}
|
|
56
|
-
if (d.config.deviceClass && d.config.unitOfMeasurement) {
|
|
57
|
-
label += ', ';
|
|
58
|
-
}
|
|
59
|
-
if (d.config.unitOfMeasurement) {
|
|
60
|
-
label += d.config.unitOfMeasurement;
|
|
61
|
-
}
|
|
62
|
-
label += ')';
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
$('<option/>')
|
package/build/nodes/out.js
CHANGED
|
@@ -18,12 +18,12 @@ module.exports = (RED) => {
|
|
|
18
18
|
self.config = config;
|
|
19
19
|
RED.nodes.createNode(this, config);
|
|
20
20
|
try {
|
|
21
|
-
self.deviceNode = RED.nodes.getNode(
|
|
21
|
+
self.deviceNode = RED.nodes.getNode(config.device);
|
|
22
22
|
}
|
|
23
23
|
catch (_) {
|
|
24
24
|
/* empty */
|
|
25
25
|
}
|
|
26
|
-
if (!self.deviceNode || !
|
|
26
|
+
if (!self.deviceNode || !config.entity) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
self.current_status = self.deviceNode.current_status;
|
|
@@ -43,22 +43,30 @@ module.exports = (RED) => {
|
|
|
43
43
|
clearStatus(timeout);
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
+
const capitalize = (s) => (s[0].toLowerCase() + s.slice(1));
|
|
46
47
|
self.on('input', (msg, send, done) => __awaiter(this, void 0, void 0, function* () {
|
|
47
48
|
const entity = self.deviceNode.entities.find((e) => e.key == config.entity);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (typeof entity == 'undefined') {
|
|
50
|
+
setStatus(utils_1.Status['error'], 3000);
|
|
51
|
+
self.error(`entity (${config.entity}) not found on device`);
|
|
52
|
+
done();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const regexpType = /^(BinarySensor|Sensor|TextSensor)$/gi;
|
|
56
|
+
const regexpEntity = /^(Logs|BLE)$/gi;
|
|
57
|
+
if (entity.type.match(regexpType) || config.entity.match(regexpEntity)) {
|
|
51
58
|
done();
|
|
52
59
|
return;
|
|
53
60
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
61
|
+
const payload = msg.payload;
|
|
62
|
+
let text = typeof payload.state !== 'undefined' && typeof payload.state !== 'object' ? payload.state : (0, util_1.inspect)(payload);
|
|
63
|
+
if (text && text.length > 32) {
|
|
64
|
+
text = text.substr(0, 32) + '...';
|
|
58
65
|
}
|
|
59
|
-
setStatus({ fill: 'yellow', shape: 'dot', text:
|
|
66
|
+
setStatus({ fill: 'yellow', shape: 'dot', text: text }, 3000);
|
|
60
67
|
try {
|
|
61
|
-
|
|
68
|
+
const command = capitalize(entity.type + 'CommandService');
|
|
69
|
+
yield self.deviceNode.client.connection[command](Object.assign({ key: config.entity }, payload));
|
|
62
70
|
}
|
|
63
71
|
catch (e) {
|
|
64
72
|
setStatus(utils_1.Status['error'], 3000);
|
package/build/nodes/out.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"out.js","sourceRoot":"","sources":["../../src/nodes/out.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,wCAAoC;AACpC,+BAA6B;AAE7B,MAAM,CAAC,OAAO,GAAG,CAAC,GAAY,EAAE,EAAE;IAChC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,UAAqB,MAAW;QACpE,4DAA4D;QAC5D,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAEnC,IAAI;YACF,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"out.js","sourceRoot":"","sources":["../../src/nodes/out.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,wCAAoC;AACpC,+BAA6B;AAE7B,MAAM,CAAC,OAAO,GAAG,CAAC,GAAY,EAAE,EAAE;IAChC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,UAAqB,MAAW;QACpE,4DAA4D;QAC5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C,CAAC;gBAC3D,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,iBAAE,GAAG,EAAE,MAAM,CAAC,MAAM,IAAK,OAAO,EAAE,CAAC;aACpF;YAAC,OAAO,CAAM,EAAE;gBACf,SAAS,CAAC,cAAM,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;gBACjC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;aACvB;YAED,IAAI,EAAE,CAAC;QACT,CAAC,CAAA,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,EAAE;YAClC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC;YAE7B,SAAS,CAAC,cAAM,CAAC,IAAI,CAAC,cAAwB,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC;QAEF,IAAI,CAAC,QAAQ,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE9C,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAM,EAAE,IAAe,EAAE,EAAE;YAC3C,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1D,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-esphome",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Node-RED nodes to ESPhome devices",
|
|
5
5
|
"homepage": "https://github.com/twocolors/node-red-contrib-esphome",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "tsc",
|
|
17
17
|
"build:clean": "npm run clean && npm run build",
|
|
18
|
-
"clean": "rm -rf build
|
|
18
|
+
"clean": "rm -rf build/**/*.js",
|
|
19
19
|
"eslint": "eslint \"src/**/*.ts\"",
|
|
20
20
|
"prettier": "prettier --write \"**/*.{js,ts}\""
|
|
21
21
|
},
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@2colors/esphome-native-api":"1.
|
|
32
|
+
"@2colors/esphome-native-api": "^1.2.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/node":"^18.11.18",
|
|
36
|
-
"@types/node-red":"^1.2.1",
|
|
35
|
+
"@types/node": "^18.11.18",
|
|
36
|
+
"@types/node-red": "^1.2.1",
|
|
37
37
|
"@typescript-eslint/eslint-plugin": "^5.45.1",
|
|
38
38
|
"@typescript-eslint/parser": "^5.45.1",
|
|
39
39
|
"eslint": "^8.31.0",
|
|
40
40
|
"eslint-config-prettier": "^8.5.0",
|
|
41
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
42
41
|
"eslint-plugin-node": "^11.1.0",
|
|
42
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
43
43
|
"prettier": "^2.8.1",
|
|
44
44
|
"typescript": "^5.0.2"
|
|
45
45
|
},
|
|
@@ -54,4 +54,4 @@
|
|
|
54
54
|
"esp32",
|
|
55
55
|
"esp8266"
|
|
56
56
|
]
|
|
57
|
-
}
|
|
57
|
+
}
|
package/readme/device.png
CHANGED
|
Binary file
|
package/readme/flow.png
CHANGED
|
Binary file
|
package/src/nodes/device.ts
CHANGED
|
@@ -20,6 +20,7 @@ module.exports = (RED: NodeAPI) => {
|
|
|
20
20
|
self.entities = [];
|
|
21
21
|
self.current_status = 'disconnected';
|
|
22
22
|
self.logger = parseInt(config?.loglevel);
|
|
23
|
+
self.ble = Boolean(config?.ble);
|
|
23
24
|
|
|
24
25
|
if (!config?.host || !config?.port) {
|
|
25
26
|
return;
|
|
@@ -34,20 +35,36 @@ module.exports = (RED: NodeAPI) => {
|
|
|
34
35
|
self.emit('onState', object);
|
|
35
36
|
};
|
|
36
37
|
|
|
38
|
+
self.onBle = function (object: any) {
|
|
39
|
+
self.emit('onBle', object);
|
|
40
|
+
};
|
|
41
|
+
|
|
37
42
|
let options: any = {
|
|
38
43
|
host: config.host,
|
|
39
44
|
port: config.port,
|
|
40
|
-
password: self.credentials.password,
|
|
41
45
|
clientInfo: Package.name + ' ' + Package.version,
|
|
42
46
|
initializeDeviceInfo: true,
|
|
43
47
|
initializeListEntities: true,
|
|
44
48
|
initializeSubscribeStates: true,
|
|
45
49
|
reconnect: true,
|
|
46
50
|
reconnectInterval: 15 * 1000,
|
|
47
|
-
pingInterval: 15 * 1000
|
|
51
|
+
pingInterval: 15 * 1000,
|
|
52
|
+
initializeSubscribeBLEAdvertisements: self.ble
|
|
48
53
|
};
|
|
49
54
|
|
|
50
|
-
if (
|
|
55
|
+
if (self.credentials.encryptionkey) {
|
|
56
|
+
options = {
|
|
57
|
+
...options,
|
|
58
|
+
encryptionKey: self.credentials.encryptionkey
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
options = {
|
|
62
|
+
...options,
|
|
63
|
+
password: self.credentials.password
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (self.logger) {
|
|
51
68
|
options = {
|
|
52
69
|
...options,
|
|
53
70
|
initializeSubscribeLogs: {
|
|
@@ -68,19 +85,6 @@ module.exports = (RED: NodeAPI) => {
|
|
|
68
85
|
}
|
|
69
86
|
|
|
70
87
|
self.client.on('error', (e: Error) => {
|
|
71
|
-
if (e.message.includes('EHOSTUNREACH')) {
|
|
72
|
-
/* empty */
|
|
73
|
-
} else if (e.message.includes('Invalid password')) {
|
|
74
|
-
/* empty */
|
|
75
|
-
} else if (e.message.includes('ECONNRESET')) {
|
|
76
|
-
/* empty */
|
|
77
|
-
} else if (e.message.includes('TIMEOUT')) {
|
|
78
|
-
/* empty */
|
|
79
|
-
} else if (e.message.includes('write after end')) {
|
|
80
|
-
/* empty */
|
|
81
|
-
} else {
|
|
82
|
-
// copy this error to issues ...
|
|
83
|
-
}
|
|
84
88
|
self.error(e.message);
|
|
85
89
|
self.onStatus('error');
|
|
86
90
|
});
|
|
@@ -93,7 +97,7 @@ module.exports = (RED: NodeAPI) => {
|
|
|
93
97
|
// clear entities
|
|
94
98
|
self.entities = [];
|
|
95
99
|
// logs to entities
|
|
96
|
-
if (
|
|
100
|
+
if (self.logger) {
|
|
97
101
|
self.entities.push({
|
|
98
102
|
key: 'logs',
|
|
99
103
|
type: 'Systems',
|
|
@@ -103,6 +107,14 @@ module.exports = (RED: NodeAPI) => {
|
|
|
103
107
|
}
|
|
104
108
|
});
|
|
105
109
|
}
|
|
110
|
+
// ble to entities
|
|
111
|
+
if (self.ble) {
|
|
112
|
+
self.entities.push({
|
|
113
|
+
key: 'ble',
|
|
114
|
+
type: 'Systems',
|
|
115
|
+
name: 'BLE'
|
|
116
|
+
});
|
|
117
|
+
}
|
|
106
118
|
|
|
107
119
|
self.onStatus('connecting');
|
|
108
120
|
});
|
|
@@ -138,12 +150,18 @@ module.exports = (RED: NodeAPI) => {
|
|
|
138
150
|
self.onState({key: 'logs', ...payload});
|
|
139
151
|
});
|
|
140
152
|
|
|
153
|
+
// ble
|
|
154
|
+
self.client.on('ble', (payload: any) => {
|
|
155
|
+
self.onBle({key: 'ble', ...payload});
|
|
156
|
+
});
|
|
157
|
+
|
|
141
158
|
self.on('close', () => {
|
|
142
159
|
self.client.disconnect();
|
|
143
160
|
});
|
|
144
161
|
},
|
|
145
162
|
{
|
|
146
163
|
credentials: {
|
|
164
|
+
encryptionkey: {type: 'password'},
|
|
147
165
|
password: {type: 'password'}
|
|
148
166
|
}
|
|
149
167
|
}
|
package/src/nodes/in.ts
CHANGED
|
@@ -11,12 +11,12 @@ module.exports = (RED: NodeAPI) => {
|
|
|
11
11
|
RED.nodes.createNode(this, config);
|
|
12
12
|
|
|
13
13
|
try {
|
|
14
|
-
self.deviceNode = RED.nodes.getNode(
|
|
14
|
+
self.deviceNode = RED.nodes.getNode(config.device);
|
|
15
15
|
} catch (_) {
|
|
16
16
|
/* empty */
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
if (!self.deviceNode || !
|
|
19
|
+
if (!self.deviceNode || !config.entity) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -60,7 +60,30 @@ module.exports = (RED: NodeAPI) => {
|
|
|
60
60
|
self.send({
|
|
61
61
|
payload: payload,
|
|
62
62
|
device: self.deviceNode.device,
|
|
63
|
-
|
|
63
|
+
entity: entity
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const onBle = (data: any) => {
|
|
68
|
+
let address: string = config.bleaddress;
|
|
69
|
+
const payload: any = {...data};
|
|
70
|
+
|
|
71
|
+
address = address.toLowerCase().replace(/[^a-f0-9]/g, '');
|
|
72
|
+
payload.address = payload.address.toString(16);
|
|
73
|
+
|
|
74
|
+
if (payload.address != address) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
delete payload.key;
|
|
79
|
+
|
|
80
|
+
setStatus({fill: 'blue', shape: 'dot', text: 'ble'}, 3000);
|
|
81
|
+
|
|
82
|
+
const entity: any = self.deviceNode.entities.find((e: any) => e.key == config.entity);
|
|
83
|
+
|
|
84
|
+
self.send({
|
|
85
|
+
payload: payload,
|
|
86
|
+
device: self.deviceNode.device,
|
|
64
87
|
entity: entity
|
|
65
88
|
});
|
|
66
89
|
};
|
|
@@ -74,11 +97,15 @@ module.exports = (RED: NodeAPI) => {
|
|
|
74
97
|
self.onState = (state: any) => onState(state);
|
|
75
98
|
self.deviceNode.on('onState', self.onState);
|
|
76
99
|
|
|
100
|
+
self.onBle = (data: any) => onBle(data);
|
|
101
|
+
self.deviceNode.on('onBle', self.onBle);
|
|
102
|
+
|
|
77
103
|
self.onStatus = (status: string) => onStatus(status);
|
|
78
104
|
self.deviceNode.on('onStatus', self.onStatus);
|
|
79
105
|
|
|
80
106
|
self.on('close', (_: any, done: () => any) => {
|
|
81
107
|
self.deviceNode.removeListener('onState', self.onState);
|
|
108
|
+
self.deviceNode.removeListener('onBle', self.onBle);
|
|
82
109
|
self.deviceNode.removeListener('onStatus', self.onStatus);
|
|
83
110
|
done();
|
|
84
111
|
});
|
package/src/nodes/out.ts
CHANGED
|
@@ -11,12 +11,12 @@ module.exports = (RED: NodeAPI) => {
|
|
|
11
11
|
RED.nodes.createNode(this, config);
|
|
12
12
|
|
|
13
13
|
try {
|
|
14
|
-
self.deviceNode = RED.nodes.getNode(
|
|
14
|
+
self.deviceNode = RED.nodes.getNode(config.device);
|
|
15
15
|
} catch (_) {
|
|
16
16
|
/* empty */
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
if (!self.deviceNode || !
|
|
19
|
+
if (!self.deviceNode || !config.entity) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -39,25 +39,35 @@ module.exports = (RED: NodeAPI) => {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
const capitalize = (s: string) => (s[0].toLowerCase() + s.slice(1)) as string;
|
|
43
|
+
|
|
42
44
|
self.on('input', async (msg: any, send: () => any, done: () => any) => {
|
|
43
45
|
const entity: any = self.deviceNode.entities.find((e: any) => e.key == config.entity);
|
|
44
|
-
|
|
46
|
+
if (typeof entity == 'undefined') {
|
|
47
|
+
setStatus(Status['error'], 3000);
|
|
48
|
+
self.error(`entity (${config.entity}) not found on device`);
|
|
49
|
+
done();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
45
52
|
|
|
46
|
-
const
|
|
47
|
-
|
|
53
|
+
const regexpType = /^(BinarySensor|Sensor|TextSensor)$/gi;
|
|
54
|
+
const regexpEntity = /^(Logs|BLE)$/gi;
|
|
55
|
+
if (entity.type.match(regexpType) || config.entity.match(regexpEntity)) {
|
|
48
56
|
done();
|
|
49
57
|
return;
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
const payload: any = msg.payload;
|
|
61
|
+
let text =
|
|
62
|
+
typeof payload.state !== 'undefined' && typeof payload.state !== 'object' ? payload.state : inspect(payload);
|
|
63
|
+
if (text && text.length > 32) {
|
|
64
|
+
text = text.substr(0, 32) + '...';
|
|
56
65
|
}
|
|
57
|
-
setStatus({fill: 'yellow', shape: 'dot', text:
|
|
66
|
+
setStatus({fill: 'yellow', shape: 'dot', text: text}, 3000);
|
|
58
67
|
|
|
59
68
|
try {
|
|
60
|
-
|
|
69
|
+
const command = capitalize(entity.type + 'CommandService');
|
|
70
|
+
await self.deviceNode.client.connection[command]({key: config.entity, ...payload});
|
|
61
71
|
} catch (e: any) {
|
|
62
72
|
setStatus(Status['error'], 3000);
|
|
63
73
|
self.error(e.message);
|