node-red-contrib-homebridge-automation 0.1.12-beta.5 → 0.1.12-beta.6

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/README.md CHANGED
@@ -60,7 +60,7 @@ The above Node-RED Flow, turns on my 'Outside Office' light when the powder room
60
60
  * [To start Node-RED in DEBUG mode, and output Homebridge-Automation debug logs start Node-RED like this.](#to-start-node-red-in-debug-mode-and-output-homebridge-automation-debug-logs-start-node-red-like-this)
61
61
 
62
62
  <!-- Created by https://github.com/ekalinin/github-markdown-toc -->
63
- <!-- Added by: runner, at: Sat Jul 6 02:02:55 UTC 2024 -->
63
+ <!-- Added by: runner, at: Sat Jul 6 02:33:18 UTC 2024 -->
64
64
 
65
65
  <!--te-->
66
66
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-homebridge-automation",
3
- "version": "0.1.12-beta.5",
3
+ "version": "0.1.12-beta.6",
4
4
  "description": "NodeRED Automation for HomeBridge",
5
5
  "main": "src/HAP-NodeRed.js",
6
6
  "scripts": {
@@ -380,9 +380,9 @@ module.exports = function (RED) {
380
380
  node.lastPayload = JSON.parse(JSON.stringify(msg.payload)); // store value not reference
381
381
  }
382
382
  } else {
383
- node.error("Homebridge not initialized", this.msg);
383
+ node.error("Homebridge not initialized - 1", this.msg);
384
384
  node.status({
385
- text: 'Homebridge not initialized',
385
+ text: 'Homebridge not initialized -1',
386
386
  shape: 'ring',
387
387
  fill: 'red'
388
388
  });
@@ -505,39 +505,12 @@ module.exports = function (RED) {
505
505
 
506
506
  node.on('input', function (msg) {
507
507
  this.msg = msg;
508
- var device;
509
-
510
- try {
511
- if (msg.name) {
512
- device = hbDevices.findDeviceByName(msg.name, {
513
- perms: 'pw'
514
- });
515
- } else {
516
- device = hbDevices.findDevice(node.device, {
517
- perms: 'pw'
518
- });
519
- }
520
- } catch (err) {
521
- var error = "Homebridge not initialized";
522
- node.status({
523
- text: error,
524
- shape: 'ring',
525
- fill: 'red'
526
- });
527
- node.error(error, this.msg);
528
- return;
529
- }
530
- device
531
- // name: 'Cottage Porch',
532
- // service: 'Camera Control',
533
- // fullName: 'Cottage Porch - Camera Control',
534
- // sortName: 'Cottage Porch:Camera Control',
535
-
536
-
537
- _control.call(this, node, device, msg.payload, function (err, data) {
538
- // debug('hbControl [%s] - [%s]', err, data); // Images produce alot of noise
539
- if (!err && data && (device.type == '00000110' || device.type == '00000111')) {
540
- // console.log('device', device, node);
508
+ Object.keys(msg.payload).sort().forEach(function (key) {
509
+ payload[key] = msg.payload[key];
510
+ });
511
+ _control.call(this, node, msg.payload, function (err, data) {
512
+ // debug('hbControl complete [%s] - [%s]', node, node.hbDevice); // Images produce alot of noise
513
+ if (!err && data && (node.deviceType == '00000110' || node.deviceType == '00000111')) {
541
514
  const msg = {
542
515
  name: node.name,
543
516
  payload: node.state,
@@ -551,7 +524,7 @@ module.exports = function (RED) {
551
524
  }
552
525
  msg.payload = data;
553
526
  node.send(msg);
554
- } else {
527
+ } else if (err) {
555
528
  node.error(err, this.msg);
556
529
  }
557
530
  }.bind(this));
@@ -563,7 +536,19 @@ module.exports = function (RED) {
563
536
  });
564
537
 
565
538
  node.conf.register(node, function () {
566
- // debug("hbControl.register:", node.fullName, node);
539
+ debug("hbControl.register:", node.fullName);
540
+ this.hbDevice = hbDevices.findDevice(node.device);
541
+ console.log('hbControl Register', this.hbDevice)
542
+ if (this.hbDevice) {
543
+ node.hbDevice = this.hbDevice;
544
+ node.deviceType = this.hbDevice.type;
545
+ // Register for events
546
+ node.listener = node.command;
547
+ // node.eventName = this.hbDevice.host + this.hbDevice.port + this.hbDevice.aid;
548
+ } else {
549
+ node.error("437:Can't find device " + node.device, null);
550
+ // this.error("Missing device " + node.device);
551
+ }
567
552
  switch (node.service) {
568
553
  case "Camera Control": // Camera Control
569
554
  debug("hbControl camera");
@@ -831,6 +816,9 @@ module.exports = function (RED) {
831
816
  // debug("_status", new Error(), hbDevices);
832
817
  var error;
833
818
  try {
819
+ if (!hbDevices) {
820
+ throw new Error('hbDevices not initialized');
821
+ }
834
822
  var device = hbDevices.findDevice(node.device, perms);
835
823
  if (device) {
836
824
  // debug("device.type", device.type);
@@ -910,8 +898,8 @@ module.exports = function (RED) {
910
898
  callback(error);
911
899
  } // end of device if
912
900
  } catch (err) {
913
- debug('_status', err);
914
- error = "Homebridge not initialized";
901
+ // debug('_status', err);
902
+ error = "Homebridge not initialized -2";
915
903
  node.status({
916
904
  text: error,
917
905
  shape: 'ring',
@@ -931,8 +919,14 @@ module.exports = function (RED) {
931
919
  * @return {type} description
932
920
  */
933
921
 
934
- function _control(node, device, payload, callback) {
922
+ function _control(node, payload, callback) {
935
923
  try {
924
+ if (!hbDevices) {
925
+ throw new Error('hbDevices not initialized');
926
+ }
927
+ var device = hbDevices.findDevice(node.device, {
928
+ perms: 'pw'
929
+ });
936
930
  if (device) {
937
931
  var message;
938
932
  // console.log('device.type', device.type)
@@ -1045,7 +1039,7 @@ module.exports = function (RED) {
1045
1039
  callback(error);
1046
1040
  }
1047
1041
  } catch (err) {
1048
- var error = "Homebridge not initialized";
1042
+ var error = "Homebridge not initialized - 3 "+ err;
1049
1043
  node.status({
1050
1044
  text: error,
1051
1045
  shape: 'ring',