node-red-contrib-homebridge-automation 0.1.12-beta.16 → 0.1.12-beta.18
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 +47 -22
- package/src/lib/logger.js +31 -0
- package/test/node-red/.flows.json.backup +0 -3
- package/test/node-red/flows.json +12 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-homebridge-automation",
|
|
3
|
-
"version": "0.1.12-beta.
|
|
3
|
+
"version": "0.1.12-beta.18",
|
|
4
4
|
"description": "NodeRED Automation for HomeBridge",
|
|
5
5
|
"main": "src/HAP-NodeRed.js",
|
|
6
6
|
"scripts": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"better-queue": ">=3.8.12",
|
|
50
50
|
"debug": "^4.3.5",
|
|
51
|
-
"hap-
|
|
51
|
+
"@homebridge/hap-client": "2.0.4"
|
|
52
52
|
},
|
|
53
53
|
"author": "NorthernMan54",
|
|
54
54
|
"license": "ISC",
|
package/src/hbConfigNode.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const hbBaseNode = require('./hbBaseNode');
|
|
2
|
-
const HAPNodeJSClient = require('hap-node-client').HAPNodeJSClient;
|
|
2
|
+
// const HAPNodeJSClient = require('hap-node-client').HAPNodeJSClient;
|
|
3
|
+
const { HapClient } = require('@homebridge/hap-client');
|
|
3
4
|
const debug = require('debug')('hapNodeRed:hbConfigNode');
|
|
4
5
|
const { Homebridges } = require('./lib/Homebridges.js');
|
|
6
|
+
const { Log } = require('./lib/logger.js');
|
|
5
7
|
var Queue = require('better-queue');
|
|
6
8
|
|
|
7
9
|
class HBConfigNode {
|
|
@@ -24,6 +26,8 @@ class HBConfigNode {
|
|
|
24
26
|
this.ctDevices = [];
|
|
25
27
|
this.hbDevices = [];
|
|
26
28
|
|
|
29
|
+
this.log = new Log(console, true);
|
|
30
|
+
|
|
27
31
|
this.reqisterQueue = new Queue(function (node, cb) {
|
|
28
32
|
this._register.call(node.that, node, cb);
|
|
29
33
|
}, {
|
|
@@ -34,33 +38,37 @@ class HBConfigNode {
|
|
|
34
38
|
});
|
|
35
39
|
this.reqisterQueue.pause();
|
|
36
40
|
|
|
37
|
-
this.
|
|
41
|
+
this.hapClient = new HapClient({
|
|
42
|
+
config: { debug: false },
|
|
43
|
+
pin: config.username,
|
|
44
|
+
logger: this.log,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
this.waitForNoMoreDiscoveries();
|
|
48
|
+
this.hapClient.on('instance-discovered', () => this.waitForNoMoreDiscoveries);
|
|
38
49
|
}
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (this.
|
|
43
|
-
|
|
44
|
-
// Register additional PIN on existing instance
|
|
45
|
-
this.homebridge.RegisterPin(this.macAddress, config.username);
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
this.homebridge = new HAPNodeJSClient({
|
|
49
|
-
pin: config.username,
|
|
50
|
-
refresh: 900,
|
|
51
|
-
debug: false,
|
|
52
|
-
timeout: 5,
|
|
53
|
-
reqTimeout: 7000,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Handle 'Ready' event
|
|
57
|
-
this.homebridge.on('Ready', this.handleReady.bind(this));
|
|
51
|
+
waitForNoMoreDiscoveries = () => {
|
|
52
|
+
// Clear any existing timeout
|
|
53
|
+
if (this.discoveryTimeout) {
|
|
54
|
+
clearTimeout(this.discoveryTimeout);
|
|
58
55
|
}
|
|
59
|
-
|
|
56
|
+
|
|
57
|
+
// Set up the timeout
|
|
58
|
+
this.discoveryTimeout = setTimeout(() => {
|
|
59
|
+
this.log.debug('No more instances discovered, publishing services');
|
|
60
|
+
this.hapClient.removeListener('instance-discovered', this.waitForNoMoreDiscoveries);
|
|
61
|
+
debug('waitfornomore', this);
|
|
62
|
+
this.handleReady();
|
|
63
|
+
// this.requestSync();
|
|
64
|
+
// this.hapClient.on('instance-discovered', this.requestSync.bind(this)); // Request sync on new instance discovery
|
|
65
|
+
}, 5000);
|
|
66
|
+
};
|
|
60
67
|
|
|
61
68
|
// Handle Homebridge 'Ready' event
|
|
62
69
|
handleReady(accessories) {
|
|
63
|
-
this
|
|
70
|
+
debug('handleReady', this);
|
|
71
|
+
this.hbDevices = this.hapClient.getAllServices(accessories);
|
|
64
72
|
debug('Discovered %s new evDevices', this.hbDevices.toList({ perms: 'ev' }).length);
|
|
65
73
|
|
|
66
74
|
this.evDevices = this.hbDevices.toList({ perms: 'ev' });
|
|
@@ -68,6 +76,23 @@ class HBConfigNode {
|
|
|
68
76
|
this.handleDuplicates(this.evDevices);
|
|
69
77
|
}
|
|
70
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Start processing
|
|
81
|
+
*/
|
|
82
|
+
async start() {
|
|
83
|
+
this.services = await this.loadAccessories();
|
|
84
|
+
this.log.info(`Discovered ${this.services.length} accessories`);
|
|
85
|
+
this.ready = true;
|
|
86
|
+
await this.buildSyncResponse();
|
|
87
|
+
const evServices = this.services.filter(x => this.evTypes.some(uuid => x.serviceCharacteristics.find(c => c.uuid === uuid)));
|
|
88
|
+
this.log.debug(`Monitoring ${evServices.length} services for changes`);
|
|
89
|
+
|
|
90
|
+
const monitor = await this.hapClient.monitorCharacteristics(evServices);
|
|
91
|
+
monitor.on('service-update', (services) => {
|
|
92
|
+
this.reportStateSubject.next(services[0].uniqueId);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
71
96
|
// Handle duplicate devices
|
|
72
97
|
handleDuplicates(list) {
|
|
73
98
|
const seenFullNames = new Set();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class Log {
|
|
2
|
+
|
|
3
|
+
constructor(logger, debugMode) {
|
|
4
|
+
this.logger = logger;
|
|
5
|
+
this.debugMode = debugMode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
debug(msg) {
|
|
9
|
+
if (this.debugMode) {
|
|
10
|
+
this.logger.info(msg);
|
|
11
|
+
} else {
|
|
12
|
+
this.logger.debug(msg);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
info(msg) {
|
|
17
|
+
this.logger.info(msg);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
warn(msg) {
|
|
21
|
+
this.logger.warn(msg);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
error(msg) {
|
|
25
|
+
this.logger.error(msg);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
log(msg) {
|
|
29
|
+
this.logger.info(msg);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -81,7 +81,6 @@
|
|
|
81
81
|
"id": "3d7babac3a298e60",
|
|
82
82
|
"type": "hb-status",
|
|
83
83
|
"z": "caef1e7b5b399e80",
|
|
84
|
-
"d": true,
|
|
85
84
|
"name": "West Bedroom",
|
|
86
85
|
"Homebridge": "homebridge",
|
|
87
86
|
"Manufacturer": "Tasmota",
|
|
@@ -119,7 +118,6 @@
|
|
|
119
118
|
"id": "bb88544904b343a1",
|
|
120
119
|
"type": "hb-event",
|
|
121
120
|
"z": "caef1e7b5b399e80",
|
|
122
|
-
"d": true,
|
|
123
121
|
"name": "West Bedroom",
|
|
124
122
|
"Homebridge": "homebridge",
|
|
125
123
|
"Manufacturer": "Tasmota",
|
|
@@ -172,7 +170,6 @@
|
|
|
172
170
|
"id": "0ed3cd7e0d60beda",
|
|
173
171
|
"type": "hb-control",
|
|
174
172
|
"z": "caef1e7b5b399e80",
|
|
175
|
-
"d": true,
|
|
176
173
|
"name": "West Bedroom",
|
|
177
174
|
"Homebridge": "homebridge",
|
|
178
175
|
"Manufacturer": "Tasmota",
|
package/test/node-red/flows.json
CHANGED
|
@@ -81,13 +81,14 @@
|
|
|
81
81
|
"id": "3d7babac3a298e60",
|
|
82
82
|
"type": "hb-status",
|
|
83
83
|
"z": "caef1e7b5b399e80",
|
|
84
|
-
"
|
|
84
|
+
"d": true,
|
|
85
|
+
"name": "",
|
|
85
86
|
"Homebridge": "homebridge",
|
|
86
87
|
"Manufacturer": "Tasmota",
|
|
87
88
|
"Service": "Lightbulb",
|
|
88
89
|
"device": "homebridge1C:22:3D:E3:CF:34TasmotaWest Bedroom00000043",
|
|
89
90
|
"conf": "557aec8e8c47e61e",
|
|
90
|
-
"x":
|
|
91
|
+
"x": 520,
|
|
91
92
|
"y": 140,
|
|
92
93
|
"wires": [
|
|
93
94
|
[
|
|
@@ -118,14 +119,15 @@
|
|
|
118
119
|
"id": "bb88544904b343a1",
|
|
119
120
|
"type": "hb-event",
|
|
120
121
|
"z": "caef1e7b5b399e80",
|
|
121
|
-
"
|
|
122
|
+
"d": true,
|
|
123
|
+
"name": "",
|
|
122
124
|
"Homebridge": "homebridge",
|
|
123
125
|
"Manufacturer": "Tasmota",
|
|
124
126
|
"Service": "Lightbulb",
|
|
125
127
|
"device": "homebridge1C:22:3D:E3:CF:34TasmotaWest Bedroom00000043",
|
|
126
128
|
"conf": "557aec8e8c47e61e",
|
|
127
129
|
"sendInitialState": false,
|
|
128
|
-
"x":
|
|
130
|
+
"x": 250,
|
|
129
131
|
"y": 380,
|
|
130
132
|
"wires": [
|
|
131
133
|
[]
|
|
@@ -135,13 +137,14 @@
|
|
|
135
137
|
"id": "452e3e6171aa7a25",
|
|
136
138
|
"type": "hb-resume",
|
|
137
139
|
"z": "caef1e7b5b399e80",
|
|
138
|
-
"
|
|
140
|
+
"d": true,
|
|
141
|
+
"name": "",
|
|
139
142
|
"Homebridge": "homebridge",
|
|
140
143
|
"Manufacturer": "Tasmota",
|
|
141
144
|
"Service": "Lightbulb",
|
|
142
145
|
"device": "homebridge1C:22:3D:E3:CF:34TasmotaWest Bedroom00000043",
|
|
143
146
|
"conf": "557aec8e8c47e61e",
|
|
144
|
-
"x":
|
|
147
|
+
"x": 520,
|
|
145
148
|
"y": 460,
|
|
146
149
|
"wires": [
|
|
147
150
|
[
|
|
@@ -170,14 +173,15 @@
|
|
|
170
173
|
"id": "0ed3cd7e0d60beda",
|
|
171
174
|
"type": "hb-control",
|
|
172
175
|
"z": "caef1e7b5b399e80",
|
|
173
|
-
"
|
|
176
|
+
"d": true,
|
|
177
|
+
"name": "",
|
|
174
178
|
"Homebridge": "homebridge",
|
|
175
179
|
"Manufacturer": "Tasmota",
|
|
176
180
|
"Service": "Lightbulb",
|
|
177
181
|
"device": "homebridge1C:22:3D:E3:CF:34TasmotaWest Bedroom00000043",
|
|
178
182
|
"conf": "557aec8e8c47e61e",
|
|
179
183
|
"outputs": 0,
|
|
180
|
-
"x":
|
|
184
|
+
"x": 540,
|
|
181
185
|
"y": 600,
|
|
182
186
|
"wires": []
|
|
183
187
|
},
|