matterbridge 3.1.0 → 3.1.1-dev-20250629-f14b886

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 (188) hide show
  1. package/CHANGELOG.md +17 -4
  2. package/README-DEV.md +14 -2
  3. package/dist/cli.js +2 -91
  4. package/dist/clusters/export.js +0 -2
  5. package/dist/defaultConfigSchema.js +0 -24
  6. package/dist/deviceManager.js +1 -94
  7. package/dist/devices/export.js +0 -2
  8. package/dist/evse.js +9 -70
  9. package/dist/frontend.js +16 -413
  10. package/dist/globalMatterbridge.js +0 -47
  11. package/dist/helpers.js +0 -53
  12. package/dist/index.js +1 -32
  13. package/dist/laundryWasher.js +7 -92
  14. package/dist/logger/export.js +0 -1
  15. package/dist/matter/behaviors.js +0 -2
  16. package/dist/matter/clusters.js +0 -2
  17. package/dist/matter/devices.js +0 -2
  18. package/dist/matter/endpoints.js +0 -2
  19. package/dist/matter/export.js +0 -3
  20. package/dist/matter/types.js +0 -3
  21. package/dist/matterbridge.js +50 -797
  22. package/dist/matterbridgeAccessoryPlatform.js +0 -36
  23. package/dist/matterbridgeBehaviors.js +1 -55
  24. package/dist/matterbridgeDeviceTypes.js +15 -579
  25. package/dist/matterbridgeDynamicPlatform.js +0 -36
  26. package/dist/matterbridgeEndpoint.js +40 -1022
  27. package/dist/matterbridgeEndpointHelpers.js +12 -322
  28. package/dist/matterbridgePlatform.js +0 -233
  29. package/dist/matterbridgeTypes.js +0 -25
  30. package/dist/pluginManager.js +3 -269
  31. package/dist/roboticVacuumCleaner.js +6 -83
  32. package/dist/shelly.js +7 -168
  33. package/dist/storage/export.js +0 -1
  34. package/dist/update.js +0 -54
  35. package/dist/utils/colorUtils.js +2 -263
  36. package/dist/utils/commandLine.js +0 -54
  37. package/dist/utils/copyDirectory.js +1 -38
  38. package/dist/utils/createDirectory.js +0 -33
  39. package/dist/utils/createZip.js +2 -47
  40. package/dist/utils/deepCopy.js +0 -39
  41. package/dist/utils/deepEqual.js +1 -72
  42. package/dist/utils/export.js +0 -1
  43. package/dist/utils/hex.js +0 -58
  44. package/dist/utils/isvalid.js +0 -101
  45. package/dist/utils/network.js +5 -83
  46. package/dist/utils/spawn.js +0 -18
  47. package/dist/utils/wait.js +9 -62
  48. package/dist/waterHeater.js +2 -77
  49. package/npm-shrinkwrap.json +2 -2
  50. package/package.json +1 -2
  51. package/dist/cli.d.ts +0 -29
  52. package/dist/cli.d.ts.map +0 -1
  53. package/dist/cli.js.map +0 -1
  54. package/dist/clusters/export.d.ts +0 -2
  55. package/dist/clusters/export.d.ts.map +0 -1
  56. package/dist/clusters/export.js.map +0 -1
  57. package/dist/defaultConfigSchema.d.ts +0 -28
  58. package/dist/defaultConfigSchema.d.ts.map +0 -1
  59. package/dist/defaultConfigSchema.js.map +0 -1
  60. package/dist/deviceManager.d.ts +0 -112
  61. package/dist/deviceManager.d.ts.map +0 -1
  62. package/dist/deviceManager.js.map +0 -1
  63. package/dist/devices/export.d.ts +0 -5
  64. package/dist/devices/export.d.ts.map +0 -1
  65. package/dist/devices/export.js.map +0 -1
  66. package/dist/evse.d.ts +0 -72
  67. package/dist/evse.d.ts.map +0 -1
  68. package/dist/evse.js.map +0 -1
  69. package/dist/frontend.d.ts +0 -285
  70. package/dist/frontend.d.ts.map +0 -1
  71. package/dist/frontend.js.map +0 -1
  72. package/dist/globalMatterbridge.d.ts +0 -59
  73. package/dist/globalMatterbridge.d.ts.map +0 -1
  74. package/dist/globalMatterbridge.js.map +0 -1
  75. package/dist/helpers.d.ts +0 -48
  76. package/dist/helpers.d.ts.map +0 -1
  77. package/dist/helpers.js.map +0 -1
  78. package/dist/index.d.ts +0 -38
  79. package/dist/index.d.ts.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/laundryWasher.d.ts +0 -243
  82. package/dist/laundryWasher.d.ts.map +0 -1
  83. package/dist/laundryWasher.js.map +0 -1
  84. package/dist/logger/export.d.ts +0 -2
  85. package/dist/logger/export.d.ts.map +0 -1
  86. package/dist/logger/export.js.map +0 -1
  87. package/dist/matter/behaviors.d.ts +0 -2
  88. package/dist/matter/behaviors.d.ts.map +0 -1
  89. package/dist/matter/behaviors.js.map +0 -1
  90. package/dist/matter/clusters.d.ts +0 -2
  91. package/dist/matter/clusters.d.ts.map +0 -1
  92. package/dist/matter/clusters.js.map +0 -1
  93. package/dist/matter/devices.d.ts +0 -2
  94. package/dist/matter/devices.d.ts.map +0 -1
  95. package/dist/matter/devices.js.map +0 -1
  96. package/dist/matter/endpoints.d.ts +0 -2
  97. package/dist/matter/endpoints.d.ts.map +0 -1
  98. package/dist/matter/endpoints.js.map +0 -1
  99. package/dist/matter/export.d.ts +0 -5
  100. package/dist/matter/export.d.ts.map +0 -1
  101. package/dist/matter/export.js.map +0 -1
  102. package/dist/matter/types.d.ts +0 -3
  103. package/dist/matter/types.d.ts.map +0 -1
  104. package/dist/matter/types.js.map +0 -1
  105. package/dist/matterbridge.d.ts +0 -450
  106. package/dist/matterbridge.d.ts.map +0 -1
  107. package/dist/matterbridge.js.map +0 -1
  108. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
  109. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  110. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  111. package/dist/matterbridgeBehaviors.d.ts +0 -1334
  112. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  113. package/dist/matterbridgeBehaviors.js.map +0 -1
  114. package/dist/matterbridgeDeviceTypes.d.ts +0 -709
  115. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  116. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  117. package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
  118. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  119. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  120. package/dist/matterbridgeEndpoint.d.ts +0 -1173
  121. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  122. package/dist/matterbridgeEndpoint.js.map +0 -1
  123. package/dist/matterbridgeEndpointHelpers.d.ts +0 -3198
  124. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  125. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  126. package/dist/matterbridgePlatform.d.ts +0 -310
  127. package/dist/matterbridgePlatform.d.ts.map +0 -1
  128. package/dist/matterbridgePlatform.js.map +0 -1
  129. package/dist/matterbridgeTypes.d.ts +0 -184
  130. package/dist/matterbridgeTypes.d.ts.map +0 -1
  131. package/dist/matterbridgeTypes.js.map +0 -1
  132. package/dist/pluginManager.d.ts +0 -291
  133. package/dist/pluginManager.d.ts.map +0 -1
  134. package/dist/pluginManager.js.map +0 -1
  135. package/dist/roboticVacuumCleaner.d.ts +0 -104
  136. package/dist/roboticVacuumCleaner.d.ts.map +0 -1
  137. package/dist/roboticVacuumCleaner.js.map +0 -1
  138. package/dist/shelly.d.ts +0 -174
  139. package/dist/shelly.d.ts.map +0 -1
  140. package/dist/shelly.js.map +0 -1
  141. package/dist/storage/export.d.ts +0 -2
  142. package/dist/storage/export.d.ts.map +0 -1
  143. package/dist/storage/export.js.map +0 -1
  144. package/dist/update.d.ts +0 -59
  145. package/dist/update.d.ts.map +0 -1
  146. package/dist/update.js.map +0 -1
  147. package/dist/utils/colorUtils.d.ts +0 -117
  148. package/dist/utils/colorUtils.d.ts.map +0 -1
  149. package/dist/utils/colorUtils.js.map +0 -1
  150. package/dist/utils/commandLine.d.ts +0 -59
  151. package/dist/utils/commandLine.d.ts.map +0 -1
  152. package/dist/utils/commandLine.js.map +0 -1
  153. package/dist/utils/copyDirectory.d.ts +0 -33
  154. package/dist/utils/copyDirectory.d.ts.map +0 -1
  155. package/dist/utils/copyDirectory.js.map +0 -1
  156. package/dist/utils/createDirectory.d.ts +0 -34
  157. package/dist/utils/createDirectory.d.ts.map +0 -1
  158. package/dist/utils/createDirectory.js.map +0 -1
  159. package/dist/utils/createZip.d.ts +0 -39
  160. package/dist/utils/createZip.d.ts.map +0 -1
  161. package/dist/utils/createZip.js.map +0 -1
  162. package/dist/utils/deepCopy.d.ts +0 -32
  163. package/dist/utils/deepCopy.d.ts.map +0 -1
  164. package/dist/utils/deepCopy.js.map +0 -1
  165. package/dist/utils/deepEqual.d.ts +0 -54
  166. package/dist/utils/deepEqual.d.ts.map +0 -1
  167. package/dist/utils/deepEqual.js.map +0 -1
  168. package/dist/utils/export.d.ts +0 -12
  169. package/dist/utils/export.d.ts.map +0 -1
  170. package/dist/utils/export.js.map +0 -1
  171. package/dist/utils/hex.d.ts +0 -49
  172. package/dist/utils/hex.d.ts.map +0 -1
  173. package/dist/utils/hex.js.map +0 -1
  174. package/dist/utils/isvalid.d.ts +0 -103
  175. package/dist/utils/isvalid.d.ts.map +0 -1
  176. package/dist/utils/isvalid.js.map +0 -1
  177. package/dist/utils/network.d.ts +0 -76
  178. package/dist/utils/network.d.ts.map +0 -1
  179. package/dist/utils/network.js.map +0 -1
  180. package/dist/utils/spawn.d.ts +0 -14
  181. package/dist/utils/spawn.d.ts.map +0 -1
  182. package/dist/utils/spawn.js.map +0 -1
  183. package/dist/utils/wait.d.ts +0 -56
  184. package/dist/utils/wait.d.ts.map +0 -1
  185. package/dist/utils/wait.js.map +0 -1
  186. package/dist/waterHeater.d.ts +0 -106
  187. package/dist/waterHeater.d.ts.map +0 -1
  188. package/dist/waterHeater.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -8,21 +8,34 @@ If you like this project and find it useful, please consider giving it a star on
8
8
  <img src="bmc-button.svg" alt="Buy me a coffee" width="120">
9
9
  </a>
10
10
 
11
+ ## [3.1.1] - 2025-07-??
12
+
13
+ ### Added
14
+
15
+ ### Changed
16
+
17
+ - [package]: Updated dependencies.
18
+
19
+ <a href="https://www.buymeacoffee.com/luligugithub">
20
+ <img src="bmc-button.svg" alt="Buy me a coffee" width="80">
21
+ </a>
22
+
11
23
  ## [3.1.0] - 2025-06-28
12
24
 
13
25
  ### Added
14
26
 
15
- - [DevContainer]: Added support for the **Matterbridge Dev Container** with an optimized named volume for `node_modules`.
27
+ - [DevContainer]: Added support for the [**Matterbridge Dev Container**](https://github.com/Luligu/matterbridge/blob/dev/README-DEV.md#matterbridge-dev-container) with an optimized named volume for `node_modules`.
28
+ - [DevContainer]: Added support for the [**Matterbridge Plugin Dev Container**](https://github.com/Luligu/matterbridge/blob/dev/README-DEV.md#matterbridge-plugin-dev-container) with an optimized named volume for `matterbridge` and `node_modules`.
16
29
  - [GitHub]: Added GitHub issue templates for bug reports and feature requests.
17
- - [Systemd]: Added a systemd service file for Matterbridge in the systemd directory.
30
+ - [Systemd]: Added a systemd service example file for Matterbridge in the systemd directory.
18
31
  - [ESLint]: Refactored ESLint configuration for TypeScript and improved plugin integration.
19
32
  - [ESLint]: Added the plugins `eslint-plugin-promise`, `eslint-plugin-jsdoc`, and `@vitest/eslint-plugin`.
20
- - [Vitest]: Added Vitest for TypeScript project testing. It will replace Jest, which does not work correctly with ESM module mocks.
33
+ - [Vitest]: Added `Vitest` for TypeScript project testing. It will replace Jest, which does not work correctly with ESM module mocks.
21
34
  - [JSDoc]: Added missing JSDoc comments, including `@param` and `@returns` tags.
22
35
  - [MatterbridgeEndpoint]: Add MatterbridgeEndpoint mode='server'. It allows to advertise a single device like an autonomous device with its server node to be paired. The device is not bridged (alpha stage).
23
36
  - [MatterbridgeEndpoint]: Add MatterbridgeEndpoint mode='matter'. It allows to add a single device to the Matterbridge server node next to the aggregator. The device is not bridged (alpha stage).
24
37
  - [storage]: Improved error handling of corrupted storage.
25
- - [test]: Improved test units on Matterbridge classes.
38
+ - [test]: Improved test units on Matterbridge classes (coverage 91%).
26
39
 
27
40
  ### Changed
28
41
 
package/README-DEV.md CHANGED
@@ -28,7 +28,7 @@ The Matterbridge Plugin Template has an already configured Jest / Vitest test un
28
28
 
29
29
  It also has a workflow configured to run on push and pull request that build, lint and test the plugin on node 20, 22 and 24 with ubuntu, macOS and windows.
30
30
 
31
- ## Dev Container
31
+ ## Matterbridge Dev Container
32
32
 
33
33
  Using a Dev Container provides a fully isolated, reproducible, and pre-configured development environment. This ensures that all contributors have the same tools, extensions, and dependencies, eliminating "works on my machine" issues. It also makes onboarding new developers fast and hassle-free, as everything needed is set up automatically.
34
34
 
@@ -36,7 +36,19 @@ For improved efficiency, the setup uses named Docker volumes for `node_modules`.
36
36
 
37
37
  To start the Dev Container, simply open the project folder in [Visual Studio Code](https://code.visualstudio.com/) and, if prompted, click "Reopen in Container". Alternatively, use the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P`), search for "Dev Containers: Reopen in Container", and select it. VS Code will automatically build and start the containerized environment for you.
38
38
 
39
- > **Note:** The first time you use the Dev Container, it may take a while to download all the required Docker images and set up the environment. Subsequent starts will be much faster.
39
+ > **Note:** The first time you use the Dev Container, it may take a while to download all the required Docker images and set up the environment. Subsequent starts will be as as fast as from the local folder.
40
+
41
+ Since Dev Container doesn't run in network mode 'host', it is not possible to pair Mattebridge running inside the Dev Container.
42
+
43
+ ## Matterbridge Plugin Dev Container
44
+
45
+ Using a Dev Container provides a fully isolated, reproducible, and pre-configured development environment. This ensures that all contributors have the same tools, extensions, and dependencies, eliminating "works on my machine" issues. It also makes onboarding new developers fast and hassle-free, as everything needed is set up automatically.
46
+
47
+ For improved efficiency, the setup uses named Docker volumes for `matterbridge` and `node_modules`. This means that the dev of matterbridge and the plugin dependencies are installed only once and persist across container rebuilds, making installs and rebuilds much faster than with bind mounts or ephemeral volumes.
48
+
49
+ To start the Dev Container, simply open the project folder in [Visual Studio Code](https://code.visualstudio.com/) and, if prompted, click "Reopen in Container". Alternatively, use the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P`), search for "Dev Containers: Reopen in Container", and select it. VS Code will automatically build and start the containerized environment for you.
50
+
51
+ > **Note:** The first time you use the Dev Container, it may take a while to download all the required Docker images and set up the environment. Subsequent starts will be as fast as from the local folder.
40
52
 
41
53
  Since Dev Container doesn't run in network mode 'host', it is not possible to pair Mattebridge running inside the Dev Container.
42
54
 
package/dist/cli.js CHANGED
@@ -1,46 +1,19 @@
1
- /**
2
- * This file contains the CLI entry point of Matterbridge.
3
- *
4
- * @file cli.ts
5
- * @author Luca Liguori
6
- * @created 2023-12-29
7
- * @version 2.0.1
8
- * @license Apache-2.0
9
- *
10
- * Copyright 2023, 2024, 2025 Luca Liguori.
11
- *
12
- * Licensed under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License.
14
- * You may obtain a copy of the License at
15
- *
16
- * http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
1
  import os from 'node:os';
25
2
  import { EventEmitter } from 'node:events';
26
3
  import { inspect } from 'node:util';
27
- // AnsiLogger module
28
4
  import { AnsiLogger, BRIGHT, CYAN, db, YELLOW } from 'node-ansi-logger';
29
- // Matterbridge
30
5
  import { getIntParameter, hasParameter } from './utils/export.js';
31
6
  import { Matterbridge } from './matterbridge.js';
32
7
  export const cliEmitter = new EventEmitter();
33
8
  export let instance;
34
- // Inspectop
35
9
  let session;
36
10
  let snapshotInterval;
37
- // Cpu and memory check
38
11
  let memoryCheckInterval;
39
12
  let prevCpus;
40
13
  export let lastCpuUsage = 0;
41
14
  let peakCpu = 0;
42
15
  let peakRss = 0;
43
- const log = new AnsiLogger({ logName: 'Cli', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: hasParameter('debug') ? "debug" /* LogLevel.DEBUG */ : "info" /* LogLevel.INFO */ });
16
+ const log = new AnsiLogger({ logName: 'Cli', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
44
17
  const formatMemoryUsage = (bytes) => {
45
18
  if (bytes >= 1024 ** 3) {
46
19
  return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
@@ -67,20 +40,14 @@ const formatOsUpTime = (seconds) => {
67
40
  }
68
41
  return `${seconds} second${seconds !== 1 ? 's' : ''}`;
69
42
  };
70
- /**
71
- * Starts the CPU and memory check interval.
72
- */
73
43
  async function startCpuMemoryCheck() {
74
- // const os = await import('node:os');
75
44
  log.debug(`Cpu memory check started`);
76
45
  prevCpus = os.cpus();
77
46
  clearInterval(memoryCheckInterval);
78
47
  const interval = () => {
79
- // Get the os uptime
80
48
  const systemUptime = formatOsUpTime(Math.floor(os.uptime()));
81
49
  const processUptime = formatOsUpTime(Math.floor(process.uptime()));
82
50
  cliEmitter.emit('uptime', systemUptime, processUptime);
83
- // Get the memory usage
84
51
  const totalMememory = formatMemoryUsage(os.totalmem());
85
52
  const freeMemory = formatMemoryUsage(os.freemem());
86
53
  const memoryUsageRaw = process.memoryUsage();
@@ -92,12 +59,10 @@ async function startCpuMemoryCheck() {
92
59
  if (memoryUsageRaw.rss > peakRss)
93
60
  peakRss = memoryUsageRaw.rss;
94
61
  cliEmitter.emit('memory', totalMememory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers);
95
- // Get the cpu usage
96
62
  const currCpus = os.cpus();
97
- // log.debug(`Cpus: ${JSON.stringify(currCpus)}`);
98
63
  let cpuUsageLog;
99
64
  if (currCpus.length !== prevCpus.length) {
100
- prevCpus = currCpus; // Reset the previous cpus
65
+ prevCpus = currCpus;
101
66
  log.debug(`Cpu check length failed, resetting previous cpus`);
102
67
  return;
103
68
  }
@@ -123,29 +88,20 @@ async function startCpuMemoryCheck() {
123
88
  cliEmitter.emit('cpu', lastCpuUsage);
124
89
  }
125
90
  prevCpus = currCpus;
126
- // Show the cpu and memory usage
127
91
  log.debug(`***${YELLOW}${BRIGHT}Cpu usage:${db} ${CYAN}${cpuUsageLog.padStart(6, ' ')} %${db} ${YELLOW}${BRIGHT}Memory usage:${db} rss ${CYAN}${rss}${db} heapTotal ${CYAN}${heapTotal}${db} heapUsed ${CYAN}${heapUsed}${db} external ${external} arrayBuffers ${arrayBuffers}`);
128
92
  };
129
93
  interval();
130
94
  clearInterval(memoryCheckInterval);
131
95
  memoryCheckInterval = setInterval(interval, getIntParameter('memoryinterval') ?? 10 * 1000).unref();
132
96
  }
133
- /**
134
- * Stops the CPU and memory check interval.
135
- */
136
97
  async function stopCpuMemoryCheck() {
137
98
  log.debug(`***Cpu memory check stopped. Peak cpu: ${CYAN}${peakCpu.toFixed(2)} %${db}. Peak rss: ${CYAN}${formatMemoryUsage(peakRss)}${db}.`);
138
99
  clearInterval(memoryCheckInterval);
139
100
  }
140
- /**
141
- * Starts the inspector for heap sampling.
142
- * This function is called when the -inspect parameter is passed.
143
- */
144
101
  async function startInspector() {
145
102
  const { Session } = await import('node:inspector');
146
103
  const { mkdirSync } = await import('node:fs');
147
104
  log.debug(`***Starting heap sampling...`);
148
- // Create the heap snapshots directory if it doesn't exist
149
105
  mkdirSync('heap_profile', { recursive: true });
150
106
  try {
151
107
  session = new Session();
@@ -154,7 +110,6 @@ async function startInspector() {
154
110
  session?.post('HeapProfiler.startSampling', (err) => (err ? reject(err) : resolve()));
155
111
  });
156
112
  log.debug(`***Started heap sampling`);
157
- // Set an interval to take heap snapshots
158
113
  const interval = getIntParameter('snapshotinterval');
159
114
  if (interval && interval >= 30000) {
160
115
  log.debug(`***Started heap snapshot interval of ${CYAN}${interval}${db} ms`);
@@ -172,19 +127,13 @@ async function startInspector() {
172
127
  return;
173
128
  }
174
129
  }
175
- /**
176
- * Stops the heap sampling and saves the profile to a file.
177
- * This function is called when the inspector is stopped.
178
- */
179
130
  async function stopInspector() {
180
131
  const { writeFileSync } = await import('node:fs');
181
132
  const path = await import('node:path');
182
133
  log.debug(`***Stopping heap sampling...`);
183
134
  if (snapshotInterval) {
184
135
  log.debug(`***Clearing heap snapshot interval...`);
185
- // Clear the snapshot interval if it exists
186
136
  clearInterval(snapshotInterval);
187
- // Take a final heap snapshot before stopping
188
137
  await takeHeapSnapshot();
189
138
  }
190
139
  if (!session) {
@@ -192,7 +141,6 @@ async function stopInspector() {
192
141
  return;
193
142
  }
194
143
  try {
195
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
196
144
  const result = await new Promise((resolve, reject) => {
197
145
  session?.post('HeapProfiler.stopSampling', (err, result) => (err ? reject(err) : resolve(result)));
198
146
  });
@@ -210,13 +158,6 @@ async function stopInspector() {
210
158
  log.debug(`***Stopped heap sampling`);
211
159
  }
212
160
  }
213
- /**
214
- * Takes a heap snapshot and saves it to the file name Heap-snapshot-<timestamp>.heapsnapshot.
215
- * This function is called periodically based on the -snapshotinterval parameter.
216
- * The -snapshotinterval parameter must at least 30000 ms.
217
- * The snapshot is saved in the heap_profile directory that is created in the current working directory.
218
- * The snapshot can be analyzed using vscode or Chrome DevTools or other tools that support heap snapshots.
219
- */
220
161
  async function takeHeapSnapshot() {
221
162
  const { writeFileSync } = await import('node:fs');
222
163
  const path = await import('node:path');
@@ -248,10 +189,6 @@ async function takeHeapSnapshot() {
248
189
  });
249
190
  });
250
191
  }
251
- /**
252
- * Triggers a manual garbage collection.
253
- * This function is working only if the process is started with --expose-gc.
254
- */
255
192
  function triggerGarbageCollection() {
256
193
  if (typeof global.gc === 'function') {
257
194
  global.gc();
@@ -261,9 +198,6 @@ function triggerGarbageCollection() {
261
198
  log.debug('Garbage collection is not exposed. Start Node.js with --expose-gc to enable manual GC.');
262
199
  }
263
200
  }
264
- /**
265
- * Registers event handlers for the Matterbridge instance.
266
- */
267
201
  function registerHandlers() {
268
202
  log.debug('Registering event handlers...');
269
203
  if (instance)
@@ -286,52 +220,32 @@ function registerHandlers() {
286
220
  instance.on('triggergarbagecollection', async () => triggerGarbageCollection());
287
221
  log.debug('Registered event handlers');
288
222
  }
289
- /**
290
- * Shuts down the Matterbridge instance and exits the process.
291
- */
292
223
  async function shutdown() {
293
224
  log.debug('Received shutdown event, exiting...');
294
225
  if (hasParameter('inspect'))
295
226
  await stopInspector();
296
227
  await stopCpuMemoryCheck();
297
228
  cliEmitter.emit('shutdown');
298
- // eslint-disable-next-line n/no-process-exit
299
229
  process.exit(0);
300
230
  }
301
- /**
302
- *
303
- */
304
231
  async function restart() {
305
232
  log.debug('Received restart event, loading...');
306
233
  instance = await Matterbridge.loadInstance(true);
307
234
  registerHandlers();
308
235
  }
309
- /**
310
- *
311
- */
312
236
  async function update() {
313
237
  log.debug('Received update event, updating...');
314
- // TODO: Implement update logic outside of matterbridge
315
238
  instance = await Matterbridge.loadInstance(true);
316
239
  registerHandlers();
317
240
  }
318
- /**
319
- * Starts the CPU and memory check when the -startmemorycheck parameter is passed.
320
- */
321
241
  async function start() {
322
242
  log.debug('Received start memory check event');
323
243
  await startCpuMemoryCheck();
324
244
  }
325
- /**
326
- * Stops the CPU and memory check when the -stopmemorycheck parameter is passed.
327
- */
328
245
  async function stop() {
329
246
  log.debug('Received stop memory check event');
330
247
  await stopCpuMemoryCheck();
331
248
  }
332
- /**
333
- * Main function that initializes the Matterbridge instance and starts the CLI.
334
- */
335
249
  async function main() {
336
250
  log.debug(`Cli main() started`);
337
251
  await startCpuMemoryCheck();
@@ -340,7 +254,6 @@ async function main() {
340
254
  log.debug(`***Matterbridge.loadInstance(true) called`);
341
255
  instance = await Matterbridge.loadInstance(true);
342
256
  log.debug(`***Matterbridge.loadInstance(true) exited`);
343
- // Check if the instance needs to shut down from parseCommandLine()
344
257
  if (!instance || instance.shutdown) {
345
258
  shutdown();
346
259
  }
@@ -349,11 +262,9 @@ async function main() {
349
262
  cliEmitter.emit('ready');
350
263
  }
351
264
  }
352
- // Run the main function
353
265
  process.title = 'matterbridge';
354
266
  main().catch((error) => {
355
267
  const errorMessage = error instanceof Error ? error.message : error;
356
268
  const errorInspect = inspect(error, { depth: 10 });
357
269
  log.error(`Matterbridge.loadInstance() failed with error: ${errorMessage}\nstack: ${errorInspect}`);
358
270
  });
359
- //# sourceMappingURL=cli.js.map
@@ -1,3 +1 @@
1
1
  export {};
2
- // Nothing to export right now, but this file is here to make it easier to add exports in the future
3
- //# sourceMappingURL=export.js.map
@@ -1,26 +1,3 @@
1
- /**
2
- * This file contains the default config for the plugins.
3
- *
4
- * @file defaultConfigSchema.ts
5
- * @author Luca Liguori
6
- * @created 2024-05-07
7
- * @version 1.0.1
8
- * @license Apache-2.0
9
- *
10
- * Copyright 2024, 2025, 2026 Luca Liguori.
11
- *
12
- * Licensed under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License.
14
- * You may obtain a copy of the License at
15
- *
16
- * http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
1
  export const zigbee2mqtt_config = {
25
2
  name: 'matterbridge-zigbee2mqtt',
26
3
  type: 'DynamicPlatform',
@@ -79,4 +56,3 @@ export const shelly_config = {
79
56
  debugWs: false,
80
57
  unregisterOnShutdown: false,
81
58
  };
82
- //# sourceMappingURL=defaultConfigSchema.js.map
@@ -1,87 +1,26 @@
1
- /**
2
- * This file contains the DeviceManager class.
3
- *
4
- * @file devices.ts
5
- * @author Luca Liguori
6
- * @created 2024-07-26
7
- * @version 1.0.11
8
- * @license Apache-2.0
9
- *
10
- * Copyright 2024, 2025, 2026 Luca Liguori.
11
- *
12
- * Licensed under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License.
14
- * You may obtain a copy of the License at
15
- *
16
- * http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
- // AnsiLogger module
25
1
  import { AnsiLogger, BLUE, er } from 'node-ansi-logger';
26
2
  import { dev } from './matterbridgeTypes.js';
27
- /**
28
- * Manages Matterbridge devices.
29
- */
30
3
  export class DeviceManager {
31
4
  _devices = new Map();
32
5
  matterbridge;
33
6
  log;
34
- /**
35
- * Creates an instance of DeviceManager.
36
- *
37
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
38
- */
39
7
  constructor(matterbridge) {
40
8
  this.matterbridge = matterbridge;
41
- this.log = new AnsiLogger({ logName: 'DeviceManager', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: matterbridge.log.logLevel });
9
+ this.log = new AnsiLogger({ logName: 'DeviceManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
42
10
  this.log.debug('Matterbridge device manager starting...');
43
11
  }
44
- /**
45
- * Gets the number of devices.
46
- *
47
- * @returns {number} The number of devices.
48
- */
49
12
  get length() {
50
13
  return this._devices.size;
51
14
  }
52
- /**
53
- * Gets the number of devices.
54
- *
55
- * @returns {number} The number of devices.
56
- */
57
15
  get size() {
58
16
  return this._devices.size;
59
17
  }
60
- /**
61
- * Checks if a device with the specified unique ID exists.
62
- *
63
- * @param {string} uniqueId - The unique ID of the device.
64
- * @returns {boolean} True if the device exists, false otherwise.
65
- */
66
18
  has(uniqueId) {
67
19
  return this._devices.has(uniqueId);
68
20
  }
69
- /**
70
- * Gets a device by its unique ID.
71
- *
72
- * @param {string} uniqueId - The unique ID of the device.
73
- * @returns {MatterbridgeEndpoint | undefined} The device, or undefined if not found.
74
- */
75
21
  get(uniqueId) {
76
22
  return this._devices.get(uniqueId);
77
23
  }
78
- /**
79
- * Adds a device to the manager.
80
- *
81
- * @param {MatterbridgeEndpoint} device - The device to add.
82
- * @returns {MatterbridgeEndpoint} The added device.
83
- * @throws {Error} If the device does not have a unique ID.
84
- */
85
24
  set(device) {
86
25
  if (!device.uniqueId)
87
26
  throw new Error(`The device ${dev}${device.deviceName}${er} has not been initialized: uniqueId is required`);
@@ -90,13 +29,6 @@ export class DeviceManager {
90
29
  this._devices.set(device.uniqueId, device);
91
30
  return device;
92
31
  }
93
- /**
94
- * Removes a device from the manager.
95
- *
96
- * @param {MatterbridgeEndpoint} device - The device to remove.
97
- * @returns {boolean} True if the device was removed, false otherwise.
98
- * @throws {Error} If the device does not have a unique ID.
99
- */
100
32
  remove(device) {
101
33
  if (!device.uniqueId)
102
34
  throw new Error(`The device ${dev}${device.deviceName}${er} has not been initialized: uniqueId is required`);
@@ -104,34 +36,15 @@ export class DeviceManager {
104
36
  this.log.error(`The device ${dev}${device.deviceName}${er} with uniqueId ${BLUE}${device.uniqueId}${er} serialNumber ${BLUE}${device.serialNumber}${er} is not registered in the device manager`);
105
37
  return this._devices.delete(device.uniqueId);
106
38
  }
107
- /**
108
- * Clears all devices from the manager.
109
- */
110
39
  clear() {
111
40
  this._devices.clear();
112
41
  }
113
- /**
114
- * Gets an array of all devices.
115
- *
116
- * @returns {MatterbridgeEndpoint[]} An array of all devices.
117
- */
118
42
  array() {
119
43
  return Array.from(this._devices.values());
120
44
  }
121
- /**
122
- * Iterates over all devices.
123
- *
124
- * @returns {IterableIterator<MatterbridgeEndpoint>} An iterator for the devices.
125
- */
126
45
  [Symbol.iterator]() {
127
46
  return this._devices.values();
128
47
  }
129
- /**
130
- * Asynchronously iterates over each device and calls the provided callback function.
131
- *
132
- * @param {(device: MatterbridgeEndpoint) => Promise<void>} callback - The callback function to call with each device.
133
- * @returns {Promise<void>} A promise that resolves when all callbacks have been called.
134
- */
135
48
  async forEach(callback) {
136
49
  if (this.size === 0)
137
50
  return;
@@ -145,13 +58,7 @@ export class DeviceManager {
145
58
  });
146
59
  await Promise.all(tasks);
147
60
  }
148
- /**
149
- * Sets the log level.
150
- *
151
- * @param {LogLevel} logLevel - The log level to set.
152
- */
153
61
  set logLevel(logLevel) {
154
62
  this.log.logLevel = logLevel;
155
63
  }
156
64
  }
157
- //# sourceMappingURL=deviceManager.js.map
@@ -1,6 +1,4 @@
1
- // Single class device types
2
1
  export * from '../roboticVacuumCleaner.js';
3
2
  export * from '../laundryWasher.js';
4
3
  export * from '../waterHeater.js';
5
4
  export * from '../evse.js';
6
- //# sourceMappingURL=export.js.map
package/dist/evse.js CHANGED
@@ -1,50 +1,12 @@
1
- /**
2
- * This file contains the Evse class.
3
- *
4
- * @file energy-evse.ts
5
- * @author Luca Liguori
6
- * @contributor Ludovic BOUÉ
7
- * @created 2025-05-27
8
- * @version 1.1.0
9
- * @license Apache-2.0
10
- *
11
- * Copyright 2025, 2026, 2027 Luca Liguori.
12
- *
13
- * Licensed under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License.
15
- * You may obtain a copy of the License at
16
- *
17
- * http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS,
21
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- * See the License for the specific language governing permissions and
23
- * limitations under the License.
24
- */
25
1
  import { EnergyEvseServer } from '@matter/main/behaviors/energy-evse';
26
2
  import { EnergyEvseModeServer } from '@matter/main/behaviors/energy-evse-mode';
27
3
  import { EnergyEvse, EnergyEvseMode } from '@matter/main/clusters';
28
4
  import { DeviceEnergyManagement } from '@matter/main/clusters/device-energy-management';
29
5
  import { ModeBase } from '@matter/main/clusters/mode-base';
30
- // Matterbridge
31
6
  import { MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
32
7
  import { MatterbridgeServer } from './matterbridgeBehaviors.js';
33
8
  import { deviceEnergyManagement, electricalSensor, evse, powerSource } from './matterbridgeDeviceTypes.js';
34
9
  export class Evse extends MatterbridgeEndpoint {
35
- /**
36
- * Creates an instance of the EVSE class.
37
- *
38
- * @param {string} name - The name of the EVSE.
39
- * @param {string} serial - The serial number of the EVSE.
40
- * @param {number} [currentMode] - The current mode of the EnergyEvseMode cluster. Defaults to mode 1 (EnergyEvseMode.ModeTag.Manual).
41
- * @param {EnergyEvseMode.ModeOption[]} [supportedModes] - The supported modes for the EnergyEvseMode cluster. This is a fixed attribute that defaults to a predefined set of EnergyEvseMode cluster modes.
42
- * @param {EnergyEvse.State} [state] - The current state of the EVSE. Defaults to NotPluggedIn.
43
- * @param {EnergyEvse.SupplyState} [supplyState] - The supply state of the EVSE. Defaults to Disabled.
44
- * @param {EnergyEvse.FaultState} [faultState] - The fault state of the EVSE. Defaults to NoError.
45
- * @param {number} [absMinPower] - Indicate the minimum electrical power that the ESA can consume when switched on. Defaults to `0` if not provided.
46
- * @param {number} [absMaxPower] - Indicate the maximum electrical power that the ESA can consume when switched on. Defaults to `0` if not provided.
47
- */
48
10
  constructor(name, serial, currentMode, supportedModes, state, supplyState, faultState, absMinPower, absMaxPower) {
49
11
  super([evse, powerSource, electricalSensor, deviceEnergyManagement], { uniqueStorageKey: `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}` }, true);
50
12
  this.createDefaultIdentifyClusterServer()
@@ -58,46 +20,29 @@ export class Evse extends MatterbridgeEndpoint {
58
20
  .createDefaultEnergyEvseModeClusterServer(currentMode, supportedModes)
59
21
  .addRequiredClusterServers();
60
22
  }
61
- /**
62
- * Creates a default EnergyEvseServer Cluster Server.
63
- *
64
- * @param {EnergyEvse.State} [state] - The initial state of the EnergyEvse cluster. Defaults to EnergyEvse.State.NotPluggedIn.
65
- * @param {EnergyEvse.SupplyState} [supplyState] - The initial supply state of the EnergyEvse cluster. Defaults to EnergyEvse.SupplyState.ChargingEnabled.
66
- * @param {EnergyEvse.FaultState} [faultState] - The initial fault state of the EnergyEvse cluster. Defaults to EnergyEvse.FaultState.NoError.
67
- * @returns {this} The current MatterbridgeEndpoint instance for chaining.
68
- */
69
23
  createDefaultEnergyEvseClusterServer(state, supplyState, faultState) {
70
24
  this.behaviors.require(MatterbridgeEnergyEvseServer, {
71
25
  state: state ?? EnergyEvse.State.NotPluggedIn,
72
26
  supplyState: supplyState ?? EnergyEvse.SupplyState.ChargingEnabled,
73
27
  faultState: faultState ?? EnergyEvse.FaultState.NoError,
74
- chargingEnabledUntil: 0, // Persistent attribute
75
- circuitCapacity: 0, // Persistent attribute in mA
76
- minimumChargeCurrent: 6000, // Persistent attribute in mA
77
- maximumChargeCurrent: 0, // Persistent attribute in mA
78
- sessionId: null, // Persistent attribute
79
- sessionDuration: 0, // Persistent attribute
80
- sessionEnergyCharged: 0, // Persistent attribute
28
+ chargingEnabledUntil: 0,
29
+ circuitCapacity: 0,
30
+ minimumChargeCurrent: 6000,
31
+ maximumChargeCurrent: 0,
32
+ sessionId: null,
33
+ sessionDuration: 0,
34
+ sessionEnergyCharged: 0,
81
35
  });
82
36
  return this;
83
37
  }
84
- /**
85
- * Creates a default EnergyEvseMode Cluster Server.
86
- *
87
- * @param {number} [currentMode] - The current mode of the EnergyEvseMode cluster. Defaults to mode 1 (EnergyEvseMode.ModeTag.Manual).
88
- * @param {EnergyEvseMode.ModeOption[]} [supportedModes] - The supported modes for the EnergyEvseMode cluster. Defaults all EnergyEvseMode cluster modes.
89
- *
90
- * @returns {this} The current MatterbridgeEndpoint instance for chaining.
91
- */
92
38
  createDefaultEnergyEvseModeClusterServer(currentMode, supportedModes) {
93
39
  this.behaviors.require(MatterbridgeEnergyEvseModeServer, {
94
40
  supportedModes: supportedModes ?? [
95
41
  { label: 'On demand', mode: 1, modeTags: [{ value: EnergyEvseMode.ModeTag.Manual }] },
96
42
  { label: 'Scheduled', mode: 2, modeTags: [{ value: EnergyEvseMode.ModeTag.TimeOfUse }] },
97
43
  { label: 'Solar charging', mode: 3, modeTags: [{ value: EnergyEvseMode.ModeTag.SolarCharging }] },
98
- // { label: 'Home to vehicle and Vehicle to home', mode: 4, modeTags: [{ value: EnergyEvseMode.ModeTag.V2X }] }, // This mode is not valid in charging only EVSEs
99
- ], // FixedAttribute
100
- currentMode: currentMode ?? 1, // Persistent attribute
44
+ ],
45
+ currentMode: currentMode ?? 1,
101
46
  });
102
47
  return this;
103
48
  }
@@ -113,8 +58,6 @@ export class MatterbridgeEnergyEvseServer extends EnergyEvseServer {
113
58
  this.state.state = EnergyEvse.State.PluggedInDemand;
114
59
  }
115
60
  this.state.chargingEnabledUntil = 0;
116
- // super.disable();
117
- // disable is not implemented in matter.js
118
61
  }
119
62
  enableCharging(request) {
120
63
  const device = this.endpoint.stateOf(MatterbridgeServer);
@@ -128,9 +71,6 @@ export class MatterbridgeEnergyEvseServer extends EnergyEvseServer {
128
71
  this.state.chargingEnabledUntil = request.chargingEnabledUntil;
129
72
  this.state.minimumChargeCurrent = request.minimumChargeCurrent;
130
73
  this.state.maximumChargeCurrent = request.maximumChargeCurrent;
131
- // The implementation should also stop the charging session at the required time and update the sessionId, sessionDuration, and sessionEnergyCharged attributes if needed.
132
- // super.enableCharging();
133
- // enableCharging is not implemented in matter.js
134
74
  }
135
75
  }
136
76
  export class MatterbridgeEnergyEvseModeServer extends EnergyEvseModeServer {
@@ -148,4 +88,3 @@ export class MatterbridgeEnergyEvseModeServer extends EnergyEvseModeServer {
148
88
  return { status: ModeBase.ModeChangeStatus.Success, statusText: 'Success' };
149
89
  }
150
90
  }
151
- //# sourceMappingURL=evse.js.map