node-red-contrib-homebridge-automation 0.3.0-beta.2 → 0.3.0-beta.4

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.3.0-beta.2",
3
+ "version": "0.3.0-beta.4",
4
4
  "description": "NodeRED Automation for HomeBridge",
5
5
  "main": "src/HAP-NodeRed.js",
6
6
  "scripts": {
@@ -53,14 +53,14 @@ class HBConfigNode {
53
53
  */
54
54
  async handleReady() {
55
55
  const updatedDevices = await this.hapClient.getAllServices();
56
- if (this.debug && updatedDevices && updatedDevices.length) {
56
+ if (this.debug && updatedDevices && updatedDevices.length && process.uptime() < 300) {
57
57
  try {
58
58
  const storagePath = path.join(process.cwd(), '/homebridge-automation-endpoints.json');
59
59
  this.warn(`Writing Homebridge endpoints to ${storagePath}`);
60
60
  fs.writeFileSync(storagePath, JSON.stringify(updatedDevices, null, 2));
61
61
  } catch (e) {
62
62
  this.error(`Error writing Homebridge endpoints to file: ${e.message}`);
63
- }
63
+ }
64
64
  }
65
65
  // Fix broken uniqueId's from HAP-Client
66
66
  updatedDevices.forEach((service) => {
@@ -136,10 +136,12 @@ class HBConfigNode {
136
136
  async connectClientNodes() {
137
137
  debug('connect %s nodes', Object.keys(this.clientNodes).length);
138
138
  for (const [key, clientNode] of Object.entries(this.clientNodes)) {
139
- // debug('_Register: %s type: %s', clientNode.type, clientNode.name, clientNode.instance);
140
- const matchedDevice = this.hbDevices.find(service =>
141
- clientNode.device === `${service.instance.name}${service.instance.username}${service.accessoryInformation.Manufacturer}${service.serviceName}${service.uuid.slice(0, 8)}`
142
- );
139
+ // debug('_Register: %s type: "%s" "%s" "%s"', clientNode.type, clientNode.name, clientNode.instance, clientNode.device);
140
+ const matchedDevice = this.hbDevices.find(service => {
141
+ const friendlyName = (service.accessoryInformation.Name ? service.accessoryInformation.Name : service.serviceName);
142
+ const deviceIdentifier = `${service.instance.name}${service.instance.username}${service.accessoryInformation.Manufacturer}${friendlyName}${service.uuid.slice(0, 8)}`;
143
+ return clientNode.device === deviceIdentifier;
144
+ });
143
145
 
144
146
  if (matchedDevice) {
145
147
  clientNode.hbDevice = matchedDevice;
@@ -147,7 +149,7 @@ class HBConfigNode {
147
149
  clientNode.emit('hbReady', matchedDevice);
148
150
  debug('_Registered: %s type: %s', clientNode.type, matchedDevice.type, matchedDevice.serviceName);
149
151
  } else {
150
- this.error(`ERROR: Device registration failed '${clientNode.fullName}'`);
152
+ this.error(`ERROR: Device registration failed '${clientNode.fullName}' - '${clientNode.device}'`);
151
153
  }
152
154
  };
153
155