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

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 23:23:03 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.7",
4
4
  "description": "NodeRED Automation for HomeBridge",
5
5
  "main": "src/HAP-NodeRed.js",
6
6
  "scripts": {
@@ -180,7 +180,7 @@ module.exports = function (RED) {
180
180
  node.command = function (event) {
181
181
  // False messages can be received from accessories with multiple services
182
182
  // if (Object.keys(_convertHBcharactericToNode(event, node)).length > 0) {
183
- debug("hbEvent", node.name, event);
183
+ // debug("hbEvent", node.name, event);
184
184
  if (event.status === true && event.value !== undefined) {
185
185
  node.state = Object.assign(node.state, _convertHBcharactericToNode([event], node));
186
186
  var msg = {
@@ -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,13 +536,18 @@ module.exports = function (RED) {
563
536
  });
564
537
 
565
538
  node.conf.register(node, function () {
566
- // debug("hbControl.register:", node.fullName, node);
567
- switch (node.service) {
568
- case "Camera Control": // Camera Control
569
- debug("hbControl camera");
570
- break;
571
- default:
572
- debug("node.conf.register", node.service);
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);
573
551
  }
574
552
  });
575
553
  }
@@ -831,6 +809,9 @@ module.exports = function (RED) {
831
809
  // debug("_status", new Error(), hbDevices);
832
810
  var error;
833
811
  try {
812
+ if (!hbDevices) {
813
+ throw new Error('hbDevices not initialized');
814
+ }
834
815
  var device = hbDevices.findDevice(node.device, perms);
835
816
  if (device) {
836
817
  // debug("device.type", device.type);
@@ -910,8 +891,8 @@ module.exports = function (RED) {
910
891
  callback(error);
911
892
  } // end of device if
912
893
  } catch (err) {
913
- debug('_status', err);
914
- error = "Homebridge not initialized";
894
+ // debug('_status', err);
895
+ error = "Homebridge not initialized -2";
915
896
  node.status({
916
897
  text: error,
917
898
  shape: 'ring',
@@ -931,8 +912,14 @@ module.exports = function (RED) {
931
912
  * @return {type} description
932
913
  */
933
914
 
934
- function _control(node, device, payload, callback) {
915
+ function _control(node, payload, callback) {
935
916
  try {
917
+ if (!hbDevices) {
918
+ throw new Error('hbDevices not initialized');
919
+ }
920
+ var device = hbDevices.findDevice(node.device, {
921
+ perms: 'pw'
922
+ });
936
923
  if (device) {
937
924
  var message;
938
925
  // console.log('device.type', device.type)
@@ -944,7 +931,7 @@ module.exports = function (RED) {
944
931
  "image-width": 1920,
945
932
  "image-height": 1080
946
933
  };
947
- debug("Control %s ->", device.id, JSON.stringify(message));
934
+ debug("Control %s ->", device.id, node.fullName, JSON.stringify(message));
948
935
  homebridge.HAPresourceByDeviceID(device.id, JSON.stringify(message), function (err, status) {
949
936
  if (!err) {
950
937
  // debug("Controlled %s ->", device.id, JSON.stringify(payload));
@@ -1045,7 +1032,7 @@ module.exports = function (RED) {
1045
1032
  callback(error);
1046
1033
  }
1047
1034
  } catch (err) {
1048
- var error = "Homebridge not initialized";
1035
+ var error = "Homebridge not initialized - 3 "+ err;
1049
1036
  node.status({
1050
1037
  text: error,
1051
1038
  shape: 'ring',