matterbridge 2.1.4 → 2.1.5-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 +14 -0
  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 +23 -232
  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 +55 -761
  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 -710
  21. package/dist/matterbridgeEndpointHelpers.js +29 -105
  22. package/dist/matterbridgePlatform.js +5 -121
  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 +13 -267
  29. package/npm-shrinkwrap.json +2 -2
  30. package/package.json +1 -2
  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 -2264
  89. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  90. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  91. package/dist/matterbridgePlatform.d.ts +0 -159
  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 -231
  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';
@@ -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,11 +479,26 @@ 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
- * Get the default TemperatureMeasurement cluster server options.
549
- *
550
- * @param {number} measuredValue - The measured value of the temperature x 100.
551
- */
482
+ export async function subscribeAttribute(endpoint, cluster, attribute, listener, log) {
483
+ const clusterName = getBehavior(endpoint, cluster)?.id;
484
+ if (!clusterName) {
485
+ endpoint.log.error(`subscribeAttribute ${hk}${attribute}${er} error: cluster not found on endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
486
+ return false;
487
+ }
488
+ if (endpoint.construction.status !== Lifecycle.Status.Active) {
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`);
490
+ await endpoint.construction.ready;
491
+ }
492
+ const events = endpoint.events;
493
+ attribute = lowercaseFirstLetter(attribute) + '$Changed';
494
+ if (!(clusterName in events) || !(attribute in events[clusterName])) {
495
+ endpoint.log.error(`subscribeAttribute error: Attribute ${hk}${attribute.replace('$Changed', '')}${er} not found on Cluster ${'0x' + getClusterId(endpoint, clusterName)?.toString(16).padStart(4, '0')}:${clusterName} on endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
496
+ return false;
497
+ }
498
+ events[clusterName][attribute].on(listener);
499
+ log?.info(`${db}Subscribed endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
500
+ return true;
501
+ }
552
502
  export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
553
503
  return optionsFor(TemperatureMeasurementServer, {
554
504
  measuredValue,
@@ -557,11 +507,6 @@ export function getDefaultTemperatureMeasurementClusterServer(measuredValue = 0)
557
507
  tolerance: 0,
558
508
  });
559
509
  }
560
- /**
561
- * Get the default RelativeHumidityMeasurement cluster server options.
562
- *
563
- * @param {number} measuredValue - The measured value of the relative humidity x 100.
564
- */
565
510
  export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
566
511
  return optionsFor(RelativeHumidityMeasurementServer, {
567
512
  measuredValue,
@@ -570,11 +515,6 @@ export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue
570
515
  tolerance: 0,
571
516
  });
572
517
  }
573
- /**
574
- * Get the default PressureMeasurement cluster server options.
575
- *
576
- * @param {number} measuredValue - The measured value for the pressure.
577
- */
578
518
  export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
579
519
  return optionsFor(PressureMeasurementServer, {
580
520
  measuredValue,
@@ -583,11 +523,6 @@ export function getDefaultPressureMeasurementClusterServer(measuredValue = 1000)
583
523
  tolerance: 0,
584
524
  });
585
525
  }
586
- /**
587
- * Get the default IlluminanceMeasurement cluster server options.
588
- *
589
- * @param {number} measuredValue - The measured value of illuminance.
590
- */
591
526
  export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
592
527
  return optionsFor(IlluminanceMeasurementServer, {
593
528
  measuredValue,
@@ -596,11 +531,6 @@ export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0)
596
531
  tolerance: 0,
597
532
  });
598
533
  }
599
- /**
600
- * Get the default FlowMeasurement cluster server options.
601
- *
602
- * @param {number} measuredValue - The measured value of the flow in 10 x m3/h.
603
- */
604
534
  export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
605
535
  return optionsFor(FlowMeasurementServer, {
606
536
  measuredValue,
@@ -609,11 +539,6 @@ export function getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
609
539
  tolerance: 0,
610
540
  });
611
541
  }
612
- /**
613
- * Get the default OccupancySensing cluster server options.
614
- *
615
- * @param {boolean} occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
616
- */
617
542
  export function getDefaultOccupancySensingClusterServer(occupied = false) {
618
543
  return optionsFor(OccupancySensingServer, {
619
544
  occupancy: { occupied },
@@ -622,4 +547,3 @@ export function getDefaultOccupancySensingClusterServer(occupied = false) {
622
547
  pirOccupiedToUnoccupiedDelay: 30,
623
548
  });
624
549
  }
625
- //# sourceMappingURL=matterbridgeEndpointHelpers.js.map
@@ -1,64 +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
- */
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
23
  if (!isValidString(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)}`);
@@ -70,32 +31,14 @@ export class MatterbridgePlatform {
70
31
  forgiveParseErrors: true,
71
32
  });
72
33
  }
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
34
  async onStart(reason) {
81
35
  this.log.error('Plugins must override onStart.', reason);
82
36
  throw new Error('Plugins must override onStart.');
83
37
  }
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
38
  async onConfigure() {
90
39
  this.log.debug(`Configuring platform ${this.name}`);
91
40
  await this.checkEndpointNumbers();
92
41
  }
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
42
  async onShutdown(reason) {
100
43
  this.log.debug(`Shutting down platform ${this.name}`, reason);
101
44
  await this.checkEndpointNumbers();
@@ -108,25 +51,12 @@ export class MatterbridgePlatform {
108
51
  await this.storage?.close();
109
52
  this.storage = undefined;
110
53
  }
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
54
  async onChangeLoggerLevel(logLevel) {
116
55
  this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
117
56
  }
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
57
  hasDeviceName(deviceName) {
124
58
  return this.registeredEndpointsByName.has(deviceName);
125
59
  }
126
- /**
127
- * Registers a device with the Matterbridge platform.
128
- * @param {MatterbridgeEndpoint} device - The device to register.
129
- */
130
60
  async registerDevice(device) {
131
61
  device.plugin = this.name;
132
62
  if (device.deviceName && this.registeredEndpointsByName.has(device.deviceName)) {
@@ -142,10 +72,6 @@ export class MatterbridgePlatform {
142
72
  if (device.deviceName)
143
73
  this.registeredEndpointsByName.set(device.deviceName, device);
144
74
  }
145
- /**
146
- * Unregisters a device registered with the Matterbridge platform.
147
- * @param {MatterbridgeEndpoint} device - The device to unregister.
148
- */
149
75
  async unregisterDevice(device) {
150
76
  await this.matterbridge.removeBridgedEndpoint(this.name, device);
151
77
  if (device.uniqueId)
@@ -153,19 +79,11 @@ export class MatterbridgePlatform {
153
79
  if (device.deviceName)
154
80
  this.registeredEndpointsByName.delete(device.deviceName);
155
81
  }
156
- /**
157
- * Unregisters all devices registered with the Matterbridge platform.
158
- */
159
82
  async unregisterAllDevices() {
160
83
  await this.matterbridge.removeAllBridgedEndpoints(this.name);
161
84
  this.registeredEndpoints.clear();
162
85
  this.registeredEndpointsByName.clear();
163
86
  }
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
87
  verifyMatterbridgeVersion(requiredVersion) {
170
88
  const compareVersions = (matterbridgeVersion, requiredVersion) => {
171
89
  const stripTag = (v) => {
@@ -190,21 +108,9 @@ export class MatterbridgePlatform {
190
108
  return false;
191
109
  return true;
192
110
  }
193
- /**
194
- * @deprecated This method is deprecated and will be removed in future versions. Use validateDevice instead.
195
- */
196
111
  validateDeviceWhiteBlackList(device, log = true) {
197
112
  return this.validateDevice(device, log);
198
113
  }
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
114
  validateDevice(device, log = true) {
209
115
  if (!Array.isArray(device))
210
116
  device = [device];
@@ -234,21 +140,9 @@ export class MatterbridgePlatform {
234
140
  this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
235
141
  return false;
236
142
  }
237
- /**
238
- * @deprecated This method is deprecated and will be removed in future versions. Use validateEntity instead.
239
- */
240
143
  validateEntityBlackList(device, entity, log = true) {
241
144
  return this.validateEntity(device, entity, log);
242
145
  }
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
146
  validateEntity(device, entity, log = true) {
253
147
  if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
254
148
  if (log)
@@ -267,15 +161,6 @@ export class MatterbridgePlatform {
267
161
  }
268
162
  return true;
269
163
  }
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
164
  async checkEndpointNumbers() {
280
165
  if (!this.storage)
281
166
  return -1;
@@ -315,4 +200,3 @@ export class MatterbridgePlatform {
315
200
  return endpointMap.size;
316
201
  }
317
202
  }
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