node-red-contrib-homekit-bridged 2.0.0-dev.0 → 2.0.0-dev.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.
Files changed (45) hide show
  1. package/build/lib/HAPHostNode.js +59 -64
  2. package/build/lib/HAPServiceNode.js +91 -95
  3. package/build/lib/HAPServiceNode2.js +93 -97
  4. package/build/lib/Storage.d.ts +3 -3
  5. package/build/lib/Storage.js +2 -2
  6. package/build/lib/api.js +26 -29
  7. package/build/lib/hap/HAPCharacteristic.d.ts +1 -1
  8. package/build/lib/hap/HAPService.d.ts +1 -1
  9. package/build/lib/hap/eve-app/EveCharacteristics.d.ts +1 -1
  10. package/build/lib/hap/eve-app/EveCharacteristics.js +10 -10
  11. package/build/lib/types/CustomCharacteristicType.d.ts +1 -1
  12. package/build/lib/types/HAPHostConfigType.d.ts +4 -4
  13. package/build/lib/types/HAPHostNodeType.d.ts +4 -4
  14. package/build/lib/types/HAPService2ConfigType.d.ts +2 -2
  15. package/build/lib/types/HAPService2NodeType.d.ts +3 -3
  16. package/build/lib/types/HAPServiceConfigType.d.ts +3 -3
  17. package/build/lib/types/HAPServiceNodeType.d.ts +10 -10
  18. package/build/lib/types/HAPStatusConfigType.d.ts +1 -1
  19. package/build/lib/types/HAPStatusNodeType.d.ts +5 -5
  20. package/build/lib/types/NodeType.d.ts +1 -1
  21. package/build/lib/types/storage/SerializedHostType.d.ts +2 -2
  22. package/build/lib/utils/AccessoryUtils.js +15 -15
  23. package/build/lib/utils/BridgeUtils.js +5 -5
  24. package/build/lib/utils/CharacteristicUtils.js +6 -6
  25. package/build/lib/utils/CharacteristicUtils2.js +6 -6
  26. package/build/lib/utils/NodeStatusUtils.d.ts +2 -2
  27. package/build/lib/utils/NodeStatusUtils.js +2 -2
  28. package/build/lib/utils/ServiceUtils.js +39 -38
  29. package/build/lib/utils/ServiceUtils2.js +39 -37
  30. package/build/lib/utils/index.js +2 -2
  31. package/build/nodes/nrchkb.js +2 -2
  32. package/build/nodes/status.js +15 -16
  33. package/examples/demo/01 - ALL Demos single import.json +64 -318
  34. package/examples/demo/02 - Air Purifier.json +279 -328
  35. package/examples/demo/03 - Air Quality sensor with Battery.json +254 -282
  36. package/examples/demo/04 - Dimmable Bulb.json +172 -189
  37. package/examples/demo/05 - Color Bulb (HSV).json +195 -216
  38. package/examples/demo/06 - Fan (simple, 3 speeds).json +240 -265
  39. package/examples/demo/07 - Fan (with speed, oscillate, rotation direction).json +175 -192
  40. package/examples/demo/08 - CO2 detector.json +224 -255
  41. package/examples/demo/09 - CO (carbon monoxide) example.json +255 -290
  42. package/examples/demo/10 - Door window contact sensor.json +234 -265
  43. package/examples/demos (advanced)/01 - Television with inputs and speaker.json +541 -607
  44. package/examples/switch/01 - Plain Switch.json +7 -27
  45. package/package.json +83 -81
@@ -7,7 +7,7 @@ const hap_nodejs_1 = require("@homebridge/hap-nodejs");
7
7
  const logger_1 = require("@nrchkb/logger");
8
8
  const NRCHKBError_1 = __importDefault(require("../NRCHKBError"));
9
9
  const Storage_1 = require("../Storage");
10
- module.exports = function (node) {
10
+ module.exports = (node) => {
11
11
  const log = (0, logger_1.logger)('NRCHKB', 'ServiceUtils2', node.config.name, node);
12
12
  const ServiceUtilsLegacy = require('./ServiceUtils')(node);
13
13
  const HapNodeJS = require('@homebridge/hap-nodejs');
@@ -20,7 +20,7 @@ module.exports = function (node) {
20
20
  log.debug(`${eventObject.name} event, oldValue: ${oldValue}, newValue: ${newValue}, connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
21
21
  const msg = {
22
22
  name: node.name,
23
- topic: node.config.topic ? node.config.topic : node.topic_in,
23
+ topic: node.config.topic ? node.config.topic : node.topic_in
24
24
  };
25
25
  msg.payload = {};
26
26
  msg.hap = {
@@ -30,27 +30,31 @@ module.exports = function (node) {
30
30
  allChars[cKey] = singleChar.value;
31
31
  return allChars;
32
32
  }, {}),
33
- oldValue,
33
+ oldValue
34
34
  };
35
35
  const key = this.constructor.name;
36
36
  msg.hap.reachable = (_a = node.reachable) !== null && _a !== void 0 ? _a : (_b = node.parentNode) === null || _b === void 0 ? void 0 : _b.reachable;
37
37
  if (msg.hap.reachable === false) {
38
38
  ;
39
- [node, ...((_c = node.childNodes) !== null && _c !== void 0 ? _c : [])].forEach((n) => n.nodeStatusUtils.setStatus({
40
- fill: 'red',
41
- shape: 'ring',
42
- text: 'Not reachable',
43
- type: 'NO_RESPONSE',
44
- }));
39
+ [node, ...((_c = node.childNodes) !== null && _c !== void 0 ? _c : [])].forEach((n) => {
40
+ n.nodeStatusUtils.setStatus({
41
+ fill: 'red',
42
+ shape: 'ring',
43
+ text: 'Not reachable',
44
+ type: 'NO_RESPONSE'
45
+ });
46
+ });
45
47
  }
46
48
  else {
47
49
  msg.hap.newValue = newValue;
48
50
  node.nodeStatusUtils.setStatus({
49
51
  fill: 'yellow',
50
52
  shape: 'dot',
51
- text: `[${eventObject.name}] ${key}${newValue != undefined ? `: ${newValue}` : ''}`,
53
+ text: `[${eventObject.name}] ${key}${newValue !== undefined ? `: ${newValue}` : ''}`
52
54
  }, 3000);
53
- (_d = node.childNodes) === null || _d === void 0 ? void 0 : _d.forEach((n) => n.nodeStatusUtils.clearStatusByType('NO_RESPONSE'));
55
+ (_d = node.childNodes) === null || _d === void 0 ? void 0 : _d.forEach((n) => {
56
+ n.nodeStatusUtils.clearStatusByType('NO_RESPONSE');
57
+ });
54
58
  (_e = node.parentNode) === null || _e === void 0 ? void 0 : _e.nodeStatusUtils.clearStatusByType('NO_RESPONSE');
55
59
  }
56
60
  msg.payload[key] = newValue;
@@ -60,7 +64,7 @@ module.exports = function (node) {
60
64
  username: connection.username,
61
65
  remoteAddress: connection.remoteAddress,
62
66
  localAddress: connection.localAddress,
63
- httpPort: connection.remotePort,
67
+ httpPort: connection.remotePort
64
68
  };
65
69
  }
66
70
  log.debug(`${node.name} received ${eventObject.name} ${key}: ${newValue}`);
@@ -69,11 +73,10 @@ module.exports = function (node) {
69
73
  }
70
74
  };
71
75
  const onCharacteristicGet = (allCharacteristics) => function (callback, _context, connection) {
72
- const characteristic = this;
73
- const oldValue = characteristic.value;
76
+ const oldValue = this.value;
74
77
  const delayedCallback = (value) => {
75
78
  var _a;
76
- const newValue = value !== null && value !== void 0 ? value : characteristic.value;
79
+ const newValue = value !== null && value !== void 0 ? value : this.value;
77
80
  if (callback) {
78
81
  try {
79
82
  callback(((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable
@@ -82,20 +85,20 @@ module.exports = function (node) {
82
85
  }
83
86
  catch (_) { }
84
87
  }
85
- output.call(characteristic, allCharacteristics, {
88
+ output.call(this, allCharacteristics, {
86
89
  name: "get",
87
- context: { key: this.displayName },
90
+ context: { key: this.displayName }
88
91
  }, { oldValue, newValue }, connection);
89
92
  };
90
93
  if (node.config.useEventCallback) {
91
94
  const callbackID = Storage_1.Storage.saveCallback({
92
95
  event: "get",
93
- callback: delayedCallback,
96
+ callback: delayedCallback
94
97
  });
95
- log.debug(`Registered callback ${callbackID} for Characteristic ${characteristic.displayName}`);
98
+ log.debug(`Registered callback ${callbackID} for Characteristic ${this.displayName}`);
96
99
  output.call(this, allCharacteristics, {
97
100
  name: "get",
98
- context: { callbackID, key: this.displayName },
101
+ context: { callbackID, key: this.displayName }
99
102
  }, { oldValue }, connection);
100
103
  }
101
104
  else {
@@ -114,19 +117,19 @@ module.exports = function (node) {
114
117
  catch (_) { }
115
118
  output.call(this, allCharacteristics, {
116
119
  name: "set",
117
- context: { key: this.displayName },
120
+ context: { key: this.displayName }
118
121
  }, { newValue }, connection);
119
122
  };
120
123
  const onCharacteristicChange = (allCharacteristics) => function (change) {
121
124
  const { oldValue, newValue, context, originator, reason } = change;
122
- if (oldValue != newValue) {
125
+ if (oldValue !== newValue) {
123
126
  output.call(this, allCharacteristics, {
124
127
  name: "change",
125
- context: { reason, key: this.displayName },
128
+ context: { reason, key: this.displayName }
126
129
  }, { oldValue, newValue, context }, originator);
127
130
  }
128
131
  };
129
- const onInput = function (msg) {
132
+ const onInput = (msg) => {
130
133
  var _a, _b;
131
134
  if (msg.payload) {
132
135
  const type = typeof msg.payload;
@@ -150,11 +153,10 @@ module.exports = function (node) {
150
153
  delete msg.payload.Context;
151
154
  }
152
155
  node.topic_in = (_b = msg.topic) !== null && _b !== void 0 ? _b : '';
153
- Object.keys(msg.payload).map((key) => {
156
+ Object.keys(msg.payload).forEach((key) => {
154
157
  var _a, _b, _c, _d, _e;
155
158
  if (node.supported.indexOf(key) < 0) {
156
- if (node.config.useEventCallback &&
157
- Storage_1.Storage.uuid4Validate(key)) {
159
+ if (node.config.useEventCallback && Storage_1.Storage.uuid4Validate(key)) {
158
160
  const callbackID = key;
159
161
  const callbackValue = (_a = msg.payload) === null || _a === void 0 ? void 0 : _a[key];
160
162
  const eventCallback = Storage_1.Storage.loadCallback(callbackID);
@@ -192,9 +194,9 @@ module.exports = function (node) {
192
194
  }
193
195
  });
194
196
  };
195
- const onClose = function (removed, done) {
197
+ const onClose = (removed, done) => {
196
198
  const characteristics = node.service.characteristics.concat(node.service.optionalCharacteristics);
197
- characteristics.forEach(function (characteristic) {
199
+ characteristics.forEach((characteristic) => {
198
200
  characteristic.removeListener('get', node.onCharacteristicGet);
199
201
  characteristic.removeListener('set', node.onCharacteristicSet);
200
202
  characteristic.removeListener('change', node.onCharacteristicChange);
@@ -214,7 +216,7 @@ module.exports = function (node) {
214
216
  }
215
217
  done();
216
218
  };
217
- const getOrCreate = function (accessory, serviceInformation, parentService) {
219
+ const getOrCreate = (accessory, serviceInformation, parentService) => {
218
220
  const newService = new Service[serviceInformation.serviceName](serviceInformation.name, serviceInformation.UUID);
219
221
  log.debug(`Looking for service with UUID ${serviceInformation.UUID} ...`);
220
222
  let service = accessory.services.find((service) => {
@@ -252,7 +254,7 @@ module.exports = function (node) {
252
254
  }
253
255
  return service;
254
256
  };
255
- const configureCameraSource = function (_accessory, _service, config) {
257
+ const configureCameraSource = (_accessory, _service, config) => {
256
258
  if (config.cameraConfigSource) {
257
259
  log.debug('Configuring Camera Source');
258
260
  if (!config.cameraConfigVideoProcessor) {
@@ -271,11 +273,11 @@ module.exports = function (node) {
271
273
  node.nodeStatusUtils.setStatus({
272
274
  fill: 'blue',
273
275
  shape: 'dot',
274
- text: 'Waiting for Parent Service',
276
+ text: 'Waiting for Parent Service'
275
277
  });
276
278
  const checkAndWait = () => {
277
279
  const parentNode = node.RED.nodes.getNode(node.config.parentService);
278
- if (parentNode && parentNode.configured) {
280
+ if (parentNode === null || parentNode === void 0 ? void 0 : parentNode.configured) {
279
281
  resolve(parentNode);
280
282
  }
281
283
  else {
@@ -292,9 +294,9 @@ module.exports = function (node) {
292
294
  if (node.setupDone) {
293
295
  return;
294
296
  }
295
- if (msg.hasOwnProperty('payload') &&
296
- msg.payload.hasOwnProperty('nrchkb') &&
297
- msg.payload.nrchkb.hasOwnProperty('setup')) {
297
+ if (Object.hasOwn(msg, 'payload') &&
298
+ Object.hasOwn(msg.payload, 'nrchkb') &&
299
+ Object.hasOwn(msg.payload.nrchkb, 'setup')) {
298
300
  node.setupDone = true;
299
301
  const newConfig = Object.assign(Object.assign({}, config), msg.payload.nrchkb.setup);
300
302
  node.removeListener('input', node.handleWaitForSetup);
@@ -313,6 +315,6 @@ module.exports = function (node) {
313
315
  onClose,
314
316
  waitForParent,
315
317
  handleWaitForSetup,
316
- configureAdaptiveLightning: ServiceUtilsLegacy.configureAdaptiveLightning,
318
+ configureAdaptiveLightning: ServiceUtilsLegacy.configureAdaptiveLightning
317
319
  };
318
320
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- module.exports = function (node) {
3
+ module.exports = (node) => {
4
4
  const ServiceUtils = require('./ServiceUtils')(node);
5
5
  const BridgeUtils = require('./BridgeUtils')();
6
6
  const AccessoryUtils = require('./AccessoryUtils')(node);
@@ -9,6 +9,6 @@ module.exports = function (node) {
9
9
  ServiceUtils,
10
10
  BridgeUtils,
11
11
  AccessoryUtils,
12
- CharacteristicUtils,
12
+ CharacteristicUtils
13
13
  };
14
14
  };
@@ -36,9 +36,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ const path = __importStar(require("node:path"));
39
40
  const hap_nodejs_1 = require("@homebridge/hap-nodejs");
40
41
  const logger_1 = require("@nrchkb/logger");
41
- const path = __importStar(require("path"));
42
42
  const semver_1 = __importDefault(require("semver"));
43
43
  const Storage_1 = require("../lib/Storage");
44
44
  (0, logger_1.loggerSetup)({ timestampEnabled: 'NRCHKB' });
@@ -68,7 +68,7 @@ module.exports = (RED) => {
68
68
  }
69
69
  else {
70
70
  log.error('RED settings not available');
71
- rootFolder = path.join(require('os').homedir(), '.node-red');
71
+ rootFolder = path.join(require('node:os').homedir(), '.node-red');
72
72
  }
73
73
  Storage_1.Storage.init(rootFolder, 'nrchkb').then(() => {
74
74
  log.debug(`nrchkb storage path set to ${Storage_1.Storage.storagePath()}`);
@@ -7,38 +7,37 @@ const log = (0, logger_1.logger)('NRCHKB', 'HAPStatusNode');
7
7
  module.exports = (RED) => {
8
8
  log.debug('Registering homekit-status type');
9
9
  RED.nodes.registerType('homekit-status', function (config) {
10
- const self = this;
11
- self.config = config;
12
- RED.nodes.createNode(self, config);
13
- self.nodeStatusUtils = new NodeStatusUtils_1.NodeStatusUtils(self);
10
+ this.config = config;
11
+ RED.nodes.createNode(this, config);
12
+ this.nodeStatusUtils = new NodeStatusUtils_1.NodeStatusUtils(this);
14
13
  try {
15
- self.serviceNode = RED.nodes.getNode(self.config.serviceNodeId);
14
+ this.serviceNode = RED.nodes.getNode(this.config.serviceNodeId);
16
15
  }
17
16
  catch (error) {
18
17
  log.error(error);
19
18
  }
20
- self.on('input', (_) => {
21
- if (self.serviceNode) {
22
- self.nodeStatusUtils.setStatus({
19
+ this.on('input', (_) => {
20
+ if (this.serviceNode) {
21
+ this.nodeStatusUtils.setStatus({
23
22
  fill: 'green',
24
23
  shape: 'dot',
25
- text: 'Done',
24
+ text: 'Done'
26
25
  }, 3000);
27
- const serializedService = hap_nodejs_1.Service.serialize(self.serviceNode.service);
28
- self.send({
29
- payload: serializedService,
26
+ const serializedService = hap_nodejs_1.Service.serialize(this.serviceNode.service);
27
+ this.send({
28
+ payload: serializedService
30
29
  });
31
30
  }
32
31
  else {
33
- self.nodeStatusUtils.setStatus({
32
+ this.nodeStatusUtils.setStatus({
34
33
  fill: 'red',
35
34
  shape: 'dot',
36
- text: 'Check your config',
35
+ text: 'Check your config'
37
36
  });
38
37
  }
39
38
  });
40
- self.on('close', (_, done) => {
41
- self.serviceNode = undefined;
39
+ this.on('close', (_, done) => {
40
+ this.serviceNode = undefined;
42
41
  done();
43
42
  });
44
43
  });