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

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.
@@ -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,9 +150,9 @@ 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
- var _a, _b, _c;
155
+ var _a, _b, _c, _d, _e;
155
156
  if (node.supported.indexOf(key) < 0) {
156
157
  if (node.config.useEventCallback &&
157
158
  Storage_1.Storage.uuid4Validate(key)) {
@@ -166,17 +167,25 @@ module.exports = function (node) {
166
167
  log.error(`Callback ${callbackID} timeout`);
167
168
  }
168
169
  }
170
+ else if (key === 'AdaptiveLightingController' &&
171
+ node.adaptiveLightingController) {
172
+ const value = (_b = msg.payload) === null || _b === void 0 ? void 0 : _b[key];
173
+ const event = value === null || value === void 0 ? void 0 : value.event;
174
+ if (event === 'disable') {
175
+ (_c = node.adaptiveLightingController) === null || _c === void 0 ? void 0 : _c.disableAdaptiveLighting();
176
+ }
177
+ }
169
178
  else {
170
179
  log.error(`Instead of '${key}' try one of these characteristics: '${node.supported.join("', '")}'`);
171
180
  }
172
181
  }
173
182
  else {
174
- const value = (_b = msg.payload) === null || _b === void 0 ? void 0 : _b[key];
175
- const parentNode = (_c = node.parentNode) !== null && _c !== void 0 ? _c : node;
183
+ const value = (_d = msg.payload) === null || _d === void 0 ? void 0 : _d[key];
184
+ const parentNode = (_e = node.parentNode) !== null && _e !== void 0 ? _e : node;
176
185
  parentNode.reachable = value !== NO_RESPONSE_MSG;
177
186
  const characteristic = node.service.getCharacteristic(Characteristic[key]);
178
187
  if (context !== null) {
179
- characteristic.setValue(value, context);
188
+ characteristic.setValue(value, undefined, context);
180
189
  }
181
190
  else {
182
191
  characteristic.setValue(value);
@@ -207,7 +216,6 @@ module.exports = function (node) {
207
216
  done();
208
217
  };
209
218
  const getOrCreate = function (accessory, serviceInformation, parentService) {
210
- var _a;
211
219
  const newService = new Service[serviceInformation.serviceName](serviceInformation.name, serviceInformation.UUID);
212
220
  log.debug(`Looking for service with UUID ${serviceInformation.UUID} ...`);
213
221
  let service = accessory.services.find((service) => {
@@ -226,21 +234,6 @@ module.exports = function (node) {
226
234
  }
227
235
  else {
228
236
  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
237
  }
245
238
  }
246
239
  else {
@@ -322,5 +315,6 @@ module.exports = function (node) {
322
315
  onClose,
323
316
  waitForParent,
324
317
  handleWaitForSetup,
318
+ configureAdaptiveLightning: ServiceUtilsLegacy.configureAdaptiveLightning,
325
319
  };
326
320
  };
@@ -55,9 +55,14 @@
55
55
  <label for="node-config-input-allowMessagePassthrough" style="width: 70%;">&nbsp;&nbsp;<i class="fa fa-step-forward"></i> Allow Message Passthrough</label>
56
56
  </div>
57
57
  <hr>
58
+ <div class="form-row">
59
+ <label for="node-config-input-bind"><i class="fa fa-filter"></i> Bind</label>
60
+ <input type="text" id="node-config-input-bind" placeholder="::">
61
+ <input type="hidden" id="node-config-input-bindType">
62
+ </div>
58
63
  <div class="form-row">
59
64
  <input type="checkbox" id="node-config-input-customMdnsConfig" style="display: inline-block; width: auto; vertical-align: top;">
60
- <label for="node-config-input-customMdnsConfig" style="width: 70%;">&nbsp;&nbsp;<i class="fa fa-filter"></i> Custom MDNS Configuration</label>
65
+ <label for="node-config-input-customMdnsConfig" style="width: 70%;">&nbsp;&nbsp;<i class="fa fa-filter"></i> Custom MDNS Configuration (DEPRECATED, use Bind)</label>
61
66
  </div>
62
67
  <div id="mdns-configuration" style="display: none;">
63
68
  <div class="form-row">
@@ -95,7 +100,7 @@
95
100
 
96
101
  <script data-help-name="homekit-bridge" type="text/x-red">
97
102
  <h3 id="toc_4">Bridge</h3>
98
- <p>The Bridge node is a configuration node, specifying the <em>bridge</em> that iOS sees, i.e. the device that is manually being added by the user. All accessories behind a bridge noded are then automatically added by iOS.
103
+ <p>The Bridge node is a configuration node, specifying the <em>bridge</em> that iOS sees, i.e. the device that is manually being added by the user. All accessories behind a bridge node are then automatically added by iOS.
99
104
  </p>
100
105
  <ul>
101
106
  <li><strong>Pin Code</strong>: Specify the Pin for the pairing process.</li>
@@ -107,8 +112,61 @@
107
112
  <li><strong>Hardware Revision</strong>: Should be a version number string in the form of <em>MAJOR.MINOR.REVISION</em> e.g. <em>1.2.0</em>. Other types of strings are ignored and won't be displayed.</li>
108
113
  <li><strong>Software Revision</strong>: Should be a version number string in the form of <em>MAJOR.MINOR.REVISION</em> e.g. <em>1.2.0</em>. Other types of strings are ignored and won't be displayed.</li>
109
114
  <li><strong>Name</strong>: If you intend to simulate a rocket, then why don&#39;t you call it <em>Rocket</em>. Name should be maximum 64 chars long and not contain <pre>.</pre></li>
110
- <li><strong>Allow Message Passthrough</strong>: If you allow then message from node input will be send to node output.</li>
111
- <li><strong>Custom MDNS Configuration</strong>: Check if you would like to use custom mdns configuration.</li>
115
+ <li><strong>Allow Message Passthrough</strong>: If you allow then message from node input will be sent to node output.</li>
116
+ <li><strong>Bind</strong>: Defines the host where the HAP server will be bound to. </li>
117
+ <ul>
118
+ <li>
119
+ Defines the host where the HAP server will be bound to.
120
+ When undefined the HAP server will bind to all available interfaces
121
+ (see https://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback).
122
+
123
+ This property accepts a mixture of IPAddresses and network interface names.
124
+ Depending on the mixture of supplied addresses/names hap-nodejs will bind differently.
125
+
126
+ It is advised to not just bind to a specific address, but specifying the interface name
127
+ in oder to bind on all address records (and ip version) available.
128
+
129
+ HAP-NodeJS (or the underlying ciao library) will not report about misspelled interface names,
130
+ as it could be that the interface is currently just down and will come up later.
131
+
132
+ Here are a few examples:
133
+ - bind: "::"
134
+ Pretty much identical to not specifying anything, as most systems (with ipv6 support)
135
+ will default to the unspecified ipv6 address (with dual stack support).
136
+
137
+ - bind: "0.0.0.0"
138
+ Binding TCP socket to the unspecified ipv4 address.
139
+ The mdns advertisement will exclude any ipv6 address records.
140
+
141
+ - bind: ["en0", "lo0"]
142
+ The mdns advertising will advertise all records of the en0 and loopback interface (if available) and
143
+ will also react to address changes on those interfaces.
144
+ In order for the HAP server to accept all those address records (which may contain ipv6 records)
145
+ it will bind on the unspecified ipv6 address "::" (assuming dual stack is supported).
146
+
147
+ - bind: ["en0", "lo0", "0.0.0.0"]
148
+ Same as above, only that the HAP server will bind on the unspecified ipv4 address "0.0.0.0".
149
+ The mdns advertisement will not advertise any ipv6 records.
150
+
151
+ - bind: "169.254.104.90"
152
+ This will bind the HAP server to the address 0.0.0.0.
153
+ The mdns advertisement will only advertise the A record 169.254.104.90.
154
+ If the given network interface of that address encounters an ip address change (to a different address),
155
+ the mdns advertisement will result in not advertising an address at all.
156
+ So it is advised to specify an interface name instead of a specific address.
157
+ This is identical with ipv6 addresses.
158
+
159
+ - bind: ["169.254.104.90", "192.168.1.4"]
160
+ As the HAP TCP socket can only bind to a single address, when specifying multiple ip addresses
161
+ the HAP server will bind to the unspecified ip address (0.0.0.0 if only ipv4 addresses are supplied,
162
+ :: if a mixture or only ipv6 addresses are supplied).
163
+ The mdns advertisement will only advertise the specified ip addresses.
164
+ If the given network interface of that address encounters an ip address change (to different addresses),
165
+ the mdns advertisement will result in not advertising an address at all.
166
+ So it is advised to specify an interface name instead of a specific address.
167
+ </li>
168
+ </ul>
169
+ <li><strong>Custom MDNS Configuration (DEPRECATED, use Bind)</strong>: Check if you would like to use custom mdns configuration.</li>
112
170
  <ul>
113
171
  <li><strong>Multicast</strong>: Use udp multicasting. Optional. Default true.</li>
114
172
  <li><strong>Multicast Interface IP:</strong>: Explicitly specify a network interface. Optional. Defaults to all.</li>
@@ -137,7 +195,7 @@
137
195
  },
138
196
  pinCode: {
139
197
  required: true,
140
- validate: pinCodeRegex,
198
+ validate: validatePinCode,
141
199
  },
142
200
  port: {
143
201
  required: false,
@@ -185,37 +243,42 @@
185
243
  required: false,
186
244
  validate: versionValidator,
187
245
  },
246
+ bind: {
247
+ value: undefined,
248
+ required: false,
249
+ },
250
+ bindType: {
251
+ value: undefined,
252
+ required: false,
253
+ },
188
254
  customMdnsConfig: {
189
255
  value: false,
190
256
  required: false,
257
+ validate: (value) => !value
191
258
  },
192
259
  mdnsMulticast: {
193
260
  value: true,
194
- required: false,
261
+ required: false
195
262
  },
196
263
  mdnsInterface: {
197
- required: false,
264
+ required: false
198
265
  },
199
266
  mdnsPort: {
200
- required: false,
201
- validate: function (value) {
202
- if (value) return RED.validators.port(value)
203
- else return true
204
- },
267
+ required: false
205
268
  },
206
269
  mdnsIp: {
207
- required: false,
270
+ required: false
208
271
  },
209
272
  mdnsTtl: {
210
- required: false,
273
+ required: false
211
274
  },
212
275
  mdnsLoopback: {
213
276
  value: true,
214
- required: false,
277
+ required: false
215
278
  },
216
279
  mdnsReuseAddr: {
217
280
  value: true,
218
- required: false,
281
+ required: false
219
282
  },
220
283
  allowMessagePassthrough: {
221
284
  value: true,
@@ -229,9 +292,9 @@
229
292
  return this.bridgeName ? 'node_label_italic' : ''
230
293
  },
231
294
  oneditprepare: function () {
232
- if (!pinCodeRegex(this.pinCode)) {
295
+ if (!validatePinCode(this.pinCode)) {
233
296
  this.pinCode = generatePinCode()
234
- $("#node-config-input-pinCode").val(this.pinCode)
297
+ $('#node-config-input-pinCode').val(this.pinCode)
235
298
  }
236
299
 
237
300
  if (typeof this.allowMessagePassthrough == 'undefined') {
@@ -256,6 +319,12 @@
256
319
  }
257
320
  })
258
321
  .change()
322
+
323
+ $('#node-config-input-bind').typedInput({
324
+ typeField: '#node-config-input-bindType',
325
+ default: 'str',
326
+ types: ['json', 'str']
327
+ })
259
328
  },
260
329
  })
261
330
  </script>