node-red-contrib-homebridge-automation 0.1.12-beta.4 → 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 00:44:15 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.4",
3
+ "version": "0.1.12-beta.6",
4
4
  "description": "NodeRED Automation for HomeBridge",
5
5
  "main": "src/HAP-NodeRed.js",
6
6
  "scripts": {
@@ -194,7 +194,7 @@ module.exports = function (RED) {
194
194
  _rawEvent: event
195
195
  };
196
196
  node.status({
197
- text: JSON.stringify(msg.payload).slice(0, 40)+'...',
197
+ text: JSON.stringify(msg.payload).slice(0, 30) + '...',
198
198
  shape: 'dot',
199
199
  fill: 'green'
200
200
  });
@@ -233,7 +233,7 @@ module.exports = function (RED) {
233
233
  }, function (err, message) {
234
234
  if (!err) {
235
235
  node.state = _convertHBcharactericToNode(message.characteristics, node);
236
- debug("hbEvent received: %s = %s", node.fullName, JSON.stringify(message.characteristics).slice(0, 80)+'...');
236
+ debug("hbEvent received: %s = %s", node.fullName, JSON.stringify(message.characteristics).slice(0, 80) + '...');
237
237
  if (node.sendInitialState) {
238
238
  var msg = {
239
239
  name: node.name,
@@ -246,7 +246,7 @@ module.exports = function (RED) {
246
246
  _rawMessage: message,
247
247
  };
248
248
  node.status({
249
- text: JSON.stringify(msg.payload).slice(0, 40)+'...',
249
+ text: JSON.stringify(msg.payload).slice(0, 30) + '...',
250
250
  shape: 'dot',
251
251
  fill: 'green'
252
252
  });
@@ -366,7 +366,7 @@ module.exports = function (RED) {
366
366
  }, newMsg));
367
367
  debug("hbResume.input: %s output", node.fullName, JSON.stringify(newMsg));
368
368
  node.status({
369
- text: JSON.stringify(newMsg.payload).slice(0, 40)+'...',
369
+ text: JSON.stringify(newMsg.payload).slice(0, 30) + '...',
370
370
  shape: 'dot',
371
371
  fill: 'green'
372
372
  });
@@ -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
  });
@@ -448,7 +448,7 @@ module.exports = function (RED) {
448
448
  }, function (err, message) {
449
449
  if (!err) {
450
450
  node.state = _convertHBcharactericToNode(message.characteristics, node);
451
- debug("hbResume received: %s = %s", node.fullName, JSON.stringify(message.characteristics).slice(0, 80)+'...');
451
+ debug("hbResume received: %s = %s", node.fullName, JSON.stringify(message.characteristics).slice(0, 80) + '...');
452
452
  } else {
453
453
  node.error(err);
454
454
  }
@@ -505,37 +505,26 @@ 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
-
531
- _control.call(this, node, device, msg.payload, function (err, data) {
532
- // debug('hbControl [%s] - [%s]', err, data); // Images produce alot of noise
533
- if (!err && data && (device.type == '00000110' || device.type == '00000111')) {
534
- // debug('hbControl', err, data); // Images produce alot of noise
535
- const msg = {};
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')) {
514
+ const msg = {
515
+ name: node.name,
516
+ payload: node.state,
517
+ _device: node.device,
518
+ _confId: node.confId
519
+ };
520
+ if (node.hbDevice) {
521
+ msg.Homebridge = node.hbDevice.homebridge;
522
+ msg.Manufacturer = node.hbDevice.manufacturer;
523
+ msg.Service = node.hbDevice.deviceType;
524
+ }
536
525
  msg.payload = data;
537
526
  node.send(msg);
538
- } else {
527
+ } else if (err) {
539
528
  node.error(err, this.msg);
540
529
  }
541
530
  }.bind(this));
@@ -547,7 +536,19 @@ module.exports = function (RED) {
547
536
  });
548
537
 
549
538
  node.conf.register(node, function () {
550
- // 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
+ }
551
552
  switch (node.service) {
552
553
  case "Camera Control": // Camera Control
553
554
  debug("hbControl camera");
@@ -599,7 +600,7 @@ module.exports = function (RED) {
599
600
  perms: 'pr'
600
601
  }, function (err, message) {
601
602
  if (!err) {
602
- debug("hbStatus received: %s = %s", JSON.stringify(node.fullName), JSON.stringify(message).slice(0, 80)+'...', JSON.stringify(node.hbDevice));
603
+ debug("hbStatus received: %s = %s", JSON.stringify(node.fullName), JSON.stringify(message).slice(0, 80) + '...', JSON.stringify(node.hbDevice));
603
604
  this.msg.name = node.name;
604
605
  this.msg._rawMessage = message;
605
606
  this.msg.payload = _convertHBcharactericToNode(message.characteristics, node);
@@ -612,7 +613,7 @@ module.exports = function (RED) {
612
613
  this.msg._confId = node.confId;
613
614
  }
614
615
  node.status({
615
- text: JSON.stringify(this.msg.payload).slice(0, 40)+'...',
616
+ text: JSON.stringify(this.msg.payload).slice(0, 30) + '...',
616
617
  shape: 'dot',
617
618
  fill: 'green'
618
619
  });
@@ -815,6 +816,9 @@ module.exports = function (RED) {
815
816
  // debug("_status", new Error(), hbDevices);
816
817
  var error;
817
818
  try {
819
+ if (!hbDevices) {
820
+ throw new Error('hbDevices not initialized');
821
+ }
818
822
  var device = hbDevices.findDevice(node.device, perms);
819
823
  if (device) {
820
824
  // debug("device.type", device.type);
@@ -828,7 +832,7 @@ module.exports = function (RED) {
828
832
  };
829
833
  debug("_status Control %s -> %s", device.id, JSON.stringify(message));
830
834
  homebridge.HAPresourceByDeviceID(device.id, JSON.stringify(message), function (err, status) {
831
- debug("status", err);
835
+ // debug("status", err);
832
836
  if (!err) {
833
837
  debug("_status Controlled %s:%s ->", device.host, device.port);
834
838
  node.status({
@@ -894,8 +898,8 @@ module.exports = function (RED) {
894
898
  callback(error);
895
899
  } // end of device if
896
900
  } catch (err) {
897
- debug('_status', err);
898
- error = "Homebridge not initialized";
901
+ // debug('_status', err);
902
+ error = "Homebridge not initialized -2";
899
903
  node.status({
900
904
  text: error,
901
905
  shape: 'ring',
@@ -915,11 +919,17 @@ module.exports = function (RED) {
915
919
  * @return {type} description
916
920
  */
917
921
 
918
- function _control(node, device, payload, callback) {
922
+ function _control(node, payload, callback) {
919
923
  try {
924
+ if (!hbDevices) {
925
+ throw new Error('hbDevices not initialized');
926
+ }
927
+ var device = hbDevices.findDevice(node.device, {
928
+ perms: 'pw'
929
+ });
920
930
  if (device) {
921
931
  var message;
922
- console.log('device.type',device.type)
932
+ // console.log('device.type', device.type)
923
933
  switch (device.type) {
924
934
  case "00000110": // Camera RTPStream Management
925
935
  case "00000111": // Camera Control
@@ -931,10 +941,10 @@ module.exports = function (RED) {
931
941
  debug("Control %s ->", device.id, JSON.stringify(message));
932
942
  homebridge.HAPresourceByDeviceID(device.id, JSON.stringify(message), function (err, status) {
933
943
  if (!err) {
934
- // debug("Controlled %s ->", device.id, JSON.stringify(payload));
935
- // debug("Payload %s ->", device.id, status);
944
+ // debug("Controlled %s ->", device.id, JSON.stringify(payload));
945
+ // debug("Payload %s ->", device.id, status);
936
946
  node.status({
937
- text: JSON.stringify(payload).slice(0, 40)+'...',
947
+ text: JSON.stringify(payload).slice(0, 30) + '...',
938
948
  shape: 'dot',
939
949
  fill: 'green'
940
950
  });
@@ -964,7 +974,7 @@ module.exports = function (RED) {
964
974
  if (!err && status && status.characteristics[0].status === 0) {
965
975
  debug("Controlled %s ->", device.id, JSON.stringify(status));
966
976
  node.status({
967
- text: JSON.stringify(payload).slice(0, 40)+'...',
977
+ text: JSON.stringify(payload).slice(0, 30) + '...',
968
978
  shape: 'dot',
969
979
  fill: 'green'
970
980
  });
@@ -976,7 +986,7 @@ module.exports = function (RED) {
976
986
  } else if (!err) {
977
987
  debug("Controlled %s ->", device.id, payload);
978
988
  node.status({
979
- text: JSON.stringify(payload).slice(0, 40)+'...',
989
+ text: JSON.stringify(payload).slice(0, 30) + '...',
980
990
  shape: 'dot',
981
991
  fill: 'green'
982
992
  });
@@ -1029,7 +1039,7 @@ module.exports = function (RED) {
1029
1039
  callback(error);
1030
1040
  }
1031
1041
  } catch (err) {
1032
- var error = "Homebridge not initialized";
1042
+ var error = "Homebridge not initialized - 3 "+ err;
1033
1043
  node.status({
1034
1044
  text: error,
1035
1045
  shape: 'ring',