node-red-contrib-homebridge-automation 0.1.12-beta.14 → 0.1.12-beta.16
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/HAP-NodeRed.html +67 -67
- package/src/HAP-NodeRed.js +30 -36
- package/src/HapDeviceRoutes.js +32 -16
- package/src/hbBaseNode.js +30 -25
- package/src/hbConfigNode.js +29 -18
- package/src/hbControlNode.js +4 -5
- package/src/hbDevices.js +10 -0
- package/src/hbEventNode.js +6 -18
- package/src/hbResumeNode.js +7 -9
- package/src/hbStatusNode.js +6 -8
- package/test/node-red/.config.nodes.json.backup +24 -0
- package/test/node-red/.flows.json.backup +158 -29
- package/test/node-red/flows.json +155 -29
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.16",
|
|
4
4
|
"description": "NodeRED Automation for HomeBridge",
|
|
5
5
|
"main": "src/HAP-NodeRed.js",
|
|
6
6
|
"scripts": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
],
|
|
63
63
|
"ext": "js,html",
|
|
64
64
|
"ignore": [],
|
|
65
|
-
"exec": "DEBUG=hapNodeRed ~/npm/bin/node-red -u test/node-red",
|
|
65
|
+
"exec": "DEBUG=hapNodeRed* ~/npm/bin/node-red -u test/node-red",
|
|
66
66
|
"signal": "SIGTERM",
|
|
67
67
|
"env": {
|
|
68
68
|
"NODE_OPTIONS": "--trace-warnings"
|
package/src/HAP-NodeRed.html
CHANGED
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
// var pass = $('#node-config-input-password').val();
|
|
53
53
|
// console.log("pass: ", pass);
|
|
54
54
|
// if (pass != '_PWD_') {
|
|
55
|
-
// var
|
|
55
|
+
// var configNode = {
|
|
56
56
|
// id: node.id,
|
|
57
57
|
// user: user,
|
|
58
58
|
// pass: pass
|
|
59
59
|
// }
|
|
60
60
|
// $.ajax({
|
|
61
|
-
// data: JSON.stringify(
|
|
62
|
-
// url: 'alexa-home/new-
|
|
61
|
+
// data: JSON.stringify(configNode),
|
|
62
|
+
// url: 'alexa-home/new-configNode',
|
|
63
63
|
// contentType: 'application/json',
|
|
64
64
|
// type: 'POST',
|
|
65
65
|
// processData: false
|
|
@@ -167,14 +167,14 @@
|
|
|
167
167
|
oneditprepare: function() {
|
|
168
168
|
var node = this;
|
|
169
169
|
// console.log("foo " + node.device);
|
|
170
|
-
if (typeof node.
|
|
171
|
-
$('#node-input-
|
|
170
|
+
if (typeof node.acknowledge === 'undefined') {
|
|
171
|
+
$('#node-input-acknowledge').prop('checked', true);
|
|
172
172
|
}
|
|
173
173
|
$('#node-input-device').change(function() {
|
|
174
174
|
$('#node-input-name').val($('#node-input-device option:selected').text());
|
|
175
175
|
});
|
|
176
|
-
var getDevs = function(
|
|
177
|
-
$.getJSON('hap-device/evDevices/' +
|
|
176
|
+
var getDevs = function(configNode) {
|
|
177
|
+
$.getJSON('hap-device/evDevices/' + configNode, function(data) {
|
|
178
178
|
$('#node-input-device').find('option').remove().end();
|
|
179
179
|
for (d in data) {
|
|
180
180
|
$('<option/>', {
|
|
@@ -196,32 +196,32 @@
|
|
|
196
196
|
|
|
197
197
|
}
|
|
198
198
|
if (node.conf) {
|
|
199
|
-
var
|
|
200
|
-
// console.log("
|
|
201
|
-
if (
|
|
202
|
-
getDevs(
|
|
199
|
+
var configNode = $('#node-input-conf').val();
|
|
200
|
+
// console.log("configNode: ", configNode);
|
|
201
|
+
if (configNode != '_ADD_') {
|
|
202
|
+
getDevs(configNode);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
$('#node-input-conf').change(function() {
|
|
206
|
-
var
|
|
207
|
-
// console.log("
|
|
208
|
-
if (
|
|
209
|
-
getDevs(
|
|
206
|
+
var configNode = $('#node-input-conf').val();
|
|
207
|
+
// console.log("configNode changed: ", configNode);
|
|
208
|
+
if (configNode != '_ADD_') {
|
|
209
|
+
getDevs(configNode);
|
|
210
210
|
} else {
|
|
211
|
-
// console.log("new
|
|
211
|
+
// console.log("new configNode");
|
|
212
212
|
$('#node-input-device').find('option').remove().end();
|
|
213
213
|
$('#node-input-device').val("");
|
|
214
214
|
}
|
|
215
215
|
});
|
|
216
216
|
$('#node-input-device-refresh').click(function() {
|
|
217
217
|
$('#node-input-device-refresh').addClass('disabled');
|
|
218
|
-
var
|
|
218
|
+
var configNode = $('#node-input-conf').val();
|
|
219
219
|
$.ajax({
|
|
220
|
-
url: 'hap-device/refresh/' +
|
|
220
|
+
url: 'hap-device/refresh/' + configNode,
|
|
221
221
|
type: 'POST'
|
|
222
222
|
}).done(function(data) {
|
|
223
223
|
setTimeout(function() {
|
|
224
|
-
getDevs(
|
|
224
|
+
getDevs(configNode);
|
|
225
225
|
$('#node-input-device-refresh').removeClass('disabled');
|
|
226
226
|
}, 3000);
|
|
227
227
|
});
|
|
@@ -317,15 +317,15 @@
|
|
|
317
317
|
oneditprepare: function() {
|
|
318
318
|
var node = this;
|
|
319
319
|
// console.log("foo " + node.device);
|
|
320
|
-
if (typeof node.
|
|
320
|
+
if (typeof node.acknowledge === 'undefined') {
|
|
321
321
|
// console.log("ben");
|
|
322
|
-
$('#node-input-
|
|
322
|
+
$('#node-input-acknowledge').prop('checked', true);
|
|
323
323
|
}
|
|
324
324
|
$('#node-input-device').change(function() {
|
|
325
325
|
$('#node-input-name').val($('#node-input-device option:selected').text());
|
|
326
326
|
});
|
|
327
|
-
var getDevs = function(
|
|
328
|
-
$.getJSON('hap-device/evDevices/' +
|
|
327
|
+
var getDevs = function(configNode) {
|
|
328
|
+
$.getJSON('hap-device/evDevices/' + configNode, function(data) {
|
|
329
329
|
$('#node-input-device').find('option').remove().end();
|
|
330
330
|
for (d in data) {
|
|
331
331
|
$('<option/>', {
|
|
@@ -348,32 +348,32 @@
|
|
|
348
348
|
|
|
349
349
|
}
|
|
350
350
|
if (node.conf) {
|
|
351
|
-
var
|
|
352
|
-
// console.log("
|
|
353
|
-
if (
|
|
354
|
-
getDevs(
|
|
351
|
+
var configNode = $('#node-input-conf').val();
|
|
352
|
+
// console.log("configNode: ", configNode);
|
|
353
|
+
if (configNode != '_ADD_') {
|
|
354
|
+
getDevs(configNode);
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
$('#node-input-conf').change(function() {
|
|
358
|
-
var
|
|
359
|
-
// console.log("
|
|
360
|
-
if (
|
|
361
|
-
getDevs(
|
|
358
|
+
var configNode = $('#node-input-conf').val();
|
|
359
|
+
// console.log("configNode changed: ", configNode);
|
|
360
|
+
if (configNode != '_ADD_') {
|
|
361
|
+
getDevs(configNode);
|
|
362
362
|
} else {
|
|
363
|
-
// console.log("new
|
|
363
|
+
// console.log("new configNode");
|
|
364
364
|
$('#node-input-device').find('option').remove().end();
|
|
365
365
|
$('#node-input-device').val("");
|
|
366
366
|
}
|
|
367
367
|
});
|
|
368
368
|
$('#node-input-device-refresh').click(function() {
|
|
369
369
|
$('#node-input-device-refresh').addClass('disabled');
|
|
370
|
-
var
|
|
370
|
+
var configNode = $('#node-input-conf').val();
|
|
371
371
|
$.ajax({
|
|
372
|
-
url: 'hap-device/refresh/' +
|
|
372
|
+
url: 'hap-device/refresh/' + configNode,
|
|
373
373
|
type: 'POST'
|
|
374
374
|
}).done(function(data) {
|
|
375
375
|
setTimeout(function() {
|
|
376
|
-
getDevs(
|
|
376
|
+
getDevs(configNode);
|
|
377
377
|
$('#node-input-device-refresh').removeClass('disabled');
|
|
378
378
|
}, 3000);
|
|
379
379
|
});
|
|
@@ -467,15 +467,15 @@
|
|
|
467
467
|
oneditprepare: function() {
|
|
468
468
|
var node = this;
|
|
469
469
|
// console.log("foo " + node.device);
|
|
470
|
-
if (typeof node.
|
|
470
|
+
if (typeof node.acknowledge === 'undefined') {
|
|
471
471
|
// console.log("ben");
|
|
472
|
-
$('#node-input-
|
|
472
|
+
$('#node-input-acknowledge').prop('checked', true);
|
|
473
473
|
}
|
|
474
474
|
$('#node-input-device').change(function() {
|
|
475
475
|
$('#node-input-name').val($('#node-input-device option:selected').text());
|
|
476
476
|
});
|
|
477
|
-
var getDevs = function(
|
|
478
|
-
$.getJSON('hap-device/evDevices/' +
|
|
477
|
+
var getDevs = function(configNode) {
|
|
478
|
+
$.getJSON('hap-device/evDevices/' + configNode, function(data) {
|
|
479
479
|
$('#node-input-device').find('option').remove().end();
|
|
480
480
|
for (d in data) {
|
|
481
481
|
$('<option/>', {
|
|
@@ -498,32 +498,32 @@
|
|
|
498
498
|
|
|
499
499
|
}
|
|
500
500
|
if (node.conf) {
|
|
501
|
-
var
|
|
502
|
-
// console.log("
|
|
503
|
-
if (
|
|
504
|
-
getDevs(
|
|
501
|
+
var configNode = $('#node-input-conf').val();
|
|
502
|
+
// console.log("configNode: ", configNode);
|
|
503
|
+
if (configNode != '_ADD_') {
|
|
504
|
+
getDevs(configNode);
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
507
|
$('#node-input-conf').change(function() {
|
|
508
|
-
var
|
|
509
|
-
// console.log("
|
|
510
|
-
if (
|
|
511
|
-
getDevs(
|
|
508
|
+
var configNode = $('#node-input-conf').val();
|
|
509
|
+
// console.log("configNode changed: ", configNode);
|
|
510
|
+
if (configNode != '_ADD_') {
|
|
511
|
+
getDevs(configNode);
|
|
512
512
|
} else {
|
|
513
|
-
// console.log("new
|
|
513
|
+
// console.log("new configNode");
|
|
514
514
|
$('#node-input-device').find('option').remove().end();
|
|
515
515
|
$('#node-input-device').val("");
|
|
516
516
|
}
|
|
517
517
|
});
|
|
518
518
|
$('#node-input-device-refresh').click(function() {
|
|
519
519
|
$('#node-input-device-refresh').addClass('disabled');
|
|
520
|
-
var
|
|
520
|
+
var configNode = $('#node-input-conf').val();
|
|
521
521
|
$.ajax({
|
|
522
|
-
url: 'hap-device/refresh/' +
|
|
522
|
+
url: 'hap-device/refresh/' + configNode,
|
|
523
523
|
type: 'POST'
|
|
524
524
|
}).done(function(data) {
|
|
525
525
|
setTimeout(function() {
|
|
526
|
-
getDevs(
|
|
526
|
+
getDevs(configNode);
|
|
527
527
|
$('#node-input-device-refresh').removeClass('disabled');
|
|
528
528
|
}, 3000);
|
|
529
529
|
});
|
|
@@ -620,15 +620,15 @@
|
|
|
620
620
|
oneditprepare: function() {
|
|
621
621
|
var node = this;
|
|
622
622
|
// console.log("foo " + node.device);
|
|
623
|
-
if (typeof node.
|
|
623
|
+
if (typeof node.acknowledge === 'undefined') {
|
|
624
624
|
// console.log("ben");
|
|
625
|
-
$('#node-input-
|
|
625
|
+
$('#node-input-acknowledge').prop('checked', true);
|
|
626
626
|
}
|
|
627
627
|
$('#node-input-device').change(function() {
|
|
628
628
|
$('#node-input-name').val($('#node-input-device option:selected').text());
|
|
629
629
|
});
|
|
630
|
-
var getDevs = function(
|
|
631
|
-
$.getJSON('hap-device/ctDevices/' +
|
|
630
|
+
var getDevs = function(configNode) {
|
|
631
|
+
$.getJSON('hap-device/ctDevices/' + configNode, function(data) {
|
|
632
632
|
$('#node-input-device').find('option').remove().end();
|
|
633
633
|
for (d in data) {
|
|
634
634
|
$('<option/>', {
|
|
@@ -651,32 +651,32 @@
|
|
|
651
651
|
|
|
652
652
|
}
|
|
653
653
|
if (node.conf) {
|
|
654
|
-
var
|
|
655
|
-
// console.log("
|
|
656
|
-
if (
|
|
657
|
-
getDevs(
|
|
654
|
+
var configNode = $('#node-input-conf').val();
|
|
655
|
+
// console.log("configNode: ", configNode);
|
|
656
|
+
if (configNode != '_ADD_') {
|
|
657
|
+
getDevs(configNode);
|
|
658
658
|
}
|
|
659
659
|
}
|
|
660
660
|
$('#node-input-conf').change(function() {
|
|
661
|
-
var
|
|
662
|
-
// console.log("
|
|
663
|
-
if (
|
|
664
|
-
getDevs(
|
|
661
|
+
var configNode = $('#node-input-conf').val();
|
|
662
|
+
// console.log("configNode changed: ", configNode);
|
|
663
|
+
if (configNode != '_ADD_') {
|
|
664
|
+
getDevs(configNode);
|
|
665
665
|
} else {
|
|
666
|
-
// console.log("new
|
|
666
|
+
// console.log("new configNode");
|
|
667
667
|
$('#node-input-device').find('option').remove().end();
|
|
668
668
|
$('#node-input-device').val("");
|
|
669
669
|
}
|
|
670
670
|
});
|
|
671
671
|
$('#node-input-device-refresh').click(function() {
|
|
672
672
|
$('#node-input-device-refresh').addClass('disabled');
|
|
673
|
-
var
|
|
673
|
+
var configNode = $('#node-input-conf').val();
|
|
674
674
|
$.ajax({
|
|
675
|
-
url: 'hap-device/refresh/' +
|
|
675
|
+
url: 'hap-device/refresh/' + configNode,
|
|
676
676
|
type: 'POST'
|
|
677
677
|
}).done(function(data) {
|
|
678
678
|
setTimeout(function() {
|
|
679
|
-
getDevs(
|
|
679
|
+
getDevs(configNode);
|
|
680
680
|
$('#node-input-device-refresh').removeClass('disabled');
|
|
681
681
|
}, 3000);
|
|
682
682
|
});
|
package/src/HAP-NodeRed.js
CHANGED
|
@@ -2,7 +2,7 @@ var debug = require('debug')('hapNodeRed');
|
|
|
2
2
|
|
|
3
3
|
// var register = require('./lib/register.js');
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const HBConfigNode = require('./hbConfigNode');
|
|
6
6
|
const HbEventNode = require('./hbEventNode'); // Import the class
|
|
7
7
|
const HbResumeNode = require('./hbResumeNode'); // Import the class
|
|
8
8
|
const HbControlNode = require('./hbControlNode');
|
|
@@ -23,20 +23,15 @@ module.exports = function (RED) {
|
|
|
23
23
|
* @return {type} description
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.hbConf = new HBConfNode(n, RED); // Initialize the class instance
|
|
33
|
-
|
|
34
|
-
this.on('close', function () {
|
|
35
|
-
this.hbConf.close(); // Close any open connections
|
|
36
|
-
});
|
|
26
|
+
class hbConfigNode extends HBConfigNode {
|
|
27
|
+
constructor(config) {
|
|
28
|
+
debug('hbConfigNode', config);
|
|
29
|
+
super(config, RED);
|
|
30
|
+
}
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
|
|
33
|
+
// console.log('Registering node types', "hb-conf", hbConfigNode);
|
|
34
|
+
RED.nodes.registerType("hb-conf", hbConfigNode, {
|
|
40
35
|
credentials: {
|
|
41
36
|
password: {
|
|
42
37
|
type: "password"
|
|
@@ -44,15 +39,16 @@ module.exports = function (RED) {
|
|
|
44
39
|
}
|
|
45
40
|
});
|
|
46
41
|
|
|
42
|
+
|
|
47
43
|
/**
|
|
48
44
|
* hbEventNode - description
|
|
49
45
|
* @param {*} n
|
|
50
46
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
class hbEventNode extends HbEventNode {
|
|
48
|
+
constructor(config) {
|
|
49
|
+
debug('hbEventNode', config);
|
|
50
|
+
super(config, RED);
|
|
51
|
+
}
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
RED.nodes.registerType("hb-event", hbEventNode);
|
|
@@ -60,20 +56,20 @@ module.exports = function (RED) {
|
|
|
60
56
|
/**
|
|
61
57
|
* hbResumeNode - description
|
|
62
58
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
class hbResumeNode extends HbResumeNode {
|
|
60
|
+
constructor(config) {
|
|
61
|
+
debug('hbResumeNode', config);
|
|
62
|
+
super(config, RED);
|
|
63
|
+
}
|
|
68
64
|
}
|
|
69
65
|
|
|
70
66
|
RED.nodes.registerType("hb-resume", hbResumeNode);
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
class hbControlNode extends HbControlNode {
|
|
69
|
+
constructor(config) {
|
|
70
|
+
debug('hbControlNode', config);
|
|
71
|
+
super(config, RED);
|
|
72
|
+
}
|
|
77
73
|
}
|
|
78
74
|
|
|
79
75
|
RED.nodes.registerType("hb-control", hbControlNode);
|
|
@@ -84,18 +80,16 @@ module.exports = function (RED) {
|
|
|
84
80
|
* @param {type} n description
|
|
85
81
|
* @return {type} description
|
|
86
82
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Create instance of HbEventNode class to handle events
|
|
93
|
-
new HbStatusNode(this, n); // Pass current node and config object
|
|
83
|
+
class hbStatusNode extends HbStatusNode {
|
|
84
|
+
constructor(config) {
|
|
85
|
+
debug('hbStatusNode', config);
|
|
86
|
+
super(config, RED);
|
|
87
|
+
}
|
|
94
88
|
}
|
|
95
89
|
|
|
96
90
|
RED.nodes.registerType("hb-status", hbStatusNode);
|
|
97
91
|
|
|
98
|
-
const hapDeviceRoutes = new HapDeviceRoutes(RED, hbDevices
|
|
92
|
+
const hapDeviceRoutes = new HapDeviceRoutes(RED, hbDevices);
|
|
99
93
|
hapDeviceRoutes.registerRoutes();
|
|
100
94
|
|
|
101
95
|
};
|
package/src/HapDeviceRoutes.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// HapDeviceRoutes.js
|
|
2
|
+
const debug = require('debug')('hapNodeRed:HapDeviceRoutes');
|
|
2
3
|
|
|
3
4
|
class HapDeviceRoutes {
|
|
4
|
-
constructor(RED
|
|
5
|
+
constructor(RED) {
|
|
5
6
|
this.RED = RED;
|
|
6
|
-
this.hbDevices =
|
|
7
|
-
this.debug = debug;
|
|
7
|
+
this.hbDevices = false; // remove this line
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
// POST /hap-device/refresh/:id
|
|
@@ -14,14 +14,14 @@ class HapDeviceRoutes {
|
|
|
14
14
|
if (conf) {
|
|
15
15
|
res.status(200).send();
|
|
16
16
|
} else {
|
|
17
|
-
|
|
17
|
+
debug("Can't refresh until deployed");
|
|
18
18
|
res.status(404).send();
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// GET /hap-device/evDevices/
|
|
23
23
|
getEvDevices(req, res) {
|
|
24
|
-
|
|
24
|
+
debug("evDevices", this.hbDevices.toList({ perms: 'ev' }).length);
|
|
25
25
|
if (this.hbDevices) {
|
|
26
26
|
res.send(this.hbDevices.toList({ perms: 'ev' }));
|
|
27
27
|
} else {
|
|
@@ -31,9 +31,12 @@ class HapDeviceRoutes {
|
|
|
31
31
|
|
|
32
32
|
// GET /hap-device/evDevices/:id
|
|
33
33
|
getEvDeviceById(req, res) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
debug('req', req.params.id);
|
|
35
|
+
var evDevices = this.RED.nodes.getNode(req.params.id).evDevices;
|
|
36
|
+
debug('hbDevices', evDevices);
|
|
37
|
+
debug("evDevices", evDevices.length);
|
|
38
|
+
if (evDevices) {
|
|
39
|
+
res.send(evDevices);
|
|
37
40
|
} else {
|
|
38
41
|
res.status(404).send();
|
|
39
42
|
}
|
|
@@ -46,14 +49,14 @@ class HapDeviceRoutes {
|
|
|
46
49
|
if (conf) {
|
|
47
50
|
res.status(200).send();
|
|
48
51
|
} else {
|
|
49
|
-
|
|
52
|
+
debug("Can't refresh until deployed");
|
|
50
53
|
res.status(404).send();
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
// GET /hap-device/evDevices/ for hb-resume
|
|
55
58
|
getEvDevicesForResume(req, res) {
|
|
56
|
-
|
|
59
|
+
debug("evDevices", this.hbDevices.toList({ perms: 'ev' }).length);
|
|
57
60
|
if (this.hbDevices) {
|
|
58
61
|
res.send(this.hbDevices.toList({ perms: 'ev' }));
|
|
59
62
|
} else {
|
|
@@ -63,7 +66,7 @@ class HapDeviceRoutes {
|
|
|
63
66
|
|
|
64
67
|
// GET /hap-device/evDevices/:id for hb-resume
|
|
65
68
|
getEvDeviceByIdForResume(req, res) {
|
|
66
|
-
|
|
69
|
+
debug("evDevices", this.hbDevices.toList({ perms: 'ev' }).length);
|
|
67
70
|
if (this.hbDevices) {
|
|
68
71
|
res.send(this.hbDevices.toList({ perms: 'ev' }));
|
|
69
72
|
} else {
|
|
@@ -73,7 +76,7 @@ class HapDeviceRoutes {
|
|
|
73
76
|
|
|
74
77
|
// GET /hap-device/ctDevices/
|
|
75
78
|
getCtDevices(req, res) {
|
|
76
|
-
|
|
79
|
+
debug("ctDevices", this.hbDevices.toList({ perms: 'pw' }).length);
|
|
77
80
|
if (this.hbDevices) {
|
|
78
81
|
res.send(this.hbDevices.toList({ perms: 'pw' }));
|
|
79
82
|
} else {
|
|
@@ -81,16 +84,29 @@ class HapDeviceRoutes {
|
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
|
|
84
|
-
// GET /hap-device/
|
|
87
|
+
// GET /hap-device/evDevices/:id
|
|
85
88
|
getCtDeviceById(req, res) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
debug('getCtDeviceById', req.params.id);
|
|
90
|
+
const ctDevices = this.RED.nodes.getNode(req.params.id).ctDevices;
|
|
91
|
+
debug('ctDevices', ctDevices);
|
|
92
|
+
debug("ctDevices", ctDevices.length);
|
|
93
|
+
if (ctDevices) {
|
|
94
|
+
res.send(ctDevices);
|
|
89
95
|
} else {
|
|
90
96
|
res.status(404).send();
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
|
|
100
|
+
// GET /hap-device/ctDevices/:id
|
|
101
|
+
// getCtDeviceById(req, res) {
|
|
102
|
+
// debug("ctDevices", this.hbDevices.toList({ perms: 'pw' }).length);
|
|
103
|
+
// if (this.hbDevices) {
|
|
104
|
+
// res.send(this.hbDevices.toList({ perms: 'pw' }));
|
|
105
|
+
// } else {
|
|
106
|
+
// res.status(404).send();
|
|
107
|
+
// }
|
|
108
|
+
// }
|
|
109
|
+
|
|
94
110
|
// Register all routes
|
|
95
111
|
registerRoutes() {
|
|
96
112
|
this.RED.httpAdmin.post('/hap-device/refresh/:id', this.RED.auth.needsPermission('hb-event.read'), this.refreshDevice.bind(this));
|
package/src/hbBaseNode.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
const debug = require('debug')('hapNodeRed:hbBaseNode');
|
|
2
2
|
|
|
3
3
|
class HbBaseNode {
|
|
4
|
-
constructor(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
constructor(config, RED) {
|
|
5
|
+
debug("HbBaseNode - constructor", config);
|
|
6
|
+
// RED.nodes.createNode(this, config);
|
|
7
|
+
RED.nodes.createNode(this, config);
|
|
8
|
+
this.hbConfigNode = RED.nodes.getNode(config.conf); // The configuration node
|
|
9
|
+
// console.log("HbBaseNode - conf", this.conf);
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.confId = config.conf;
|
|
12
|
+
this.device = config.device;
|
|
13
|
+
this.service = config.Service;
|
|
14
|
+
this.name = config.name;
|
|
15
|
+
this.fullName = `${config.name} - ${config.Service}`;
|
|
16
|
+
|
|
17
|
+
this.node = this;
|
|
18
|
+
|
|
19
|
+
this.on('input', this.handleInput.bind(this));
|
|
20
20
|
this.on('close', this.handleClose.bind(this));
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -117,10 +117,11 @@ class HbBaseNode {
|
|
|
117
117
|
* @returns
|
|
118
118
|
*/
|
|
119
119
|
async _status(nrDevice, node, perms) {
|
|
120
|
+
debug("_status", nrDevice);
|
|
120
121
|
let error;
|
|
121
122
|
try {
|
|
122
|
-
if (!hbDevices) {
|
|
123
|
-
throw new Error('hbDevices not initialized');
|
|
123
|
+
if (!this.hbDevices) {
|
|
124
|
+
throw new Error('_status hbDevices not initialized');
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
const device = hbDevices.findDevice(node.device, perms);
|
|
@@ -187,13 +188,14 @@ class HbBaseNode {
|
|
|
187
188
|
throw new Error(error);
|
|
188
189
|
}
|
|
189
190
|
} catch (err) {
|
|
191
|
+
debug("Error in _status:", err);
|
|
190
192
|
error = "Homebridge not initialized -2";
|
|
191
193
|
node.status({
|
|
192
194
|
text: error,
|
|
193
195
|
shape: 'ring',
|
|
194
196
|
fill: 'red'
|
|
195
197
|
});
|
|
196
|
-
throw new Error(error);
|
|
198
|
+
// throw new Error(error);
|
|
197
199
|
}
|
|
198
200
|
}
|
|
199
201
|
|
|
@@ -204,8 +206,9 @@ class HbBaseNode {
|
|
|
204
206
|
* @returns
|
|
205
207
|
*/
|
|
206
208
|
async _control(node, payload) {
|
|
209
|
+
debug("_control", node, payload);
|
|
207
210
|
try {
|
|
208
|
-
if (!hbDevices) {
|
|
211
|
+
if (!this.hbDevices) {
|
|
209
212
|
throw new Error('hbDevices not initialized');
|
|
210
213
|
}
|
|
211
214
|
|
|
@@ -292,30 +295,32 @@ class HbBaseNode {
|
|
|
292
295
|
throw new Error('Device not available');
|
|
293
296
|
}
|
|
294
297
|
} catch (err) {
|
|
298
|
+
debug("Error in _control:", err);
|
|
295
299
|
let error = err.message || "Homebridge not initialized - 3";
|
|
296
300
|
node.status({
|
|
297
301
|
text: error,
|
|
298
302
|
shape: 'ring',
|
|
299
303
|
fill: 'red'
|
|
300
304
|
});
|
|
301
|
-
throw new Error(error);
|
|
305
|
+
// throw new Error(error);
|
|
302
306
|
}
|
|
303
307
|
}
|
|
304
308
|
|
|
305
309
|
async _register(node) {
|
|
310
|
+
debug("_register", node.device);
|
|
306
311
|
try {
|
|
307
312
|
debug("_register", node.device);
|
|
308
313
|
const device = hbDevices.findDevice(node.device, { perms: 'ev' });
|
|
309
|
-
|
|
314
|
+
|
|
310
315
|
if (node.type === 'hb-event' || node.type === 'hb-resume') {
|
|
311
316
|
const message = {
|
|
312
317
|
"characteristics": device.eventRegisters
|
|
313
318
|
};
|
|
314
319
|
debug("_register", node.fullName, device.id, message);
|
|
315
|
-
|
|
320
|
+
|
|
316
321
|
// Use the shared async function here
|
|
317
322
|
const status = await hapEventByDeviceIDAsync(device.id, JSON.stringify(message));
|
|
318
|
-
|
|
323
|
+
|
|
319
324
|
// Check the result of the operation
|
|
320
325
|
if (status === null) {
|
|
321
326
|
debug("%s registered: %s -> %s", node.type, node.fullName, device.id);
|
|
@@ -334,7 +339,7 @@ class HbBaseNode {
|
|
|
334
339
|
});
|
|
335
340
|
}
|
|
336
341
|
}
|
|
337
|
-
|
|
342
|
+
|
|
338
343
|
_getObjectDiff(obj1, obj2) {
|
|
339
344
|
const diff = Object.keys(obj1).reduce((result, key) => {
|
|
340
345
|
if (!obj2.hasOwnProperty(key)) {
|