matterbridge 1.0.6 → 1.1.3

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 (74) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +202 -21
  3. package/README.md +160 -5
  4. package/Screenshot devices page.png +0 -0
  5. package/Screenshot home page.png +0 -0
  6. package/dist/AirQualityCluster.d.ts +22 -0
  7. package/dist/AirQualityCluster.d.ts.map +1 -1
  8. package/dist/AirQualityCluster.js +23 -1
  9. package/dist/AirQualityCluster.js.map +1 -1
  10. package/dist/ColorControlServer.d.ts +20 -3
  11. package/dist/ColorControlServer.d.ts.map +1 -1
  12. package/dist/ColorControlServer.js +20 -3
  13. package/dist/ColorControlServer.js.map +1 -1
  14. package/dist/TvocCluster.d.ts +262 -0
  15. package/dist/TvocCluster.d.ts.map +1 -0
  16. package/dist/TvocCluster.js +114 -0
  17. package/dist/TvocCluster.js.map +1 -0
  18. package/dist/index.d.ts +30 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +37 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/matterbridge.d.ts +188 -17
  23. package/dist/matterbridge.d.ts.map +1 -1
  24. package/dist/matterbridge.js +762 -224
  25. package/dist/matterbridge.js.map +1 -1
  26. package/dist/matterbridgeAccessoryPlatform.d.ts +65 -11
  27. package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -1
  28. package/dist/matterbridgeAccessoryPlatform.js +73 -39
  29. package/dist/matterbridgeAccessoryPlatform.js.map +1 -1
  30. package/dist/matterbridgeComposed.d.ts +43 -0
  31. package/dist/matterbridgeComposed.d.ts.map +1 -0
  32. package/dist/matterbridgeComposed.js +58 -0
  33. package/dist/matterbridgeComposed.js.map +1 -0
  34. package/dist/matterbridgeController.d.ts +2 -0
  35. package/dist/matterbridgeController.d.ts.map +1 -0
  36. package/dist/matterbridgeController.js +309 -0
  37. package/dist/matterbridgeController.js.map +1 -0
  38. package/dist/matterbridgeDevice.d.ts +209 -4
  39. package/dist/matterbridgeDevice.d.ts.map +1 -1
  40. package/dist/matterbridgeDevice.js +587 -51
  41. package/dist/matterbridgeDevice.js.map +1 -1
  42. package/dist/matterbridgeDynamicPlatform.d.ts +65 -11
  43. package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -1
  44. package/dist/matterbridgeDynamicPlatform.js +73 -39
  45. package/dist/matterbridgeDynamicPlatform.js.map +1 -1
  46. package/dist/utils.d.ts +2 -0
  47. package/dist/utils.d.ts.map +1 -0
  48. package/dist/utils.js +33 -0
  49. package/dist/utils.js.map +1 -0
  50. package/frontend/build/Matterbridge.jpg +0 -0
  51. package/frontend/build/asset-manifest.json +6 -6
  52. package/frontend/build/index.html +1 -1
  53. package/frontend/build/static/css/main.6d93e0db.css +2 -0
  54. package/frontend/build/static/css/main.6d93e0db.css.map +1 -0
  55. package/frontend/build/static/js/main.b5a876cf.js +3 -0
  56. package/frontend/build/static/js/{main.a000062f.js.LICENSE.txt → main.b5a876cf.js.LICENSE.txt} +2 -0
  57. package/frontend/build/static/js/main.b5a876cf.js.map +1 -0
  58. package/package.json +16 -12
  59. package/.eslintrc.json +0 -45
  60. package/.gitattributes +0 -2
  61. package/.prettierignore +0 -2
  62. package/.prettierrc.json +0 -12
  63. package/frontend/README.md +0 -70
  64. package/frontend/build/static/css/main.8b969fd5.css +0 -2
  65. package/frontend/build/static/css/main.8b969fd5.css.map +0 -1
  66. package/frontend/build/static/js/main.a000062f.js +0 -3
  67. package/frontend/build/static/js/main.a000062f.js.map +0 -1
  68. package/frontend/package-lock.json +0 -18351
  69. package/frontend/package.json +0 -40
  70. package/frontend/public/favicon.ico +0 -0
  71. package/frontend/public/index.html +0 -15
  72. package/frontend/public/manifest.json +0 -15
  73. package/frontend/public/matter.png +0 -0
  74. package/frontend/public/robots.txt +0 -3
@@ -1,6 +1,26 @@
1
- /// <reference types="node" resolution-mode="require"/>
1
+ /**
2
+ * This file contains the class Matterbridge.
3
+ *
4
+ * @file matterbridge.ts
5
+ * @author Luca Liguori
6
+ * @date 2023-12-29
7
+ * @version 1.1.1
8
+ *
9
+ * Copyright 2023, 2024 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
+ */
2
23
  import { MatterbridgeDevice } from './matterbridgeDevice.js';
3
- import EventEmitter from 'events';
4
24
  interface SystemInformation {
5
25
  ipv4Address: string;
6
26
  ipv6Address: string;
@@ -14,23 +34,21 @@ interface SystemInformation {
14
34
  freeMemory: string;
15
35
  systemUptime: string;
16
36
  }
17
- export interface MatterbridgeEvents {
18
- shutdown: (reason: string) => void;
19
- startAccessoryPlatform: (reason: string) => void;
20
- startDynamicPlatform: (reason: string) => void;
21
- registerDeviceAccessoryPlatform: (device: MatterbridgeDevice) => void;
22
- registerDeviceDynamicPlatform: (device: MatterbridgeDevice) => void;
23
- }
24
- export declare class Matterbridge extends EventEmitter {
37
+ /**
38
+ * Represents the Matterbridge application.
39
+ */
40
+ export declare class Matterbridge {
25
41
  systemInformation: SystemInformation;
42
+ homeDirectory: string;
26
43
  rootDirectory: string;
44
+ matterbridgeDirectory: string;
27
45
  bridgeMode: 'bridge' | 'childbridge' | 'controller' | '';
28
46
  private log;
29
47
  private hasCleanupStarted;
30
48
  private registeredPlugins;
31
49
  private registeredDevices;
32
- private storage;
33
- private context;
50
+ private nodeStorage;
51
+ private nodeContext;
34
52
  private app;
35
53
  private storageManager;
36
54
  private matterbridgeContext;
@@ -39,32 +57,185 @@ export declare class Matterbridge extends EventEmitter {
39
57
  private matterAggregator;
40
58
  private commissioningServer;
41
59
  private commissioningController;
42
- constructor();
43
- private initialize;
60
+ private static instance;
61
+ private constructor();
62
+ /**
63
+ * Loads an instance of the Matterbridge class.
64
+ * If an instance already exists, an error will be thrown.
65
+ * @returns The loaded instance of the Matterbridge class.
66
+ * @throws Error if an instance of Matterbridge already exists.
67
+ */
68
+ static loadInstance(): Promise<Matterbridge>;
69
+ /**
70
+ * Initializes the Matterbridge application.
71
+ *
72
+ * @remarks
73
+ * This method performs the necessary setup and initialization steps for the Matterbridge application.
74
+ * It displays the help information if the 'help' parameter is provided, sets up the logger, checks the
75
+ * node version, registers signal handlers, initializes storage, and parses the command line.
76
+ *
77
+ * @returns A Promise that resolves when the initialization is complete.
78
+ */
79
+ initialize(): Promise<void>;
80
+ /**
81
+ * Parses the command line arguments and performs the corresponding actions.
82
+ * @private
83
+ * @returns {Promise<void>} A promise that resolves when the command line arguments have been processed.
84
+ */
44
85
  private parseCommandLine;
45
- emit<Event extends keyof MatterbridgeEvents>(event: Event, ...args: Parameters<MatterbridgeEvents[Event]>): boolean;
46
- on<Event extends keyof MatterbridgeEvents>(event: Event, listener: MatterbridgeEvents[Event]): this;
86
+ /**
87
+ * Loads a plugin from the specified package.json file path.
88
+ * @param packageJsonPath - The path to the package.json file of the plugin.
89
+ * @param mode - The mode of operation. Possible values are 'load', 'add', 'remove', 'enable', 'disable'.
90
+ * @returns A Promise that resolves when the plugin is loaded successfully, or rejects with an error if loading fails.
91
+ */
47
92
  private loadPlugin;
93
+ /**
94
+ * Registers the signal handlers for SIGINT and SIGTERM.
95
+ * When either of these signals are received, the cleanup method is called with an appropriate message.
96
+ */
48
97
  private registerSignalHandlers;
98
+ /**
99
+ * Performs cleanup operations before shutting down Matterbridge.
100
+ * @param message - The reason for the cleanup.
101
+ */
49
102
  private cleanup;
103
+ /**
104
+ * Sets the reachable attribute of a device.
105
+ *
106
+ * @param device - The device for which to set the reachable attribute.
107
+ * @param reachable - The value to set for the reachable attribute.
108
+ */
109
+ private setReachableAttribute;
110
+ /**
111
+ * Adds a device to the Matterbridge.
112
+ * @param pluginName - The name of the plugin.
113
+ * @param device - The device to be added.
114
+ */
50
115
  addDevice(pluginName: string, device: MatterbridgeDevice): Promise<void>;
116
+ /**
117
+ * Adds a bridged device to the Matterbridge.
118
+ * @param pluginName - The name of the plugin.
119
+ * @param device - The bridged device to add.
120
+ */
51
121
  addBridgedDevice(pluginName: string, device: MatterbridgeDevice): Promise<void>;
122
+ /**
123
+ * Starts the storage process based on the specified storage type and name.
124
+ * @param {string} storageType - The type of storage to start (e.g., 'disk', 'json').
125
+ * @param {string} storageName - The name of the storage file.
126
+ * @returns {Promise<void>} - A promise that resolves when the storage process is started.
127
+ */
52
128
  private startStorage;
129
+ /**
130
+ * Makes a backup copy of the specified JSON storage file.
131
+ *
132
+ * @param storageName - The name of the JSON storage file to be backed up.
133
+ * @param backupName - The name of the backup file to be created.
134
+ */
53
135
  private backupJsonStorage;
136
+ /**
137
+ * Stops the storage.
138
+ * @returns {Promise<void>} A promise that resolves when the storage is stopped.
139
+ */
54
140
  private stopStorage;
141
+ /**
142
+ * Starts the Matterbridge based on the bridge mode.
143
+ * If the bridge mode is 'bridge', it creates a commissioning server, matter aggregator,
144
+ * and starts the matter server.
145
+ * If the bridge mode is 'childbridge', it starts the plugins, creates commissioning servers,
146
+ * and starts the matter server when all plugins are loaded and started.
147
+ * @private
148
+ * @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
149
+ */
55
150
  private startMatterBridge;
151
+ private startMatterServer;
152
+ /**
153
+ * Imports the commissioning server context for a specific plugin and device.
154
+ * @param pluginName - The name of the plugin.
155
+ * @param device - The MatterbridgeDevice object representing the device.
156
+ * @returns The commissioning server context.
157
+ * @throws Error if the BasicInformationCluster is not found.
158
+ */
159
+ private importCommissioningServerContext;
160
+ /**
161
+ * Creates a commissioning server storage context.
162
+ *
163
+ * @param pluginName - The name of the plugin.
164
+ * @param deviceName - The name of the device.
165
+ * @param deviceType - The type of the device.
166
+ * @param vendorId - The vendor ID.
167
+ * @param vendorName - The vendor name.
168
+ * @param productId - The product ID.
169
+ * @param productName - The product name.
170
+ * @param serialNumber - The serial number of the device (optional).
171
+ * @param uniqueId - The unique ID of the device (optional).
172
+ * @param softwareVersion - The software version of the device (optional).
173
+ * @param softwareVersionString - The software version string of the device (optional).
174
+ * @param hardwareVersion - The hardware version of the device (optional).
175
+ * @param hardwareVersionString - The hardware version string of the device (optional).
176
+ * @returns The storage context for the commissioning server.
177
+ */
178
+ private createCommissioningServerContext;
179
+ /**
180
+ * Shows the commissioning QR code for a given commissioning server, storage context, and name.
181
+ * If any of the parameters are missing, the method returns early.
182
+ * If the commissioning server is not commissioned, it logs the QR code and pairing code.
183
+ * If the commissioning server is already commissioned, it waits for controllers to connect.
184
+ * If the bridge mode is 'childbridge', it sets the 'paired' property of the plugin to true.
185
+ *
186
+ * @param commissioningServer - The commissioning server to show the QR code for.
187
+ * @param storageContext - The storage context to store the pairing codes.
188
+ * @param name - The name of the commissioning server.
189
+ */
56
190
  private showCommissioningQRCode;
57
- private createMatterCommisioningServer;
191
+ /**
192
+ * Finds a plugin by its name.
193
+ *
194
+ * @param pluginName - The name of the plugin to find.
195
+ * @returns The found plugin, or undefined if not found.
196
+ */
197
+ private findPlugin;
198
+ /**
199
+ * Creates a matter commissioning server.
200
+ *
201
+ * @param {StorageContext} context - The storage context.
202
+ * @param {string} name - The name of the commissioning server.
203
+ * @returns {CommissioningServer} The created commissioning server.
204
+ */
205
+ private createCommisioningServer;
206
+ /**
207
+ * Creates a Matter server using the provided storage manager.
208
+ * @param storageManager The storage manager to be used by the Matter server.
209
+ *
210
+ */
58
211
  private createMatterServer;
212
+ /**
213
+ * Creates a Matter Aggregator.
214
+ * @param {StorageContext} context - The storage context.
215
+ * @returns {Aggregator} - The created Matter Aggregator.
216
+ */
59
217
  private createMatterAggregator;
218
+ /**
219
+ * Stops the Matter server and associated controllers.
220
+ */
60
221
  private stopMatter;
222
+ /**
223
+ * Logs the node and system information.
224
+ */
61
225
  private logNodeAndSystemInfo;
226
+ private getBaseRegisteredPlugin;
62
227
  /**
63
228
  * Initializes the frontend of Matterbridge.
64
229
  *
65
230
  * @param port The port number to run the frontend server on. Default is 3000.
66
231
  */
67
232
  initializeFrontend(port?: number): Promise<void>;
233
+ /**
234
+ * Retrieves the cluster text from a given device.
235
+ * @param device - The MatterbridgeDevice object.
236
+ * @returns The attributes of the cluster servers in the device.
237
+ */
238
+ private getClusterTextFromDevice;
68
239
  }
69
240
  export {};
70
241
  //# sourceMappingURL=matterbridge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"matterbridge.d.ts","sourceRoot":"","sources":["../src/matterbridge.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAwB7D,OAAO,YAAY,MAAM,QAAQ,CAAC;AAsClC,UAAU,iBAAiB;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAGD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,sBAAsB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,oBAAoB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,+BAA+B,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACtE,6BAA6B,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACrE;AAED,qBAAa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