matterbridge 2.2.5-dev.4 → 2.2.6-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.
package/dist/frontend.js CHANGED
@@ -556,31 +556,34 @@ export class Frontend {
556
556
  return;
557
557
  }
558
558
  if (command === 'setmdnsinterface') {
559
- param = param.slice(1, -1);
560
- this.matterbridge.matterbridgeInformation.mattermdnsinterface = param;
561
- this.log.debug('Matter.js mdns interface:', param === '' ? 'All interfaces' : param);
562
- await this.matterbridge.nodeContext?.set('mattermdnsinterface', param);
559
+ if (param === 'json' && isValidString(req.body.value)) {
560
+ this.matterbridge.matterbridgeInformation.mattermdnsinterface = req.body.value;
561
+ this.log.debug(`Matter.js mdns interface: ${req.body.value === '' ? 'all interfaces' : req.body.value}`);
562
+ await this.matterbridge.nodeContext?.set('mattermdnsinterface', req.body.value);
563
+ }
563
564
  res.json({ message: 'Command received' });
564
565
  return;
565
566
  }
566
567
  if (command === 'setipv4address') {
567
- param = param.slice(1, -1);
568
- this.matterbridge.matterbridgeInformation.matteripv4address = param;
569
- this.log.debug('Matter.js ipv4 address:', param === '' ? 'All ipv4 addresses' : param);
570
- await this.matterbridge.nodeContext?.set('matteripv4address', param);
568
+ if (param === 'json' && isValidString(req.body.value)) {
569
+ this.log.debug(`Matter.js ipv4 address: ${req.body.value === '' ? 'all ipv4 addresses' : req.body.value}`);
570
+ this.matterbridge.matterbridgeInformation.matteripv4address = req.body.value;
571
+ await this.matterbridge.nodeContext?.set('matteripv4address', req.body.value);
572
+ }
571
573
  res.json({ message: 'Command received' });
572
574
  return;
573
575
  }
574
576
  if (command === 'setipv6address') {
575
- param = param.slice(1, -1);
576
- this.matterbridge.matterbridgeInformation.matteripv6address = param;
577
- this.log.debug('Matter.js ipv6 address:', param === '' ? 'All ipv6 addresses' : param);
578
- await this.matterbridge.nodeContext?.set('matteripv6address', param);
577
+ if (param === 'json' && isValidString(req.body.value)) {
578
+ this.log.debug(`Matter.js ipv6 address: ${req.body.value === '' ? 'all ipv6 addresses' : req.body.value}`);
579
+ this.matterbridge.matterbridgeInformation.matteripv6address = req.body.value;
580
+ await this.matterbridge.nodeContext?.set('matteripv6address', req.body.value);
581
+ }
579
582
  res.json({ message: 'Command received' });
580
583
  return;
581
584
  }
582
585
  if (command === 'setmatterport') {
583
- const port = Math.min(Math.max(parseInt(param), 5540), 5560);
586
+ const port = Math.min(Math.max(parseInt(req.body.value), 5540), 5560);
584
587
  this.matterbridge.matterbridgeInformation.matterPort = port;
585
588
  this.log.debug(`Set matter commissioning port to ${CYAN}${port}${db}`);
586
589
  await this.matterbridge.nodeContext?.set('matterport', port);
@@ -588,7 +591,7 @@ export class Frontend {
588
591
  return;
589
592
  }
590
593
  if (command === 'setmatterdiscriminator') {
591
- const discriminator = Math.min(Math.max(parseInt(param), 1000), 4095);
594
+ const discriminator = Math.min(Math.max(parseInt(req.body.value), 1000), 4095);
592
595
  this.matterbridge.matterbridgeInformation.matterDiscriminator = discriminator;
593
596
  this.log.debug(`Set matter commissioning discriminator to ${CYAN}${discriminator}${db}`);
594
597
  await this.matterbridge.nodeContext?.set('matterdiscriminator', discriminator);
@@ -596,7 +599,7 @@ export class Frontend {
596
599
  return;
597
600
  }
598
601
  if (command === 'setmatterpasscode') {
599
- const passcode = Math.min(Math.max(parseInt(param), 10000000), 90000000);
602
+ const passcode = Math.min(Math.max(parseInt(req.body.value), 10000000), 90000000);
600
603
  this.matterbridge.matterbridgeInformation.matterPasscode = passcode;
601
604
  this.log.debug(`Set matter commissioning passcode to ${CYAN}${passcode}${db}`);
602
605
  await this.matterbridge.nodeContext?.set('matterpasscode', passcode);
@@ -338,6 +338,17 @@ export class Matterbridge extends EventEmitter {
338
338
  });
339
339
  }
340
340
  this.log.debug(`Matter logLevel: ${Logger.defaultLogLevel} fileLoger: ${this.matterbridgeInformation.matterFileLogger}.`);
341
+ const networkInterfaces = os.networkInterfaces();
342
+ const availableAddresses = Object.entries(networkInterfaces);
343
+ const availableInterfaces = Object.keys(networkInterfaces);
344
+ for (const [ifaceName, ifaces] of availableAddresses) {
345
+ if (ifaces && ifaces.length > 0) {
346
+ this.log.debug(`Network interface: ${CYAN}${ifaceName}${db}:`);
347
+ ifaces.forEach((iface) => {
348
+ this.log.debug(`- ${CYAN}${iface.family}${db} address ${CYAN}${iface.address}${db} netmask ${CYAN}${iface.netmask}${db} mac ${CYAN}${iface.mac}${db} scopeid ${CYAN}${iface.scopeid}${db} ${iface.internal ? 'internal' : 'external'}`);
349
+ });
350
+ }
351
+ }
341
352
  if (hasParameter('mdnsinterface')) {
342
353
  this.mdnsInterface = getParameter('mdnsinterface');
343
354
  }
@@ -347,14 +358,12 @@ export class Matterbridge extends EventEmitter {
347
358
  this.mdnsInterface = undefined;
348
359
  }
349
360
  if (this.mdnsInterface) {
350
- const networkInterfaces = os.networkInterfaces();
351
- const availableInterfaces = Object.keys(networkInterfaces);
352
361
  if (!availableInterfaces.includes(this.mdnsInterface)) {
353
362
  this.log.error(`Invalid mdnsInterface: ${this.mdnsInterface}. Available interfaces are: ${availableInterfaces.join(', ')}. Using all available interfaces.`);
354
363
  this.mdnsInterface = undefined;
355
364
  }
356
365
  else {
357
- this.log.info(`Using mdnsInterface '${this.mdnsInterface}' for the Matter server MdnsBroadcaster.`);
366
+ this.log.info(`Using mdnsInterface ${CYAN}${this.mdnsInterface}${nf} for the Matter MdnsBroadcaster.`);
358
367
  }
359
368
  }
360
369
  if (this.mdnsInterface)
@@ -367,6 +376,20 @@ export class Matterbridge extends EventEmitter {
367
376
  if (this.ipv4address === '')
368
377
  this.ipv4address = undefined;
369
378
  }
379
+ if (this.ipv4address) {
380
+ let isValid = false;
381
+ for (const [ifaceName, ifaces] of availableAddresses) {
382
+ if (ifaces && ifaces.find((iface) => iface.address === this.ipv4address)) {
383
+ this.log.info(`Using ipv4address ${CYAN}${this.ipv4address}${nf} on interface ${CYAN}${ifaceName}${nf} for the Matter server node.`);
384
+ isValid = true;
385
+ break;
386
+ }
387
+ }
388
+ if (!isValid) {
389
+ this.log.error(`Invalid ipv4address: ${this.ipv4address}. Using all available addresses.`);
390
+ this.ipv4address = undefined;
391
+ }
392
+ }
370
393
  if (hasParameter('ipv6address')) {
371
394
  this.ipv6address = getParameter('ipv6address');
372
395
  }
@@ -375,6 +398,25 @@ export class Matterbridge extends EventEmitter {
375
398
  if (this.ipv6address === '')
376
399
  this.ipv6address = undefined;
377
400
  }
401
+ if (this.ipv6address) {
402
+ let isValid = false;
403
+ for (const [ifaceName, ifaces] of availableAddresses) {
404
+ if (ifaces && ifaces.find((iface) => (iface.scopeid === undefined || iface.scopeid === 0) && iface.address === this.ipv6address)) {
405
+ this.log.info(`Using ipv6address ${CYAN}${this.ipv6address}${nf} on interface ${CYAN}${ifaceName}${nf} for the Matter server node.`);
406
+ isValid = true;
407
+ break;
408
+ }
409
+ if (ifaces && ifaces.find((iface) => iface.scopeid && iface.scopeid > 0 && iface.address + '%' + (process.platform === 'win32' ? iface.scopeid : ifaceName) === this.ipv6address)) {
410
+ this.log.info(`Using ipv6address ${CYAN}${this.ipv6address}${nf} on interface ${CYAN}${ifaceName}${nf} for the Matter server node.`);
411
+ isValid = true;
412
+ break;
413
+ }
414
+ }
415
+ if (!isValid) {
416
+ this.log.error(`Invalid ipv6address: ${this.ipv6address}. Using all available addresses.`);
417
+ this.ipv6address = undefined;
418
+ }
419
+ }
378
420
  this.plugins = new PluginManager(this);
379
421
  await this.plugins.loadFromStorage();
380
422
  this.plugins.logLevel = this.log.logLevel;
@@ -4,7 +4,7 @@ import { isValidNumber, isValidObject } from './utils/export.js';
4
4
  import { MatterbridgeBehavior, MatterbridgeBehaviorDevice, MatterbridgeIdentifyServer, MatterbridgeOnOffServer, MatterbridgeLevelControlServer, MatterbridgeColorControlServer, MatterbridgeWindowCoveringServer, MatterbridgeThermostatServer, MatterbridgeFanControlServer, MatterbridgeDoorLockServer, MatterbridgeModeSelectServer, MatterbridgeValveConfigurationAndControlServer, MatterbridgeSmokeCoAlarmServer, MatterbridgeBooleanStateConfigurationServer, MatterbridgeSwitchServer, } from './matterbridgeBehaviors.js';
5
5
  import { addClusterServers, addFixedLabel, addOptionalClusterServers, addRequiredClusterServers, addUserLabel, capitalizeFirstLetter, createUniqueId, getBehavior, getBehaviourTypesFromClusterClientIds, getBehaviourTypesFromClusterServerIds, getDefaultFlowMeasurementClusterServer, getDefaultIlluminanceMeasurementClusterServer, getDefaultPressureMeasurementClusterServer, getDefaultRelativeHumidityMeasurementClusterServer, getDefaultTemperatureMeasurementClusterServer, getDefaultOccupancySensingClusterServer, lowercaseFirstLetter, updateAttribute, getClusterId, getAttributeId, setAttribute, getAttribute, checkNotLatinCharacters, generateUniqueId, subscribeAttribute, } from './matterbridgeEndpointHelpers.js';
6
6
  import { Endpoint, Lifecycle, MutableEndpoint, NamedHandler, SupportedBehaviors, VendorId } from '@matter/main';
7
- import { getClusterNameById, MeasurementType } from '@matter/main/types';
7
+ import { ClusterType, getClusterNameById, MeasurementType } from '@matter/main/types';
8
8
  import { Descriptor } from '@matter/main/clusters/descriptor';
9
9
  import { PowerSource } from '@matter/main/clusters/power-source';
10
10
  import { BridgedDeviceBasicInformation } from '@matter/main/clusters/bridged-device-basic-information';
@@ -518,7 +518,7 @@ export class MatterbridgeEndpoint extends Endpoint {
518
518
  return this;
519
519
  }
520
520
  createOnOffClusterServer(onOff = false) {
521
- this.behaviors.require(MatterbridgeOnOffServer, {
521
+ this.behaviors.require(MatterbridgeOnOffServer.for(ClusterType(OnOff.Base)), {
522
522
  onOff,
523
523
  });
524
524
  return this;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.ea7910e9.css",
4
- "main.js": "./static/js/main.839276c2.js",
4
+ "main.js": "./static/js/main.a45801ac.js",
5
5
  "static/js/453.d855a71b.chunk.js": "./static/js/453.d855a71b.chunk.js",
6
6
  "static/media/roboto-latin-700-normal.woff2": "./static/media/roboto-latin-700-normal.c4d6cab43bec89049809.woff2",
7
7
  "static/media/roboto-latin-500-normal.woff2": "./static/media/roboto-latin-500-normal.599f66a60bdf974e578e.woff2",
@@ -77,11 +77,11 @@
77
77
  "static/media/roboto-greek-ext-300-normal.woff": "./static/media/roboto-greek-ext-300-normal.60729cafbded24073dfb.woff",
78
78
  "index.html": "./index.html",
79
79
  "main.ea7910e9.css.map": "./static/css/main.ea7910e9.css.map",
80
- "main.839276c2.js.map": "./static/js/main.839276c2.js.map",
80
+ "main.a45801ac.js.map": "./static/js/main.a45801ac.js.map",
81
81
  "453.d855a71b.chunk.js.map": "./static/js/453.d855a71b.chunk.js.map"
82
82
  },
83
83
  "entrypoints": [
84
84
  "static/css/main.ea7910e9.css",
85
- "static/js/main.839276c2.js"
85
+ "static/js/main.a45801ac.js"
86
86
  ]
87
87
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.839276c2.js"></script><link href="./static/css/main.ea7910e9.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.a45801ac.js"></script><link href="./static/css/main.ea7910e9.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>