node-red-contrib-homebridge-automation 0.1.12-beta.23 → 0.1.12-beta.24
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 +1 -1
- package/src/hbBaseNode.js +8 -6
- package/src/hbConfigNode.js +16 -51
- package/src/hbStatusNode.js +2 -2
package/package.json
CHANGED
package/src/hbBaseNode.js
CHANGED
|
@@ -24,16 +24,18 @@ class HbBaseNode {
|
|
|
24
24
|
this.on('input', this.handleInput.bind(this));
|
|
25
25
|
}
|
|
26
26
|
this.on('close', this.handleClose.bind(this));
|
|
27
|
-
this.
|
|
28
|
-
this.on('topic', this.handleHBTopicMessage.bind(this));
|
|
27
|
+
this.on('event', this.handleHBEventMessage.bind(this));
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
handleHBEventMessage(service) {
|
|
32
|
-
debug('event for', this.id, service.serviceName, service.values);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
handleHBTopicMessage(service) {
|
|
36
31
|
debug('topic for', this.id, service.serviceName, service.values);
|
|
32
|
+
|
|
33
|
+
this.status({
|
|
34
|
+
text: JSON.stringify(service.values),
|
|
35
|
+
shape: 'dot',
|
|
36
|
+
fill: 'green',
|
|
37
|
+
});
|
|
38
|
+
this.send({ payload: service.values });
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
|
package/src/hbConfigNode.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
// const EventEmitter = require('events'); // Import EventEmitter
|
|
2
1
|
const { HapClient } = require('@homebridge/hap-client');
|
|
3
2
|
const debug = require('debug')('hapNodeRed:hbConfigNode');
|
|
4
3
|
const { Log } = require('./lib/logger.js');
|
|
5
4
|
const Queue = require('better-queue');
|
|
6
5
|
|
|
7
|
-
class HBConfigNode {
|
|
6
|
+
class HBConfigNode {
|
|
8
7
|
constructor(config, RED) {
|
|
9
|
-
// super(); // Call EventEmitter's constructor
|
|
10
|
-
|
|
11
8
|
if (!config.jest) {
|
|
12
9
|
RED.nodes.createNode(this, config);
|
|
13
10
|
|
|
@@ -41,10 +38,7 @@ class HBConfigNode { // Extend EventEmitter
|
|
|
41
38
|
this.waitForNoMoreDiscoveries();
|
|
42
39
|
this.hapClient.on('instance-discovered', this.waitForNoMoreDiscoveries);
|
|
43
40
|
|
|
44
|
-
this.on('close', ()
|
|
45
|
-
debug('close');
|
|
46
|
-
this.close();
|
|
47
|
-
});
|
|
41
|
+
this.on('close', this.close.bind(this));
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
44
|
|
|
@@ -70,19 +64,16 @@ class HBConfigNode { // Extend EventEmitter
|
|
|
70
64
|
}
|
|
71
65
|
|
|
72
66
|
toList(perms) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
];
|
|
81
|
-
return supportedTypes.includes(service.humanType);
|
|
82
|
-
};
|
|
67
|
+
const supportedTypes = [
|
|
68
|
+
'Battery', 'Carbon Dioxide Sensor', 'Carbon Monoxide Sensor', 'Doorbell',
|
|
69
|
+
'Fan', 'Fanv2', 'Garage Door Opener', 'Humidity Sensor', 'Input Source',
|
|
70
|
+
'Leak Sensor', 'Lightbulb', 'Lock Mechanism', 'Motion Sensor', 'Occupancy Sensor',
|
|
71
|
+
'Outlet', 'Smoke Sensor', 'Speaker', 'Stateless Programmable Switch', 'Switch',
|
|
72
|
+
'Television', 'Temperature Sensor', 'Thermostat', 'Contact Sensor',
|
|
73
|
+
];
|
|
83
74
|
|
|
84
75
|
return this.hbDevices
|
|
85
|
-
.filter(service =>
|
|
76
|
+
.filter(service => supportedTypes.includes(service.humanType))
|
|
86
77
|
.map(service => ({
|
|
87
78
|
name: service.serviceName,
|
|
88
79
|
fullName: `${service.serviceName} - ${service.type}`,
|
|
@@ -130,49 +121,27 @@ class HBConfigNode { // Extend EventEmitter
|
|
|
130
121
|
return clientNode.device === deviceUnique;
|
|
131
122
|
});
|
|
132
123
|
|
|
133
|
-
debug(clientNode.type);
|
|
134
124
|
if (clientNode.config.type === 'hb-status') {
|
|
135
|
-
debug('Adding', clientNode.name, clientNode.device)
|
|
136
125
|
this.monitorNodes[clientNode.device] = clientNode.hbDevice;
|
|
137
126
|
}
|
|
138
|
-
|
|
127
|
+
|
|
139
128
|
if (!clientNode.hbDevice) {
|
|
140
129
|
console.error('ERROR: _register - HB Device Missing', clientNode.name);
|
|
141
130
|
}
|
|
142
131
|
}
|
|
143
|
-
|
|
144
|
-
// console.log(Object.keys(this.monitorNodes));
|
|
132
|
+
|
|
145
133
|
if (Object.keys(this.monitorNodes).length) {
|
|
146
|
-
debug(`Registering ${Object.keys(this.monitorNodes).length} nodes for events`);
|
|
147
134
|
this.monitor = await this.hapClient.monitorCharacteristics(Object.values(this.monitorNodes));
|
|
148
135
|
this.monitor.on('service-update', (services) => {
|
|
149
|
-
// Emit events for updated services
|
|
150
136
|
for (const service of services) {
|
|
151
|
-
debug(`${service.instance.name}${service.instance.username}${service.accessoryInformation.Manufacturer}${service.serviceName}${service.uuid.slice(0, 8)}`,
|
|
152
|
-
service.values)
|
|
153
|
-
this.emit(
|
|
154
|
-
`${service.instance.name}${service.instance.username}${service.accessoryInformation.Manufacturer}${service.serviceName}${service.uuid.slice(0, 8)}`,
|
|
155
|
-
service.values
|
|
156
|
-
);
|
|
157
|
-
debug('event',
|
|
158
|
-
service.serviceName, service.values)
|
|
159
|
-
this.emit(
|
|
160
|
-
'event',
|
|
161
|
-
service
|
|
162
|
-
);
|
|
163
|
-
// console.log(this.clientNodes);
|
|
164
|
-
|
|
165
137
|
const eventNodes = Object.values(this.clientNodes).filter(
|
|
166
|
-
|
|
167
|
-
(clientNode) =>
|
|
138
|
+
clientNode =>
|
|
168
139
|
clientNode.config.device === `${service.instance.name}${service.instance.username}${service.accessoryInformation.Manufacturer}${service.serviceName}${service.uuid.slice(0, 8)}`
|
|
169
|
-
|
|
170
140
|
);
|
|
171
|
-
|
|
141
|
+
|
|
172
142
|
eventNodes.forEach((eventNode) => {
|
|
173
|
-
debug('emit', eventNode.name, eventNode.type)
|
|
174
143
|
if (eventNode._events && typeof eventNode.emit === 'function') {
|
|
175
|
-
eventNode.emit('
|
|
144
|
+
eventNode.emit('event', service);
|
|
176
145
|
}
|
|
177
146
|
});
|
|
178
147
|
}
|
|
@@ -182,11 +151,7 @@ class HBConfigNode { // Extend EventEmitter
|
|
|
182
151
|
}
|
|
183
152
|
|
|
184
153
|
deregister(clientNode) {
|
|
185
|
-
clientNode.status({
|
|
186
|
-
text: 'disconnected',
|
|
187
|
-
shape: 'ring',
|
|
188
|
-
fill: 'red',
|
|
189
|
-
});
|
|
154
|
+
clientNode.status({ text: 'disconnected', shape: 'ring', fill: 'red' });
|
|
190
155
|
delete this.clientNodes[clientNode.id];
|
|
191
156
|
}
|
|
192
157
|
|
package/src/hbStatusNode.js
CHANGED
|
@@ -6,7 +6,7 @@ class HbStatusNode extends HbBaseNode {
|
|
|
6
6
|
super(config, RED);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
async handleInput(message) {
|
|
9
|
+
async handleInput(message, send) {
|
|
10
10
|
debug('handleInput', message.payload, this.name);
|
|
11
11
|
|
|
12
12
|
if (!this.hbDevice) {
|
|
@@ -23,7 +23,7 @@ class HbStatusNode extends HbBaseNode {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
message.payload = result.values;
|
|
26
|
-
|
|
26
|
+
send(message);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|