matterbridge 2.2.5 → 2.2.6-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 (152) hide show
  1. package/CHANGELOG.md +104 -65
  2. package/dist/cli.js +2 -37
  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 +37 -340
  7. package/dist/index.js +1 -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 +108 -746
  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 +27 -711
  21. package/dist/matterbridgeEndpointHelpers.js +9 -118
  22. package/dist/matterbridgePlatform.js +11 -210
  23. package/dist/matterbridgeTypes.js +0 -24
  24. package/dist/pluginManager.js +3 -229
  25. package/dist/shelly.js +6 -121
  26. package/dist/storage/export.js +0 -1
  27. package/dist/update.js +0 -45
  28. package/dist/utils/colorUtils.js +2 -205
  29. package/dist/utils/copyDirectory.js +1 -37
  30. package/dist/utils/createZip.js +2 -42
  31. package/dist/utils/deepCopy.js +0 -40
  32. package/dist/utils/deepEqual.js +1 -65
  33. package/dist/utils/export.js +0 -1
  34. package/dist/utils/isvalid.js +0 -86
  35. package/dist/utils/network.js +5 -77
  36. package/dist/utils/parameter.js +0 -41
  37. package/dist/utils/wait.js +5 -48
  38. package/frontend/build/asset-manifest.json +3 -3
  39. package/frontend/build/index.html +1 -1
  40. package/frontend/build/static/js/{main.66936fef.js → main.a45801ac.js} +3 -3
  41. package/frontend/build/static/js/{main.66936fef.js.map → main.a45801ac.js.map} +1 -1
  42. package/npm-shrinkwrap.json +51 -51
  43. package/package.json +3 -4
  44. package/dist/cli.d.ts +0 -29
  45. package/dist/cli.d.ts.map +0 -1
  46. package/dist/cli.js.map +0 -1
  47. package/dist/cluster/export.d.ts +0 -2
  48. package/dist/cluster/export.d.ts.map +0 -1
  49. package/dist/cluster/export.js.map +0 -1
  50. package/dist/defaultConfigSchema.d.ts +0 -27
  51. package/dist/defaultConfigSchema.d.ts.map +0 -1
  52. package/dist/defaultConfigSchema.js.map +0 -1
  53. package/dist/deviceManager.d.ts +0 -114
  54. package/dist/deviceManager.d.ts.map +0 -1
  55. package/dist/deviceManager.js.map +0 -1
  56. package/dist/frontend.d.ts +0 -221
  57. package/dist/frontend.d.ts.map +0 -1
  58. package/dist/frontend.js.map +0 -1
  59. package/dist/index.d.ts +0 -35
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/index.js.map +0 -1
  62. package/dist/logger/export.d.ts +0 -2
  63. package/dist/logger/export.d.ts.map +0 -1
  64. package/dist/logger/export.js.map +0 -1
  65. package/dist/matter/behaviors.d.ts +0 -2
  66. package/dist/matter/behaviors.d.ts.map +0 -1
  67. package/dist/matter/behaviors.js.map +0 -1
  68. package/dist/matter/clusters.d.ts +0 -2
  69. package/dist/matter/clusters.d.ts.map +0 -1
  70. package/dist/matter/clusters.js.map +0 -1
  71. package/dist/matter/devices.d.ts +0 -2
  72. package/dist/matter/devices.d.ts.map +0 -1
  73. package/dist/matter/devices.js.map +0 -1
  74. package/dist/matter/endpoints.d.ts +0 -2
  75. package/dist/matter/endpoints.d.ts.map +0 -1
  76. package/dist/matter/endpoints.js.map +0 -1
  77. package/dist/matter/export.d.ts +0 -5
  78. package/dist/matter/export.d.ts.map +0 -1
  79. package/dist/matter/export.js.map +0 -1
  80. package/dist/matter/types.d.ts +0 -3
  81. package/dist/matter/types.d.ts.map +0 -1
  82. package/dist/matter/types.js.map +0 -1
  83. package/dist/matterbridge.d.ts +0 -422
  84. package/dist/matterbridge.d.ts.map +0 -1
  85. package/dist/matterbridge.js.map +0 -1
  86. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
  87. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  88. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  89. package/dist/matterbridgeBehaviors.d.ts +0 -1056
  90. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  91. package/dist/matterbridgeBehaviors.js.map +0 -1
  92. package/dist/matterbridgeDeviceTypes.d.ts +0 -177
  93. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  94. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  95. package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
  96. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  97. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  98. package/dist/matterbridgeEndpoint.d.ts +0 -835
  99. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  100. package/dist/matterbridgeEndpoint.js.map +0 -1
  101. package/dist/matterbridgeEndpointHelpers.d.ts +0 -2275
  102. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  103. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  104. package/dist/matterbridgePlatform.d.ts +0 -278
  105. package/dist/matterbridgePlatform.d.ts.map +0 -1
  106. package/dist/matterbridgePlatform.js.map +0 -1
  107. package/dist/matterbridgeTypes.d.ts +0 -178
  108. package/dist/matterbridgeTypes.d.ts.map +0 -1
  109. package/dist/matterbridgeTypes.js.map +0 -1
  110. package/dist/pluginManager.d.ts +0 -236
  111. package/dist/pluginManager.d.ts.map +0 -1
  112. package/dist/pluginManager.js.map +0 -1
  113. package/dist/shelly.d.ts +0 -77
  114. package/dist/shelly.d.ts.map +0 -1
  115. package/dist/shelly.js.map +0 -1
  116. package/dist/storage/export.d.ts +0 -2
  117. package/dist/storage/export.d.ts.map +0 -1
  118. package/dist/storage/export.js.map +0 -1
  119. package/dist/update.d.ts +0 -32
  120. package/dist/update.d.ts.map +0 -1
  121. package/dist/update.js.map +0 -1
  122. package/dist/utils/colorUtils.d.ts +0 -61
  123. package/dist/utils/colorUtils.d.ts.map +0 -1
  124. package/dist/utils/colorUtils.js.map +0 -1
  125. package/dist/utils/copyDirectory.d.ts +0 -32
  126. package/dist/utils/copyDirectory.d.ts.map +0 -1
  127. package/dist/utils/copyDirectory.js.map +0 -1
  128. package/dist/utils/createZip.d.ts +0 -38
  129. package/dist/utils/createZip.d.ts.map +0 -1
  130. package/dist/utils/createZip.js.map +0 -1
  131. package/dist/utils/deepCopy.d.ts +0 -31
  132. package/dist/utils/deepCopy.d.ts.map +0 -1
  133. package/dist/utils/deepCopy.js.map +0 -1
  134. package/dist/utils/deepEqual.d.ts +0 -53
  135. package/dist/utils/deepEqual.d.ts.map +0 -1
  136. package/dist/utils/deepEqual.js.map +0 -1
  137. package/dist/utils/export.d.ts +0 -10
  138. package/dist/utils/export.d.ts.map +0 -1
  139. package/dist/utils/export.js.map +0 -1
  140. package/dist/utils/isvalid.d.ts +0 -87
  141. package/dist/utils/isvalid.d.ts.map +0 -1
  142. package/dist/utils/isvalid.js.map +0 -1
  143. package/dist/utils/network.d.ts +0 -70
  144. package/dist/utils/network.d.ts.map +0 -1
  145. package/dist/utils/network.js.map +0 -1
  146. package/dist/utils/parameter.d.ts +0 -44
  147. package/dist/utils/parameter.d.ts.map +0 -1
  148. package/dist/utils/parameter.js.map +0 -1
  149. package/dist/utils/wait.d.ts +0 -43
  150. package/dist/utils/wait.d.ts.map +0 -1
  151. package/dist/utils/wait.js.map +0 -1
  152. /package/frontend/build/static/js/{main.66936fef.js.LICENSE.txt → main.a45801ac.js.LICENSE.txt} +0 -0
@@ -1,15 +1,9 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- // Node.js modules
3
1
  import { createHash } from 'node:crypto';
4
- // AnsiLogger module
5
2
  import { BLUE, CYAN, db, debugStringify, er, hk, or, YELLOW, zb } from './logger/export.js';
6
- // Matterbridge
7
3
  import { deepCopy, deepEqual, isValidArray } from './utils/export.js';
8
4
  import { MatterbridgeIdentifyServer, MatterbridgeOnOffServer, MatterbridgeLevelControlServer, MatterbridgeColorControlServer, MatterbridgeWindowCoveringServer, MatterbridgeThermostatServer, MatterbridgeFanControlServer, MatterbridgeDoorLockServer, MatterbridgeModeSelectServer, MatterbridgeValveConfigurationAndControlServer, MatterbridgeSmokeCoAlarmServer, MatterbridgeBooleanStateConfigurationServer, } from './matterbridgeBehaviors.js';
9
- // @matter
10
5
  import { Lifecycle } from '@matter/main';
11
6
  import { getClusterNameById } from '@matter/main/types';
12
- // @matter clusters
13
7
  import { PowerSource } from '@matter/main/clusters/power-source';
14
8
  import { UserLabel } from '@matter/main/clusters/user-label';
15
9
  import { FixedLabel } from '@matter/main/clusters/fixed-label';
@@ -51,7 +45,6 @@ import { Pm25ConcentrationMeasurement } from '@matter/main/clusters/pm25-concent
51
45
  import { Pm10ConcentrationMeasurement } from '@matter/main/clusters/pm10-concentration-measurement';
52
46
  import { RadonConcentrationMeasurement } from '@matter/main/clusters/radon-concentration-measurement';
53
47
  import { TotalVolatileOrganicCompoundsConcentrationMeasurement } from '@matter/main/clusters/total-volatile-organic-compounds-concentration-measurement';
54
- // @matter behaviors
55
48
  import { PowerSourceServer } from '@matter/main/behaviors/power-source';
56
49
  import { UserLabelServer } from '@matter/main/behaviors/user-label';
57
50
  import { FixedLabelServer } from '@matter/main/behaviors/fixed-label';
@@ -93,19 +86,19 @@ export function lowercaseFirstLetter(name) {
93
86
  }
94
87
  export function checkNotLatinCharacters(deviceName) {
95
88
  const nonLatinRegexList = [
96
- /[\u0400-\u04FF\u0500-\u052F]/, // Cyrillic
97
- /[\u2E80-\u9FFF]/, // CJK (Chinese, Japanese, Korean)
98
- /[\uAC00-\uD7AF]/, // Korean Hangul
99
- /[\u0600-\u06FF\u0750-\u077F]/, // Arabic, Persian
100
- /[\u0590-\u05FF]/, // Hebrew
101
- /[\u0900-\u097F]/, // Devanagari (Hindi, Sanskrit)
102
- /[\u0E00-\u0E7F]/, // Thai
103
- /[\u1200-\u137F]/, // Ethiopic (Amharic, Tigrinya)
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]/,
104
97
  ];
105
98
  return nonLatinRegexList.some((regex) => regex.test(deviceName));
106
99
  }
107
100
  export function generateUniqueId(deviceName) {
108
- return createHash('md5').update(deviceName).digest('hex'); // MD5 hash of the device name
101
+ return createHash('md5').update(deviceName).digest('hex');
109
102
  }
110
103
  export function createUniqueId(param1, param2, param3, param4) {
111
104
  const hash = createHash('md5');
@@ -113,7 +106,6 @@ export function createUniqueId(param1, param2, param3, param4) {
113
106
  return hash.digest('hex');
114
107
  }
115
108
  export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
116
- // Map Server ClusterId to Behavior.Type
117
109
  const behaviorTypes = [];
118
110
  clusterServerList.forEach((clusterId) => {
119
111
  behaviorTypes.push(getBehaviourTypeFromClusterServerId(clusterId));
@@ -121,15 +113,12 @@ export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
121
113
  return behaviorTypes;
122
114
  }
123
115
  export function getBehaviourTypesFromClusterClientIds(clusterClientList) {
124
- // Map Client ClusterId to Behavior.Type
125
116
  const behaviorTypes = [];
126
117
  clusterClientList.forEach((clusterId) => {
127
- // behaviorTypes.push(getBehaviourTypeFromClusterClientId(clusterId));
128
118
  });
129
119
  return behaviorTypes;
130
120
  }
131
121
  export function getBehaviourTypeFromClusterServerId(clusterId) {
132
- // Map ClusterId to Server Behavior.Type
133
122
  if (clusterId === PowerSource.Cluster.id)
134
123
  return PowerSourceServer.with(PowerSource.Feature.Wired);
135
124
  if (clusterId === UserLabel.Cluster.id)
@@ -215,8 +204,6 @@ export function getBehaviourTypeFromClusterServerId(clusterId) {
215
204
  return MatterbridgeIdentifyServer;
216
205
  }
217
206
  export function getBehaviourTypeFromClusterClientId(clusterId) {
218
- // Map ClusterId to Client Behavior.Type
219
- // return IdentifyClient;
220
207
  }
221
208
  export function getBehavior(endpoint, cluster) {
222
209
  let behavior;
@@ -262,13 +249,6 @@ export function addOptionalClusterServers(endpoint) {
262
249
  });
263
250
  addClusterServers(endpoint, optionalServerList);
264
251
  }
265
- /**
266
- * Adds cluster servers to the specified endpoint based on the provided server list.
267
- *
268
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
269
- * @param {ClusterId[]} serverList - The list of cluster IDs to add.
270
- * @returns void
271
- */
272
252
  export function addClusterServers(endpoint, serverList) {
273
253
  if (serverList.includes(PowerSource.Cluster.id))
274
254
  endpoint.createDefaultPowerSourceWiredClusterServer();
@@ -342,16 +322,7 @@ export function addClusterServers(endpoint, serverList) {
342
322
  endpoint.createDefaultRadonConcentrationMeasurementClusterServer();
343
323
  if (serverList.includes(TotalVolatileOrganicCompoundsConcentrationMeasurement.Cluster.id))
344
324
  endpoint.createDefaultTvocMeasurementClusterServer();
345
- // if (serverList.includes(DeviceEnergyManagement.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementClusterServer();
346
- // if (serverList.includes(DeviceEnergyManagementMode.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementModeClusterServer();
347
325
  }
348
- /**
349
- * Adds a fixed label to the FixedLabel cluster. The FixedLabel cluster is created if it does not exist.
350
- *
351
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
352
- * @param {string} label - The label to add.
353
- * @param {string} value - The value of the label.
354
- */
355
326
  export async function addFixedLabel(endpoint, label, value) {
356
327
  if (!endpoint.hasClusterServer(FixedLabel.Cluster.id)) {
357
328
  endpoint.log.debug(`addFixedLabel: add cluster ${hk}FixedLabel${db}:${hk}fixedLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
@@ -368,13 +339,6 @@ export async function addFixedLabel(endpoint, label, value) {
368
339
  await endpoint.setAttribute(FixedLabel.Cluster.id, 'labelList', labelList, endpoint.log);
369
340
  }
370
341
  }
371
- /**
372
- * Adds a user label to the UserLabel cluster. The UserLabel cluster is created if it does not exist.
373
- *
374
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
375
- * @param {string} label - The label to add.
376
- * @param {string} value - The value of the label.
377
- */
378
342
  export async function addUserLabel(endpoint, label, value) {
379
343
  if (!endpoint.hasClusterServer(UserLabel.Cluster.id)) {
380
344
  endpoint.log.debug(`addUserLabel: add cluster ${hk}UserLabel${db}:${hk}userLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
@@ -438,16 +402,6 @@ export function getAttributeId(endpoint, cluster, attribute) {
438
402
  return endpoint.behaviors.supported[lowercaseFirstLetter(cluster)]?.schema?.children?.find((child) => child.name === capitalizeFirstLetter(attribute))?.id;
439
403
  }
440
404
  }
441
- /**
442
- * Retrieves the value of the provided attribute from the given cluster.
443
- *
444
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to retrieve the attribute from.
445
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the attribute from.
446
- * @param {string} attribute - The name of the attribute to retrieve.
447
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging the retrieve. Errors are logged to the endpoint logger.
448
- * @returns {any} The value of the attribute, or undefined if the attribute is not found.
449
- */
450
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
451
405
  export function getAttribute(endpoint, cluster, attribute, log) {
452
406
  const clusterName = getBehavior(endpoint, cluster)?.id;
453
407
  if (!clusterName) {
@@ -470,16 +424,6 @@ export function getAttribute(endpoint, cluster, attribute, log) {
470
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}`);
471
425
  return value;
472
426
  }
473
- /**
474
- * Sets the value of an attribute on a cluster server.
475
- *
476
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to set the attribute on.
477
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to set the attribute on.
478
- * @param {string} attribute - The name of the attribute.
479
- * @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
480
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging the set. Errors are logged to the endpoint logger.
481
- * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
482
- */
483
427
  export async function setAttribute(endpoint, cluster, attribute, value, log) {
484
428
  const clusterName = getBehavior(endpoint, cluster)?.id;
485
429
  if (!clusterName) {
@@ -505,16 +449,6 @@ export async function setAttribute(endpoint, cluster, attribute, value, log) {
505
449
  `to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
506
450
  return true;
507
451
  }
508
- /**
509
- * Sets the value of an attribute on a cluster server.
510
- *
511
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to update the attribute on.
512
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to update the attribute on.
513
- * @param {string} attribute - The name of the attribute.
514
- * @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
515
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging the update. Errors are logged to the endpoint logger.
516
- * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
517
- */
518
452
  export async function updateAttribute(endpoint, cluster, attribute, value, log) {
519
453
  const clusterName = getBehavior(endpoint, cluster)?.id;
520
454
  if (!clusterName) {
@@ -545,17 +479,6 @@ export async function updateAttribute(endpoint, cluster, attribute, value, log)
545
479
  `to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
546
480
  return true;
547
481
  }
548
- /**
549
- * Subscribes to the provided attribute on a cluster.
550
- *
551
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to subscribe the attribute to.
552
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to subscribe the attribute to.
553
- * @param {string} attribute - The name of the attribute to subscribe to.
554
- * @param {(newValue: any, oldValue: any) => void} listener - A callback function that will be called when the attribute value changes.
555
- * @param {AnsiLogger} [log] - Optional logger for logging errors and information.
556
- * @returns {boolean} - A boolean indicating whether the subscription was successful.
557
- */
558
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
559
482
  export async function subscribeAttribute(endpoint, cluster, attribute, listener, log) {
560
483
  const clusterName = getBehavior(endpoint, cluster)?.id;
561
484
  if (!clusterName) {
@@ -566,7 +489,6 @@ export async function subscribeAttribute(endpoint, cluster, attribute, listener,
566
489
  endpoint.log.debug(`subscribeAttribute ${hk}${clusterName}.${attribute}${db}: Endpoint ${or}${endpoint.maybeId}${db}:${or}${endpoint.maybeNumber}${db} is in the ${BLUE}${endpoint.construction.status}${db} state`);
567
490
  await endpoint.construction.ready;
568
491
  }
569
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
570
492
  const events = endpoint.events;
571
493
  attribute = lowercaseFirstLetter(attribute) + '$Changed';
572
494
  if (!(clusterName in events) || !(attribute in events[clusterName])) {
@@ -577,11 +499,6 @@ export async function subscribeAttribute(endpoint, cluster, attribute, listener,
577
499
  log?.info(`${db}Subscribed endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
578
500
  return true;
579
501
  }
580
- /**
581
- * Get the default TemperatureMeasurement cluster server options.
582
- *
583
- * @param {number} measuredValue - The measured value of the temperature x 100.
584
- */
585
502
  export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
586
503
  return optionsFor(TemperatureMeasurementServer, {
587
504
  measuredValue,
@@ -590,11 +507,6 @@ export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0)
590
507
  tolerance: 0,
591
508
  });
592
509
  }
593
- /**
594
- * Get the default RelativeHumidityMeasurement cluster server options.
595
- *
596
- * @param {number} measuredValue - The measured value of the relative humidity x 100.
597
- */
598
510
  export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
599
511
  return optionsFor(RelativeHumidityMeasurementServer, {
600
512
  measuredValue,
@@ -603,11 +515,6 @@ export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue
603
515
  tolerance: 0,
604
516
  });
605
517
  }
606
- /**
607
- * Get the default PressureMeasurement cluster server options.
608
- *
609
- * @param {number} measuredValue - The measured value for the pressure.
610
- */
611
518
  export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
612
519
  return optionsFor(PressureMeasurementServer, {
613
520
  measuredValue,
@@ -616,11 +523,6 @@ export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000)
616
523
  tolerance: 0,
617
524
  });
618
525
  }
619
- /**
620
- * Get the default IlluminanceMeasurement cluster server options.
621
- *
622
- * @param {number} measuredValue - The measured value of illuminance.
623
- */
624
526
  export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
625
527
  return optionsFor(IlluminanceMeasurementServer, {
626
528
  measuredValue,
@@ -629,11 +531,6 @@ export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0)
629
531
  tolerance: 0,
630
532
  });
631
533
  }
632
- /**
633
- * Get the default FlowMeasurement cluster server options.
634
- *
635
- * @param {number} measuredValue - The measured value of the flow in 10 x m3/h.
636
- */
637
534
  export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
638
535
  return optionsFor(FlowMeasurementServer, {
639
536
  measuredValue,
@@ -642,11 +539,6 @@ export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
642
539
  tolerance: 0,
643
540
  });
644
541
  }
645
- /**
646
- * Get the default OccupancySensing cluster server options.
647
- *
648
- * @param {boolean} occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
649
- */
650
542
  export function getDefaultOccupancySensingClusterServer(occupied = false) {
651
543
  return optionsFor(OccupancySensingServer, {
652
544
  occupancy: { occupied },
@@ -655,4 +547,3 @@ export function getDefaultOccupancySensingClusterServer(occupied = false) {
655
547
  pirOccupiedToUnoccupiedDelay: 30,
656
548
  });
657
549
  }
658
- //# sourceMappingURL=matterbridgeEndpointHelpers.js.map
@@ -1,71 +1,30 @@
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
- */
23
1
  import { checkNotLatinCharacters } from './matterbridgeEndpointHelpers.js';
24
2
  import { isValidArray, isValidObject, isValidString } from './utils/export.js';
25
- // AnsiLogger module
26
3
  import { CYAN, db, er, nf, wr } from './logger/export.js';
27
- // Storage module
28
4
  import { NodeStorageManager } from './storage/export.js';
29
- // Node.js module
30
5
  import path from 'node:path';
31
- /**
32
- * Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
33
- *
34
- */
35
6
  export class MatterbridgePlatform {
36
7
  matterbridge;
37
8
  log;
38
9
  config = {};
39
- name = ''; // Will be set by the loadPlugin() method using the package.json value.
40
- type = ''; // Will be set by the extending classes.
41
- version = '1.0.0'; // Will be set by the loadPlugin() method using the package.json value.
42
- // Platform storage
10
+ name = '';
11
+ type = '';
12
+ version = '1.0.0';
43
13
  storage;
44
14
  context;
45
- // Device and entity selection
46
15
  selectDevice = new Map();
47
16
  selectEntity = new Map();
48
- // Promises for storage
49
17
  _contextReady;
50
18
  _selectDeviceContextReady;
51
19
  _selectEntityContextReady;
52
20
  ready;
53
- // Registered devices
54
- _registeredEndpoints = new Map(); // uniqueId, MatterbridgeEndpoint
55
- _registeredEndpointsByName = new Map(); // deviceName, MatterbridgeEndpoint
56
- // Stored devices
57
- _storedDevices = new Map(); // serial, { serial, name }
58
- /**
59
- * Creates an instance of the base MatterbridgePlatform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
60
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
61
- * @param {AnsiLogger} log - The logger instance.
62
- * @param {PlatformConfig} config - The platform configuration.
63
- */
21
+ _registeredEndpoints = new Map();
22
+ _registeredEndpointsByName = new Map();
23
+ _storedDevices = new Map();
64
24
  constructor(matterbridge, log, config) {
65
25
  this.matterbridge = matterbridge;
66
26
  this.log = log;
67
27
  this.config = config;
68
- // create the NodeStorageManager for the plugin platform
69
28
  if (!isValidString(this.config.name) || this.config.name === '')
70
29
  throw new Error('Platform: the plugin name is missing or invalid.');
71
30
  this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
@@ -76,14 +35,12 @@ export class MatterbridgePlatform {
76
35
  logging: false,
77
36
  forgiveParseErrors: true,
78
37
  });
79
- // create the context storage for the plugin platform
80
38
  this.log.debug(`Creating context for plugin ${this.config.name}`);
81
39
  this._contextReady = this.storage.createStorage('context').then((context) => {
82
40
  this.context = context;
83
- this.context.remove('endpointMap'); // Remove the old endpointMap TODO: remove in future versions
41
+ this.context.remove('endpointMap');
84
42
  this.log.debug(`Created context for plugin ${this.config.name}`);
85
43
  });
86
- // create the selectDevice storage for the plugin platform
87
44
  this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
88
45
  this._selectDeviceContextReady = this.storage.createStorage('selectDevice').then(async (context) => {
89
46
  const selectDevice = await context.get('selectDevice', []);
@@ -91,7 +48,6 @@ export class MatterbridgePlatform {
91
48
  this.selectDevice.set(device.serial, device);
92
49
  this.log.debug(`Loaded ${this.selectDevice.size} selectDevice for plugin ${this.config.name}`);
93
50
  });
94
- // create the selectEntity storage for the plugin platform
95
51
  this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
96
52
  this._selectEntityContextReady = this.storage.createStorage('selectEntity').then(async (context) => {
97
53
  const selectEntity = await context.get('selectEntity', []);
@@ -99,107 +55,44 @@ export class MatterbridgePlatform {
99
55
  this.selectEntity.set(entity.name, entity);
100
56
  this.log.debug(`Loaded ${this.selectEntity.size} selectEntity for plugin ${this.config.name}`);
101
57
  });
102
- // Create the `ready` promise for the platform
103
58
  this.ready = Promise.all([this._contextReady, this._selectDeviceContextReady, this._selectEntityContextReady]).then(() => {
104
59
  this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
105
60
  });
106
61
  }
107
- /**
108
- * This method must be overridden in the extended class.
109
- * It is called when the platform is started.
110
- * Use this method to create the MatterbridgeDevice and call this.registerDevice().
111
- * @param {string} [reason] - The reason for starting.
112
- * @throws {Error} - Throws an error if the method is not overridden.
113
- */
114
62
  async onStart(reason) {
115
63
  this.log.error('Plugins must override onStart.', reason);
116
64
  throw new Error('Plugins must override onStart.');
117
65
  }
118
- /**
119
- * This method can be overridden in the extended class. Call super.onConfigure() to run checkEndpointNumbers().
120
- * It is called after the platform has started.
121
- * Use this method to perform any configuration of your devices.
122
- */
123
66
  async onConfigure() {
124
67
  this.log.debug(`Configuring platform ${this.name}`);
125
- // Save the selectDevice and selectEntity
126
68
  await this.saveSelects();
127
- // Check and update the endpoint numbers
128
69
  await this.checkEndpointNumbers();
129
70
  }
130
- /**
131
- * This method can be overridden in the extended class. In this case always call super.onShutdown() to save the selects, run checkEndpointNumbers() and cleanup memory.
132
- * It is called when the platform is shutting down.
133
- * Use this method to clean up any resources.
134
- * @param {string} [reason] - The reason for shutting down.
135
- */
136
71
  async onShutdown(reason) {
137
72
  this.log.debug(`Shutting down platform ${this.name}`, reason);
138
- // Save the selectDevice and selectEntity
139
73
  await this.saveSelects();
140
- // Check and update the endpoint numbers
141
74
  await this.checkEndpointNumbers();
142
- // Cleanup memory
143
75
  this.selectDevice.clear();
144
76
  this.selectEntity.clear();
145
77
  this._registeredEndpoints.clear();
146
78
  this._registeredEndpointsByName.clear();
147
79
  this._storedDevices.clear();
148
- // Close the storage
149
80
  await this.context?.close();
150
81
  this.context = undefined;
151
82
  await this.storage?.close();
152
83
  }
153
- /**
154
- * Sets the logger level and logs a debug message indicating that the plugin doesn't override this method.
155
- * @param {LogLevel} logLevel The new logger level.
156
- */
157
84
  async onChangeLoggerLevel(logLevel) {
158
85
  this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
159
86
  }
160
- /**
161
- * Called when a plugin config includes an action button or an action button with text field.
162
- * @param {string} action The action triggered by the button in plugin config.
163
- * @param {string} value The value of the field of the action button.
164
- * @param {string} id The id of the schema associated with the action.
165
- *
166
- * @remarks
167
- * This method can be overridden in the extended class.
168
- *
169
- * Use this method to handle the action defined in the plugin schema:
170
- * "addDevice": {
171
- * "description": "Manually add a device that has not been discovered with mdns:",
172
- * "type": "boolean",
173
- * "buttonText": "ADD", // The text on the button.
174
- * "buttonField": "ADD", // The text on the button. This is used when the action includes a text field.
175
- * "buttonClose": false, // optional, default is false. When true, the dialog will close after the action is sent.
176
- * "buttonSave": false, // optional, default is false. When true, the dialog will close and trigger the restart required after the action is sent.
177
- * "textPlaceholder": "Enter the device IP address", // optional: the placeholder text for the text field.
178
- * "default": false
179
- * },
180
- */
181
87
  async onAction(action, value, id) {
182
88
  this.log.debug(`The plugin doesn't override onAction. Received action ${CYAN}${action}${db}${value ? ' with ' + CYAN + value + db : ''} ${id ? ' for schema ' + CYAN + id + db : ''}`);
183
89
  }
184
- /**
185
- * Called when the plugin config has been updated.
186
- * @param {PlatformConfig} config The new plugin config.
187
- */
188
90
  async onConfigChanged(config) {
189
91
  this.log.debug(`The plugin ${CYAN}${config.name}${db} doesn't override onConfigChanged. Received new config.`);
190
92
  }
191
- /**
192
- * Check if a device with this name is already registered in the platform.
193
- * @param {string} deviceName - The device name to check.
194
- * @returns {boolean} True if the device is already registered, false otherwise.
195
- */
196
93
  hasDeviceName(deviceName) {
197
94
  return this._registeredEndpointsByName.has(deviceName);
198
95
  }
199
- /**
200
- * Registers a device with the Matterbridge platform.
201
- * @param {MatterbridgeEndpoint} device - The device to register.
202
- */
203
96
  async registerDevice(device) {
204
97
  device.plugin = this.name;
205
98
  if (device.deviceName && this._registeredEndpointsByName.has(device.deviceName)) {
@@ -215,10 +108,6 @@ export class MatterbridgePlatform {
215
108
  if (device.deviceName)
216
109
  this._registeredEndpointsByName.set(device.deviceName, device);
217
110
  }
218
- /**
219
- * Unregisters a device registered with the Matterbridge platform.
220
- * @param {MatterbridgeEndpoint} device - The device to unregister.
221
- */
222
111
  async unregisterDevice(device) {
223
112
  await this.matterbridge.removeBridgedEndpoint(this.name, device);
224
113
  if (device.uniqueId)
@@ -226,22 +115,11 @@ export class MatterbridgePlatform {
226
115
  if (device.deviceName)
227
116
  this._registeredEndpointsByName.delete(device.deviceName);
228
117
  }
229
- /**
230
- * Unregisters all devices registered with the Matterbridge platform.
231
- */
232
118
  async unregisterAllDevices() {
233
119
  await this.matterbridge.removeAllBridgedEndpoints(this.name);
234
120
  this._registeredEndpoints.clear();
235
121
  this._registeredEndpointsByName.clear();
236
122
  }
237
- /**
238
- * Saves the select devices and entities to storage.
239
- *
240
- * This method saves the current state of `selectDevice` and `selectEntity` maps to their respective storage.
241
- * It logs the number of items being saved and ensures that the storage is properly closed after saving.
242
- *
243
- * @returns {Promise<void>} A promise that resolves when the save operation is complete.
244
- */
245
123
  async saveSelects() {
246
124
  if (this.storage) {
247
125
  this.log.debug(`Saving ${this.selectDevice.size} selectDevice...`);
@@ -254,26 +132,15 @@ export class MatterbridgePlatform {
254
132
  await selectEntity.close();
255
133
  }
256
134
  }
257
- /**
258
- * Clears the select device and entity maps.
259
- *
260
- * @returns {void}
261
- */
262
135
  async clearSelect() {
263
136
  this.selectDevice.clear();
264
137
  this.selectEntity.clear();
265
138
  await this.saveSelects();
266
139
  }
267
- /**
268
- * Set the select device in the platform map.
269
- *
270
- * @param {string} serial - The serial number of the device.
271
- * @param {string} name - The name of the device.
272
- * @param {string} [configUrl] - The configuration URL of the device.
273
- * @param {string} [icon] - The icon of the device.
274
- * @param {Array<{ name: string; description: string; icon?: string }>} [entities] - The entities associated with the device.
275
- * @returns {void}
276
- */
140
+ async clearDeviceSelect(device) {
141
+ this.selectDevice.delete(device);
142
+ await this.saveSelects();
143
+ }
277
144
  setSelectDevice(serial, name, configUrl, icon, entities) {
278
145
  const device = this.selectDevice.get(serial);
279
146
  if (device) {
@@ -290,15 +157,6 @@ export class MatterbridgePlatform {
290
157
  this.selectDevice.set(serial, { serial, name, configUrl, icon, entities });
291
158
  }
292
159
  }
293
- /**
294
- * Set the select device entity in the platform map.
295
- *
296
- * @param {string} serial - The serial number of the device.
297
- * @param {string} entityName - The name of the entity.
298
- * @param {string} entityDescription - The description of the entity.
299
- * @param {string} [entityIcon] - The icon of the entity.
300
- * @returns {void}
301
- */
302
160
  setSelectDeviceEntity(serial, entityName, entityDescription, entityIcon) {
303
161
  const device = this.selectDevice.get(serial);
304
162
  if (device) {
@@ -308,11 +166,6 @@ export class MatterbridgePlatform {
308
166
  device.entities.push({ name: entityName, description: entityDescription, icon: entityIcon });
309
167
  }
310
168
  }
311
- /**
312
- * Retrieves the select devices from the platform map.
313
- *
314
- * @returns {{ pluginName: string; serial: string; name: string; configUrl?: string; icon?: string; entities?: { name: string; description: string; icon?: string }[] }[]} The selected devices array.
315
- */
316
169
  getSelectDevices() {
317
170
  const selectDevices = [];
318
171
  this.selectDevice.values().forEach((device) => {
@@ -320,22 +173,9 @@ export class MatterbridgePlatform {
320
173
  });
321
174
  return selectDevices;
322
175
  }
323
- /**
324
- * Set the select entity in the platform map.
325
- *
326
- * @param {string} name - The entity name.
327
- * @param {string} description - The entity description.
328
- * @param {string} [icon] - The entity icon.
329
- * @returns {void}
330
- */
331
176
  setSelectEntity(name, description, icon) {
332
177
  this.selectEntity.set(name, { name, description, icon });
333
178
  }
334
- /**
335
- * Retrieve the select entities.
336
- *
337
- * @returns {{ pluginName: string; name: string; description: string; icon?: string }[]} The select entities array.
338
- */
339
179
  getSelectEntities() {
340
180
  const selectEntities = [];
341
181
  this.selectEntity.values().forEach((entity) => {
@@ -343,11 +183,6 @@ export class MatterbridgePlatform {
343
183
  });
344
184
  return selectEntities;
345
185
  }
346
- /**
347
- * Verifies if the Matterbridge version meets the required version.
348
- * @param {string} requiredVersion - The required version to compare against.
349
- * @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
350
- */
351
186
  verifyMatterbridgeVersion(requiredVersion) {
352
187
  const compareVersions = (matterbridgeVersion, requiredVersion) => {
353
188
  const stripTag = (v) => {
@@ -372,21 +207,9 @@ export class MatterbridgePlatform {
372
207
  return false;
373
208
  return true;
374
209
  }
375
- /**
376
- * @deprecated This method is deprecated and will be removed in future versions. Use validateDevice instead.
377
- */
378
210
  validateDeviceWhiteBlackList(device, log = true) {
379
211
  return this.validateDevice(device, log);
380
212
  }
381
- /**
382
- * Validates if a device is allowed based on the whitelist and blacklist configurations.
383
- * The blacklist has priority over the whitelist.
384
- *
385
- * @param {string | string[]} device - The device name(s) to validate.
386
- * @param {boolean} [log=true] - Whether to log the validation result.
387
- * @returns {boolean} - Returns true if the device is allowed, false otherwise.
388
- *
389
- */
390
213
  validateDevice(device, log = true) {
391
214
  if (!Array.isArray(device))
392
215
  device = [device];
@@ -416,21 +239,9 @@ export class MatterbridgePlatform {
416
239
  this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
417
240
  return false;
418
241
  }
419
- /**
420
- * @deprecated This method is deprecated and will be removed in future versions. Use validateEntity instead.
421
- */
422
242
  validateEntityBlackList(device, entity, log = true) {
423
243
  return this.validateEntity(device, entity, log);
424
244
  }
425
- /**
426
- * Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
427
- *
428
- * @param {string} device - The device to which the entity belongs.
429
- * @param {string} entity - The entity to validate.
430
- * @param {boolean} [log=true] - Whether to log the validation result.
431
- * @returns {boolean} - Returns true if the entity is allowed, false otherwise.
432
- *
433
- */
434
245
  validateEntity(device, entity, log = true) {
435
246
  if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
436
247
  if (log)
@@ -449,15 +260,6 @@ export class MatterbridgePlatform {
449
260
  }
450
261
  return true;
451
262
  }
452
- /**
453
- * Checks and updates the endpoint numbers for Matterbridge devices.
454
- *
455
- * This method retrieves the list of Matterbridge devices and their child endpoints,
456
- * compares their current endpoint numbers with the stored ones, and updates the storage
457
- * if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
458
- *
459
- * @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
460
- */
461
263
  async checkEndpointNumbers() {
462
264
  if (!this.storage)
463
265
  return -1;
@@ -498,4 +300,3 @@ export class MatterbridgePlatform {
498
300
  return endpointMap.size;
499
301
  }
500
302
  }
501
- //# sourceMappingURL=matterbridgePlatform.js.map