node-red-contrib-homekit-bridged 1.7.0-dev.0 → 1.7.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.
@@ -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')();
@@ -161,6 +161,7 @@ module.exports = (RED) => {
161
161
  config: self.config,
162
162
  }, self.parentService);
163
163
  self.characteristicProperties = CharacteristicUtils.load(self.service, self.config);
164
+ ServiceUtils.configureAdaptiveLightning();
164
165
  if (self.config.isParent) {
165
166
  BridgeUtils.delayedPublish(self);
166
167
  }
@@ -161,6 +161,7 @@ module.exports = (RED) => {
161
161
  config: self.config,
162
162
  }, self.parentService);
163
163
  self.characteristicProperties = CharacteristicUtils.load(self.service, self.config);
164
+ ServiceUtils.configureAdaptiveLightning();
164
165
  if (self.config.isParent) {
165
166
  BridgeUtils.delayedPublish(self);
166
167
  }
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');
@@ -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;
@@ -120,7 +120,8 @@ module.exports = function (node) {
120
120
  }
121
121
  };
122
122
  const onInput = function (msg) {
123
- if (msg.hasOwnProperty('payload')) {
123
+ var _a, _b;
124
+ if (msg.payload) {
124
125
  const type = typeof msg.payload;
125
126
  if (type !== 'object') {
126
127
  log.error(`Invalid payload type: ${type}`);
@@ -131,17 +132,17 @@ module.exports = function (node) {
131
132
  log.error('Invalid message (payload missing)');
132
133
  return;
133
134
  }
134
- const topic = node.config.topic ? node.config.topic : node.name;
135
+ const topic = (_a = node.config.topic) !== null && _a !== void 0 ? _a : node.name;
135
136
  if (node.config.filter && msg.topic !== topic) {
136
137
  log.debug("msg.topic doesn't match configured value and filter is enabled. Dropping message.");
137
138
  return;
138
139
  }
139
140
  let context = null;
140
- if (msg.payload.hasOwnProperty('Context')) {
141
+ if (msg.payload.Context) {
141
142
  context = msg.payload.Context;
142
143
  delete msg.payload.Context;
143
144
  }
144
- node.topic_in = msg.topic ? msg.topic : '';
145
+ node.topic_in = (_b = msg.topic) !== null && _b !== void 0 ? _b : '';
145
146
  Object.keys(msg.payload).map((key) => {
146
147
  var _a, _b;
147
148
  if (node.supported.indexOf(key) < 0) {
@@ -153,7 +154,7 @@ module.exports = function (node) {
153
154
  parentNode.reachable = value !== NO_RESPONSE_MSG;
154
155
  const characteristic = node.service.getCharacteristic(Characteristic[key]);
155
156
  if (context !== null) {
156
- characteristic.setValue(value, context);
157
+ characteristic.setValue(value, undefined, context);
157
158
  }
158
159
  else {
159
160
  characteristic.setValue(value);
@@ -274,6 +275,23 @@ module.exports = function (node) {
274
275
  log.error('Invalid message (required {"payload":{"nrchkb":{"setup":{}}}})');
275
276
  }
276
277
  };
278
+ const configureAdaptiveLightning = () => {
279
+ var _a;
280
+ if (node.service.name === 'Lightbulb' &&
281
+ node.config.adaptiveLightingOptionsEnable) {
282
+ try {
283
+ const adaptiveLightingController = new hap_nodejs_1.AdaptiveLightingController(node.service, {
284
+ controllerMode: (_a = node.config.adaptiveLightingOptionsMode) !== null && _a !== void 0 ? _a : 1,
285
+ customTemperatureAdjustment: node.config
286
+ .adaptiveLightingOptionsCustomTemperatureAdjustment,
287
+ });
288
+ node.accessory.configureController(adaptiveLightingController);
289
+ }
290
+ catch (error) {
291
+ log.error(`Failed to configure adaptive lightning due to ${error}`);
292
+ }
293
+ }
294
+ };
277
295
  return {
278
296
  getOrCreate,
279
297
  onCharacteristicGet,
@@ -283,5 +301,6 @@ module.exports = function (node) {
283
301
  onClose,
284
302
  waitForParent,
285
303
  handleWaitForSetup,
304
+ configureAdaptiveLightning,
286
305
  };
287
306
  };
@@ -9,6 +9,7 @@ const NRCHKBError_1 = __importDefault(require("../NRCHKBError"));
9
9
  const Storage_1 = require("../Storage");
10
10
  module.exports = function (node) {
11
11
  const log = (0, logger_1.logger)('NRCHKB', 'ServiceUtils2', node.config.name, node);
12
+ const ServiceUtilsLegacy = require('./ServiceUtils')(node);
12
13
  const HapNodeJS = require('hap-nodejs');
13
14
  const Service = HapNodeJS.Service;
14
15
  const Characteristic = HapNodeJS.Characteristic;
@@ -127,7 +128,7 @@ module.exports = function (node) {
127
128
  }
128
129
  };
129
130
  const onInput = function (msg) {
130
- var _a;
131
+ var _a, _b;
131
132
  if (msg.payload) {
132
133
  const type = typeof msg.payload;
133
134
  if (type !== 'object') {
@@ -139,7 +140,7 @@ module.exports = function (node) {
139
140
  log.error('Invalid message (payload missing)');
140
141
  return;
141
142
  }
142
- const topic = node.config.topic ? node.config.topic : node.name;
143
+ const topic = (_a = node.config.topic) !== null && _a !== void 0 ? _a : node.name;
143
144
  if (node.config.filter && msg.topic !== topic) {
144
145
  log.debug("msg.topic doesn't match configured value and filter is enabled. Dropping message.");
145
146
  return;
@@ -149,7 +150,7 @@ module.exports = function (node) {
149
150
  context = msg.payload.Context;
150
151
  delete msg.payload.Context;
151
152
  }
152
- node.topic_in = (_a = msg.topic) !== null && _a !== void 0 ? _a : '';
153
+ node.topic_in = (_b = msg.topic) !== null && _b !== void 0 ? _b : '';
153
154
  Object.keys(msg.payload).map((key) => {
154
155
  var _a, _b, _c;
155
156
  if (node.supported.indexOf(key) < 0) {
@@ -176,7 +177,7 @@ module.exports = function (node) {
176
177
  parentNode.reachable = value !== NO_RESPONSE_MSG;
177
178
  const characteristic = node.service.getCharacteristic(Characteristic[key]);
178
179
  if (context !== null) {
179
- characteristic.setValue(value, context);
180
+ characteristic.setValue(value, undefined, context);
180
181
  }
181
182
  else {
182
183
  characteristic.setValue(value);
@@ -306,5 +307,6 @@ module.exports = function (node) {
306
307
  onClose,
307
308
  waitForParent,
308
309
  handleWaitForSetup,
310
+ configureAdaptiveLightning: ServiceUtilsLegacy.configureAdaptiveLightning,
309
311
  };
310
312
  };
@@ -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" disabled>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" disabled>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,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-homekit-bridged",
3
- "version": "1.7.0-dev.0",
3
+ "version": "1.7.0-dev.2",
4
4
  "description": "Node-RED nodes to simulate Apple HomeKit devices.",
5
5
  "main": "build/nodes/nrchkb.js",
6
6
  "scripts": {
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@homebridge/ciao": "^1.2.0",
53
- "@node-red/registry": "^3.1.10",
53
+ "@node-red/registry": "^3.1.11",
54
54
  "@types/mocha": "^10.0.6",
55
55
  "@types/node": "^18",
56
56
  "@types/node-persist": "^3.1.8",
@@ -58,8 +58,8 @@
58
58
  "@types/node-red-node-test-helper": "^0.3.4",
59
59
  "@types/semver": "^7.5.8",
60
60
  "@types/uuid": "^9.0.8",
61
- "@typescript-eslint/eslint-plugin": "^7.13.0",
62
- "@typescript-eslint/parser": "^7.13.0",
61
+ "@typescript-eslint/eslint-plugin": "^7.13.1",
62
+ "@typescript-eslint/parser": "^7.13.1",
63
63
  "babel-eslint": "^10.1.0",
64
64
  "del-cli": "^5.1.0",
65
65
  "eslint": "^8",
@@ -68,7 +68,7 @@
68
68
  "eslint-plugin-simple-import-sort": "^12.1.0",
69
69
  "husky": "^9.0.11",
70
70
  "mocha": "^10.4.0",
71
- "node-red": "^3.1.10",
71
+ "node-red": "^3.1.11",
72
72
  "node-red-node-test-helper": "^0.3.4",
73
73
  "prettier": "^3.3.2",
74
74
  "ts-node": "^10.9.2",