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

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.2",
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) {
@@ -137,21 +137,17 @@ class HBConfigNode {
137
137
 
138
138
  async monitorDevices() {
139
139
  if (Object.keys(this.clientNodes).length) {
140
- const uniqueDevices = new Set();
141
140
 
142
141
  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
- })
142
+ .filter(node => ['hb-status', 'hb-event', 'hb-resume'].includes(node.type)) // Filter by type
151
143
  .map(node => node.hbDevice) // Map to hbDevice property
152
144
  .filter(Boolean); // Remove any undefined or null values, if present;
153
- debug('monitorNodes', Object.keys(monitorNodes).length);
145
+ this.log(`Connected to ${Object.keys(monitorNodes).length} Homebridge devices`);
154
146
  // console.log('monitorNodes', monitorNodes);
147
+ if (this.monitor) {
148
+ // This is kinda brute force, but it works
149
+ this.monitor.finish();
150
+ }
155
151
  this.monitor = await this.hapClient.monitorCharacteristics(monitorNodes);
156
152
  this.monitor.on('service-update', (services) => {
157
153
  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;
@@ -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"
@@ -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
  {