node-red-contrib-homebridge-automation 0.1.12-beta.35 → 0.1.12-beta.37
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
CHANGED
package/src/hbConfigNode.js
CHANGED
|
@@ -40,6 +40,7 @@ class HBConfigNode {
|
|
|
40
40
|
refreshDevices = () => {
|
|
41
41
|
if (!this.refreshInProcess) {
|
|
42
42
|
|
|
43
|
+
this.monitor.finish();
|
|
43
44
|
this.log.debug('Monitor reported homebridge stability issues, refreshing devices');
|
|
44
45
|
this.hapClient.on('instance-discovered', this.waitForNoMoreDiscoveries);
|
|
45
46
|
this.hapClient.resetInstancePool();
|
|
@@ -85,16 +86,16 @@ class HBConfigNode {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
toList(perms) {
|
|
88
|
-
const supportedTypes = [
|
|
89
|
-
'Battery', 'Carbon Dioxide Sensor', 'Carbon Monoxide Sensor', 'Camera Rtp Stream Management',
|
|
90
|
-
'Fan', 'Fanv2', 'Garage Door Opener', 'Humidity Sensor', 'Input Source',
|
|
89
|
+
const supportedTypes = new Set([
|
|
90
|
+
'Battery', 'Carbon Dioxide Sensor', 'Carbon Monoxide Sensor', 'Camera Rtp Stream Management',
|
|
91
|
+
'Doorbell', 'Fan', 'Fanv2', 'Garage Door Opener', 'Humidity Sensor', 'Input Source',
|
|
91
92
|
'Leak Sensor', 'Lightbulb', 'Lock Mechanism', 'Motion Sensor', 'Occupancy Sensor',
|
|
92
93
|
'Outlet', 'Smoke Sensor', 'Speaker', 'Stateless Programmable Switch', 'Switch',
|
|
93
94
|
'Television', 'Temperature Sensor', 'Thermostat', 'Contact Sensor',
|
|
94
|
-
];
|
|
95
|
+
]);
|
|
95
96
|
|
|
96
97
|
return filterUnique(this.hbDevices)
|
|
97
|
-
.filter(service => supportedTypes.
|
|
98
|
+
.filter(service => supportedTypes.has(service.humanType))
|
|
98
99
|
.map(service => ({
|
|
99
100
|
name: service.serviceName,
|
|
100
101
|
fullName: `${service.serviceName} - ${service.type}`,
|
|
@@ -107,18 +108,22 @@ class HBConfigNode {
|
|
|
107
108
|
.sort((a, b) => a.sortName.localeCompare(b.sortName));
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
|
|
110
112
|
handleDuplicates(list) {
|
|
111
|
-
const
|
|
112
|
-
const seenUniqueIds = new Set();
|
|
113
|
+
const seen = new Map();
|
|
113
114
|
|
|
114
115
|
list.forEach(endpoint => {
|
|
115
|
-
|
|
116
|
-
console.warn('WARNING: Duplicate device name', endpoint.fullName);
|
|
117
|
-
}
|
|
116
|
+
const { fullName, uniqueId } = endpoint;
|
|
118
117
|
|
|
119
|
-
if (
|
|
120
|
-
|
|
118
|
+
if (seen.has(fullName)) {
|
|
119
|
+
this.log.warn(`Duplicate device name detected: ${fullName}`);
|
|
121
120
|
}
|
|
121
|
+
if (seen.has(uniqueId)) {
|
|
122
|
+
this.log.error(`Duplicate uniqueId detected: ${uniqueId}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
seen.set(fullName, true);
|
|
126
|
+
seen.set(uniqueId, true);
|
|
122
127
|
});
|
|
123
128
|
}
|
|
124
129
|
|
|
@@ -130,7 +135,6 @@ class HBConfigNode {
|
|
|
130
135
|
|
|
131
136
|
async connectClientNodes() {
|
|
132
137
|
debug('connect %s nodes', Object.keys(this.clientNodes).length);
|
|
133
|
-
console.log(this.clientNodes);
|
|
134
138
|
for (const [key, clientNode] of Object.entries(this.clientNodes)) {
|
|
135
139
|
// debug('_Register: %s type: %s', clientNode.type, clientNode.name, clientNode.instance);
|
|
136
140
|
const matchedDevice = this.hbDevices.find(service =>
|
|
@@ -151,9 +155,22 @@ class HBConfigNode {
|
|
|
151
155
|
}
|
|
152
156
|
|
|
153
157
|
async monitorDevices() {
|
|
154
|
-
debug('monitorDevices', Object.keys(this.clientNodes).length);
|
|
155
158
|
if (Object.keys(this.clientNodes).length) {
|
|
156
|
-
const
|
|
159
|
+
const uniqueDevices = new Set();
|
|
160
|
+
|
|
161
|
+
const monitorNodes = Object.values(this.clientNodes)
|
|
162
|
+
.filter(node => ['hb-status', 'hb-control'].includes(node.type)) // Filter by type
|
|
163
|
+
.filter(node => {
|
|
164
|
+
if (uniqueDevices.has(node.device)) {
|
|
165
|
+
return false; // Exclude duplicates
|
|
166
|
+
}
|
|
167
|
+
uniqueDevices.add(node.device);
|
|
168
|
+
return true; // Include unique devices
|
|
169
|
+
})
|
|
170
|
+
.map(node => node.hbDevice) // Map to hbDevice property
|
|
171
|
+
.filter(Boolean); // Remove any undefined or null values, if present;
|
|
172
|
+
debug('monitorNodes', Object.keys(monitorNodes).length);
|
|
173
|
+
// console.log('monitorNodes', monitorNodes);
|
|
157
174
|
this.monitor = await this.hapClient.monitorCharacteristics(monitorNodes);
|
|
158
175
|
this.monitor.on('service-update', (services) => {
|
|
159
176
|
services.forEach(service => {
|
|
@@ -166,7 +183,12 @@ class HBConfigNode {
|
|
|
166
183
|
this.monitor.on('monitor-close', (instance, hadError) => {
|
|
167
184
|
debug('monitor-close', instance.name, instance.ipAddress, instance.port, hadError)
|
|
168
185
|
this.disconnectClientNodes(instance);
|
|
169
|
-
this.refreshDevices();
|
|
186
|
+
// this.refreshDevices();
|
|
187
|
+
})
|
|
188
|
+
this.monitor.on('monitor-refresh', (instance, hadError) => {
|
|
189
|
+
debug('monitor-refresh', instance.name, instance.ipAddress, instance.port, hadError)
|
|
190
|
+
this.reconnectClientNodes(instance);
|
|
191
|
+
// this.refreshDevices();
|
|
170
192
|
})
|
|
171
193
|
this.monitor.on('monitor-error', (instance, hadError) => {
|
|
172
194
|
debug('monitor-error', instance, hadError)
|
|
@@ -186,6 +208,18 @@ class HBConfigNode {
|
|
|
186
208
|
});
|
|
187
209
|
}
|
|
188
210
|
|
|
211
|
+
reconnectClientNodes(instance) {
|
|
212
|
+
debug('reconnectClientNodes', `${instance.ipAddress}:${instance.port}`);
|
|
213
|
+
const clientNodes = Object.values(this.clientNodes).filter(clientNode => {
|
|
214
|
+
return `${clientNode.hbDevice.instance.ipAddress}:${clientNode.hbDevice.instance.port}` === `${instance.ipAddress}:${instance.port}`;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
clientNodes.forEach(clientNode => {
|
|
218
|
+
clientNode.status({ fill: 'green', shape: 'dot', text: 'connected' });
|
|
219
|
+
clientNode.emit('hbReady', clientNode.hbDevice);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
189
223
|
close() {
|
|
190
224
|
debug('hb-config: close');
|
|
191
225
|
this.hapClient?.destroy();
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"vt": "str"
|
|
62
62
|
}
|
|
63
63
|
],
|
|
64
|
-
"repeat": "
|
|
64
|
+
"repeat": "",
|
|
65
65
|
"crontab": "",
|
|
66
66
|
"once": true,
|
|
67
67
|
"onceDelay": "60",
|
|
@@ -300,7 +300,7 @@
|
|
|
300
300
|
"topic": "",
|
|
301
301
|
"payload": "",
|
|
302
302
|
"payloadType": "date",
|
|
303
|
-
"x":
|
|
303
|
+
"x": 280,
|
|
304
304
|
"y": 260,
|
|
305
305
|
"wires": [
|
|
306
306
|
[
|
|
@@ -672,7 +672,7 @@
|
|
|
672
672
|
"vt": "str"
|
|
673
673
|
}
|
|
674
674
|
],
|
|
675
|
-
"repeat": "
|
|
675
|
+
"repeat": "",
|
|
676
676
|
"crontab": "",
|
|
677
677
|
"once": true,
|
|
678
678
|
"onceDelay": "60",
|
|
@@ -757,7 +757,7 @@
|
|
|
757
757
|
"statusVal": "payload",
|
|
758
758
|
"statusType": "msg",
|
|
759
759
|
"x": 1190,
|
|
760
|
-
"y":
|
|
760
|
+
"y": 280,
|
|
761
761
|
"wires": []
|
|
762
762
|
}
|
|
763
763
|
]
|