matterbridge 2.2.0-dev.5 → 2.2.0-dev.7

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 (127) hide show
  1. package/CHANGELOG.md +1 -8
  2. package/dist/cli.js +2 -37
  3. package/dist/cluster/export.js +0 -2
  4. package/dist/defaultConfigSchema.js +0 -23
  5. package/dist/deviceManager.js +1 -94
  6. package/dist/frontend.js +42 -265
  7. package/dist/index.js +2 -29
  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 +1 -3
  15. package/dist/matterbridge.js +51 -720
  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 +6 -690
  21. package/dist/matterbridgeEndpointHelpers.js +9 -118
  22. package/dist/matterbridgePlatform.js +7 -140
  23. package/dist/matterbridgeTypes.js +0 -24
  24. package/dist/pluginManager.js +3 -229
  25. package/dist/shelly.js +33 -136
  26. package/dist/storage/export.js +0 -1
  27. package/dist/update.js +0 -45
  28. package/dist/utils/colorUtils.js +2 -205
  29. package/dist/utils/copyDirectory.js +1 -37
  30. package/dist/utils/createZip.js +2 -42
  31. package/dist/utils/deepCopy.js +0 -40
  32. package/dist/utils/deepEqual.js +1 -65
  33. package/dist/utils/export.js +0 -1
  34. package/dist/utils/isvalid.js +0 -86
  35. package/dist/utils/network.js +5 -77
  36. package/dist/utils/parameter.js +0 -41
  37. package/dist/utils/wait.js +5 -48
  38. package/frontend/build/asset-manifest.json +3 -3
  39. package/frontend/build/index.html +1 -1
  40. package/frontend/build/static/js/{main.f60aae10.js → main.8240902c.js} +3 -3
  41. package/frontend/build/static/js/main.8240902c.js.map +1 -0
  42. package/npm-shrinkwrap.json +44 -44
  43. package/package.json +2 -2
  44. package/dist/cli.d.ts +0 -28
  45. package/dist/cli.d.ts.map +0 -1
  46. package/dist/cli.js.map +0 -1
  47. package/dist/cluster/export.d.ts.map +0 -1
  48. package/dist/cluster/export.js.map +0 -1
  49. package/dist/defaultConfigSchema.d.ts.map +0 -1
  50. package/dist/defaultConfigSchema.js.map +0 -1
  51. package/dist/deviceManager.d.ts +0 -109
  52. package/dist/deviceManager.d.ts.map +0 -1
  53. package/dist/deviceManager.js.map +0 -1
  54. package/dist/frontend.d.ts +0 -172
  55. package/dist/frontend.d.ts.map +0 -1
  56. package/dist/frontend.js.map +0 -1
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js.map +0 -1
  59. package/dist/logger/export.d.ts.map +0 -1
  60. package/dist/logger/export.js.map +0 -1
  61. package/dist/matter/behaviors.d.ts.map +0 -1
  62. package/dist/matter/behaviors.js.map +0 -1
  63. package/dist/matter/clusters.d.ts.map +0 -1
  64. package/dist/matter/clusters.js.map +0 -1
  65. package/dist/matter/devices.d.ts.map +0 -1
  66. package/dist/matter/devices.js.map +0 -1
  67. package/dist/matter/endpoints.d.ts.map +0 -1
  68. package/dist/matter/endpoints.js.map +0 -1
  69. package/dist/matter/export.d.ts.map +0 -1
  70. package/dist/matter/export.js.map +0 -1
  71. package/dist/matter/types.d.ts.map +0 -1
  72. package/dist/matter/types.js.map +0 -1
  73. package/dist/matterbridge.d.ts +0 -410
  74. package/dist/matterbridge.d.ts.map +0 -1
  75. package/dist/matterbridge.js.map +0 -1
  76. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  77. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  78. package/dist/matterbridgeBehaviors.d.ts +0 -148
  79. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  80. package/dist/matterbridgeBehaviors.js.map +0 -1
  81. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  82. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  83. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  84. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  85. package/dist/matterbridgeEndpoint.d.ts +0 -827
  86. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  87. package/dist/matterbridgeEndpoint.js.map +0 -1
  88. package/dist/matterbridgeEndpointHelpers.d.ts +0 -123
  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.map +0 -1
  95. package/dist/matterbridgeTypes.js.map +0 -1
  96. package/dist/pluginManager.d.ts +0 -236
  97. package/dist/pluginManager.d.ts.map +0 -1
  98. package/dist/pluginManager.js.map +0 -1
  99. package/dist/shelly.d.ts.map +0 -1
  100. package/dist/shelly.js.map +0 -1
  101. package/dist/storage/export.d.ts.map +0 -1
  102. package/dist/storage/export.js.map +0 -1
  103. package/dist/update.d.ts.map +0 -1
  104. package/dist/update.js.map +0 -1
  105. package/dist/utils/colorUtils.d.ts.map +0 -1
  106. package/dist/utils/colorUtils.js.map +0 -1
  107. package/dist/utils/copyDirectory.d.ts.map +0 -1
  108. package/dist/utils/copyDirectory.js.map +0 -1
  109. package/dist/utils/createZip.d.ts.map +0 -1
  110. package/dist/utils/createZip.js.map +0 -1
  111. package/dist/utils/deepCopy.d.ts.map +0 -1
  112. package/dist/utils/deepCopy.js.map +0 -1
  113. package/dist/utils/deepEqual.d.ts.map +0 -1
  114. package/dist/utils/deepEqual.js.map +0 -1
  115. package/dist/utils/export.d.ts.map +0 -1
  116. package/dist/utils/export.js.map +0 -1
  117. package/dist/utils/isvalid.d.ts.map +0 -1
  118. package/dist/utils/isvalid.js.map +0 -1
  119. package/dist/utils/network.d.ts.map +0 -1
  120. package/dist/utils/network.js.map +0 -1
  121. package/dist/utils/parameter.d.ts.map +0 -1
  122. package/dist/utils/parameter.js.map +0 -1
  123. package/dist/utils/wait.d.ts +0 -43
  124. package/dist/utils/wait.d.ts.map +0 -1
  125. package/dist/utils/wait.js.map +0 -1
  126. package/frontend/build/static/js/main.f60aae10.js.map +0 -1
  127. /package/frontend/build/static/js/{main.f60aae10.js.LICENSE.txt → main.8240902c.js.LICENSE.txt} +0 -0
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,25 @@ 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
- */
105
+ export async function createShellySystemLog(matterbridge) {
106
+ const { promises: fs } = await import('node:fs');
107
+ const path = await import('node:path');
108
+ matterbridge.log.debug(`Downloading Shelly system log...`);
109
+ getShelly('/api/logs/system', 60 * 1000)
110
+ .then(async (data) => {
111
+ fs.writeFile(path.join(matterbridge.matterbridgeDirectory, 'shelly.log'), data)
112
+ .then(() => {
113
+ matterbridge.log.notice(`Shelly system log ready for download`);
114
+ matterbridge.frontend.wssSendSnackbarMessage('Shelly system log ready for download');
115
+ })
116
+ .catch((error) => {
117
+ matterbridge.log.warn(`Error writing Shelly system log to file: ${error instanceof Error ? error.message : error}`);
118
+ });
119
+ })
120
+ .catch((error) => {
121
+ matterbridge.log.warn(`Error getting Shelly system log: ${error instanceof Error ? error.message : error}`);
122
+ });
123
+ }
179
124
  async function getShelly(api, timeout = 60000) {
180
125
  const http = await import('node:http');
181
126
  return new Promise((resolve, reject) => {
@@ -189,8 +134,8 @@ async function getShelly(api, timeout = 60000) {
189
134
  let data = '';
190
135
  if (res.statusCode !== 200) {
191
136
  clearTimeout(timeoutId);
192
- res.resume(); // Discard response data to close the socket properly
193
- req.destroy(); // Forcefully close the request
137
+ res.resume();
138
+ req.destroy();
194
139
  reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
195
140
  return;
196
141
  }
@@ -199,12 +144,17 @@ async function getShelly(api, timeout = 60000) {
199
144
  });
200
145
  res.on('end', () => {
201
146
  clearTimeout(timeoutId);
202
- try {
203
- const jsonData = JSON.parse(data);
204
- resolve(jsonData);
147
+ if (api !== '/api/logs/system') {
148
+ try {
149
+ const jsonData = JSON.parse(data);
150
+ resolve(jsonData);
151
+ }
152
+ catch (error) {
153
+ reject(new Error(`Failed to parse response JSON: ${error instanceof Error ? error.message : error}`));
154
+ }
205
155
  }
206
- catch (error) {
207
- reject(new Error(`Failed to parse response JSON: ${error instanceof Error ? error.message : error}`));
156
+ else {
157
+ resolve(data);
208
158
  }
209
159
  });
210
160
  });
@@ -214,29 +164,6 @@ async function getShelly(api, timeout = 60000) {
214
164
  });
215
165
  });
216
166
  }
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
167
  async function postShelly(api, data, timeout = 60000) {
241
168
  const http = await import('node:http');
242
169
  return new Promise((resolve, reject) => {
@@ -257,11 +184,10 @@ async function postShelly(api, data, timeout = 60000) {
257
184
  };
258
185
  const req = http.request(url, options, (res) => {
259
186
  let responseData = '';
260
- // Check for non-success status codes (e.g., 300+)
261
187
  if (res.statusCode && res.statusCode >= 300) {
262
188
  clearTimeout(timeoutId);
263
- res.resume(); // Discard response data to free up memory
264
- req.destroy(); // Close the request
189
+ res.resume();
190
+ req.destroy();
265
191
  return reject(new Error(`Failed to post data. Status code: ${res.statusCode}`));
266
192
  }
267
193
  res.on('data', (chunk) => {
@@ -282,36 +208,7 @@ async function postShelly(api, data, timeout = 60000) {
282
208
  clearTimeout(timeoutId);
283
209
  reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
284
210
  });
285
- // Send the JSON data
286
211
  req.write(jsonData);
287
212
  req.end();
288
213
  });
289
214
  }
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