node-red-contrib-homebridge-automation 0.2.1-beta.1 → 0.2.1-beta.3

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-homebridge-automation",
3
- "version": "0.2.1-beta.1",
3
+ "version": "0.2.1-beta.3",
4
4
  "description": "NodeRED Automation for HomeBridge",
5
5
  "main": "src/HAP-NodeRed.js",
6
6
  "scripts": {
package/src/hbBaseNode.js CHANGED
@@ -27,18 +27,9 @@ class HbBaseNode {
27
27
  this.on('hbReady', this.handleHbReady.bind(this))
28
28
  }
29
29
  this.on('close', this.handleClose.bind(this));
30
- this.on('hbEvent', this.handleHBEventMessage.bind(this));
31
- }
32
-
33
- handleHBEventMessage(service) {
34
- debug('hbEvent for', this.id, this.type, service.serviceName, JSON.stringify(service.values));
35
-
36
- this.status({
37
- text: JSON.stringify(service.values),
38
- shape: 'dot',
39
- fill: 'green',
40
- });
41
- this.send({ payload: service.values });
30
+ if (this.handleHBEventMessage) {
31
+ this.on('hbEvent', this.handleHBEventMessage.bind(this));
32
+ }
42
33
  }
43
34
 
44
35
  createMessage(service) {
@@ -35,9 +35,9 @@ class HBConfigNode {
35
35
  * Wait for no more instance discoveries to be made before publishing services
36
36
  */
37
37
  waitForNoMoreDiscoveries = (instance) => {
38
- debug('Instance discovered: %s - %s %s:%s', instance?.name, instance?.username, instance?.ipAddress, instance?.port);
38
+ if (instance)
39
+ debug('Instance discovered: %s - %s %s:%s', instance?.name, instance?.username, instance?.ipAddress, instance?.port);
39
40
  if (!this.discoveryTimeout) {
40
- clearTimeout(this.discoveryTimeout);
41
41
  this.discoveryTimeout = setTimeout(() => {
42
42
  this.debug('No more instances discovered, publishing services');
43
43
  this.handleReady();
@@ -112,6 +112,7 @@ class HBConfigNode {
112
112
  debug('Register: %s type: %s', clientNode.type, clientNode.name);
113
113
  this.clientNodes[clientNode.id] = clientNode;
114
114
  clientNode.status({ fill: 'yellow', shape: 'ring', text: 'connecting' });
115
+ this.waitForNoMoreDiscoveries(); // Connect new nodes created after startup has ended ( Need a function to rather than brute forcing it )
115
116
  }
116
117
 
117
118
  async connectClientNodes() {
@@ -128,7 +129,7 @@ class HBConfigNode {
128
129
  clientNode.emit('hbReady', matchedDevice);
129
130
  debug('_Registered: %s type: %s', clientNode.type, matchedDevice.type, matchedDevice.serviceName);
130
131
  } else {
131
- this.error(`ERROR: Device registration failed ${clientNode.name}`);
132
+ this.error(`ERROR: Device registration failed '${clientNode.fullName}'`);
132
133
  }
133
134
  };
134
135
 
@@ -137,21 +138,17 @@ class HBConfigNode {
137
138
 
138
139
  async monitorDevices() {
139
140
  if (Object.keys(this.clientNodes).length) {
140
- const uniqueDevices = new Set();
141
141
 
142
142
  const monitorNodes = Object.values(this.clientNodes)
143
- .filter(node => ['hb-status', 'hb-control', 'hb-event', 'hb-resume'].includes(node.type)) // Filter by type
144
- .filter(node => {
145
- if (uniqueDevices.has(node.device)) {
146
- return false; // Exclude duplicates
147
- }
148
- uniqueDevices.add(node.device);
149
- return true; // Include unique devices
150
- })
143
+ .filter(node => ['hb-status', 'hb-event', 'hb-resume'].includes(node.type)) // Filter by type
151
144
  .map(node => node.hbDevice) // Map to hbDevice property
152
145
  .filter(Boolean); // Remove any undefined or null values, if present;
153
- debug('monitorNodes', Object.keys(monitorNodes).length);
146
+ this.log(`Connected to ${Object.keys(monitorNodes).length} Homebridge devices`);
154
147
  // console.log('monitorNodes', monitorNodes);
148
+ if (this.monitor) {
149
+ // This is kinda brute force, and should be refactored to only refresh the changed monitorNodes
150
+ this.monitor.finish();
151
+ }
155
152
  this.monitor = await this.hapClient.monitorCharacteristics(monitorNodes);
156
153
  this.monitor.on('service-update', (services) => {
157
154
  services.forEach(service => {
@@ -18,6 +18,17 @@ class HbEventNode extends hbBaseNode {
18
18
  this.send({ ...this.createMessage(service) });
19
19
  }
20
20
  }
21
+
22
+ handleHBEventMessage(service) {
23
+ debug('hbEvent for', this.id, this.type, service.serviceName, JSON.stringify(service.values));
24
+
25
+ this.status({
26
+ text: JSON.stringify(service.values),
27
+ shape: 'dot',
28
+ fill: 'green',
29
+ });
30
+ this.send({ payload: service.values });
31
+ }
21
32
  }
22
33
 
23
34
  module.exports = HbEventNode;
@@ -32,6 +32,17 @@ class HbStatusNode extends HbBaseNode {
32
32
  }
33
33
 
34
34
  }
35
+
36
+ handleHBEventMessage(service) {
37
+ debug('hbEvent for', this.id, this.type, service.serviceName, JSON.stringify(service.values));
38
+
39
+ this.status({
40
+ text: JSON.stringify(service.values),
41
+ shape: 'dot',
42
+ fill: 'green',
43
+ });
44
+ this.send({ payload: service.values });
45
+ }
35
46
  }
36
47
 
37
48
  module.exports = HbStatusNode;
@@ -18,6 +18,8 @@
18
18
  },
19
19
  "debug": {
20
20
  "filter": "filterCurrent"
21
- }
21
+ },
22
+ "menu-deploymenu-item-node": true,
23
+ "menu-deploymenu-item-full": false
22
24
  }
23
25
  }
@@ -15,6 +15,9 @@
15
15
  "tours": {
16
16
  "welcome": "4.0.2"
17
17
  }
18
+ },
19
+ "debug": {
20
+ "filter": "filterCurrent"
18
21
  }
19
22
  }
20
23
  }
@@ -180,7 +180,7 @@
180
180
  "conf": "7e647d67.f33acc",
181
181
  "outputs": 1,
182
182
  "x": 500,
183
- "y": 300,
183
+ "y": 320,
184
184
  "wires": [
185
185
  [
186
186
  "f194fc4bcb1997a9"
@@ -453,7 +453,7 @@
453
453
  "statusVal": "payload",
454
454
  "statusType": "auto",
455
455
  "x": 800,
456
- "y": 300,
456
+ "y": 320,
457
457
  "wires": []
458
458
  },
459
459
  {
@@ -825,7 +825,7 @@
825
825
  "Manufacturer": "Tasmota",
826
826
  "Service": "Lightbulb",
827
827
  "device": "homebridge1C:22:3D:E3:CF:34TasmotaMaster00000043",
828
- "conf": "557aec8e8c47e61e",
828
+ "conf": "7e647d67.f33acc",
829
829
  "sendInitialState": true,
830
830
  "x": 170,
831
831
  "y": 280,
@@ -180,7 +180,7 @@
180
180
  "conf": "7e647d67.f33acc",
181
181
  "outputs": 1,
182
182
  "x": 500,
183
- "y": 300,
183
+ "y": 320,
184
184
  "wires": [
185
185
  [
186
186
  "f194fc4bcb1997a9"
@@ -453,7 +453,7 @@
453
453
  "statusVal": "payload",
454
454
  "statusType": "auto",
455
455
  "x": 800,
456
- "y": 300,
456
+ "y": 320,
457
457
  "wires": []
458
458
  },
459
459
  {
@@ -2250,13 +2250,13 @@
2250
2250
  "id": "7ceb11204ab233ad",
2251
2251
  "type": "hb-resume",
2252
2252
  "z": "efb3c9c5f6bdfd6c",
2253
- "name": "Bunkie Lower",
2253
+ "name": "Bunkie Fan",
2254
2254
  "Homebridge": "homebridge",
2255
- "Manufacturer": "WLED",
2256
- "Service": "Lightbulb",
2257
- "device": "homebridge0E:03:4B:B3:AF:4CWLEDBunkie Lower00000043",
2255
+ "Manufacturer": "Tasmota",
2256
+ "Service": "Fan",
2257
+ "device": "homebridge1C:22:3D:E3:CF:34TasmotaBunkie Fan00000040",
2258
2258
  "conf": "7e647d67.f33acc",
2259
- "x": 580,
2259
+ "x": 570,
2260
2260
  "y": 680,
2261
2261
  "wires": [
2262
2262
  [
@@ -2351,14 +2351,14 @@
2351
2351
  "id": "2abd3edc55335405",
2352
2352
  "type": "hb-control",
2353
2353
  "z": "efb3c9c5f6bdfd6c",
2354
- "name": "Bunkie Lower",
2354
+ "name": "Bunkie Fan",
2355
2355
  "Homebridge": "homebridge",
2356
- "Manufacturer": "WLED",
2357
- "Service": "Lightbulb",
2358
- "device": "homebridge0E:03:4B:B3:AF:4CWLEDBunkie Lower00000043",
2356
+ "Manufacturer": "Tasmota",
2357
+ "Service": "Fan",
2358
+ "device": "homebridge1C:22:3D:E3:CF:34TasmotaBunkie Fan00000040",
2359
2359
  "conf": "7e647d67.f33acc",
2360
2360
  "outputs": 0,
2361
- "x": 800,
2361
+ "x": 790,
2362
2362
  "y": 680,
2363
2363
  "wires": []
2364
2364
  },