node-red-contrib-homebridge-automation 0.2.2-beta.5 → 0.3.0-beta.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/package.json +2 -2
- package/src/hbConfigNode.js +38 -28
- package/src/hbConfigNode.test.js +2205 -2040
- package/test/node-red/flows_cred.json +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-homebridge-automation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-beta.0",
|
|
4
4
|
"description": "NodeRED Automation for HomeBridge",
|
|
5
5
|
"main": "src/HAP-NodeRed.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"watch": "nodemon",
|
|
9
9
|
"lint": "eslint --max-warnings=10 .",
|
|
10
10
|
"lint:fix": "eslint --fix --max-warnings=0 .",
|
|
11
|
-
"test": "jest --detectOpenHandles",
|
|
11
|
+
"test": "jest --forceExit --detectOpenHandles --verbose=true",
|
|
12
12
|
"test-coverage": "jest --coverage"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
package/src/hbConfigNode.js
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
const { HapClient } = require('@homebridge/hap-client');
|
|
2
2
|
const debug = require('debug')('hapNodeRed:hbConfigNode');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
3
5
|
|
|
4
6
|
class HBConfigNode {
|
|
5
7
|
constructor(config, RED) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
|
|
10
|
+
// Initialize properties
|
|
11
|
+
this.username = config.username;
|
|
12
|
+
this.macAddress = config.macAddress || '';
|
|
13
|
+
this.users = {};
|
|
14
|
+
this.homebridge = null;
|
|
15
|
+
this.evDevices = [];
|
|
16
|
+
this.ctDevices = [];
|
|
17
|
+
this.hbDevices = [];
|
|
18
|
+
this.clientNodes = [];
|
|
19
|
+
// this.log = new Log(console, true);
|
|
20
|
+
this.discoveryTimeout = null;
|
|
21
|
+
|
|
22
|
+
// Initialize HAP client
|
|
23
|
+
this.hapClient = new HapClient({
|
|
24
|
+
config: { debug: false },
|
|
25
|
+
pin: config.username
|
|
26
|
+
});
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
this.hapClient.on('instance-discovered', this.waitForNoMoreDiscoveries);
|
|
29
|
+
this.hapClient.on('discovery-ended', this.hapClient.refreshInstances);
|
|
30
|
+
if (this.on)
|
|
29
31
|
this.on('close', this.close.bind(this));
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
+
this.refreshInProcess = true; // Prevents multiple refreshes, hapClient kicks of a discovery on start
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -52,9 +53,18 @@ class HBConfigNode {
|
|
|
52
53
|
*/
|
|
53
54
|
async handleReady() {
|
|
54
55
|
const updatedDevices = await this.hapClient.getAllServices();
|
|
56
|
+
if (this.debug && updatedDevices && updatedDevices.length) {
|
|
57
|
+
try {
|
|
58
|
+
const storagePath = path.join(process.cwd(), '/homebridge-automation-endpoints.json');
|
|
59
|
+
this.warn(`Writing Homebridge endpoints to ${storagePath}`);
|
|
60
|
+
fs.writeFileSync(storagePath, JSON.stringify(updatedDevices, null, 2));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
this.error(`Error writing Homebridge endpoints to file: ${e.message}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
55
65
|
// Fix broken uniqueId's from HAP-Client
|
|
56
66
|
updatedDevices.forEach((service) => {
|
|
57
|
-
const friendlyName = (service.
|
|
67
|
+
const friendlyName = (service.accessoryInformation.Name ? service.accessoryInformation.Name : service.serviceName);
|
|
58
68
|
service.uniqueId = `${service.instance.name}${service.instance.username}${service.accessoryInformation.Manufacturer}${friendlyName}${service.uuid.slice(0, 8)}`;
|
|
59
69
|
});
|
|
60
70
|
updatedDevices.forEach((updatedService, index) => {
|
|
@@ -86,9 +96,9 @@ class HBConfigNode {
|
|
|
86
96
|
return filterUnique(this.hbDevices)
|
|
87
97
|
.filter(service => supportedTypes.has(service.humanType))
|
|
88
98
|
.map(service => ({
|
|
89
|
-
name: (service.
|
|
90
|
-
fullName: `${(service.
|
|
91
|
-
sortName: `${(service.
|
|
99
|
+
name: (service.accessoryInformation.Name ? service.accessoryInformation.Name : service.serviceName),
|
|
100
|
+
fullName: `${(service.accessoryInformation.Name ? service.accessoryInformation.Name : service.serviceName)} - ${service.humanType}`,
|
|
101
|
+
sortName: `${(service.accessoryInformation.Name ? service.accessoryInformation.Name : service.serviceName)}:${service.type}`,
|
|
92
102
|
uniqueId: service.uniqueId,
|
|
93
103
|
homebridge: service.instance.name,
|
|
94
104
|
service: service.type,
|