node-red-contrib-esphome 0.0.2 → 0.0.4
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/build/lib/utils.d.ts +0 -1
- package/build/lib/utils.js +1 -55
- package/build/lib/utils.js.map +1 -1
- package/build/nodes/api.js +3 -2
- package/build/nodes/api.js.map +1 -1
- package/build/nodes/device.html +2 -2
- package/build/nodes/device.js +1 -1
- package/package.json +3 -4
- package/src/lib/utils.ts +0 -47
- package/src/nodes/api.ts +3 -2
- package/src/nodes/device.ts +1 -1
package/build/lib/utils.d.ts
CHANGED
package/build/lib/utils.js
CHANGED
|
@@ -1,60 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Status =
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
|
-
const mdns = require('node-dns-sd');
|
|
15
|
-
// {
|
|
16
|
-
// address: '192.168.0.114',
|
|
17
|
-
// fqdn: 'corridor-waylight._esphomelib._tcp.local',
|
|
18
|
-
// modelName: null,
|
|
19
|
-
// familyName: null,
|
|
20
|
-
// service: { port: 6053, protocol: 'tcp', type: 'esphomelib' },
|
|
21
|
-
// packet: {
|
|
22
|
-
// header: [Object],
|
|
23
|
-
// questions: [],
|
|
24
|
-
// answers: [Array],
|
|
25
|
-
// authorities: [],
|
|
26
|
-
// additionals: [Array],
|
|
27
|
-
// address: '192.168.0.114'
|
|
28
|
-
// }
|
|
29
|
-
// }
|
|
30
|
-
function discovery(name = '_esphomelib._tcp.local', wait = 3) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
return yield new Promise((resolve, reject) => {
|
|
33
|
-
mdns
|
|
34
|
-
.discover({
|
|
35
|
-
name: name,
|
|
36
|
-
wait: wait
|
|
37
|
-
})
|
|
38
|
-
.then((items) => {
|
|
39
|
-
const devices = [];
|
|
40
|
-
items
|
|
41
|
-
.sort((a, b) => (a.fqdn > b.fqdn ? 1 : -1))
|
|
42
|
-
.map((device) => {
|
|
43
|
-
devices.push({
|
|
44
|
-
host: device.address,
|
|
45
|
-
port: device.service.port,
|
|
46
|
-
fqdn: device.fqdn.replace(/_esphomelib\._tcp./gi, '')
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
resolve(devices);
|
|
50
|
-
})
|
|
51
|
-
.catch((e) => {
|
|
52
|
-
reject(e);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
exports.discovery = discovery;
|
|
3
|
+
exports.Status = void 0;
|
|
58
4
|
exports.Status = {
|
|
59
5
|
error: {
|
|
60
6
|
fill: 'red',
|
package/build/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAyB;IAC1C,KAAK,EAAE;QACL,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,OAAO;KACd;IACD,YAAY,EAAE;QACZ,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,cAAc;KACrB;IACD,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,YAAY;KACnB;IACD,SAAS,EAAE;QACT,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,WAAW;KAClB;CACO,CAAC"}
|
package/build/nodes/api.js
CHANGED
|
@@ -9,11 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
13
|
+
const { Discovery } = require('esphome-native-api');
|
|
13
14
|
module.exports = (RED) => {
|
|
14
15
|
const NODE_PATH = '/esphome/';
|
|
15
16
|
RED.httpAdmin.post(NODE_PATH + 'discovery', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
(
|
|
17
|
+
Discovery()
|
|
17
18
|
.then((devices) => {
|
|
18
19
|
res.json(devices);
|
|
19
20
|
})
|
package/build/nodes/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/nodes/api.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/nodes/api.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,8DAA8D;AAC9D,MAAM,EAAC,SAAS,EAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElD,MAAM,CAAC,OAAO,GAAG,CAAC,GAAY,EAAE,EAAE;IAChC,MAAM,SAAS,GAAG,WAAW,CAAC;IAE9B,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,GAAG,WAAW,EAAE,CAAO,GAAoB,EAAE,GAAqB,EAAE,EAAE;QAChG,SAAS,EAAE;aACR,IAAI,CAAC,CAAC,OAAsB,EAAE,EAAE;YAC/B,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,CAAQ,EAAE,EAAE;YAClB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC,CAAA,CAAC,CAAC;IAEH,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,EAAE,CAAO,GAAoB,EAAE,GAAqB,EAAE,EAAE;QAC/F,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAQ,CAAC;QAEjE,IAAI,UAAU,EAAE;YACd,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;SAC/B;aAAM;YACL,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SACd;IACH,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/build/nodes/device.html
CHANGED
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
$('#node-config-input-host').replaceWith(
|
|
52
52
|
`<select id="node-config-input-host" style="width: 100%;"></select>`
|
|
53
53
|
);
|
|
54
|
-
data.map(function (d) {
|
|
54
|
+
data.sort((a, b) => (a.host > b.host ? 1 : -1)).map(function (d) {
|
|
55
55
|
$('#node-config-input-host').append(
|
|
56
|
-
`<option value="${d.
|
|
56
|
+
`<option value="${d.address}" data-host="${d.address}" data-port="${d.port}" data-fqdn="${d.host}">${d.host} (${d.board})</option>`
|
|
57
57
|
);
|
|
58
58
|
});
|
|
59
59
|
|
package/build/nodes/device.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-esphome",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Node-RED nodes to ESPhome devices.",
|
|
5
5
|
"homepage": "https://github.com/twocolors/node-red-contrib-esphome",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/twocolors/node-red-contrib-esphome.git"
|
|
9
|
+
"url": "git+https://github.com/twocolors/node-red-contrib-esphome.git"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/twocolors/node-red-contrib-esphome/issues"
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"
|
|
33
|
-
"esphome-native-api":"twocolors/esphome-native-api#main"
|
|
32
|
+
"esphome-native-api":"git+https://github.com/twocolors/esphome-native-api.git"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
35
|
"@types/node":"^18.11.18",
|
package/src/lib/utils.ts
CHANGED
|
@@ -1,50 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
-
const mdns = require('node-dns-sd');
|
|
3
|
-
|
|
4
|
-
// {
|
|
5
|
-
// address: '192.168.0.114',
|
|
6
|
-
// fqdn: 'corridor-waylight._esphomelib._tcp.local',
|
|
7
|
-
// modelName: null,
|
|
8
|
-
// familyName: null,
|
|
9
|
-
// service: { port: 6053, protocol: 'tcp', type: 'esphomelib' },
|
|
10
|
-
// packet: {
|
|
11
|
-
// header: [Object],
|
|
12
|
-
// questions: [],
|
|
13
|
-
// answers: [Array],
|
|
14
|
-
// authorities: [],
|
|
15
|
-
// additionals: [Array],
|
|
16
|
-
// address: '192.168.0.114'
|
|
17
|
-
// }
|
|
18
|
-
// }
|
|
19
|
-
|
|
20
|
-
export async function discovery(name = '_esphomelib._tcp.local', wait = 3): Promise<any> {
|
|
21
|
-
return await new Promise((resolve, reject) => {
|
|
22
|
-
mdns
|
|
23
|
-
.discover({
|
|
24
|
-
name: name,
|
|
25
|
-
wait: wait
|
|
26
|
-
})
|
|
27
|
-
.then((items: Array<object>) => {
|
|
28
|
-
const devices: Array<object> = [];
|
|
29
|
-
|
|
30
|
-
items
|
|
31
|
-
.sort((a: any, b: any) => (a.fqdn > b.fqdn ? 1 : -1))
|
|
32
|
-
.map((device: any) => {
|
|
33
|
-
devices.push({
|
|
34
|
-
host: device.address,
|
|
35
|
-
port: device.service.port,
|
|
36
|
-
fqdn: device.fqdn.replace(/_esphomelib\._tcp./gi, '')
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
resolve(devices);
|
|
41
|
-
})
|
|
42
|
-
.catch((e: Error) => {
|
|
43
|
-
reject(e);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
1
|
export const Status: {[key: string]: any} = {
|
|
49
2
|
error: {
|
|
50
3
|
fill: 'red',
|
package/src/nodes/api.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {NodeAPI} from 'node-red';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
+
const {Discovery} = require('esphome-native-api');
|
|
4
5
|
|
|
5
6
|
module.exports = (RED: NodeAPI) => {
|
|
6
7
|
const NODE_PATH = '/esphome/';
|
|
7
8
|
|
|
8
9
|
RED.httpAdmin.post(NODE_PATH + 'discovery', async (req: express.Request, res: express.Response) => {
|
|
9
|
-
|
|
10
|
+
Discovery()
|
|
10
11
|
.then((devices: Array<object>) => {
|
|
11
12
|
res.json(devices);
|
|
12
13
|
})
|
package/src/nodes/device.ts
CHANGED
|
@@ -57,7 +57,7 @@ module.exports = (RED: NodeAPI) => {
|
|
|
57
57
|
self.error(e.message);
|
|
58
58
|
} else if (e.message.includes('ECONNRESET')) {
|
|
59
59
|
/* empty */
|
|
60
|
-
} else if (e.message.includes('
|
|
60
|
+
} else if (e.message.includes('TIMEOUT')) {
|
|
61
61
|
/* empty */
|
|
62
62
|
} else if (e.message.includes('write after end')) {
|
|
63
63
|
/* empty */
|