matterbridge 2.2.0-dev.5 → 2.2.0-dev.6

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 (120) hide show
  1. package/dist/cli.js +2 -37
  2. package/dist/cluster/export.js +0 -2
  3. package/dist/defaultConfigSchema.js +0 -23
  4. package/dist/deviceManager.js +1 -94
  5. package/dist/frontend.js +22 -265
  6. package/dist/index.js +2 -29
  7. package/dist/logger/export.js +0 -1
  8. package/dist/matter/behaviors.js +0 -2
  9. package/dist/matter/clusters.js +0 -2
  10. package/dist/matter/devices.js +0 -2
  11. package/dist/matter/endpoints.js +0 -2
  12. package/dist/matter/export.js +0 -2
  13. package/dist/matter/types.js +1 -3
  14. package/dist/matterbridge.js +47 -718
  15. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  16. package/dist/matterbridgeBehaviors.js +1 -32
  17. package/dist/matterbridgeDeviceTypes.js +11 -112
  18. package/dist/matterbridgeDynamicPlatform.js +0 -33
  19. package/dist/matterbridgeEndpoint.js +6 -690
  20. package/dist/matterbridgeEndpointHelpers.js +9 -118
  21. package/dist/matterbridgePlatform.js +7 -140
  22. package/dist/matterbridgeTypes.js +0 -24
  23. package/dist/pluginManager.js +3 -229
  24. package/dist/shelly.js +4 -131
  25. package/dist/storage/export.js +0 -1
  26. package/dist/update.js +0 -45
  27. package/dist/utils/colorUtils.js +2 -205
  28. package/dist/utils/copyDirectory.js +1 -37
  29. package/dist/utils/createZip.js +2 -42
  30. package/dist/utils/deepCopy.js +0 -40
  31. package/dist/utils/deepEqual.js +1 -65
  32. package/dist/utils/export.js +0 -1
  33. package/dist/utils/isvalid.js +0 -86
  34. package/dist/utils/network.js +5 -77
  35. package/dist/utils/parameter.js +0 -41
  36. package/dist/utils/wait.js +5 -48
  37. package/npm-shrinkwrap.json +2 -2
  38. package/package.json +1 -1
  39. package/dist/cli.d.ts +0 -28
  40. package/dist/cli.d.ts.map +0 -1
  41. package/dist/cli.js.map +0 -1
  42. package/dist/cluster/export.d.ts.map +0 -1
  43. package/dist/cluster/export.js.map +0 -1
  44. package/dist/defaultConfigSchema.d.ts.map +0 -1
  45. package/dist/defaultConfigSchema.js.map +0 -1
  46. package/dist/deviceManager.d.ts +0 -109
  47. package/dist/deviceManager.d.ts.map +0 -1
  48. package/dist/deviceManager.js.map +0 -1
  49. package/dist/frontend.d.ts +0 -172
  50. package/dist/frontend.d.ts.map +0 -1
  51. package/dist/frontend.js.map +0 -1
  52. package/dist/index.d.ts.map +0 -1
  53. package/dist/index.js.map +0 -1
  54. package/dist/logger/export.d.ts.map +0 -1
  55. package/dist/logger/export.js.map +0 -1
  56. package/dist/matter/behaviors.d.ts.map +0 -1
  57. package/dist/matter/behaviors.js.map +0 -1
  58. package/dist/matter/clusters.d.ts.map +0 -1
  59. package/dist/matter/clusters.js.map +0 -1
  60. package/dist/matter/devices.d.ts.map +0 -1
  61. package/dist/matter/devices.js.map +0 -1
  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.map +0 -1
  65. package/dist/matter/export.js.map +0 -1
  66. package/dist/matter/types.d.ts.map +0 -1
  67. package/dist/matter/types.js.map +0 -1
  68. package/dist/matterbridge.d.ts +0 -410
  69. package/dist/matterbridge.d.ts.map +0 -1
  70. package/dist/matterbridge.js.map +0 -1
  71. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  72. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  73. package/dist/matterbridgeBehaviors.d.ts +0 -148
  74. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  75. package/dist/matterbridgeBehaviors.js.map +0 -1
  76. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  77. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  78. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  79. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  80. package/dist/matterbridgeEndpoint.d.ts +0 -827
  81. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  82. package/dist/matterbridgeEndpoint.js.map +0 -1
  83. package/dist/matterbridgeEndpointHelpers.d.ts +0 -123
  84. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  85. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  86. package/dist/matterbridgePlatform.d.ts +0 -159
  87. package/dist/matterbridgePlatform.d.ts.map +0 -1
  88. package/dist/matterbridgePlatform.js.map +0 -1
  89. package/dist/matterbridgeTypes.d.ts.map +0 -1
  90. package/dist/matterbridgeTypes.js.map +0 -1
  91. package/dist/pluginManager.d.ts +0 -236
  92. package/dist/pluginManager.d.ts.map +0 -1
  93. package/dist/pluginManager.js.map +0 -1
  94. package/dist/shelly.d.ts.map +0 -1
  95. package/dist/shelly.js.map +0 -1
  96. package/dist/storage/export.d.ts.map +0 -1
  97. package/dist/storage/export.js.map +0 -1
  98. package/dist/update.d.ts.map +0 -1
  99. package/dist/update.js.map +0 -1
  100. package/dist/utils/colorUtils.d.ts.map +0 -1
  101. package/dist/utils/colorUtils.js.map +0 -1
  102. package/dist/utils/copyDirectory.d.ts.map +0 -1
  103. package/dist/utils/copyDirectory.js.map +0 -1
  104. package/dist/utils/createZip.d.ts.map +0 -1
  105. package/dist/utils/createZip.js.map +0 -1
  106. package/dist/utils/deepCopy.d.ts.map +0 -1
  107. package/dist/utils/deepCopy.js.map +0 -1
  108. package/dist/utils/deepEqual.d.ts.map +0 -1
  109. package/dist/utils/deepEqual.js.map +0 -1
  110. package/dist/utils/export.d.ts.map +0 -1
  111. package/dist/utils/export.js.map +0 -1
  112. package/dist/utils/isvalid.d.ts.map +0 -1
  113. package/dist/utils/isvalid.js.map +0 -1
  114. package/dist/utils/network.d.ts.map +0 -1
  115. package/dist/utils/network.js.map +0 -1
  116. package/dist/utils/parameter.d.ts.map +0 -1
  117. package/dist/utils/parameter.js.map +0 -1
  118. package/dist/utils/wait.d.ts +0 -43
  119. package/dist/utils/wait.d.ts.map +0 -1
  120. package/dist/utils/wait.js.map +0 -1
package/dist/shelly.js CHANGED
@@ -1,34 +1,5 @@
1
- /**
2
- * This file contains the shelly api functions.
3
- *
4
- * @file shelly.ts
5
- * @author Luca Liguori
6
- * @date 2025-02-19
7
- * @version 1.0.3
8
- *
9
- * Copyright 2025, 2026, 2027 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
- /* eslint-disable @typescript-eslint/no-explicit-any */
24
1
  import { WS_ID_SHELLY_MAIN_UPDATE, WS_ID_SHELLY_SYS_UPDATE } from './frontend.js';
25
2
  import { debugStringify } from './logger/export.js';
26
- /**
27
- * Fetches Shelly system updates. If available: logs the result, sends a snackbar message, and broadcasts the message.
28
- *
29
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
30
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
31
- */
32
3
  export async function getShellySysUpdate(matterbridge) {
33
4
  getShelly('/api/updates/sys/check', 60 * 1000)
34
5
  .then(async (data) => {
@@ -47,16 +18,9 @@ export async function getShellySysUpdate(matterbridge) {
47
18
  matterbridge.log.warn(`Error getting Shelly system updates: ${error instanceof Error ? error.message : error}`);
48
19
  });
49
20
  }
50
- /**
51
- * Triggers Shelly system updates.
52
- *
53
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
54
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
55
- */
56
21
  export async function triggerShellySysUpdate(matterbridge) {
57
22
  getShelly('/api/updates/sys/perform', 10 * 1000)
58
23
  .then(async () => {
59
- // {"updatingInProgress":true} or {"updatingInProgress":false}
60
24
  matterbridge.log.debug(`Triggered Shelly system updates`);
61
25
  })
62
26
  .catch((error) => {
@@ -69,12 +33,6 @@ export async function triggerShellySysUpdate(matterbridge) {
69
33
  matterbridge.frontend.wssBroadcastMessage(WS_ID_SHELLY_SYS_UPDATE, 'shelly-sys-update', { available: false });
70
34
  });
71
35
  }
72
- /**
73
- * Fetches Shelly main updates. If available: logs the result, sends a snackbar message, and broadcasts the message.
74
- *
75
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
76
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
77
- */
78
36
  export async function getShellyMainUpdate(matterbridge) {
79
37
  getShelly('/api/updates/main/check', 60 * 1000)
80
38
  .then(async (data) => {
@@ -93,15 +51,9 @@ export async function getShellyMainUpdate(matterbridge) {
93
51
  matterbridge.log.warn(`Error getting Shelly main updates: ${error instanceof Error ? error.message : error}`);
94
52
  });
95
53
  }
96
- /**
97
- * Triggers Shelly main updates.
98
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
99
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
100
- */
101
54
  export async function triggerShellyMainUpdate(matterbridge) {
102
55
  getShelly('/api/updates/main/perform', 10 * 1000)
103
56
  .then(async () => {
104
- // {"updatingInProgress":true} or {"updatingInProgress":false}
105
57
  matterbridge.log.debug(`Triggered Shelly main updates`);
106
58
  })
107
59
  .catch((error) => {
@@ -114,12 +66,6 @@ export async function triggerShellyMainUpdate(matterbridge) {
114
66
  matterbridge.frontend.wssBroadcastMessage(WS_ID_SHELLY_MAIN_UPDATE, 'shelly-main-update', { available: false });
115
67
  });
116
68
  }
117
- /**
118
- * Triggers Shelly change network configuration.
119
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
120
- * @param {object} config - The network configuration.
121
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
122
- */
123
69
  export async function triggerShellyChangeIp(matterbridge, config) {
124
70
  const api = config.type === 'static' ? '/api/network/connection/static' : '/api/network/connection/dynamic';
125
71
  const data = { interface: 'end0' };
@@ -142,11 +88,6 @@ export async function triggerShellyChangeIp(matterbridge, config) {
142
88
  matterbridge.frontend.wssSendSnackbarMessage('Changed Shelly network configuration');
143
89
  });
144
90
  }
145
- /**
146
- * Triggers Shelly system reboot.
147
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
148
- * @returns {Promise<void>} A promise that resolves when the operation is complete.
149
- */
150
91
  export async function triggerShellyReboot(matterbridge) {
151
92
  matterbridge.log.debug(`Triggering Shelly system reboot`);
152
93
  postShelly('/api/system/reboot', {}, 60 * 1000)
@@ -161,21 +102,6 @@ export async function triggerShellyReboot(matterbridge) {
161
102
  matterbridge.frontend.wssSendSnackbarMessage('Rebooting Shelly board...');
162
103
  });
163
104
  }
164
- /**
165
- * Perform a GET to Shelly board apis.
166
- * @param {string} api - The api to call:
167
- *
168
- * /api/updates/sys/check => [{name:string; ...}]
169
- * /api/updates/sys/perform => {"updatingInProgress":true} or {"updatingInProgress":false}
170
- * /api/updates/sys/status => {"updatingInProgress":true} or {"updatingInProgress":false}
171
- * /api/updates/main/check => [{name:string; ...}]
172
- * /api/updates/main/perform => {"updatingInProgress":true} or {"updatingInProgress":false}
173
- * /api/updates/main/status => {"updatingInProgress":true} or {"updatingInProgress":false}
174
- *
175
- * @param {number} [timeout=5000] - The timeout duration in milliseconds (default is 60000ms).
176
- * @returns {Promise<any>} A promise that resolves to the response.
177
- * @throws {Error} If the request fails.
178
- */
179
105
  async function getShelly(api, timeout = 60000) {
180
106
  const http = await import('node:http');
181
107
  return new Promise((resolve, reject) => {
@@ -189,8 +115,8 @@ async function getShelly(api, timeout = 60000) {
189
115
  let data = '';
190
116
  if (res.statusCode !== 200) {
191
117
  clearTimeout(timeoutId);
192
- res.resume(); // Discard response data to close the socket properly
193
- req.destroy(); // Forcefully close the request
118
+ res.resume();
119
+ req.destroy();
194
120
  reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
195
121
  return;
196
122
  }
@@ -214,29 +140,6 @@ async function getShelly(api, timeout = 60000) {
214
140
  });
215
141
  });
216
142
  }
217
- /**
218
- * Perform a POST request to Shelly board apis.
219
- * @param {string} api - The api to call:
220
- *
221
- * Set static ip
222
- * /api/network/connection/static -d '{"interface": "end0", "addr": "10.11.12.101", "mask": "255.255.255.0", "gw": "10.11.12.1", "dns": "1.1.1.1"}' => {}
223
- *
224
- * Set dhcp
225
- * /api/network/connection/dynamic -d '{"interface": "end0"}' => {}
226
- *
227
- * Reboot
228
- * /api/system/reboot => {"success":true}
229
- *
230
- * curl -H "Content-Type: application/json" -X POST http://127.0.0.1:8101/api/network/connection/dynamic
231
- * -d '{"interface": "end0"}'
232
- *
233
- * curl -H "Content-Type: application/json" -X POST http://127.0.0.1:8101/api/network/connection/static
234
- * -d '{"interface": "end0", "addr": "192.168.1.64", "mask": "255.255.255.0", "gw": "192.168.1.1", "dns": "192.168.1.1"}'
235
- *
236
- * @param {number} [timeout=5000] - The timeout duration in milliseconds (default is 60000ms).
237
- * @returns {Promise<any>} A promise that resolves to the response.
238
- * @throws {Error} If the request fails.
239
- */
240
143
  async function postShelly(api, data, timeout = 60000) {
241
144
  const http = await import('node:http');
242
145
  return new Promise((resolve, reject) => {
@@ -257,11 +160,10 @@ async function postShelly(api, data, timeout = 60000) {
257
160
  };
258
161
  const req = http.request(url, options, (res) => {
259
162
  let responseData = '';
260
- // Check for non-success status codes (e.g., 300+)
261
163
  if (res.statusCode && res.statusCode >= 300) {
262
164
  clearTimeout(timeoutId);
263
- res.resume(); // Discard response data to free up memory
264
- req.destroy(); // Close the request
165
+ res.resume();
166
+ req.destroy();
265
167
  return reject(new Error(`Failed to post data. Status code: ${res.statusCode}`));
266
168
  }
267
169
  res.on('data', (chunk) => {
@@ -282,36 +184,7 @@ async function postShelly(api, data, timeout = 60000) {
282
184
  clearTimeout(timeoutId);
283
185
  reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
284
186
  });
285
- // Send the JSON data
286
187
  req.write(jsonData);
287
188
  req.end();
288
189
  });
289
190
  }
290
- /*
291
- https://mtrbrgup.shelly.cloud/updates/system/dpkg.json
292
- https://mtrbrgup.shelly.cloud/updates/npm/latest
293
-
294
- apt-get install -y nodejs=22.12.0-1nodesource1 -y --allow-downgrades
295
- apt-get install -y nodejs=22.14.0-1nodesource1 -y
296
- */
297
- /*
298
- Feb 21 16:40:22 matterbridge matterbridge-updater.sh[1704]: INFO [16:40:21.481] (shelly-matter-bridge/1704): npm install -g https://mtrbrgup.shelly.cloud/updates/npm/matterbridge-2.1.5.tgz
299
- Feb 21 16:42:16 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:15.991] (shelly-matter-bridge/1704): npm install -g https://mtrbrgup.shelly.cloud/updates/npm/matterbridge-2.1.5.tgz -> changed 172 packages in 2m
300
- Feb 21 16:42:16 matterbridge matterbridge-updater.sh[1704]: 42 packages are looking for funding
301
- Feb 21 16:42:16 matterbridge matterbridge-updater.sh[1704]: run `npm fund` for details
302
- Feb 21 16:42:16 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:16.010] (shelly-matter-bridge/1704): npm install -g https://mtrbrgup.shelly.cloud/updates/npm/matterbridge-shelly-1.1.6.tgz
303
- Feb 21 16:42:41 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:41.172] (shelly-matter-bridge/1704): npm install -g https://mtrbrgup.shelly.cloud/updates/npm/matterbridge-shelly-1.1.6.tgz -> changed 40 packages in 20s
304
- Feb 21 16:42:41 matterbridge matterbridge-updater.sh[1704]: 12 packages are looking for funding
305
- Feb 21 16:42:41 matterbridge matterbridge-updater.sh[1704]: run `npm fund` for details
306
- Feb 21 16:42:41 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:41.174] (shelly-matter-bridge/1704): cp /root/.npm/lib/node_modules/shelly-matter-bridge/image-build/files/var/services/shelly-matter-bridge/matterbridge.sh /var/services/shelly-matter-bridge/
307
- Feb 21 16:42:44 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:44.136] (shelly-matter-bridge/1704): cp /root/.npm/lib/node_modules/shelly-matter-bridge/image-build/files/var/services/shelly-matter-bridge/matterbridge-updater.sh /var/services/shelly-matter-bridge/
308
- Feb 21 16:42:47 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:46.998] (shelly-matter-bridge/1704): cp /root/.npm/lib/node_modules/shelly-matter-bridge/image-build/files/var/services/shelly-matter-bridge/matterbridge-updater-gpio.sh /var/services/shelly-matter-bridge/
309
- Feb 21 16:42:50 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:49.878] (shelly-matter-bridge/1704): chmod +x /var/services/shelly-matter-bridge/matterbridge.sh
310
- Feb 21 16:42:53 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:52.753] (shelly-matter-bridge/1704): chmod +x /var/services/shelly-matter-bridge/matterbridge-updater.sh
311
- Feb 21 16:42:56 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:55.600] (shelly-matter-bridge/1704): chmod +x /var/services/shelly-matter-bridge/matterbridge-updater-gpio.sh
312
- Feb 21 16:42:59 matterbridge matterbridge-updater.sh[1704]: INFO [16:42:58.452] (shelly-matter-bridge/1704): matterbridge -add matterbridge-shelly
313
- Feb 21 16:43:28 matterbridge matterbridge-updater.sh[1704]: [150B blob data]
314
- Feb 21 16:43:28 matterbridge matterbridge-updater.sh[1704]: [134B blob data]
315
- Feb 21 16:43:28 matterbridge matterbridge-updater.sh[1704]: INFO [16:43:27.466] (shelly-matter-bridge/1704): systemctl restart matterbridge
316
- */
317
- //# sourceMappingURL=shelly.js.map
@@ -1,2 +1 @@
1
1
  export * from 'node-persist-manager';
2
- //# sourceMappingURL=export.js.map
package/dist/update.js CHANGED
@@ -1,34 +1,5 @@
1
- /**
2
- * This file contains the check updates functions.
3
- *
4
- * @file update.ts
5
- * @author Luca Liguori
6
- * @date 2025-02-24
7
- * @version 1.0.0
8
- *
9
- * Copyright 2025, 2026, 2027 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 { plg } from './matterbridgeTypes.js';
24
2
  import { db, er, nt } from './logger/export.js';
25
- /**
26
- * Checks for updates for Matterbridge and its plugins.
27
- * If the 'shelly' parameter is present, also checks for Shelly updates.
28
- *
29
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
30
- * @returns {Promise<void>} A promise that resolves when the update checks are complete.
31
- */
32
3
  export async function checkUpdates(matterbridge) {
33
4
  const { hasParameter } = await import('./utils/parameter.js');
34
5
  getMatterbridgeLatestVersion(matterbridge);
@@ -41,13 +12,6 @@ export async function checkUpdates(matterbridge) {
41
12
  getShellyMainUpdate(matterbridge);
42
13
  }
43
14
  }
44
- /**
45
- * Retrieves the latest version of Matterbridge and updates the matterbridgeLatestVersion property.
46
- * If there is an error retrieving the latest version, logs an error message.
47
- *
48
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
49
- * @returns {Promise<void>} A promise that resolves when the latest version is retrieved.
50
- */
51
15
  async function getMatterbridgeLatestVersion(matterbridge) {
52
16
  const { getNpmPackageVersion } = await import('./utils/network.js');
53
17
  getNpmPackageVersion('matterbridge')
@@ -67,14 +31,6 @@ async function getMatterbridgeLatestVersion(matterbridge) {
67
31
  matterbridge.log.warn(`Error getting Matterbridge latest version: ${error.message}`);
68
32
  });
69
33
  }
70
- /**
71
- * Retrieves the latest version of a plugin and updates the plugin's latestVersion property.
72
- * If there is an error retrieving the latest version, logs an error message.
73
- *
74
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
75
- * @param {RegisteredPlugin} plugin - The plugin for which to retrieve the latest version.
76
- * @returns {Promise<void>} A promise that resolves when the latest version is retrieved.
77
- */
78
34
  async function getPluginLatestVersion(matterbridge, plugin) {
79
35
  const { getNpmPackageVersion } = await import('./utils/network.js');
80
36
  getNpmPackageVersion(plugin.name)
@@ -92,4 +48,3 @@ async function getPluginLatestVersion(matterbridge, plugin) {
92
48
  matterbridge.log.warn(`Error getting ${plg}${plugin.name}${er} latest version: ${error.message}`);
93
49
  });
94
50
  }
95
- //# sourceMappingURL=update.js.map
@@ -1,25 +1,3 @@
1
- /**
2
- * This file contains the color utilities.
3
- *
4
- * @file colorUtils.ts
5
- * @author Luca Liguori
6
- * @date 2023-10-05
7
- * @version 1.3.0
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
1
  import { assert } from 'node:console';
24
2
  export function hslColorToRgbColor(hue, saturation, luminance) {
25
3
  if (hue === 360) {
@@ -32,7 +10,7 @@ export function hslColorToRgbColor(hue, saturation, luminance) {
32
10
  luminance /= 100;
33
11
  let r, g, b;
34
12
  if (saturation === 0) {
35
- r = g = b = luminance; // achromatic
13
+ r = g = b = luminance;
36
14
  }
37
15
  else {
38
16
  const hue2rgb = (p, q, t) => {
@@ -65,27 +43,21 @@ export function hslColorToRgbColor(hue, saturation, luminance) {
65
43
  b: Math.ceil(b * 255),
66
44
  };
67
45
  }
68
- // Converts from RGB to the XY color (CIE 1931 color space)
69
46
  export function rgbColorToXYColor(rgb) {
70
47
  let r = rgb.r / 255;
71
48
  let g = rgb.g / 255;
72
49
  let b = rgb.b / 255;
73
- // Apply gamma correction
74
50
  r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
75
51
  g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
76
52
  b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
77
- // Scale the values to the D65 illuminant
78
53
  r = r * 100;
79
54
  g = g * 100;
80
55
  b = b * 100;
81
- // Convert RGB to XYZ
82
56
  const X = r * 0.664511 + g * 0.154324 + b * 0.162028;
83
57
  const Y = r * 0.283881 + g * 0.668433 + b * 0.047685;
84
58
  const Z = r * 0.000088 + g * 0.07231 + b * 0.986039;
85
- // Normalization
86
59
  let x = X / (X + Y + Z);
87
60
  let y = Y / (X + Y + Z);
88
- // Round to 4 digits
89
61
  x = Math.round(x * 10000) / 10000;
90
62
  y = Math.round(y * 10000) / 10000;
91
63
  return { x, y };
@@ -95,11 +67,9 @@ export function xyColorToRgbColor(x, y, brightness = 254) {
95
67
  const Y = (brightness / 254).toFixed(2);
96
68
  const X = (Number(Y) / y) * x;
97
69
  const Z = (Number(Y) / y) * z;
98
- // Convert to RGB using Wide RGB D65 conversion
99
70
  let red = X * 1.656492 - Number(Y) * 0.354851 - Z * 0.255038;
100
71
  let green = -X * 0.707196 + Number(Y) * 1.655397 + Z * 0.036152;
101
72
  let blue = X * 0.051713 - Number(Y) * 0.121364 + Z * 1.01153;
102
- // If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
103
73
  if (red > blue && red > green && red > 1.0) {
104
74
  green = green / red;
105
75
  blue = blue / red;
@@ -115,15 +85,12 @@ export function xyColorToRgbColor(x, y, brightness = 254) {
115
85
  green = green / blue;
116
86
  blue = 1.0;
117
87
  }
118
- // Reverse gamma correction
119
88
  red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, 1.0 / 2.4) - 0.055;
120
89
  green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, 1.0 / 2.4) - 0.055;
121
90
  blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, 1.0 / 2.4) - 0.055;
122
- // Convert normalized decimal to decimal
123
91
  red = Math.round(red * 255);
124
92
  green = Math.round(green * 255);
125
93
  blue = Math.round(blue * 255);
126
- // Normalize
127
94
  if (isNaN(red) || red < 0) {
128
95
  red = 0;
129
96
  }
@@ -144,7 +111,7 @@ export function rgbColorToHslColor(rgb) {
144
111
  let h = 0, s = 0;
145
112
  const l = (max + min) / 2;
146
113
  if (max === min) {
147
- h = s = 0; // achromatic
114
+ h = s = 0;
148
115
  }
149
116
  else {
150
117
  const d = max - min;
@@ -179,10 +146,8 @@ export function kelvinToMired(kelvin) {
179
146
  return Math.round(1000000 / kelvin);
180
147
  }
181
148
  export function kelvinToRGB(kelvin) {
182
- // Clamp the temperature to the range 1000K to 40000K
183
149
  kelvin = Math.max(1000, Math.min(40000, kelvin)) / 100;
184
150
  let r, g, b;
185
- // Calculate red
186
151
  if (kelvin <= 66) {
187
152
  r = 255;
188
153
  }
@@ -191,7 +156,6 @@ export function kelvinToRGB(kelvin) {
191
156
  r = 329.698727446 * Math.pow(r, -0.1332047592);
192
157
  r = Math.max(0, Math.min(255, r));
193
158
  }
194
- // Calculate green
195
159
  if (kelvin <= 66) {
196
160
  g = kelvin;
197
161
  g = 99.4708025861 * Math.log(g) - 161.1195681661;
@@ -202,7 +166,6 @@ export function kelvinToRGB(kelvin) {
202
166
  g = 288.1221695283 * Math.pow(g, -0.0755148492);
203
167
  g = Math.max(0, Math.min(255, g));
204
168
  }
205
- // Calculate blue
206
169
  if (kelvin >= 66) {
207
170
  b = 255;
208
171
  }
@@ -216,169 +179,3 @@ export function kelvinToRGB(kelvin) {
216
179
  }
217
180
  return { r: Math.round(r), g: Math.round(g), b: Math.round(b) };
218
181
  }
219
- /*
220
- export function testColors(): void {
221
- // this table has been checked with different apps and sites and is correct 100%
222
- const colors = [
223
- { name: 'Pure Red 0', hsl: { h: 0, s: 100, l: 50 }, rgb: { r: 255, g: 0, b: 0 }, xy: { x: 0.7006, y: 0.2993 } },
224
- { name: 'Bright Orange 30', hsl: { h: 30, s: 100, l: 50 }, rgb: { r: 255, g: 128, b: 0 }, xy: { x: 0.6112, y: 0.375 } },
225
- { name: 'Pure Yellow 60', hsl: { h: 60, s: 100, l: 50 }, rgb: { r: 255, g: 255, b: 0 }, xy: { x: 0.4442, y: 0.5166 } },
226
- { name: 'Lime Green 90', hsl: { h: 90, s: 100, l: 50 }, rgb: { r: 128, g: 255, b: 0 }, xy: { x: 0.2707, y: 0.6635 } },
227
- { name: 'Pure Green 120', hsl: { h: 120, s: 100, l: 50 }, rgb: { r: 0, g: 255, b: 0 }, xy: { x: 0.1724, y: 0.7468 } },
228
- { name: 'Light Sea Green 150', hsl: { h: 150, s: 100, l: 50 }, rgb: { r: 0, g: 255, b: 128 }, xy: { x: 0.1642, y: 0.5886 } },
229
- { name: 'Pure Cyan 180', hsl: { h: 180, s: 100, l: 50 }, rgb: { r: 0, g: 255, b: 255 }, xy: { x: 0.1513, y: 0.3425 } },
230
- { name: 'Deep Sky Blue 210', hsl: { h: 210, s: 100, l: 50 }, rgb: { r: 0, g: 128, b: 255 }, xy: { x: 0.1406, y: 0.1382 } },
231
- { name: 'Pure Blue 240', hsl: { h: 240, s: 100, l: 50 }, rgb: { r: 0, g: 0, b: 255 }, xy: { x: 0.1355, y: 0.0399 } },
232
- { name: 'Blue Violet 270', hsl: { h: 270, s: 100, l: 50 }, rgb: { r: 128, g: 0, b: 255 }, xy: { x: 0.2181, y: 0.0778 } },
233
- { name: 'Pure Magenta 300', hsl: { h: 300, s: 100, l: 50 }, rgb: { r: 255, g: 0, b: 255 }, xy: { x: 0.3855, y: 0.1546 } },
234
- { name: 'Deep Pink 330', hsl: { h: 330, s: 100, l: 50 }, rgb: { r: 255, g: 0, b: 128 }, xy: { x: 0.5797, y: 0.2438 } },
235
-
236
- { name: 'Pure Red 50% 0', hsl: { h: 0, s: 50, l: 50 }, rgb: { r: 192, g: 64, b: 64 }, xy: { x: 0.6036, y: 0.3069 } },
237
- { name: 'Bright Orange 50% 30', hsl: { h: 30, s: 50, l: 50 }, rgb: { r: 192, g: 128, b: 64 }, xy: { x: 0.5194, y: 0.3928 } },
238
- { name: 'Pure Yellow 50% 60', hsl: { h: 60, s: 50, l: 50 }, rgb: { r: 192, g: 192, b: 64 }, xy: { x: 0.4258, y: 0.4883 } },
239
- { name: 'Lime Green 50% 90', hsl: { h: 90, s: 50, l: 50 }, rgb: { r: 128, g: 192, b: 64 }, xy: { x: 0.3159, y: 0.5639 } },
240
- { name: 'Pure Green 50% 120', hsl: { h: 120, s: 50, l: 50 }, rgb: { r: 64, g: 192, b: 64 }, xy: { x: 0.2127, y: 0.6349 } },
241
- { name: 'Light Sea Green 50% 150', hsl: { h: 150, s: 50, l: 50 }, rgb: { r: 64, g: 192, b: 128 }, xy: { x: 0.1932, y: 0.4845 } },
242
- { name: 'Pure Cyan 50% 180', hsl: { h: 180, s: 50, l: 50 }, rgb: { r: 64, g: 192, b: 192 }, xy: { x: 0.1745, y: 0.3407 } },
243
- { name: 'Deep Sky Blue 50% 210', hsl: { h: 210, s: 50, l: 50 }, rgb: { r: 64, g: 128, b: 192 }, xy: { x: 0.1752, y: 0.211 } },
244
- { name: 'Pure Blue 50% 240', hsl: { h: 240, s: 50, l: 50 }, rgb: { r: 64, g: 64, b: 192 }, xy: { x: 0.1758, y: 0.102 } },
245
- { name: 'Blue Violet 50% 270', hsl: { h: 270, s: 50, l: 50 }, rgb: { r: 128, g: 64, b: 192 }, xy: { x: 0.2688, y: 0.137 } },
246
- { name: 'Pure Magenta 50% 300', hsl: { h: 300, s: 50, l: 50 }, rgb: { r: 192, g: 64, b: 192 }, xy: { x: 0.3772, y: 0.1777 } },
247
- { name: 'Deep Pink 50% 330', hsl: { h: 330, s: 50, l: 50 }, rgb: { r: 192, g: 64, b: 128 }, xy: { x: 0.489, y: 0.2416 } },
248
- ];
249
-
250
- colors.forEach((color) => {
251
- // eslint-disable-next-line no-console
252
- console.log(
253
- `\x1b[48;2;${color.rgb.r};${color.rgb.g};${color.rgb.b}mColor: ${color.name}\x1b[0m, hsl: { h: ${color.hsl.h}, s: ${color.hsl.s}, l: ${color.hsl.l} }, rgb: { r: ${color.rgb.r}, g: ${color.rgb.g}, b: ${color.rgb.b} }, xy: { x: ${color.xy.x}, y: ${color.xy.y} }`,
254
- );
255
-
256
- const rgb = hslColorToRgbColor(color.hsl.h, color.hsl.s, color.hsl.l);
257
- assert(rgb.r === color.rgb.r && rgb.g === color.rgb.g && rgb.b === color.rgb.b, `\x1b[48;2;${rgb.r};${rgb.g};${rgb.b}mColor: ${color.name}\x1b[0m hslColorToRgbColor { r: ${rgb.r}, g: ${rgb.g}, b: ${rgb.b} } conversion error`);
258
-
259
- const hsl = rgbColorToHslColor({ r: color.rgb.r, g: color.rgb.g, b: color.rgb.b });
260
- assert(hsl.h === color.hsl.h && hsl.s === color.hsl.s && hsl.l === color.hsl.l, `Color: ${color.name} rgbColorToHslColor conversion error`);
261
-
262
- const xy = rgbColorToXYColor({ r: color.rgb.r, g: color.rgb.g, b: color.rgb.b });
263
- assert(xy.x === color.xy.x && xy.y === color.xy.y, `Color: ${color.name} rgbColorToXYColor conversion error got x ${xy.x} y ${xy.y}`);
264
-
265
- const rgb2 = xyColorToRgbColor(color.xy.x, color.xy.y);
266
- assert(
267
- rgb2.r === color.rgb.r && rgb2.g === color.rgb.g && rgb2.b === color.rgb.b,
268
- `\x1b[48;2;${rgb2.r};${rgb2.g};${rgb2.b}mColor: ${color.name}\x1b[0m xyColorToRgbColor(${color.xy.x}, ${color.xy.y}) conversion error -> r: ${rgb2.r} g: ${rgb2.g} b: ${rgb2.g}`,
269
- );
270
- });
271
- }
272
- */
273
- /**
274
- * Converts CIE color space to RGB color space
275
- * @param {Number} x
276
- * @param {Number} y
277
- * @param {Number} brightness - Ranges from 1 to 254
278
- * @return {Array} Array that contains the color values for red, green and blue
279
- * From: https://github.com/usolved/cie-rgb-converter/blob/master/cie_rgb_converter.js
280
- */
281
- /*
282
- export function cie_to_rgb(x: number, y: number, brightness = 254): RGB {
283
- // Set to maximum brightness if no custom value was given (Not the slick ECMAScript 6 way for compatibility reasons)
284
-
285
- const z = 1.0 - x - y;
286
- const Y = (brightness / 254).toFixed(2);
287
- const X = (Number(Y) / y) * x;
288
- const Z = (Number(Y) / y) * z;
289
-
290
- // Convert to RGB using Wide RGB D65 conversion
291
- let red = X * 1.656492 - Number(Y) * 0.354851 - Z * 0.255038;
292
- let green = -X * 0.707196 + Number(Y) * 1.655397 + Z * 0.036152;
293
- let blue = X * 0.051713 - Number(Y) * 0.121364 + Z * 1.01153;
294
-
295
- // If red, green or blue is larger than 1.0 set it back to the maximum of 1.0
296
- if (red > blue && red > green && red > 1.0) {
297
- green = green / red;
298
- blue = blue / red;
299
- red = 1.0;
300
- } else if (green > blue && green > red && green > 1.0) {
301
- red = red / green;
302
- blue = blue / green;
303
- green = 1.0;
304
- } else if (blue > red && blue > green && blue > 1.0) {
305
- red = red / blue;
306
- green = green / blue;
307
- blue = 1.0;
308
- }
309
-
310
- // Reverse gamma correction
311
- red = red <= 0.0031308 ? 12.92 * red : (1.0 + 0.055) * Math.pow(red, 1.0 / 2.4) - 0.055;
312
- green = green <= 0.0031308 ? 12.92 * green : (1.0 + 0.055) * Math.pow(green, 1.0 / 2.4) - 0.055;
313
- blue = blue <= 0.0031308 ? 12.92 * blue : (1.0 + 0.055) * Math.pow(blue, 1.0 / 2.4) - 0.055;
314
-
315
- // Convert normalized decimal to decimal
316
- red = Math.round(red * 255);
317
- green = Math.round(green * 255);
318
- blue = Math.round(blue * 255);
319
-
320
- // Normalize
321
- if (isNaN(red) || red < 0) {
322
- red = 0;
323
- }
324
- if (isNaN(green) || green < 0) {
325
- green = 0;
326
- }
327
- if (isNaN(blue) || blue < 0) {
328
- blue = 0;
329
- }
330
-
331
- return { r: red, g: green, b: blue };
332
- }
333
- */
334
- /**
335
- * Converts RGB color space to CIE color space
336
- * @param {Number} red
337
- * @param {Number} green
338
- * @param {Number} blue
339
- * @return {Array} Array that contains the CIE color values for x and y
340
- * From: https://github.com/usolved/cie-rgb-converter/blob/master/cie_rgb_converter.js
341
- */
342
- /*
343
- export function rgb_to_cie(red: number, green: number, blue: number): XY {
344
- // Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device
345
- red = red > 0.04045 ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : red / 12.92;
346
- green = green > 0.04045 ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : green / 12.92;
347
- blue = blue > 0.04045 ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : blue / 12.92;
348
-
349
- // RGB values to XYZ using the Wide RGB D65 conversion formula
350
- const X = red * 0.664511 + green * 0.154324 + blue * 0.162028;
351
- const Y = red * 0.283881 + green * 0.668433 + blue * 0.047685;
352
- const Z = red * 0.000088 + green * 0.07231 + blue * 0.986039;
353
-
354
- // Calculate the xy values from the XYZ values
355
- let x = (X / (X + Y + Z)).toFixed(4);
356
- let y = (Y / (X + Y + Z)).toFixed(4);
357
-
358
- if (isNaN(Number(x))) {
359
- x = '0';
360
- }
361
-
362
- if (isNaN(Number(y))) {
363
- y = '0';
364
- }
365
-
366
- return { x: Number(x), y: Number(y) };
367
- }
368
- */
369
- /*
370
- testColors();
371
- console.log('rgb_to_cie(0, 128, 255)', rgb_to_cie(0, 128, 255));
372
- console.log('cie_to_rgb(0.1401, 0.1284, 254)', cie_to_rgb(0.1401, 0.1284, 254));
373
- console.log('cie_to_rgb(0.1406, 0.1382, 254)', cie_to_rgb(0.1406, 0.1382, 254));
374
- for (let h = 0; h < 360; h++) {
375
- const rgb = hslColorToRgbColor(h, 100, 50);
376
- const xy = rgbColorToXYColor({ r: rgb.r, g: rgb.g, b: rgb.b });
377
- const rgb2 = cie_to_rgb(xy.x, xy.y, 254);
378
- const hsl = rgbColorToHslColor({ r: rgb2.r, g: rgb2.g, b: rgb2.b });
379
- assert(rgb.r === rgb2.r && rgb.g === rgb2.g && rgb.b === rgb2.b, 'Color rgb conversion error');
380
- assert(h === hsl.h, 'Color hsl conversion error');
381
- console.log(`\x1b[48;2;${rgb.r};${rgb.g};${rgb.b}mColor: r:${rgb.r} g:${rgb.g} b:${rgb.b}\x1b[0m => x:${xy.x} y:${xy.y} => \x1b[48;2;${rgb2.r};${rgb2.g};${rgb2.b}mColor: r:${rgb2.r} g:${rgb2.g} b:${rgb2.b} h:${hsl.h} s:${hsl.s}\x1b[0m\x1b[K`);
382
- }
383
- */
384
- //# sourceMappingURL=colorUtils.js.map
@@ -1,54 +1,19 @@
1
- /**
2
- * This file contains the copyDirectory function.
3
- *
4
- * @file copyDirectory.ts
5
- * @author Luca Liguori
6
- * @date 2025-02-16
7
- * @version 1.0.0
8
- *
9
- * Copyright 2025, 2026, 2027 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
- // AnsiLogger module
24
1
  import { AnsiLogger } from '../logger/export.js';
25
- /**
26
- * Copies a directory and all its subdirectories and files to a new location.
27
- *
28
- * @param {string} srcDir - The path to the source directory.
29
- * @param {string} destDir - The path to the destination directory.
30
- * @returns {Promise<boolean>} - A promise that resolves when the copy operation is complete or fails for error.
31
- * @throws {Error} - Throws an error if the copy operation fails.
32
- */
33
2
  export async function copyDirectory(srcDir, destDir) {
34
- const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "info" /* LogLevel.INFO */ });
3
+ const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4, logLevel: "info" });
35
4
  const fs = await import('node:fs').then((mod) => mod.promises);
36
5
  const path = await import('node:path');
37
6
  log.debug(`copyDirectory: copying directory from ${srcDir} to ${destDir}`);
38
7
  try {
39
- // Create destination directory if it doesn't exist
40
8
  await fs.mkdir(destDir, { recursive: true });
41
- // Read contents of the source directory
42
9
  const entries = await fs.readdir(srcDir, { withFileTypes: true });
43
10
  for (const entry of entries) {
44
11
  const srcPath = path.join(srcDir, entry.name);
45
12
  const destPath = path.join(destDir, entry.name);
46
13
  if (entry.isDirectory()) {
47
- // Recursive call if entry is a directory
48
14
  await copyDirectory(srcPath, destPath);
49
15
  }
50
16
  else if (entry.isFile()) {
51
- // Copy file if entry is a file
52
17
  await fs.copyFile(srcPath, destPath);
53
18
  }
54
19
  }
@@ -59,4 +24,3 @@ export async function copyDirectory(srcDir, destDir) {
59
24
  return false;
60
25
  }
61
26
  }
62
- //# sourceMappingURL=copyDirectory.js.map