node-red-contrib-homebridge-automation 0.1.12-beta.35 → 0.1.12-beta.36
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/hbConfigNode.js +32 -15
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 => {
|