matterbridge 2.1.5 → 2.1.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README-DOCKER.md +17 -7
  3. package/dist/cli.js +0 -26
  4. package/dist/cluster/export.js +0 -2
  5. package/dist/defaultConfigSchema.js +0 -23
  6. package/dist/deviceManager.js +1 -94
  7. package/dist/frontend.js +55 -280
  8. package/dist/index.js +0 -28
  9. package/dist/logger/export.js +0 -1
  10. package/dist/matter/behaviors.js +0 -2
  11. package/dist/matter/clusters.js +0 -2
  12. package/dist/matter/devices.js +0 -2
  13. package/dist/matter/endpoints.js +0 -2
  14. package/dist/matter/export.js +0 -2
  15. package/dist/matter/types.js +0 -2
  16. package/dist/matterbridge.js +68 -765
  17. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  18. package/dist/matterbridgeBehaviors.js +1 -32
  19. package/dist/matterbridgeDeviceTypes.js +11 -112
  20. package/dist/matterbridgeDynamicPlatform.js +0 -33
  21. package/dist/matterbridgeEndpoint.js +6 -690
  22. package/dist/matterbridgeEndpointHelpers.js +9 -117
  23. package/dist/matterbridgePlatform.js +41 -123
  24. package/dist/matterbridgeTypes.js +0 -24
  25. package/dist/pluginManager.js +3 -230
  26. package/dist/storage/export.js +0 -1
  27. package/dist/utils/colorUtils.js +2 -205
  28. package/dist/utils/export.js +0 -1
  29. package/dist/utils/utils.js +10 -264
  30. package/frontend/build/asset-manifest.json +3 -3
  31. package/frontend/build/index.html +1 -1
  32. package/frontend/build/static/js/{main.cd192588.js → main.a241d4f0.js} +9 -9
  33. package/frontend/build/static/js/main.a241d4f0.js.map +1 -0
  34. package/npm-shrinkwrap.json +47 -47
  35. package/package.json +2 -3
  36. package/dist/cli.d.ts +0 -25
  37. package/dist/cli.d.ts.map +0 -1
  38. package/dist/cli.js.map +0 -1
  39. package/dist/cluster/export.d.ts +0 -2
  40. package/dist/cluster/export.d.ts.map +0 -1
  41. package/dist/cluster/export.js.map +0 -1
  42. package/dist/defaultConfigSchema.d.ts +0 -27
  43. package/dist/defaultConfigSchema.d.ts.map +0 -1
  44. package/dist/defaultConfigSchema.js.map +0 -1
  45. package/dist/deviceManager.d.ts +0 -114
  46. package/dist/deviceManager.d.ts.map +0 -1
  47. package/dist/deviceManager.js.map +0 -1
  48. package/dist/frontend.d.ts +0 -143
  49. package/dist/frontend.d.ts.map +0 -1
  50. package/dist/frontend.js.map +0 -1
  51. package/dist/index.d.ts +0 -35
  52. package/dist/index.d.ts.map +0 -1
  53. package/dist/index.js.map +0 -1
  54. package/dist/logger/export.d.ts +0 -2
  55. package/dist/logger/export.d.ts.map +0 -1
  56. package/dist/logger/export.js.map +0 -1
  57. package/dist/matter/behaviors.d.ts +0 -2
  58. package/dist/matter/behaviors.d.ts.map +0 -1
  59. package/dist/matter/behaviors.js.map +0 -1
  60. package/dist/matter/clusters.d.ts +0 -2
  61. package/dist/matter/clusters.d.ts.map +0 -1
  62. package/dist/matter/clusters.js.map +0 -1
  63. package/dist/matter/devices.d.ts +0 -2
  64. package/dist/matter/devices.d.ts.map +0 -1
  65. package/dist/matter/devices.js.map +0 -1
  66. package/dist/matter/endpoints.d.ts +0 -2
  67. package/dist/matter/endpoints.d.ts.map +0 -1
  68. package/dist/matter/endpoints.js.map +0 -1
  69. package/dist/matter/export.d.ts +0 -5
  70. package/dist/matter/export.d.ts.map +0 -1
  71. package/dist/matter/export.js.map +0 -1
  72. package/dist/matter/types.d.ts +0 -3
  73. package/dist/matter/types.d.ts.map +0 -1
  74. package/dist/matter/types.js.map +0 -1
  75. package/dist/matterbridge.d.ts +0 -409
  76. package/dist/matterbridge.d.ts.map +0 -1
  77. package/dist/matterbridge.js.map +0 -1
  78. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
  79. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  80. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  81. package/dist/matterbridgeBehaviors.d.ts +0 -1056
  82. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  83. package/dist/matterbridgeBehaviors.js.map +0 -1
  84. package/dist/matterbridgeDeviceTypes.d.ts +0 -177
  85. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  86. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  87. package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
  88. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  89. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  90. package/dist/matterbridgeEndpoint.d.ts +0 -835
  91. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  92. package/dist/matterbridgeEndpoint.js.map +0 -1
  93. package/dist/matterbridgeEndpointHelpers.d.ts +0 -2275
  94. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  95. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  96. package/dist/matterbridgePlatform.d.ts +0 -159
  97. package/dist/matterbridgePlatform.d.ts.map +0 -1
  98. package/dist/matterbridgePlatform.js.map +0 -1
  99. package/dist/matterbridgeTypes.d.ts +0 -169
  100. package/dist/matterbridgeTypes.d.ts.map +0 -1
  101. package/dist/matterbridgeTypes.js.map +0 -1
  102. package/dist/pluginManager.d.ts +0 -236
  103. package/dist/pluginManager.d.ts.map +0 -1
  104. package/dist/pluginManager.js.map +0 -1
  105. package/dist/storage/export.d.ts +0 -2
  106. package/dist/storage/export.d.ts.map +0 -1
  107. package/dist/storage/export.js.map +0 -1
  108. package/dist/utils/colorUtils.d.ts +0 -61
  109. package/dist/utils/colorUtils.d.ts.map +0 -1
  110. package/dist/utils/colorUtils.js.map +0 -1
  111. package/dist/utils/export.d.ts +0 -3
  112. package/dist/utils/export.d.ts.map +0 -1
  113. package/dist/utils/export.js.map +0 -1
  114. package/dist/utils/utils.d.ts +0 -231
  115. package/dist/utils/utils.d.ts.map +0 -1
  116. package/dist/utils/utils.js.map +0 -1
  117. package/frontend/build/static/js/main.cd192588.js.map +0 -1
  118. /package/frontend/build/static/js/{main.cd192588.js.LICENSE.txt → main.a241d4f0.js.LICENSE.txt} +0 -0
@@ -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';
@@ -92,19 +86,19 @@ export function lowercaseFirstLetter(name) {
92
86
  }
93
87
  export function checkNotLatinCharacters(deviceName) {
94
88
  const nonLatinRegexList = [
95
- /[\u0400-\u04FF\u0500-\u052F]/, // Cyrillic
96
- /[\u2E80-\u9FFF]/, // CJK (Chinese, Japanese, Korean)
97
- /[\uAC00-\uD7AF]/, // Korean Hangul
98
- /[\u0600-\u06FF\u0750-\u077F]/, // Arabic, Persian
99
- /[\u0590-\u05FF]/, // Hebrew
100
- /[\u0900-\u097F]/, // Devanagari (Hindi, Sanskrit)
101
- /[\u0E00-\u0E7F]/, // Thai
102
- /[\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]/,
103
97
  ];
104
98
  return nonLatinRegexList.some((regex) => regex.test(deviceName));
105
99
  }
106
100
  export function generateUniqueId(deviceName) {
107
- return createHash('md5').update(deviceName).digest('hex'); // MD5 hash of the device name
101
+ return createHash('md5').update(deviceName).digest('hex');
108
102
  }
109
103
  export function createUniqueId(param1, param2, param3, param4) {
110
104
  const hash = createHash('md5');
@@ -112,7 +106,6 @@ export function createUniqueId(param1, param2, param3, param4) {
112
106
  return hash.digest('hex');
113
107
  }
114
108
  export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
115
- // Map Server ClusterId to Behavior.Type
116
109
  const behaviorTypes = [];
117
110
  clusterServerList.forEach((clusterId) => {
118
111
  behaviorTypes.push(getBehaviourTypeFromClusterServerId(clusterId));
@@ -120,15 +113,12 @@ export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
120
113
  return behaviorTypes;
121
114
  }
122
115
  export function getBehaviourTypesFromClusterClientIds(clusterClientList) {
123
- // Map Client ClusterId to Behavior.Type
124
116
  const behaviorTypes = [];
125
117
  clusterClientList.forEach((clusterId) => {
126
- // behaviorTypes.push(getBehaviourTypeFromClusterClientId(clusterId));
127
118
  });
128
119
  return behaviorTypes;
129
120
  }
130
121
  export function getBehaviourTypeFromClusterServerId(clusterId) {
131
- // Map ClusterId to Server Behavior.Type
132
122
  if (clusterId === PowerSource.Cluster.id)
133
123
  return PowerSourceServer.with(PowerSource.Feature.Wired);
134
124
  if (clusterId === UserLabel.Cluster.id)
@@ -214,8 +204,6 @@ export function getBehaviourTypeFromClusterServerId(clusterId) {
214
204
  return MatterbridgeIdentifyServer;
215
205
  }
216
206
  export function getBehaviourTypeFromClusterClientId(clusterId) {
217
- // Map ClusterId to Client Behavior.Type
218
- // return IdentifyClient;
219
207
  }
220
208
  export function getBehavior(endpoint, cluster) {
221
209
  let behavior;
@@ -261,13 +249,6 @@ export function addOptionalClusterServers(endpoint) {
261
249
  });
262
250
  addClusterServers(endpoint, optionalServerList);
263
251
  }
264
- /**
265
- * Adds cluster servers to the specified endpoint based on the provided server list.
266
- *
267
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
268
- * @param {ClusterId[]} serverList - The list of cluster IDs to add.
269
- * @returns void
270
- */
271
252
  export function addClusterServers(endpoint, serverList) {
272
253
  if (serverList.includes(PowerSource.Cluster.id))
273
254
  endpoint.createDefaultPowerSourceWiredClusterServer();
@@ -341,16 +322,7 @@ export function addClusterServers(endpoint, serverList) {
341
322
  endpoint.createDefaultRadonConcentrationMeasurementClusterServer();
342
323
  if (serverList.includes(TotalVolatileOrganicCompoundsConcentrationMeasurement.Cluster.id))
343
324
  endpoint.createDefaultTvocMeasurementClusterServer();
344
- // if (serverList.includes(DeviceEnergyManagement.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementClusterServer();
345
- // if (serverList.includes(DeviceEnergyManagementMode.Cluster.id)) endpoint.createDefaultDeviceEnergyManagementModeClusterServer();
346
325
  }
347
- /**
348
- * Adds a fixed label to the FixedLabel cluster. The FixedLabel cluster is created if it does not exist.
349
- *
350
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
351
- * @param {string} label - The label to add.
352
- * @param {string} value - The value of the label.
353
- */
354
326
  export async function addFixedLabel(endpoint, label, value) {
355
327
  if (!endpoint.hasClusterServer(FixedLabel.Cluster.id)) {
356
328
  endpoint.log.debug(`addFixedLabel: add cluster ${hk}FixedLabel${db}:${hk}fixedLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
@@ -367,13 +339,6 @@ export async function addFixedLabel(endpoint, label, value) {
367
339
  await endpoint.setAttribute(FixedLabel.Cluster.id, 'labelList', labelList, endpoint.log);
368
340
  }
369
341
  }
370
- /**
371
- * Adds a user label to the UserLabel cluster. The UserLabel cluster is created if it does not exist.
372
- *
373
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
374
- * @param {string} label - The label to add.
375
- * @param {string} value - The value of the label.
376
- */
377
342
  export async function addUserLabel(endpoint, label, value) {
378
343
  if (!endpoint.hasClusterServer(UserLabel.Cluster.id)) {
379
344
  endpoint.log.debug(`addUserLabel: add cluster ${hk}UserLabel${db}:${hk}userLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
@@ -437,16 +402,6 @@ export function getAttributeId(endpoint, cluster, attribute) {
437
402
  return endpoint.behaviors.supported[lowercaseFirstLetter(cluster)]?.schema?.children?.find((child) => child.name === capitalizeFirstLetter(attribute))?.id;
438
403
  }
439
404
  }
440
- /**
441
- * Retrieves the value of the provided attribute from the given cluster.
442
- *
443
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to retrieve the attribute from.
444
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the attribute from.
445
- * @param {string} attribute - The name of the attribute to retrieve.
446
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging the retrieve. Errors are logged to the endpoint logger.
447
- * @returns {any} The value of the attribute, or undefined if the attribute is not found.
448
- */
449
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
450
405
  export function getAttribute(endpoint, cluster, attribute, log) {
451
406
  const clusterName = getBehavior(endpoint, cluster)?.id;
452
407
  if (!clusterName) {
@@ -469,16 +424,6 @@ export function getAttribute(endpoint, cluster, attribute, log) {
469
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}`);
470
425
  return value;
471
426
  }
472
- /**
473
- * Sets the value of an attribute on a cluster server.
474
- *
475
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to set the attribute on.
476
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to set the attribute on.
477
- * @param {string} attribute - The name of the attribute.
478
- * @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
479
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging the set. Errors are logged to the endpoint logger.
480
- * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
481
- */
482
427
  export async function setAttribute(endpoint, cluster, attribute, value, log) {
483
428
  const clusterName = getBehavior(endpoint, cluster)?.id;
484
429
  if (!clusterName) {
@@ -504,16 +449,6 @@ export async function setAttribute(endpoint, cluster, attribute, value, log) {
504
449
  `to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
505
450
  return true;
506
451
  }
507
- /**
508
- * Sets the value of an attribute on a cluster server.
509
- *
510
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to update the attribute on.
511
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to update the attribute on.
512
- * @param {string} attribute - The name of the attribute.
513
- * @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
514
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging the update. Errors are logged to the endpoint logger.
515
- * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
516
- */
517
452
  export async function updateAttribute(endpoint, cluster, attribute, value, log) {
518
453
  const clusterName = getBehavior(endpoint, cluster)?.id;
519
454
  if (!clusterName) {
@@ -544,17 +479,6 @@ export async function updateAttribute(endpoint, cluster, attribute, value, log)
544
479
  `to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
545
480
  return true;
546
481
  }
547
- /**
548
- * Subscribes to the provided attribute on a cluster.
549
- *
550
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to subscribe the attribute to.
551
- * @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to subscribe the attribute to.
552
- * @param {string} attribute - The name of the attribute to subscribe to.
553
- * @param {(newValue: any, oldValue: any) => void} listener - A callback function that will be called when the attribute value changes.
554
- * @param {AnsiLogger} [log] - Optional logger for logging errors and information.
555
- * @returns {boolean} - A boolean indicating whether the subscription was successful.
556
- */
557
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
558
482
  export async function subscribeAttribute(endpoint, cluster, attribute, listener, log) {
559
483
  const clusterName = getBehavior(endpoint, cluster)?.id;
560
484
  if (!clusterName) {
@@ -565,7 +489,6 @@ export async function subscribeAttribute(endpoint, cluster, attribute, listener,
565
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`);
566
490
  await endpoint.construction.ready;
567
491
  }
568
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
569
492
  const events = endpoint.events;
570
493
  attribute = lowercaseFirstLetter(attribute) + '$Changed';
571
494
  if (!(clusterName in events) || !(attribute in events[clusterName])) {
@@ -576,11 +499,6 @@ export async function subscribeAttribute(endpoint, cluster, attribute, listener,
576
499
  log?.info(`${db}Subscribed endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
577
500
  return true;
578
501
  }
579
- /**
580
- * Get the default TemperatureMeasurement cluster server options.
581
- *
582
- * @param {number} measuredValue - The measured value of the temperature x 100.
583
- */
584
502
  export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
585
503
  return optionsFor(TemperatureMeasurementServer, {
586
504
  measuredValue,
@@ -589,11 +507,6 @@ export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0)
589
507
  tolerance: 0,
590
508
  });
591
509
  }
592
- /**
593
- * Get the default RelativeHumidityMeasurement cluster server options.
594
- *
595
- * @param {number} measuredValue - The measured value of the relative humidity x 100.
596
- */
597
510
  export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
598
511
  return optionsFor(RelativeHumidityMeasurementServer, {
599
512
  measuredValue,
@@ -602,11 +515,6 @@ export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue
602
515
  tolerance: 0,
603
516
  });
604
517
  }
605
- /**
606
- * Get the default PressureMeasurement cluster server options.
607
- *
608
- * @param {number} measuredValue - The measured value for the pressure.
609
- */
610
518
  export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
611
519
  return optionsFor(PressureMeasurementServer, {
612
520
  measuredValue,
@@ -615,11 +523,6 @@ export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000)
615
523
  tolerance: 0,
616
524
  });
617
525
  }
618
- /**
619
- * Get the default IlluminanceMeasurement cluster server options.
620
- *
621
- * @param {number} measuredValue - The measured value of illuminance.
622
- */
623
526
  export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
624
527
  return optionsFor(IlluminanceMeasurementServer, {
625
528
  measuredValue,
@@ -628,11 +531,6 @@ export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0)
628
531
  tolerance: 0,
629
532
  });
630
533
  }
631
- /**
632
- * Get the default FlowMeasurement cluster server options.
633
- *
634
- * @param {number} measuredValue - The measured value of the flow in 10 x m3/h.
635
- */
636
534
  export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
637
535
  return optionsFor(FlowMeasurementServer, {
638
536
  measuredValue,
@@ -641,11 +539,6 @@ export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
641
539
  tolerance: 0,
642
540
  });
643
541
  }
644
- /**
645
- * Get the default OccupancySensing cluster server options.
646
- *
647
- * @param {boolean} occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
648
- */
649
542
  export function getDefaultOccupancySensingClusterServer(occupied = false) {
650
543
  return optionsFor(OccupancySensingServer, {
651
544
  occupancy: { occupied },
@@ -654,4 +547,3 @@ export function getDefaultOccupancySensingClusterServer(occupied = false) {
654
547
  pirOccupiedToUnoccupiedDelay: 30,
655
548
  });
656
549
  }
657
- //# sourceMappingURL=matterbridgeEndpointHelpers.js.map
@@ -1,65 +1,26 @@
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/utils.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 '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
- // Registered devices
49
- registeredEndpoints = new Map(); // uniqueId, MatterbridgeEndpoint
50
- registeredEndpointsByName = new Map(); // deviceName, MatterbridgeEndpoint
51
- /**
52
- * Creates an instance of the base MatterbridgePlatform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
53
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
54
- * @param {AnsiLogger} log - The logger instance.
55
- * @param {PlatformConfig} config - The platform configuration.
56
- */
17
+ registeredEndpoints = new Map();
18
+ registeredEndpointsByName = new Map();
57
19
  constructor(matterbridge, log, config) {
58
20
  this.matterbridge = matterbridge;
59
21
  this.log = log;
60
22
  this.config = config;
61
- // create the NodeStorageManager for the plugin platform
62
- if (!isValidString(this.config.name))
23
+ if (!isValidString(this.config.name) || this.config.name === '')
63
24
  return;
64
25
  this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
65
26
  this.storage = new NodeStorageManager({
@@ -69,64 +30,65 @@ export class MatterbridgePlatform {
69
30
  logging: false,
70
31
  forgiveParseErrors: true,
71
32
  });
33
+ this.log.debug(`Creating context for plugin ${this.config.name}`);
34
+ this.storage.createStorage('context').then((context) => {
35
+ this.context = context;
36
+ this.log.debug(`Created context for plugin ${this.config.name}`);
37
+ });
38
+ this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
39
+ this.storage.createStorage('selectDevice').then((context) => {
40
+ context.get('selectDevice', []).then((selectDevice) => {
41
+ for (const device of selectDevice)
42
+ this.selectDevice.set(device.serial, device);
43
+ });
44
+ this.log.debug(`Loaded ${this.selectDevice.size} selectDevice for plugin ${this.config.name}`);
45
+ });
46
+ this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
47
+ this.storage.createStorage('selectEntity').then((context) => {
48
+ context.get('selectEntity', []).then((selectEntity) => {
49
+ for (const entity of selectEntity)
50
+ this.selectEntity.set(entity.name, entity);
51
+ });
52
+ this.log.debug(`Loaded ${this.selectEntity.size} selectEntity for plugin ${this.config.name}`);
53
+ });
72
54
  }
73
- /**
74
- * This method must be overridden in the extended class.
75
- * It is called when the platform is started.
76
- * Use this method to create the MatterbridgeDevice and call this.registerDevice().
77
- * @param {string} [reason] - The reason for starting.
78
- * @throws {Error} - Throws an error if the method is not overridden.
79
- */
80
55
  async onStart(reason) {
81
56
  this.log.error('Plugins must override onStart.', reason);
82
57
  throw new Error('Plugins must override onStart.');
83
58
  }
84
- /**
85
- * This method can be overridden in the extended class. Call super.onConfigure() to run checkEndpointNumbers().
86
- * It is called after the platform has been commissioned.
87
- * Use this method to perform any configuration of your devices.
88
- */
89
59
  async onConfigure() {
90
60
  this.log.debug(`Configuring platform ${this.name}`);
91
61
  await this.checkEndpointNumbers();
92
62
  }
93
- /**
94
- * This method can be overridden in the extended class. Call super.onShutdown() to run checkEndpointNumbers() and cleanup memory.
95
- * It is called when the platform is shutting down.
96
- * Use this method to clean up any resources.
97
- * @param {string} [reason] - The reason for shutting down.
98
- */
99
63
  async onShutdown(reason) {
100
64
  this.log.debug(`Shutting down platform ${this.name}`, reason);
65
+ if (this.storage) {
66
+ this.log.debug(`Saving ${this.selectDevice.size} selectDevice...`);
67
+ const selectDevice = await this.storage.createStorage('selectDevice');
68
+ await selectDevice.set('selectDevice', Array.from(this.selectDevice.values()));
69
+ await selectDevice.close();
70
+ this.log.debug(`Saving ${this.selectEntity.size} selectEntity...`);
71
+ const selectEntity = await this.storage.createStorage('selectEntity');
72
+ await selectEntity.set('selectEntity', Array.from(this.selectEntity.values()));
73
+ await selectEntity.close();
74
+ }
101
75
  await this.checkEndpointNumbers();
102
76
  this.selectDevice.clear();
103
77
  this.selectEntity.clear();
104
78
  this.registeredEndpoints.clear();
105
79
  this.registeredEndpointsByName.clear();
80
+ this.log.debug('Saving context...');
106
81
  await this.context?.close();
107
82
  this.context = undefined;
108
83
  await this.storage?.close();
109
84
  this.storage = undefined;
110
85
  }
111
- /**
112
- * Sets the logger level and logs a debug message indicating that the plugin doesn't override this method.
113
- * @param {LogLevel} logLevel The new logger level.
114
- */
115
86
  async onChangeLoggerLevel(logLevel) {
116
87
  this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
117
88
  }
118
- /**
119
- * Check if a device with this name is already registered in the platform.
120
- * @param {string} deviceName - The device name to check.
121
- * @returns {boolean} True if the device is already registered, false otherwise.
122
- */
123
89
  hasDeviceName(deviceName) {
124
90
  return this.registeredEndpointsByName.has(deviceName);
125
91
  }
126
- /**
127
- * Registers a device with the Matterbridge platform.
128
- * @param {MatterbridgeEndpoint} device - The device to register.
129
- */
130
92
  async registerDevice(device) {
131
93
  device.plugin = this.name;
132
94
  if (device.deviceName && this.registeredEndpointsByName.has(device.deviceName)) {
@@ -142,10 +104,6 @@ export class MatterbridgePlatform {
142
104
  if (device.deviceName)
143
105
  this.registeredEndpointsByName.set(device.deviceName, device);
144
106
  }
145
- /**
146
- * Unregisters a device registered with the Matterbridge platform.
147
- * @param {MatterbridgeEndpoint} device - The device to unregister.
148
- */
149
107
  async unregisterDevice(device) {
150
108
  await this.matterbridge.removeBridgedEndpoint(this.name, device);
151
109
  if (device.uniqueId)
@@ -153,19 +111,11 @@ export class MatterbridgePlatform {
153
111
  if (device.deviceName)
154
112
  this.registeredEndpointsByName.delete(device.deviceName);
155
113
  }
156
- /**
157
- * Unregisters all devices registered with the Matterbridge platform.
158
- */
159
114
  async unregisterAllDevices() {
160
115
  await this.matterbridge.removeAllBridgedEndpoints(this.name);
161
116
  this.registeredEndpoints.clear();
162
117
  this.registeredEndpointsByName.clear();
163
118
  }
164
- /**
165
- * Verifies if the Matterbridge version meets the required version.
166
- * @param {string} requiredVersion - The required version to compare against.
167
- * @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
168
- */
169
119
  verifyMatterbridgeVersion(requiredVersion) {
170
120
  const compareVersions = (matterbridgeVersion, requiredVersion) => {
171
121
  const stripTag = (v) => {
@@ -190,21 +140,9 @@ export class MatterbridgePlatform {
190
140
  return false;
191
141
  return true;
192
142
  }
193
- /**
194
- * @deprecated This method is deprecated and will be removed in future versions. Use validateDevice instead.
195
- */
196
143
  validateDeviceWhiteBlackList(device, log = true) {
197
144
  return this.validateDevice(device, log);
198
145
  }
199
- /**
200
- * Validates if a device is allowed based on the whitelist and blacklist configurations.
201
- * The blacklist has priority over the whitelist.
202
- *
203
- * @param {string | string[]} device - The device name(s) to validate.
204
- * @param {boolean} [log=true] - Whether to log the validation result.
205
- * @returns {boolean} - Returns true if the device is allowed, false otherwise.
206
- *
207
- */
208
146
  validateDevice(device, log = true) {
209
147
  if (!Array.isArray(device))
210
148
  device = [device];
@@ -234,21 +172,9 @@ export class MatterbridgePlatform {
234
172
  this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
235
173
  return false;
236
174
  }
237
- /**
238
- * @deprecated This method is deprecated and will be removed in future versions. Use validateEntity instead.
239
- */
240
175
  validateEntityBlackList(device, entity, log = true) {
241
176
  return this.validateEntity(device, entity, log);
242
177
  }
243
- /**
244
- * Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
245
- *
246
- * @param {string} device - The device to which the entity belongs.
247
- * @param {string} entity - The entity to validate.
248
- * @param {boolean} [log=true] - Whether to log the validation result.
249
- * @returns {boolean} - Returns true if the entity is allowed, false otherwise.
250
- *
251
- */
252
178
  validateEntity(device, entity, log = true) {
253
179
  if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
254
180
  if (log)
@@ -267,20 +193,11 @@ export class MatterbridgePlatform {
267
193
  }
268
194
  return true;
269
195
  }
270
- /**
271
- * Checks and updates the endpoint numbers for Matterbridge devices.
272
- *
273
- * This method retrieves the list of Matterbridge devices and their child endpoints,
274
- * compares their current endpoint numbers with the stored ones, and updates the storage
275
- * if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
276
- *
277
- * @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
278
- */
279
196
  async checkEndpointNumbers() {
280
197
  if (!this.storage)
281
198
  return -1;
282
199
  this.log.debug('Checking endpoint numbers...');
283
- const context = await this.storage.createStorage('context');
200
+ const context = await this.storage.createStorage('endpointNumbers');
284
201
  const separator = '|.|';
285
202
  const endpointMap = new Map(await context.get('endpointMap', []));
286
203
  for (const device of this.matterbridge.getDevices().filter((d) => d.plugin === this.name)) {
@@ -310,9 +227,10 @@ export class MatterbridgePlatform {
310
227
  }
311
228
  }
312
229
  }
230
+ this.log.debug('Saving endpointNumbers...');
313
231
  await context.set('endpointMap', Array.from(endpointMap.entries()));
232
+ await context.close();
314
233
  this.log.debug('Endpoint numbers check completed.');
315
234
  return endpointMap.size;
316
235
  }
317
236
  }
318
- //# 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