matterbridge 2.1.3 → 2.1.4-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.
Files changed (111) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/cli.js +0 -26
  3. package/dist/cluster/export.js +0 -2
  4. package/dist/defaultConfigSchema.js +0 -23
  5. package/dist/deviceManager.js +1 -94
  6. package/dist/frontend.js +34 -233
  7. package/dist/index.js +0 -28
  8. package/dist/logger/export.js +0 -1
  9. package/dist/matter/behaviors.js +0 -2
  10. package/dist/matter/clusters.js +0 -2
  11. package/dist/matter/devices.js +0 -2
  12. package/dist/matter/endpoints.js +0 -2
  13. package/dist/matter/export.js +0 -2
  14. package/dist/matter/types.js +0 -2
  15. package/dist/matterbridge.js +60 -750
  16. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  17. package/dist/matterbridgeBehaviors.js +1 -32
  18. package/dist/matterbridgeDeviceTypes.js +11 -112
  19. package/dist/matterbridgeDynamicPlatform.js +0 -33
  20. package/dist/matterbridgeEndpoint.js +10 -691
  21. package/dist/matterbridgeEndpointHelpers.js +16 -96
  22. package/dist/matterbridgePlatform.js +30 -112
  23. package/dist/matterbridgeTypes.js +0 -24
  24. package/dist/pluginManager.js +3 -230
  25. package/dist/storage/export.js +0 -1
  26. package/dist/utils/colorUtils.js +2 -205
  27. package/dist/utils/export.js +0 -1
  28. package/dist/utils/utils.js +7 -251
  29. package/npm-shrinkwrap.json +47 -47
  30. package/package.json +2 -3
  31. package/dist/cli.d.ts +0 -25
  32. package/dist/cli.d.ts.map +0 -1
  33. package/dist/cli.js.map +0 -1
  34. package/dist/cluster/export.d.ts +0 -2
  35. package/dist/cluster/export.d.ts.map +0 -1
  36. package/dist/cluster/export.js.map +0 -1
  37. package/dist/defaultConfigSchema.d.ts +0 -27
  38. package/dist/defaultConfigSchema.d.ts.map +0 -1
  39. package/dist/defaultConfigSchema.js.map +0 -1
  40. package/dist/deviceManager.d.ts +0 -114
  41. package/dist/deviceManager.d.ts.map +0 -1
  42. package/dist/deviceManager.js.map +0 -1
  43. package/dist/frontend.d.ts +0 -110
  44. package/dist/frontend.d.ts.map +0 -1
  45. package/dist/frontend.js.map +0 -1
  46. package/dist/index.d.ts +0 -35
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index.js.map +0 -1
  49. package/dist/logger/export.d.ts +0 -2
  50. package/dist/logger/export.d.ts.map +0 -1
  51. package/dist/logger/export.js.map +0 -1
  52. package/dist/matter/behaviors.d.ts +0 -2
  53. package/dist/matter/behaviors.d.ts.map +0 -1
  54. package/dist/matter/behaviors.js.map +0 -1
  55. package/dist/matter/clusters.d.ts +0 -2
  56. package/dist/matter/clusters.d.ts.map +0 -1
  57. package/dist/matter/clusters.js.map +0 -1
  58. package/dist/matter/devices.d.ts +0 -2
  59. package/dist/matter/devices.d.ts.map +0 -1
  60. package/dist/matter/devices.js.map +0 -1
  61. package/dist/matter/endpoints.d.ts +0 -2
  62. package/dist/matter/endpoints.d.ts.map +0 -1
  63. package/dist/matter/endpoints.js.map +0 -1
  64. package/dist/matter/export.d.ts +0 -5
  65. package/dist/matter/export.d.ts.map +0 -1
  66. package/dist/matter/export.js.map +0 -1
  67. package/dist/matter/types.d.ts +0 -3
  68. package/dist/matter/types.d.ts.map +0 -1
  69. package/dist/matter/types.js.map +0 -1
  70. package/dist/matterbridge.d.ts +0 -409
  71. package/dist/matterbridge.d.ts.map +0 -1
  72. package/dist/matterbridge.js.map +0 -1
  73. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
  74. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  75. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  76. package/dist/matterbridgeBehaviors.d.ts +0 -1056
  77. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  78. package/dist/matterbridgeBehaviors.js.map +0 -1
  79. package/dist/matterbridgeDeviceTypes.d.ts +0 -177
  80. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  81. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  82. package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
  83. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  84. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  85. package/dist/matterbridgeEndpoint.d.ts +0 -834
  86. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  87. package/dist/matterbridgeEndpoint.js.map +0 -1
  88. package/dist/matterbridgeEndpointHelpers.d.ts +0 -2262
  89. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  90. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  91. package/dist/matterbridgePlatform.d.ts +0 -152
  92. package/dist/matterbridgePlatform.d.ts.map +0 -1
  93. package/dist/matterbridgePlatform.js.map +0 -1
  94. package/dist/matterbridgeTypes.d.ts +0 -167
  95. package/dist/matterbridgeTypes.d.ts.map +0 -1
  96. package/dist/matterbridgeTypes.js.map +0 -1
  97. package/dist/pluginManager.d.ts +0 -236
  98. package/dist/pluginManager.d.ts.map +0 -1
  99. package/dist/pluginManager.js.map +0 -1
  100. package/dist/storage/export.d.ts +0 -2
  101. package/dist/storage/export.d.ts.map +0 -1
  102. package/dist/storage/export.js.map +0 -1
  103. package/dist/utils/colorUtils.d.ts +0 -61
  104. package/dist/utils/colorUtils.d.ts.map +0 -1
  105. package/dist/utils/colorUtils.js.map +0 -1
  106. package/dist/utils/export.d.ts +0 -3
  107. package/dist/utils/export.d.ts.map +0 -1
  108. package/dist/utils/export.js.map +0 -1
  109. package/dist/utils/utils.d.ts +0 -221
  110. package/dist/utils/utils.d.ts.map +0 -1
  111. package/dist/utils/utils.js.map +0 -1
@@ -1,13 +1,8 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- // Node.js modules
3
1
  import { createHash } from 'crypto';
4
- // AnsiLogger module
5
2
  import { BLUE, CYAN, db, debugStringify, er, hk, or, YELLOW, zb } from './logger/export.js';
6
3
  import { MatterbridgeIdentifyServer, MatterbridgeOnOffServer, MatterbridgeLevelControlServer, MatterbridgeColorControlServer, MatterbridgeWindowCoveringServer, MatterbridgeThermostatServer, MatterbridgeFanControlServer, MatterbridgeDoorLockServer, MatterbridgeModeSelectServer, MatterbridgeValveConfigurationAndControlServer, MatterbridgeSmokeCoAlarmServer, MatterbridgeBooleanStateConfigurationServer, } from './matterbridgeBehaviors.js';
7
- // @matter
8
4
  import { Lifecycle } from '@matter/main';
9
5
  import { getClusterNameById } from '@matter/main/types';
10
- // @matter clusters
11
6
  import { PowerSource } from '@matter/main/clusters/power-source';
12
7
  import { UserLabel } from '@matter/main/clusters/user-label';
13
8
  import { FixedLabel } from '@matter/main/clusters/fixed-label';
@@ -49,7 +44,6 @@ import { Pm25ConcentrationMeasurement } from '@matter/main/clusters/pm25-concent
49
44
  import { Pm10ConcentrationMeasurement } from '@matter/main/clusters/pm10-concentration-measurement';
50
45
  import { RadonConcentrationMeasurement } from '@matter/main/clusters/radon-concentration-measurement';
51
46
  import { TotalVolatileOrganicCompoundsConcentrationMeasurement } from '@matter/main/clusters/total-volatile-organic-compounds-concentration-measurement';
52
- // @matter behaviors
53
47
  import { PowerSourceServer } from '@matter/main/behaviors/power-source';
54
48
  import { UserLabelServer } from '@matter/main/behaviors/user-label';
55
49
  import { FixedLabelServer } from '@matter/main/behaviors/fixed-label';
@@ -90,13 +84,28 @@ export function lowercaseFirstLetter(name) {
90
84
  return name;
91
85
  return name.charAt(0).toLowerCase() + name.slice(1);
92
86
  }
87
+ export function checkNotLatinCharacters(deviceName) {
88
+ const nonLatinRegexList = [
89
+ /[\u0400-\u04FF\u0500-\u052F]/,
90
+ /[\u2E80-\u9FFF]/,
91
+ /[\uAC00-\uD7AF]/,
92
+ /[\u0600-\u06FF\u0750-\u077F]/,
93
+ /[\u0590-\u05FF]/,
94
+ /[\u0900-\u097F]/,
95
+ /[\u0E00-\u0E7F]/,
96
+ /[\u1200-\u137F]/,
97
+ ];
98
+ return nonLatinRegexList.some((regex) => regex.test(deviceName));
99
+ }
100
+ export function generateUniqueId(deviceName) {
101
+ return createHash('md5').update(deviceName).digest('hex');
102
+ }
93
103
  export function createUniqueId(param1, param2, param3, param4) {
94
104
  const hash = createHash('md5');
95
105
  hash.update(param1 + param2 + param3 + param4);
96
106
  return hash.digest('hex');
97
107
  }
98
108
  export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
99
- // Map Server ClusterId to Behavior.Type
100
109
  const behaviorTypes = [];
101
110
  clusterServerList.forEach((clusterId) => {
102
111
  behaviorTypes.push(getBehaviourTypeFromClusterServerId(clusterId));
@@ -104,15 +113,12 @@ export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
104
113
  return behaviorTypes;
105
114
  }
106
115
  export function getBehaviourTypesFromClusterClientIds(clusterClientList) {
107
- // Map Client ClusterId to Behavior.Type
108
116
  const behaviorTypes = [];
109
117
  clusterClientList.forEach((clusterId) => {
110
- // behaviorTypes.push(getBehaviourTypeFromClusterClientId(clusterId));
111
118
  });
112
119
  return behaviorTypes;
113
120
  }
114
121
  export function getBehaviourTypeFromClusterServerId(clusterId) {
115
- // Map ClusterId to Server Behavior.Type
116
122
  if (clusterId === PowerSource.Cluster.id)
117
123
  return PowerSourceServer.with(PowerSource.Feature.Wired);
118
124
  if (clusterId === UserLabel.Cluster.id)
@@ -198,8 +204,6 @@ export function getBehaviourTypeFromClusterServerId(clusterId) {
198
204
  return MatterbridgeIdentifyServer;
199
205
  }
200
206
  export function getBehaviourTypeFromClusterClientId(clusterId) {
201
- // Map ClusterId to Client Behavior.Type
202
- // return IdentifyClient;
203
207
  }
204
208
  export function getBehavior(endpoint, cluster) {
205
209
  let behavior;
@@ -245,13 +249,6 @@ export function addOptionalClusterServers(endpoint) {
245
249
  });
246
250
  addClusterServers(endpoint, optionalServerList);
247
251
  }
248
- /**
249
- * Adds cluster servers to the specified endpoint based on the provided server list.
250
- *
251
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
252
- * @param {ClusterId[]} serverList - The list of cluster IDs to add.
253
- * @returns void
254
- */
255
252
  export function addClusterServers(endpoint, serverList) {
256
253
  if (serverList.includes(PowerSource.Cluster.id))
257
254
  endpoint.createDefaultPowerSourceWiredClusterServer();
@@ -325,16 +322,7 @@ export function addClusterServers(endpoint, serverList) {
325
322
  endpoint.createDefaultRadonConcentrationMeasurementClusterServer();
326
323
  if (serverList.includes(TotalVolatileOrganicCompoundsConcentrationMeasurement.Cluster.id))
327
324
  endpoint.createDefaultTvocMeasurementClusterServer();
328
- // if (serverList.includes(DeviceEnergyManagement.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementClusterServer();
329
- // if (serverList.includes(DeviceEnergyManagementMode.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementModeClusterServer();
330
325
  }
331
- /**
332
- * Adds a fixed label to the FixedLabel cluster. The FixedLabel cluster is created if it does not exist.
333
- *
334
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
335
- * @param {string} label - The label to add.
336
- * @param {string} value - The value of the label.
337
- */
338
326
  export async function addFixedLabel(endpoint, label, value) {
339
327
  if (!endpoint.hasClusterServer(FixedLabel.Cluster.id)) {
340
328
  endpoint.log.debug(`addFixedLabel: add cluster ${hk}FixedLabel${db}:${hk}fixedLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
@@ -351,13 +339,6 @@ export async function addFixedLabel(endpoint, label, value) {
351
339
  await endpoint.setAttribute(FixedLabel.Cluster.id, 'labelList', labelList, endpoint.log);
352
340
  }
353
341
  }
354
- /**
355
- * Adds a user label to the UserLabel cluster. The UserLabel cluster is created if it does not exist.
356
- *
357
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
358
- * @param {string} label - The label to add.
359
- * @param {string} value - The value of the label.
360
- */
361
342
  export async function addUserLabel(endpoint, label, value) {
362
343
  if (!endpoint.hasClusterServer(UserLabel.Cluster.id)) {
363
344
  endpoint.log.debug(`addUserLabel: add cluster ${hk}UserLabel${db}:${hk}userLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
@@ -421,16 +402,6 @@ export function getAttributeId(endpoint, cluster, attribute) {
421
402
  return endpoint.behaviors.supported[lowercaseFirstLetter(cluster)]?.schema?.children?.find((child) => child.name === capitalizeFirstLetter(attribute))?.id;
422
403
  }
423
404
  }
424
- /**
425
- * Retrieves the value of the provided attribute from the given cluster.
426
- *
427
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to retrieve the attribute from.
428
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the attribute from.
429
- * @param {string} attribute - The name of the attribute to retrieve.
430
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging the retrieve. Errors are logged to the endpoint logger.
431
- * @returns {any} The value of the attribute, or undefined if the attribute is not found.
432
- */
433
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
434
405
  export function getAttribute(endpoint, cluster, attribute, log) {
435
406
  const clusterName = getBehavior(endpoint, cluster)?.id;
436
407
  if (!clusterName) {
@@ -453,16 +424,6 @@ export function getAttribute(endpoint, cluster, attribute, log) {
453
424
  log?.info(`${db}Get endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db} value ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
454
425
  return value;
455
426
  }
456
- /**
457
- * Sets the value of an attribute on a cluster server.
458
- *
459
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to set the attribute on.
460
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to set the attribute on.
461
- * @param {string} attribute - The name of the attribute.
462
- * @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
463
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging the set. Errors are logged to the endpoint logger.
464
- * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
465
- */
466
427
  export async function setAttribute(endpoint, cluster, attribute, value, log) {
467
428
  const clusterName = getBehavior(endpoint, cluster)?.id;
468
429
  if (!clusterName) {
@@ -488,16 +449,6 @@ export async function setAttribute(endpoint, cluster, attribute, value, log) {
488
449
  `to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
489
450
  return true;
490
451
  }
491
- /**
492
- * Sets the value of an attribute on a cluster server.
493
- *
494
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to update the attribute on.
495
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to update the attribute on.
496
- * @param {string} attribute - The name of the attribute.
497
- * @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
498
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging the update. Errors are logged to the endpoint logger.
499
- * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
500
- */
501
452
  export async function updateAttribute(endpoint, cluster, attribute, value, log) {
502
453
  const clusterName = getBehavior(endpoint, cluster)?.id;
503
454
  if (!clusterName) {
@@ -528,11 +479,6 @@ export async function updateAttribute(endpoint, cluster, attribute, value, log)
528
479
  `to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
529
480
  return true;
530
481
  }
531
- /**
532
- * Get the default TemperatureMeasurement cluster server options.
533
- *
534
- * @param {number} measuredValue - The measured value of the temperature x 100.
535
- */
536
482
  export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
537
483
  return optionsFor(TemperatureMeasurementServer, {
538
484
  measuredValue,
@@ -541,11 +487,6 @@ export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0)
541
487
  tolerance: 0,
542
488
  });
543
489
  }
544
- /**
545
- * Get the default RelativeHumidityMeasurement cluster server options.
546
- *
547
- * @param {number} measuredValue - The measured value of the relative humidity x 100.
548
- */
549
490
  export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
550
491
  return optionsFor(RelativeHumidityMeasurementServer, {
551
492
  measuredValue,
@@ -554,11 +495,6 @@ export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue
554
495
  tolerance: 0,
555
496
  });
556
497
  }
557
- /**
558
- * Get the default PressureMeasurement cluster server options.
559
- *
560
- * @param {number} measuredValue - The measured value for the pressure.
561
- */
562
498
  export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
563
499
  return optionsFor(PressureMeasurementServer, {
564
500
  measuredValue,
@@ -567,11 +503,6 @@ export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000)
567
503
  tolerance: 0,
568
504
  });
569
505
  }
570
- /**
571
- * Get the default IlluminanceMeasurement cluster server options.
572
- *
573
- * @param {number} measuredValue - The measured value of illuminance.
574
- */
575
506
  export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
576
507
  return optionsFor(IlluminanceMeasurementServer, {
577
508
  measuredValue,
@@ -580,11 +511,6 @@ export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0)
580
511
  tolerance: 0,
581
512
  });
582
513
  }
583
- /**
584
- * Get the default FlowMeasurement cluster server options.
585
- *
586
- * @param {number} measuredValue - The measured value of the flow in 10 x m3/h.
587
- */
588
514
  export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
589
515
  return optionsFor(FlowMeasurementServer, {
590
516
  measuredValue,
@@ -593,11 +519,6 @@ export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
593
519
  tolerance: 0,
594
520
  });
595
521
  }
596
- /**
597
- * Get the default OccupancySensing cluster server options.
598
- *
599
- * @param {boolean} occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
600
- */
601
522
  export function getDefaultOccupancySensingClusterServer(occupied = false) {
602
523
  return optionsFor(OccupancySensingServer, {
603
524
  occupancy: { occupied },
@@ -606,4 +527,3 @@ export function getDefaultOccupancySensingClusterServer(occupied = false) {
606
527
  pirOccupiedToUnoccupiedDelay: 30,
607
528
  });
608
529
  }
609
- //# sourceMappingURL=matterbridgeEndpointHelpers.js.map
@@ -1,59 +1,25 @@
1
- /**
2
- * This file contains the class MatterbridgeAccessoryPlatform.
3
- *
4
- * @file matterbridgePlatform.ts
5
- * @author Luca Liguori
6
- * @date 2024-03-21
7
- * @version 1.1.0
8
- *
9
- * Copyright 2024, 2025, 2026 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License. *
22
- */
1
+ import { checkNotLatinCharacters } from './matterbridgeEndpointHelpers.js';
23
2
  import { isValidArray, isValidObject, isValidString } from './utils/utils.js';
24
- // AnsiLogger module
25
- import { CYAN, db, nf, wr } from './logger/export.js';
26
- // Storage module
3
+ import { CYAN, db, er, nf, wr } from './logger/export.js';
27
4
  import { NodeStorageManager } from './storage/export.js';
28
- // Node.js module
29
5
  import path from 'path';
30
- /**
31
- * Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
32
- *
33
- */
34
6
  export class MatterbridgePlatform {
35
7
  matterbridge;
36
8
  log;
37
9
  config = {};
38
- name = ''; // Will be set by the loadPlugin() method using the package.json value.
39
- type = ''; // Will be set by the extending classes.
40
- version = '1.0.0'; // Will be set by the loadPlugin() method using the package.json value.
10
+ name = '';
11
+ type = '';
12
+ version = '1.0.0';
41
13
  storage;
42
14
  context;
43
15
  selectDevice = new Map();
44
16
  selectEntity = new Map();
45
17
  registeredEndpoints = new Map();
46
- /**
47
- * Creates an instance of the base MatterbridgePlatform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
48
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
49
- * @param {AnsiLogger} log - The logger instance.
50
- * @param {PlatformConfig} config - The platform configuration.
51
- */
18
+ registeredEndpointsByName = new Map();
52
19
  constructor(matterbridge, log, config) {
53
20
  this.matterbridge = matterbridge;
54
21
  this.log = log;
55
22
  this.config = config;
56
- // create the NodeStorageManager for the plugin platform
57
23
  if (!isValidString(this.config.name))
58
24
  return;
59
25
  this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
@@ -65,74 +31,60 @@ export class MatterbridgePlatform {
65
31
  forgiveParseErrors: true,
66
32
  });
67
33
  }
68
- /**
69
- * This method must be overridden in the extended class.
70
- * It is called when the platform is started.
71
- * Use this method to create the MatterbridgeDevice and call this.registerDevice().
72
- * @param {string} [reason] - The reason for starting.
73
- * @throws {Error} - Throws an error if the method is not overridden.
74
- */
75
34
  async onStart(reason) {
76
35
  this.log.error('Plugins must override onStart.', reason);
77
36
  throw new Error('Plugins must override onStart.');
78
37
  }
79
- /**
80
- * This method can be overridden in the extended class. Call super.onConfigure() to run checkEndpointNumbers().
81
- * It is called after the platform has been commissioned.
82
- * Use this method to perform any configuration of your devices.
83
- */
84
38
  async onConfigure() {
85
39
  this.log.debug(`Configuring platform ${this.name}`);
86
40
  await this.checkEndpointNumbers();
87
41
  }
88
- /**
89
- * This method can be overridden in the extended class. Call super.onShutdown() to run checkEndpointNumbers().
90
- * It is called when the platform is shutting down.
91
- * Use this method to clean up any resources.
92
- * @param {string} [reason] - The reason for shutting down.
93
- */
94
42
  async onShutdown(reason) {
95
43
  this.log.debug(`Shutting down platform ${this.name}`, reason);
96
44
  await this.checkEndpointNumbers();
45
+ this.selectDevice.clear();
46
+ this.selectEntity.clear();
47
+ this.registeredEndpoints.clear();
48
+ this.registeredEndpointsByName.clear();
49
+ await this.context?.close();
50
+ this.context = undefined;
51
+ await this.storage?.close();
52
+ this.storage = undefined;
97
53
  }
98
- /**
99
- * Sets the logger level and logs a debug message indicating that the plugin doesn't override this method.
100
- * @param {LogLevel} logLevel The new logger level.
101
- */
102
54
  async onChangeLoggerLevel(logLevel) {
103
55
  this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
104
56
  }
105
- /**
106
- * Registers a device with the Matterbridge platform.
107
- * @param {MatterbridgeEndpoint} device - The device to register.
108
- */
57
+ hasDeviceName(deviceName) {
58
+ return this.registeredEndpointsByName.has(deviceName);
59
+ }
109
60
  async registerDevice(device) {
110
61
  device.plugin = this.name;
62
+ if (device.deviceName && this.registeredEndpointsByName.has(device.deviceName)) {
63
+ this.log.error(`Device with name ${CYAN}${device.deviceName}${er} is already registered. The device will not be added. Please change the device name.`);
64
+ return;
65
+ }
66
+ if (device.deviceName && checkNotLatinCharacters(device.deviceName)) {
67
+ this.log.debug(`Device with name ${CYAN}${device.deviceName}${er} has not latin characters. Please keep the name as short as possible.`);
68
+ return;
69
+ }
111
70
  await this.matterbridge.addBridgedEndpoint(this.name, device);
112
71
  if (device.uniqueId)
113
72
  this.registeredEndpoints.set(device.uniqueId, device);
73
+ if (device.deviceName)
74
+ this.registeredEndpointsByName.set(device.deviceName, device);
114
75
  }
115
- /**
116
- * Unregisters a device registered with the Matterbridge platform.
117
- * @param {MatterbridgeEndpoint} device - The device to unregister.
118
- */
119
76
  async unregisterDevice(device) {
120
77
  await this.matterbridge.removeBridgedEndpoint(this.name, device);
121
78
  if (device.uniqueId)
122
79
  this.registeredEndpoints.delete(device.uniqueId);
80
+ if (device.deviceName)
81
+ this.registeredEndpointsByName.delete(device.deviceName);
123
82
  }
124
- /**
125
- * Unregisters all devices registered with the Matterbridge platform.
126
- */
127
83
  async unregisterAllDevices() {
128
84
  await this.matterbridge.removeAllBridgedEndpoints(this.name);
129
85
  this.registeredEndpoints.clear();
86
+ this.registeredEndpointsByName.clear();
130
87
  }
131
- /**
132
- * Verifies if the Matterbridge version meets the required version.
133
- * @param {string} requiredVersion - The required version to compare against.
134
- * @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
135
- */
136
88
  verifyMatterbridgeVersion(requiredVersion) {
137
89
  const compareVersions = (matterbridgeVersion, requiredVersion) => {
138
90
  const stripTag = (v) => {
@@ -157,21 +109,9 @@ export class MatterbridgePlatform {
157
109
  return false;
158
110
  return true;
159
111
  }
160
- /**
161
- * @deprecated This method is deprecated and will be removed in future versions. Use validateDevice instead.
162
- */
163
112
  validateDeviceWhiteBlackList(device, log = true) {
164
113
  return this.validateDevice(device, log);
165
114
  }
166
- /**
167
- * Validates if a device is allowed based on the whitelist and blacklist configurations.
168
- * The blacklist has priority over the whitelist.
169
- *
170
- * @param {string | string[]} device - The device name(s) to validate.
171
- * @param {boolean} [log=true] - Whether to log the validation result.
172
- * @returns {boolean} - Returns true if the device is allowed, false otherwise.
173
- *
174
- */
175
115
  validateDevice(device, log = true) {
176
116
  if (!Array.isArray(device))
177
117
  device = [device];
@@ -201,21 +141,9 @@ export class MatterbridgePlatform {
201
141
  this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
202
142
  return false;
203
143
  }
204
- /**
205
- * @deprecated This method is deprecated and will be removed in future versions. Use validateEntity instead.
206
- */
207
144
  validateEntityBlackList(device, entity, log = true) {
208
145
  return this.validateEntity(device, entity, log);
209
146
  }
210
- /**
211
- * Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
212
- *
213
- * @param {string} device - The device to which the entity belongs.
214
- * @param {string} entity - The entity to validate.
215
- * @param {boolean} [log=true] - Whether to log the validation result.
216
- * @returns {boolean} - Returns true if the entity is allowed, false otherwise.
217
- *
218
- */
219
147
  validateEntity(device, entity, log = true) {
220
148
  if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
221
149
  if (log)
@@ -234,15 +162,6 @@ export class MatterbridgePlatform {
234
162
  }
235
163
  return true;
236
164
  }
237
- /**
238
- * Checks and updates the endpoint numbers for Matterbridge devices.
239
- *
240
- * This method retrieves the list of Matterbridge devices and their child endpoints,
241
- * compares their current endpoint numbers with the stored ones, and updates the storage
242
- * if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
243
- *
244
- * @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
245
- */
246
165
  async checkEndpointNumbers() {
247
166
  if (!this.storage)
248
167
  return -1;
@@ -282,4 +201,3 @@ export class MatterbridgePlatform {
282
201
  return endpointMap.size;
283
202
  }
284
203
  }
285
- //# sourceMappingURL=matterbridgePlatform.js.map
@@ -1,27 +1,3 @@
1
- /**
2
- * This file contains the types for Matterbridge.
3
- *
4
- * @file matterbridgeTypes.ts
5
- * @author Luca Liguori
6
- * @date 2024-07-12
7
- * @version 1.0.2
8
- *
9
- * Copyright 2023, 2024, 2025 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License. *
22
- */
23
- // Default colors
24
1
  export const plg = '\u001B[38;5;33m';
25
2
  export const dev = '\u001B[38;5;79m';
26
3
  export const typ = '\u001B[38;5;207m';
27
- //# sourceMappingURL=matterbridgeTypes.js.map