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.
@@ -1,4 +1,3 @@
1
- export declare function discovery(name?: string, wait?: number): Promise<any>;
2
1
  export declare const Status: {
3
2
  [key: string]: any;
4
3
  };
@@ -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 = exports.discovery = void 0;
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',
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8DAA8D;AAC9D,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAEpC,IAAI;AACJ,8BAA8B;AAC9B,sDAAsD;AACtD,qBAAqB;AACrB,sBAAsB;AACtB,kEAAkE;AAClE,cAAc;AACd,wBAAwB;AACxB,qBAAqB;AACrB,wBAAwB;AACxB,uBAAuB;AACvB,4BAA4B;AAC5B,+BAA+B;AAC/B,MAAM;AACN,IAAI;AAEJ,SAAsB,SAAS,CAAC,IAAI,GAAG,wBAAwB,EAAE,IAAI,GAAG,CAAC;;QACvE,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI;iBACD,QAAQ,CAAC;gBACR,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,IAAI;aACX,CAAC;iBACD,IAAI,CAAC,CAAC,KAAoB,EAAE,EAAE;gBAC7B,MAAM,OAAO,GAAkB,EAAE,CAAC;gBAElC,KAAK;qBACF,IAAI,CAAC,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;qBACpD,GAAG,CAAC,CAAC,MAAW,EAAE,EAAE;oBACnB,OAAO,CAAC,IAAI,CAAC;wBACX,IAAI,EAAE,MAAM,CAAC,OAAO;wBACpB,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI;wBACzB,IAAI,EA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@@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const utils_1 = require("../lib/utils");
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
- (0, utils_1.discovery)()
17
+ Discovery()
17
18
  .then((devices) => {
18
19
  res.json(devices);
19
20
  })
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/nodes/api.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,wCAAuC;AAEvC,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,IAAA,iBAAS,GAAE;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"}
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"}
@@ -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.host}" data-host="${d.host}" data-port="${d.port}" data-fqdn="${d.fqdn}">${d.fqdn}</option>`
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
 
@@ -52,7 +52,7 @@ module.exports = (RED) => {
52
52
  else if (e.message.includes('ECONNRESET')) {
53
53
  /* empty */
54
54
  }
55
- else if (e.message.includes('timeout')) {
55
+ else if (e.message.includes('TIMEOUT')) {
56
56
  /* empty */
57
57
  }
58
58
  else if (e.message.includes('write after end')) {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "node-red-contrib-esphome",
3
- "version": "0.0.2",
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
- "node-dns-sd":"^0.4.2",
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
- import {discovery} from '../lib/utils';
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
- discovery()
10
+ Discovery()
10
11
  .then((devices: Array<object>) => {
11
12
  res.json(devices);
12
13
  })
@@ -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('timeout')) {
60
+ } else if (e.message.includes('TIMEOUT')) {
61
61
  /* empty */
62
62
  } else if (e.message.includes('write after end')) {
63
63
  /* empty */