node-red-contrib-homekit-bridged 1.6.1 → 1.7.0-dev.1

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.
@@ -17,7 +17,7 @@ const hap_nodejs_1 = require("hap-nodejs");
17
17
  const semver_1 = require("semver");
18
18
  const preload_1 = __importDefault(require("semver/preload"));
19
19
  const NRCHKBError_1 = __importDefault(require("./NRCHKBError"));
20
- const HapCategories_1 = __importDefault(require("./types/HapCategories"));
20
+ const HapCategories_1 = __importDefault(require("./types/hap-nodejs/HapCategories"));
21
21
  const HostType_1 = __importDefault(require("./types/HostType"));
22
22
  module.exports = (RED, hostType) => {
23
23
  const MdnsUtils = require('./utils/MdnsUtils')();
package/build/lib/api.js CHANGED
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const logger_1 = require("@nrchkb/logger");
27
27
  const hap_nodejs_1 = require("hap-nodejs");
28
28
  const Storage_1 = require("./Storage");
29
- const HapCategories_1 = __importDefault(require("./types/HapCategories"));
29
+ const HapCategories_1 = __importDefault(require("./types/hap-nodejs/HapCategories"));
30
30
  const version = require('../../package.json').version.trim();
31
31
  module.exports = function (RED) {
32
32
  const log = (0, logger_1.logger)('NRCHKB', 'API');
@@ -30,7 +30,7 @@ const uuid = HapNodeJS.uuid;
30
30
  const StreamController = HapNodeJS.StreamController;
31
31
  const crypto = require('crypto');
32
32
  const fs = require('fs');
33
- const ip = require('ip');
33
+ const os = require('os');
34
34
  const spawn = require('child_process').spawn;
35
35
  const log = (0, logger_1.logger)('CameraSource');
36
36
  module.exports = {
@@ -249,17 +249,16 @@ Camera.prototype.prepareStream = function (request, callback) {
249
249
  sessionInfo['audio_srtp'] = Buffer.concat([srtp_key, srtp_salt]);
250
250
  sessionInfo['audio_ssrc'] = ssrc;
251
251
  }
252
- let currentAddress = ip.address(this.interfaceName);
253
- const addressResp = {
254
- address: currentAddress,
255
- };
256
- if (ip.isV4Format(currentAddress)) {
257
- addressResp['type'] = 'v4';
258
- }
259
- else {
260
- addressResp['type'] = 'v6';
252
+ const networkInterfaces = os.networkInterfaces();
253
+ if (this.interfaceName && networkInterfaces[this.interfaceName]) {
254
+ const currentAddress = networkInterfaces[this.interfaceName];
255
+ if (currentAddress === null || currentAddress === void 0 ? void 0 : currentAddress[0]) {
256
+ response['address'] = {
257
+ address: currentAddress[0].address,
258
+ type: currentAddress[0].family === 'IPv4' ? 'v4' : 'v6',
259
+ };
260
+ }
261
261
  }
262
- response['address'] = addressResp;
263
262
  this.pendingSessions[uuid.unparse(sessionID)] = sessionInfo;
264
263
  callback(response);
265
264
  };
@@ -1,7 +1,7 @@
1
1
  import { MDNSAdvertiser } from 'hap-nodejs';
2
2
  import { NodeDef } from 'node-red';
3
3
  import { SemVer } from 'semver';
4
- import HapCategories from './HapCategories';
4
+ import HapCategories from './hap-nodejs/HapCategories';
5
5
  type HAPHostConfigType = NodeDef & {
6
6
  bridgeName: string;
7
7
  pinCode: string;
@@ -1,23 +1,6 @@
1
1
  import { NodeDef } from 'node-red';
2
- import CameraConfigType from './CameraConfigType';
3
- type HAPService2ConfigType = NodeDef & {
4
- isParent: boolean;
5
- hostType: number;
6
- bridge: string;
7
- accessoryId: string;
8
- parentService: string;
9
- name: string;
10
- serviceName: string;
11
- topic: string;
12
- filter: boolean;
13
- manufacturer: string;
14
- model: string;
15
- serialNo: string;
16
- firmwareRev?: string;
17
- hardwareRev?: string;
18
- softwareRev?: string;
19
- characteristicProperties: string;
20
- waitForSetupMsg: boolean;
2
+ import HAPServiceConfigType from './HAPServiceConfigType';
3
+ type HAPService2ConfigType = NodeDef & HAPServiceConfigType & {
21
4
  useEventCallback: boolean;
22
- } & CameraConfigType;
5
+ };
23
6
  export default HAPService2ConfigType;
@@ -1,36 +1,7 @@
1
- import { Accessory, Characteristic, CharacteristicChange, CharacteristicGetCallback, CharacteristicProps, CharacteristicSetCallback, CharacteristicValue, Service } from 'hap-nodejs';
2
- import { HAPConnection } from 'hap-nodejs/dist/lib/util/eventedhttp';
3
- import { NodeAPI } from 'node-red';
4
- import { NodeStatusUtils } from '../utils/NodeStatusUtils';
5
- import HAPHostNodeType from './HAPHostNodeType';
6
1
  import HAPService2ConfigType from './HAPService2ConfigType';
7
2
  import HAPServiceNodeType from './HAPServiceNodeType';
8
3
  import NodeType from './NodeType';
9
- import PublishTimersType from './PublishTimersType';
10
- type HAPService2NodeType = NodeType & {
4
+ type HAPService2NodeType = NodeType & HAPServiceNodeType & {
11
5
  config: HAPService2ConfigType;
12
- RED: NodeAPI;
13
- setupDone: boolean;
14
- configured: boolean;
15
- handleWaitForSetup: (msg: any) => any;
16
- onIdentify: (paired: boolean, callback: () => any) => void;
17
- hostNode: HAPHostNodeType;
18
- childNodes?: (HAPService2NodeType | HAPServiceNodeType)[];
19
- service: Service;
20
- parentService: Service;
21
- parentNode?: HAPService2NodeType | HAPServiceNodeType;
22
- accessory: Accessory;
23
- characteristicProperties: {
24
- [key: string]: CharacteristicProps;
25
- };
26
- supported: string[];
27
- publishTimers: PublishTimersType;
28
- topic_in: string;
29
- onCharacteristicGet: (this: Characteristic, callback: CharacteristicGetCallback, context: any, connection?: HAPConnection) => void;
30
- onCharacteristicSet: (this: Characteristic, newValue: CharacteristicValue, callback: CharacteristicSetCallback, context: any, connection?: HAPConnection) => void;
31
- onCharacteristicChange: (this: Characteristic, change: CharacteristicChange) => void;
32
- uniqueIdentifier: string;
33
- reachable?: boolean;
34
- nodeStatusUtils: NodeStatusUtils;
35
6
  };
36
7
  export default HAPService2NodeType;
@@ -1,3 +1,4 @@
1
+ import { AdaptiveLightingControllerMode } from 'hap-nodejs/dist/lib/controller/AdaptiveLightingController';
1
2
  import { NodeDef } from 'node-red';
2
3
  import CameraConfigType from './CameraConfigType';
3
4
  type HAPServiceConfigType = NodeDef & {
@@ -18,5 +19,8 @@ type HAPServiceConfigType = NodeDef & {
18
19
  softwareRev?: string;
19
20
  characteristicProperties: string;
20
21
  waitForSetupMsg: boolean;
22
+ adaptiveLightingOptionsEnable?: boolean;
23
+ adaptiveLightingOptionsMode?: AdaptiveLightingControllerMode;
24
+ adaptiveLightingOptionsCustomTemperatureAdjustment?: number;
21
25
  } & CameraConfigType;
22
26
  export default HAPServiceConfigType;
@@ -0,0 +1,5 @@
1
+ declare enum HapAdaptiveLightingControllerMode {
2
+ AUTOMATIC = 1,
3
+ MANUAL = 2
4
+ }
5
+ export default HapAdaptiveLightingControllerMode;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var HapAdaptiveLightingControllerMode;
4
+ (function (HapAdaptiveLightingControllerMode) {
5
+ HapAdaptiveLightingControllerMode[HapAdaptiveLightingControllerMode["AUTOMATIC"] = 1] = "AUTOMATIC";
6
+ HapAdaptiveLightingControllerMode[HapAdaptiveLightingControllerMode["MANUAL"] = 2] = "MANUAL";
7
+ })(HapAdaptiveLightingControllerMode || (HapAdaptiveLightingControllerMode = {}));
8
+ exports.default = HapAdaptiveLightingControllerMode;
@@ -37,7 +37,10 @@ const MdnsUtils = () => {
37
37
  if (!availableInterfaces) {
38
38
  availableInterfaces = [];
39
39
  const networkInterfaces = os.networkInterfaces();
40
- Object.keys(networkInterfaces).forEach((key) => networkInterfaces[key].forEach((networkInterface) => availableInterfaces.push(networkInterface.address)));
40
+ Object.keys(networkInterfaces).forEach((key) => {
41
+ var _a;
42
+ return (_a = networkInterfaces[key]) === null || _a === void 0 ? void 0 : _a.forEach((networkInterface) => availableInterfaces.push(networkInterface.address));
43
+ });
41
44
  }
42
45
  return availableInterfaces.indexOf(value) > -1;
43
46
  };
@@ -184,6 +184,7 @@ module.exports = function (node) {
184
184
  done();
185
185
  };
186
186
  const getOrCreate = function (accessory, serviceInformation, parentService) {
187
+ var _a;
187
188
  const newService = new Service[serviceInformation.serviceName](serviceInformation.name, serviceInformation.UUID);
188
189
  log.debug(`Looking for service with UUID ${serviceInformation.UUID} ...`);
189
190
  let service = accessory.services.find((service) => {
@@ -202,6 +203,21 @@ module.exports = function (node) {
202
203
  }
203
204
  else {
204
205
  service = accessory.addService(newService);
206
+ if (serviceInformation.serviceName === 'Lightbulb' &&
207
+ serviceInformation.config.adaptiveLightingOptionsEnable) {
208
+ try {
209
+ const adaptiveLightingController = new hap_nodejs_1.AdaptiveLightingController(service, {
210
+ controllerMode: (_a = serviceInformation.config
211
+ .adaptiveLightingOptionsMode) !== null && _a !== void 0 ? _a : 1,
212
+ customTemperatureAdjustment: serviceInformation.config
213
+ .adaptiveLightingOptionsCustomTemperatureAdjustment,
214
+ });
215
+ accessory.configureController(adaptiveLightingController);
216
+ }
217
+ catch (error) {
218
+ log.error(`Failed to configure adaptive lightning due to ${error}`);
219
+ }
220
+ }
205
221
  }
206
222
  }
207
223
  else {
@@ -207,6 +207,7 @@ module.exports = function (node) {
207
207
  done();
208
208
  };
209
209
  const getOrCreate = function (accessory, serviceInformation, parentService) {
210
+ var _a;
210
211
  const newService = new Service[serviceInformation.serviceName](serviceInformation.name, serviceInformation.UUID);
211
212
  log.debug(`Looking for service with UUID ${serviceInformation.UUID} ...`);
212
213
  let service = accessory.services.find((service) => {
@@ -225,6 +226,21 @@ module.exports = function (node) {
225
226
  }
226
227
  else {
227
228
  service = accessory.addService(newService);
229
+ if (serviceInformation.serviceName === 'Lightbulb' &&
230
+ serviceInformation.config.adaptiveLightingOptionsEnable) {
231
+ try {
232
+ const adaptiveLightingController = new hap_nodejs_1.AdaptiveLightingController(service, {
233
+ controllerMode: (_a = serviceInformation.config
234
+ .adaptiveLightingOptionsMode) !== null && _a !== void 0 ? _a : 1,
235
+ customTemperatureAdjustment: serviceInformation.config
236
+ .adaptiveLightingOptionsCustomTemperatureAdjustment,
237
+ });
238
+ accessory.configureController(adaptiveLightingController);
239
+ }
240
+ catch (error) {
241
+ log.error(`Failed to configure adaptive lightning due to ${error}`);
242
+ }
243
+ }
228
244
  }
229
245
  }
230
246
  else {
@@ -194,6 +194,25 @@
194
194
  </div>
195
195
  </div>
196
196
 
197
+ <div id="adaptive-lightning-configuration" style="display: none; border: 1px solid var(--red-ui-secondary-border-color); padding: 12px 12px 0 12px; margin-bottom: 12px;">
198
+ <label>&nbsp;&nbsp;<i class="fa fa-cog"></i> Adaptive Lightning Configuration</label>
199
+ <div class="form-row">
200
+ <label for="node-input-adaptiveLightingOptionsEnable"><i class="fa fa-toggle-on"></i> Enable</label>
201
+ <input type="checkbox" id="node-input-adaptiveLightingOptionsEnable">
202
+ </div>
203
+ <div class="form-row">
204
+ <label for="node-input-adaptiveLightingOptionsMode"><i class="fa fa-hand-o-up"></i> Mode</label>
205
+ <select id="node-input-adaptiveLightingOptionsMode">
206
+ <option value="0" selected="selected">AUTOMATIC</option>
207
+ <option value="1">MANUAL</option>
208
+ </select>
209
+ </div>
210
+ <div class="form-row">
211
+ <label for="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment"><i class="fa fa-thermometer-quarter"></i> Custom Temperature Adjustment</label>
212
+ <input type="text" id="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment">
213
+ </div>
214
+ </div>
215
+
197
216
  <div class="form-row">
198
217
  <label for="node-input-characteristicProperties"><i class="fa fa-wrench"></i> Characteristic Properties</label>
199
218
  <input type="text" id="node-input-characteristicProperties" style="width: 70%">
@@ -474,7 +493,16 @@
474
493
  },
475
494
  outputs: {
476
495
  value: 2,
477
- }
496
+ },
497
+ adaptiveLightingOptionsEnable: {
498
+ value: false,
499
+ },
500
+ adaptiveLightingOptionsMode: {
501
+ value: 0,
502
+ },
503
+ adaptiveLightingOptionsCustomTemperatureAdjustment: {
504
+ value: undefined,
505
+ },
478
506
  },
479
507
  inputs: 1,
480
508
  outputs: 2,
@@ -581,6 +609,7 @@
581
609
  })
582
610
 
583
611
  let cameraConfiguration = $('#camera-configuration')
612
+ let adaptiveLightningConfiguration = $('#adaptive-lightning-configuration')
584
613
 
585
614
  selectServiceName
586
615
  .find('option')
@@ -601,6 +630,16 @@
601
630
  })
602
631
  .change()
603
632
 
633
+ selectServiceName
634
+ .change(function () {
635
+ if (this.value === 'Lightbulb') {
636
+ adaptiveLightningConfiguration.fadeIn('fast')
637
+ } else {
638
+ adaptiveLightningConfiguration.fadeOut('fast')
639
+ }
640
+ })
641
+ .change()
642
+
604
643
  $('#node-input-characteristicProperties').typedInput({
605
644
  type: 'json',
606
645
  types: ['json'],
@@ -194,6 +194,25 @@
194
194
  </div>
195
195
  </div>
196
196
 
197
+ <div id="adaptive-lightning-configuration" style="display: none; border: 1px solid var(--red-ui-secondary-border-color); padding: 12px 12px 0 12px; margin-bottom: 12px;">
198
+ <label>&nbsp;&nbsp;<i class="fa fa-cog"></i> Adaptive Lightning Configuration</label>
199
+ <div class="form-row">
200
+ <label for="node-input-adaptiveLightingOptionsEnable"><i class="fa fa-toggle-on"></i> Enable</label>
201
+ <input type="checkbox" id="node-input-adaptiveLightingOptionsEnable">
202
+ </div>
203
+ <div class="form-row">
204
+ <label for="node-input-adaptiveLightingOptionsMode"><i class="fa fa-hand-o-up"></i> Mode</label>
205
+ <select id="node-input-adaptiveLightingOptionsMode">
206
+ <option value="0" selected="selected">AUTOMATIC</option>
207
+ <option value="1">MANUAL</option>
208
+ </select>
209
+ </div>
210
+ <div class="form-row">
211
+ <label for="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment"><i class="fa fa-thermometer-quarter"></i> Custom Temperature Adjustment</label>
212
+ <input type="text" id="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment">
213
+ </div>
214
+ </div>
215
+
197
216
  <div class="form-row">
198
217
  <label for="node-input-characteristicProperties"><i class="fa fa-wrench"></i> Characteristic Properties</label>
199
218
  <input type="text" id="node-input-characteristicProperties" style="width: 70%">
@@ -484,7 +503,16 @@ if (nrchkbExperimental) {
484
503
  },
485
504
  outputs: {
486
505
  value: 1,
487
- }
506
+ },
507
+ adaptiveLightingOptionsEnable: {
508
+ value: false,
509
+ },
510
+ adaptiveLightingOptionsMode: {
511
+ value: 0,
512
+ },
513
+ adaptiveLightingOptionsCustomTemperatureAdjustment: {
514
+ value: undefined,
515
+ },
488
516
  },
489
517
  inputs: 1,
490
518
  outputs: 1,
@@ -583,6 +611,7 @@ if (nrchkbExperimental) {
583
611
  })
584
612
 
585
613
  let cameraConfiguration = $('#camera-configuration')
614
+ let adaptiveLightningConfiguration = $('#adaptive-lightning-configuration')
586
615
 
587
616
  selectServiceName
588
617
  .find('option')
@@ -603,6 +632,16 @@ if (nrchkbExperimental) {
603
632
  })
604
633
  .change()
605
634
 
635
+ selectServiceName
636
+ .change(function () {
637
+ if (this.value === 'Lightbulb') {
638
+ adaptiveLightningConfiguration.fadeIn('fast')
639
+ } else {
640
+ adaptiveLightningConfiguration.fadeOut('fast')
641
+ }
642
+ })
643
+ .change()
644
+
606
645
  $('#node-input-characteristicProperties').typedInput({
607
646
  type: 'json',
608
647
  types: ['json'],
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "node-red-contrib-homekit-bridged",
3
- "version": "1.6.1",
3
+ "version": "1.7.0-dev.1",
4
4
  "description": "Node-RED nodes to simulate Apple HomeKit devices.",
5
5
  "main": "build/nodes/nrchkb.js",
6
6
  "scripts": {
7
7
  "build": "npm run clean && tsc",
8
- "clean": "rimraf build/lib build/**/*.js",
8
+ "clean": "del-cli \"build/lib\" \"build/**/*.js\"",
9
9
  "test": "mocha -r ts-node/register './src/**/*.test.[tj]s' --exit --timeout 30000",
10
10
  "prettier": "prettier --write \"**/*.{js,ts}\"",
11
11
  "eslint": "eslint \"src/**/*.ts\"",
@@ -43,40 +43,39 @@
43
43
  "homepage": "https://github.com/NRCHKB/node-red-contrib-homekit-bridged#readme",
44
44
  "dependencies": {
45
45
  "@nrchkb/logger": "^2.0.2",
46
- "hap-nodejs": "0.11.1",
47
- "ip": "^2.0.1",
48
- "node-persist": "^3.1.3",
49
- "semver": "^7.6.0",
50
- "uuid": "^9.0.1"
46
+ "hap-nodejs": "0.12.2",
47
+ "node-persist": "^4.0.1",
48
+ "semver": "^7.6.2",
49
+ "uuid": "^10.0.0"
51
50
  },
52
51
  "devDependencies": {
53
- "@homebridge/ciao": "^1.1.8",
54
- "@node-red/registry": "^3.1.3",
52
+ "@homebridge/ciao": "^1.2.0",
53
+ "@node-red/registry": "^3.1.10",
55
54
  "@types/mocha": "^10.0.6",
56
- "@types/node": "^12",
55
+ "@types/node": "^18",
57
56
  "@types/node-persist": "^3.1.8",
58
- "@types/node-red": "^1.3.4",
59
- "@types/node-red-node-test-helper": "^0.3.3",
60
- "@types/semver": "^7.5.7",
57
+ "@types/node-red": "^1.3.5",
58
+ "@types/node-red-node-test-helper": "^0.3.4",
59
+ "@types/semver": "^7.5.8",
61
60
  "@types/uuid": "^9.0.8",
62
- "@typescript-eslint/eslint-plugin": "^7.0.2",
63
- "@typescript-eslint/parser": "^7.0.2",
61
+ "@typescript-eslint/eslint-plugin": "^7.13.0",
62
+ "@typescript-eslint/parser": "^7.13.0",
64
63
  "babel-eslint": "^10.1.0",
65
- "eslint": "^8.56.0",
64
+ "del-cli": "^5.1.0",
65
+ "eslint": "^8",
66
66
  "eslint-config-prettier": "^9.1.0",
67
67
  "eslint-plugin-prettier": "^5.1.3",
68
- "eslint-plugin-simple-import-sort": "^12.0.0",
68
+ "eslint-plugin-simple-import-sort": "^12.1.0",
69
69
  "husky": "^9.0.11",
70
- "mocha": "^10.3.0",
71
- "node-red": "^3.1.3",
72
- "node-red-node-test-helper": "^0.3.3",
73
- "prettier": "^3.2.5",
74
- "rimraf": "^5.0.5",
70
+ "mocha": "^10.4.0",
71
+ "node-red": "^3.1.10",
72
+ "node-red-node-test-helper": "^0.3.4",
73
+ "prettier": "^3.3.2",
75
74
  "ts-node": "^10.9.2",
76
- "typescript": "^5.3.3"
75
+ "typescript": "^5.4.5"
77
76
  },
78
77
  "engines": {
79
- "node": ">=12"
78
+ "node": ">=18"
80
79
  },
81
80
  "files": [
82
81
  "/build",