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

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.
@@ -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
  }
@@ -1,8 +1,32 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ const util = __importStar(require("node:util"));
6
30
  const logger_1 = require("@nrchkb/logger");
7
31
  const hap_nodejs_1 = require("hap-nodejs");
8
32
  const NRCHKBError_1 = __importDefault(require("../NRCHKBError"));
@@ -32,7 +56,7 @@ module.exports = function (node) {
32
56
  };
33
57
  const onCharacteristicGet = function (callback, context, connection) {
34
58
  var _a, _b;
35
- log.debug(`onCharacteristicGet with status: ${this.statusCode}, value: ${this.value}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable} with context ${JSON.stringify(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
59
+ log.debug(`onCharacteristicGet with status: ${this.statusCode}, value: ${this.value}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable} with context ${util.inspect(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
36
60
  if (callback) {
37
61
  try {
38
62
  callback(((_b = node.parentNode) !== null && _b !== void 0 ? _b : node).reachable
@@ -92,7 +116,7 @@ module.exports = function (node) {
92
116
  const onCharacteristicSet = (allCharacteristics) => function (newValue, callback, context, connection) {
93
117
  var _a, _b;
94
118
  log.debug(`onCharacteristicSet with status: ${this.statusCode}, value: ${this.value}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable}
95
- with context ${JSON.stringify(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
119
+ with context ${util.inspect(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
96
120
  try {
97
121
  if (callback) {
98
122
  callback(((_b = node.parentNode) !== null && _b !== void 0 ? _b : node).reachable
@@ -110,7 +134,7 @@ module.exports = function (node) {
110
134
  var _a;
111
135
  const { oldValue, newValue, context, originator, reason } = change;
112
136
  log.debug(`onCharacteristicChange with reason: ${reason}, oldValue: ${oldValue}, newValue: ${newValue}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable}
113
- with context ${JSON.stringify(context)} on connection ${originator === null || originator === void 0 ? void 0 : originator.sessionID}`);
137
+ with context ${util.inspect(context)} on connection ${originator === null || originator === void 0 ? void 0 : originator.sessionID}`);
114
138
  if (oldValue != newValue) {
115
139
  onValueChange.call(this, allCharacteristics, 0, {
116
140
  oldValue,
@@ -120,7 +144,8 @@ module.exports = function (node) {
120
144
  }
121
145
  };
122
146
  const onInput = function (msg) {
123
- if (msg.hasOwnProperty('payload')) {
147
+ var _a, _b;
148
+ if (msg.payload) {
124
149
  const type = typeof msg.payload;
125
150
  if (type !== 'object') {
126
151
  log.error(`Invalid payload type: ${type}`);
@@ -131,17 +156,17 @@ module.exports = function (node) {
131
156
  log.error('Invalid message (payload missing)');
132
157
  return;
133
158
  }
134
- const topic = node.config.topic ? node.config.topic : node.name;
159
+ const topic = (_a = node.config.topic) !== null && _a !== void 0 ? _a : node.name;
135
160
  if (node.config.filter && msg.topic !== topic) {
136
161
  log.debug("msg.topic doesn't match configured value and filter is enabled. Dropping message.");
137
162
  return;
138
163
  }
139
164
  let context = null;
140
- if (msg.payload.hasOwnProperty('Context')) {
165
+ if (msg.payload.Context) {
141
166
  context = msg.payload.Context;
142
167
  delete msg.payload.Context;
143
168
  }
144
- node.topic_in = msg.topic ? msg.topic : '';
169
+ node.topic_in = (_b = msg.topic) !== null && _b !== void 0 ? _b : '';
145
170
  Object.keys(msg.payload).map((key) => {
146
171
  var _a, _b;
147
172
  if (node.supported.indexOf(key) < 0) {
@@ -153,7 +178,7 @@ module.exports = function (node) {
153
178
  parentNode.reachable = value !== NO_RESPONSE_MSG;
154
179
  const characteristic = node.service.getCharacteristic(Characteristic[key]);
155
180
  if (context !== null) {
156
- characteristic.setValue(value, context);
181
+ characteristic.setValue(value, undefined, context);
157
182
  }
158
183
  else {
159
184
  characteristic.setValue(value);
@@ -184,7 +209,6 @@ module.exports = function (node) {
184
209
  done();
185
210
  };
186
211
  const getOrCreate = function (accessory, serviceInformation, parentService) {
187
- var _a;
188
212
  const newService = new Service[serviceInformation.serviceName](serviceInformation.name, serviceInformation.UUID);
189
213
  log.debug(`Looking for service with UUID ${serviceInformation.UUID} ...`);
190
214
  let service = accessory.services.find((service) => {
@@ -203,21 +227,6 @@ module.exports = function (node) {
203
227
  }
204
228
  else {
205
229
  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
- }
221
230
  }
222
231
  }
223
232
  else {
@@ -290,6 +299,31 @@ module.exports = function (node) {
290
299
  log.error('Invalid message (required {"payload":{"nrchkb":{"setup":{}}}})');
291
300
  }
292
301
  };
302
+ const configureAdaptiveLightning = () => {
303
+ if (node.service.UUID === Service.Lightbulb.UUID &&
304
+ node.config.adaptiveLightingOptionsEnable) {
305
+ try {
306
+ node.service.getCharacteristic(Characteristic.Brightness);
307
+ node.service.getCharacteristic(Characteristic.ColorTemperature);
308
+ const options = {
309
+ controllerMode: node.config.adaptiveLightingOptionsMode
310
+ ? +node.config.adaptiveLightingOptionsMode
311
+ : 1,
312
+ customTemperatureAdjustment: node.config
313
+ .adaptiveLightingOptionsCustomTemperatureAdjustment
314
+ ? +node.config
315
+ .adaptiveLightingOptionsCustomTemperatureAdjustment
316
+ : undefined,
317
+ };
318
+ log.trace(`Configuring Adaptive Lighting with options: ${options}`);
319
+ const adaptiveLightingController = new hap_nodejs_1.AdaptiveLightingController(node.service, options);
320
+ node.accessory.configureController(adaptiveLightingController);
321
+ }
322
+ catch (error) {
323
+ log.error(`Failed to configure Adaptive Lightning due to ${error}`);
324
+ }
325
+ }
326
+ };
293
327
  return {
294
328
  getOrCreate,
295
329
  onCharacteristicGet,
@@ -299,5 +333,6 @@ module.exports = function (node) {
299
333
  onClose,
300
334
  waitForParent,
301
335
  handleWaitForSetup,
336
+ configureAdaptiveLightning,
302
337
  };
303
338
  };
@@ -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);
@@ -207,7 +208,6 @@ module.exports = function (node) {
207
208
  done();
208
209
  };
209
210
  const getOrCreate = function (accessory, serviceInformation, parentService) {
210
- var _a;
211
211
  const newService = new Service[serviceInformation.serviceName](serviceInformation.name, serviceInformation.UUID);
212
212
  log.debug(`Looking for service with UUID ${serviceInformation.UUID} ...`);
213
213
  let service = accessory.services.find((service) => {
@@ -226,21 +226,6 @@ module.exports = function (node) {
226
226
  }
227
227
  else {
228
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
- }
244
229
  }
245
230
  }
246
231
  else {
@@ -322,5 +307,6 @@ module.exports = function (node) {
322
307
  onClose,
323
308
  waitForParent,
324
309
  handleWaitForSetup,
310
+ configureAdaptiveLightning: ServiceUtilsLegacy.configureAdaptiveLightning,
325
311
  };
326
312
  };
@@ -203,13 +203,13 @@
203
203
  <div class="form-row">
204
204
  <label for="node-input-adaptiveLightingOptionsMode"><i class="fa fa-hand-o-up"></i> Mode</label>
205
205
  <select id="node-input-adaptiveLightingOptionsMode">
206
- <option value="0" selected="selected">AUTOMATIC</option>
207
- <option value="1">MANUAL</option>
206
+ <option value="1" selected="selected">AUTOMATIC</option>
207
+ <option value="2" disabled>MANUAL</option>
208
208
  </select>
209
209
  </div>
210
210
  <div class="form-row">
211
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">
212
+ <input type="number" id="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment">
213
213
  </div>
214
214
  </div>
215
215
 
@@ -498,10 +498,12 @@
498
498
  value: false,
499
499
  },
500
500
  adaptiveLightingOptionsMode: {
501
- value: 0,
501
+ value: 1,
502
+ validate: RED.validators.number()
502
503
  },
503
504
  adaptiveLightingOptionsCustomTemperatureAdjustment: {
504
- value: undefined,
505
+ value: 0,
506
+ validate: RED.validators.number()
505
507
  },
506
508
  },
507
509
  inputs: 1,
@@ -203,13 +203,13 @@
203
203
  <div class="form-row">
204
204
  <label for="node-input-adaptiveLightingOptionsMode"><i class="fa fa-hand-o-up"></i> Mode</label>
205
205
  <select id="node-input-adaptiveLightingOptionsMode">
206
- <option value="0" selected="selected">AUTOMATIC</option>
207
- <option value="1">MANUAL</option>
206
+ <option value="1" selected="selected">AUTOMATIC</option>
207
+ <option value="2" disabled>MANUAL</option>
208
208
  </select>
209
209
  </div>
210
210
  <div class="form-row">
211
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">
212
+ <input type="number" id="node-input-adaptiveLightingOptionsCustomTemperatureAdjustment">
213
213
  </div>
214
214
  </div>
215
215
 
@@ -508,10 +508,12 @@ if (nrchkbExperimental) {
508
508
  value: false,
509
509
  },
510
510
  adaptiveLightingOptionsMode: {
511
- value: 0,
511
+ value: 1,
512
+ validate: RED.validators.number()
512
513
  },
513
514
  adaptiveLightingOptionsCustomTemperatureAdjustment: {
514
- value: undefined,
515
+ value: 0,
516
+ validate: RED.validators.number()
515
517
  },
516
518
  },
517
519
  inputs: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-homekit-bridged",
3
- "version": "1.7.0-dev.1",
3
+ "version": "1.7.0-dev.3",
4
4
  "description": "Node-RED nodes to simulate Apple HomeKit devices.",
5
5
  "main": "build/nodes/nrchkb.js",
6
6
  "scripts": {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "homepage": "https://github.com/NRCHKB/node-red-contrib-homekit-bridged#readme",
44
44
  "dependencies": {
45
- "@nrchkb/logger": "^2.0.2",
45
+ "@nrchkb/logger": "^3.0.0",
46
46
  "hap-nodejs": "0.12.2",
47
47
  "node-persist": "^4.0.1",
48
48
  "semver": "^7.6.2",
@@ -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",