homebridge 2.0.0-alpha.5 → 2.0.0-alpha.50
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.
- package/README.md +1 -1
- package/bin/homebridge.js +22 -0
- package/dist/api.d.ts +219 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +79 -0
- package/dist/api.js.map +1 -1
- package/dist/bridgeService.d.ts +10 -3
- package/dist/bridgeService.d.ts.map +1 -1
- package/dist/bridgeService.js +9 -5
- package/dist/bridgeService.js.map +1 -1
- package/dist/childBridgeFork.d.ts +17 -2
- package/dist/childBridgeFork.d.ts.map +1 -1
- package/dist/childBridgeFork.js +161 -4
- package/dist/childBridgeFork.js.map +1 -1
- package/dist/childBridgeService.d.ts +21 -0
- package/dist/childBridgeService.d.ts.map +1 -1
- package/dist/childBridgeService.js +72 -25
- package/dist/childBridgeService.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/externalPortService.js.map +1 -1
- package/dist/index.d.ts +48 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/ipcService.d.ts +20 -0
- package/dist/ipcService.d.ts.map +1 -1
- package/dist/ipcService.js.map +1 -1
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +8 -0
- package/dist/logger.js.map +1 -1
- package/dist/matter/index.d.ts +51 -0
- package/dist/matter/index.d.ts.map +1 -0
- package/dist/matter/index.js +11 -0
- package/dist/matter/index.js.map +1 -0
- package/dist/matter/matterAccessoryCache.d.ts +77 -0
- package/dist/matter/matterAccessoryCache.d.ts.map +1 -0
- package/dist/matter/matterAccessoryCache.js +176 -0
- package/dist/matter/matterAccessoryCache.js.map +1 -0
- package/dist/matter/matterBehaviors.d.ts +127 -0
- package/dist/matter/matterBehaviors.d.ts.map +1 -0
- package/dist/matter/matterBehaviors.js +611 -0
- package/dist/matter/matterBehaviors.js.map +1 -0
- package/dist/matter/matterConfigValidator.d.ts +81 -0
- package/dist/matter/matterConfigValidator.d.ts.map +1 -0
- package/dist/matter/matterConfigValidator.js +240 -0
- package/dist/matter/matterConfigValidator.js.map +1 -0
- package/dist/matter/matterErrorHandler.d.ts +94 -0
- package/dist/matter/matterErrorHandler.d.ts.map +1 -0
- package/dist/matter/matterErrorHandler.js +485 -0
- package/dist/matter/matterErrorHandler.js.map +1 -0
- package/dist/matter/matterLogFormatter.d.ts +18 -0
- package/dist/matter/matterLogFormatter.d.ts.map +1 -0
- package/dist/matter/matterLogFormatter.js +128 -0
- package/dist/matter/matterLogFormatter.js.map +1 -0
- package/dist/matter/matterNetworkMonitor.d.ts +68 -0
- package/dist/matter/matterNetworkMonitor.d.ts.map +1 -0
- package/dist/matter/matterNetworkMonitor.js +250 -0
- package/dist/matter/matterNetworkMonitor.js.map +1 -0
- package/dist/matter/matterServer.d.ts +283 -0
- package/dist/matter/matterServer.d.ts.map +1 -0
- package/dist/matter/matterServer.js +1416 -0
- package/dist/matter/matterServer.js.map +1 -0
- package/dist/matter/matterSharedTypes.d.ts +165 -0
- package/dist/matter/matterSharedTypes.d.ts.map +1 -0
- package/dist/matter/matterSharedTypes.js +51 -0
- package/dist/matter/matterSharedTypes.js.map +1 -0
- package/dist/matter/matterStorage.d.ts +126 -0
- package/dist/matter/matterStorage.d.ts.map +1 -0
- package/dist/matter/matterStorage.js +419 -0
- package/dist/matter/matterStorage.js.map +1 -0
- package/dist/matter/matterTypes.d.ts +250 -0
- package/dist/matter/matterTypes.d.ts.map +1 -0
- package/dist/matter/matterTypes.js +142 -0
- package/dist/matter/matterTypes.js.map +1 -0
- package/dist/platformAccessory.d.ts +1 -0
- package/dist/platformAccessory.d.ts.map +1 -1
- package/dist/platformAccessory.js +8 -1
- package/dist/platformAccessory.js.map +1 -1
- package/dist/plugin.d.ts +0 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +9 -12
- package/dist/plugin.js.map +1 -1
- package/dist/pluginManager.d.ts.map +1 -1
- package/dist/pluginManager.js +22 -21
- package/dist/pluginManager.js.map +1 -1
- package/dist/server.d.ts +16 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +276 -8
- package/dist/server.js.map +1 -1
- package/dist/storageService.js +8 -8
- package/dist/storageService.js.map +1 -1
- package/dist/user.d.ts +1 -0
- package/dist/user.d.ts.map +1 -1
- package/dist/user.js +10 -7
- package/dist/user.js.map +1 -1
- package/dist/util/mac.d.ts.map +1 -1
- package/dist/util/mac.js +2 -2
- package/dist/util/mac.js.map +1 -1
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/package.json +25 -26
- package/bin/homebridge +0 -19
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/* global NodeJS */
|
|
2
|
+
/**
|
|
3
|
+
* Custom Matter.js Storage Implementation for Homebridge
|
|
4
|
+
*
|
|
5
|
+
* Provides persistent storage for Matter fabric data and device configuration.
|
|
6
|
+
* This ensures commissioning data persists across Homebridge restarts.
|
|
7
|
+
*/
|
|
8
|
+
import { Buffer } from 'node:buffer';
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as fsp from 'node:fs/promises';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import { Logger } from '../logger.js';
|
|
13
|
+
const log = Logger.withPrefix('Matter/Storage');
|
|
14
|
+
// Storage configuration constants
|
|
15
|
+
const STORAGE_WRITE_DEBOUNCE_MS = 100; // Delay for non-critical writes
|
|
16
|
+
/**
|
|
17
|
+
* Custom Matter.js StorageContext implementation for Homebridge
|
|
18
|
+
* Provides persistent storage for fabric data and device configuration
|
|
19
|
+
*/
|
|
20
|
+
export class HomebridgeMatterStorage {
|
|
21
|
+
namespace;
|
|
22
|
+
storage = new Map();
|
|
23
|
+
filePath;
|
|
24
|
+
isInitialized = false;
|
|
25
|
+
writeTimer = null;
|
|
26
|
+
pendingWrite = false;
|
|
27
|
+
persistLock = null;
|
|
28
|
+
constructor(namespace, storagePath) {
|
|
29
|
+
this.namespace = namespace;
|
|
30
|
+
this.filePath = path.join(storagePath, `${namespace}.json`);
|
|
31
|
+
// Synchronously load existing data to avoid race conditions with Matter.js
|
|
32
|
+
// Matter.js expects storage to be immediately available
|
|
33
|
+
this.initializeSync();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Synchronously initialize storage by loading existing data
|
|
37
|
+
* This is called in the constructor to ensure storage is ready immediately
|
|
38
|
+
*/
|
|
39
|
+
initializeSync() {
|
|
40
|
+
try {
|
|
41
|
+
const fileContent = fs.readFileSync(this.filePath, 'utf-8');
|
|
42
|
+
// Parse WITHOUT a reviver - we'll deserialize manually
|
|
43
|
+
const data = JSON.parse(fileContent);
|
|
44
|
+
// Ensure data is valid before loading
|
|
45
|
+
if (data && typeof data === 'object') {
|
|
46
|
+
// Deserialize ALL values as we load them into the Map
|
|
47
|
+
const entries = Object.entries(data).map(([key, value]) => [
|
|
48
|
+
key,
|
|
49
|
+
this.deserializeValue(value),
|
|
50
|
+
]);
|
|
51
|
+
this.storage = new Map(entries);
|
|
52
|
+
log.debug(`Loaded ${this.storage.size} entries for namespace: ${this.namespace}`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
log.warn(`Invalid storage data for ${this.namespace}, starting fresh`);
|
|
56
|
+
this.storage = new Map();
|
|
57
|
+
}
|
|
58
|
+
this.isInitialized = true;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error.code === 'ENOENT') {
|
|
62
|
+
log.debug(`No existing storage for namespace: ${this.namespace}`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
log.warn(`Failed to load storage for ${this.namespace} (${error.message}), starting fresh`);
|
|
66
|
+
}
|
|
67
|
+
// Create fresh storage if file doesn't exist or is corrupted
|
|
68
|
+
this.storage = new Map();
|
|
69
|
+
this.isInitialized = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Initialize storage and load existing data (async for compatibility)
|
|
74
|
+
* Note: Storage is now initialized synchronously in constructor
|
|
75
|
+
*/
|
|
76
|
+
async initialize() {
|
|
77
|
+
// Storage is already initialized in constructor
|
|
78
|
+
return Promise.resolve();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build a context key from an array of contexts
|
|
82
|
+
*/
|
|
83
|
+
buildContextKey(contexts) {
|
|
84
|
+
return contexts.join('.');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Recursively convert special serialized types back to their original types
|
|
88
|
+
*
|
|
89
|
+
* This is necessary because JSON.parse() doesn't automatically reconstruct:
|
|
90
|
+
* - BigInt values (serialized as {__type: 'bigint', value: string})
|
|
91
|
+
* - Uint8Array values (serialized as {__type: 'Uint8Array', value: number[]})
|
|
92
|
+
* - Buffer values (Node.js format: {type: 'Buffer', data: number[]})
|
|
93
|
+
*
|
|
94
|
+
* Matter.js fabric data contains these types which must be properly restored
|
|
95
|
+
* for commissioning to work across restarts.
|
|
96
|
+
*
|
|
97
|
+
* @param value - The value to deserialize (might be nested object/array)
|
|
98
|
+
* @returns The deserialized value with proper types restored
|
|
99
|
+
*/
|
|
100
|
+
deserializeValue(value) {
|
|
101
|
+
if (value && typeof value === 'object') {
|
|
102
|
+
// Handle special type markers
|
|
103
|
+
const obj = value;
|
|
104
|
+
if (obj.__type === 'bigint' && typeof obj.value === 'string') {
|
|
105
|
+
return BigInt(obj.value);
|
|
106
|
+
}
|
|
107
|
+
if (obj.__type === 'Uint8Array' && Array.isArray(obj.value)) {
|
|
108
|
+
return new Uint8Array(obj.value);
|
|
109
|
+
}
|
|
110
|
+
// Handle Node.js Buffer JSON format: {type: "Buffer", data: [...]}
|
|
111
|
+
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
112
|
+
return new Uint8Array(obj.data);
|
|
113
|
+
}
|
|
114
|
+
// Recursively process arrays
|
|
115
|
+
if (Array.isArray(value)) {
|
|
116
|
+
return value.map(item => this.deserializeValue(item));
|
|
117
|
+
}
|
|
118
|
+
// Recursively process plain objects
|
|
119
|
+
if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
120
|
+
const result = {};
|
|
121
|
+
for (const [k, v] of Object.entries(value)) {
|
|
122
|
+
result[k] = this.deserializeValue(v);
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get a value from storage (Matter.js interface)
|
|
131
|
+
*/
|
|
132
|
+
get(contexts, key) {
|
|
133
|
+
// Storage is initialized in constructor, so this should always work
|
|
134
|
+
const fullKey = contexts.length ? `${this.buildContextKey(contexts)}.${key}` : key;
|
|
135
|
+
const value = this.storage.get(fullKey);
|
|
136
|
+
// Ensure value is fully deserialized (handles nested special types)
|
|
137
|
+
return this.deserializeValue(value);
|
|
138
|
+
}
|
|
139
|
+
set(contexts, keyOrValues, value) {
|
|
140
|
+
const contextKey = this.buildContextKey(contexts);
|
|
141
|
+
if (typeof keyOrValues === 'string') {
|
|
142
|
+
const fullKey = contextKey ? `${contextKey}.${keyOrValues}` : keyOrValues;
|
|
143
|
+
this.storage.set(fullKey, value);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
for (const [k, v] of Object.entries(keyOrValues)) {
|
|
147
|
+
const fullKey = contextKey ? `${contextKey}.${k}` : k;
|
|
148
|
+
this.storage.set(fullKey, v);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Debounce writes to avoid excessive disk I/O
|
|
152
|
+
void this.schedulePersist();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Delete a key from storage (Matter.js interface)
|
|
156
|
+
*/
|
|
157
|
+
delete(contexts, key) {
|
|
158
|
+
const fullKey = contexts.length ? `${this.buildContextKey(contexts)}.${key}` : key;
|
|
159
|
+
const deleted = this.storage.delete(fullKey);
|
|
160
|
+
if (deleted) {
|
|
161
|
+
void this.schedulePersist();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Clear all storage in a context (Matter.js interface)
|
|
166
|
+
*/
|
|
167
|
+
clearAll(contexts) {
|
|
168
|
+
const contextKey = this.buildContextKey(contexts);
|
|
169
|
+
const prefix = contextKey ? `${contextKey}.` : '';
|
|
170
|
+
// Collect keys to delete first to avoid modifying during iteration
|
|
171
|
+
const keysToDelete = [];
|
|
172
|
+
for (const key of this.storage.keys()) {
|
|
173
|
+
if (!prefix || key.startsWith(prefix)) {
|
|
174
|
+
keysToDelete.push(key);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Delete collected keys
|
|
178
|
+
for (const key of keysToDelete) {
|
|
179
|
+
this.storage.delete(key);
|
|
180
|
+
}
|
|
181
|
+
if (keysToDelete.length > 0) {
|
|
182
|
+
void this.schedulePersist();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get all keys in a context (Matter.js interface)
|
|
187
|
+
*/
|
|
188
|
+
keys(contexts) {
|
|
189
|
+
if (!this.isInitialized) {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
const contextKey = this.buildContextKey(contexts);
|
|
193
|
+
const prefix = contextKey ? `${contextKey}.` : '';
|
|
194
|
+
const contextKeys = [];
|
|
195
|
+
for (const key of this.storage.keys()) {
|
|
196
|
+
if (prefix) {
|
|
197
|
+
// Return keys within this context (strip context prefix)
|
|
198
|
+
if (key.startsWith(prefix)) {
|
|
199
|
+
const subKey = key.substring(prefix.length);
|
|
200
|
+
// Only include direct children (no further nesting)
|
|
201
|
+
if (!subKey.includes('.')) {
|
|
202
|
+
contextKeys.push(subKey);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// Root level - return keys with no dots
|
|
208
|
+
if (!key.includes('.')) {
|
|
209
|
+
contextKeys.push(key);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return contextKeys;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get all child context names (Matter.js interface)
|
|
217
|
+
*/
|
|
218
|
+
contexts(contexts) {
|
|
219
|
+
if (!this.isInitialized) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
const contextKey = this.buildContextKey(contexts);
|
|
223
|
+
const prefix = contextKey ? `${contextKey}.` : '';
|
|
224
|
+
const childContexts = new Set();
|
|
225
|
+
for (const key of this.storage.keys()) {
|
|
226
|
+
if (prefix) {
|
|
227
|
+
// Find sub-contexts within this context
|
|
228
|
+
if (key.startsWith(prefix)) {
|
|
229
|
+
const subKey = key.substring(prefix.length);
|
|
230
|
+
const nextDot = subKey.indexOf('.');
|
|
231
|
+
if (nextDot > 0) {
|
|
232
|
+
childContexts.add(subKey.substring(0, nextDot));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
// Root level - find top-level contexts
|
|
238
|
+
const dotIndex = key.indexOf('.');
|
|
239
|
+
if (dotIndex > 0) {
|
|
240
|
+
childContexts.add(key.substring(0, dotIndex));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return Array.from(childContexts);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Check if a key exists (Matter.js interface)
|
|
248
|
+
*/
|
|
249
|
+
has(contexts, key) {
|
|
250
|
+
if (!this.isInitialized) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
const fullKey = contexts.length ? `${this.buildContextKey(contexts)}.${key}` : key;
|
|
254
|
+
return this.storage.has(fullKey);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get all values in a context
|
|
258
|
+
*/
|
|
259
|
+
async values(contexts) {
|
|
260
|
+
await this.initialize();
|
|
261
|
+
const contextKey = this.buildContextKey(contexts);
|
|
262
|
+
const prefix = contextKey ? `${contextKey}.` : '';
|
|
263
|
+
const values = {};
|
|
264
|
+
for (const [key, value] of this.storage.entries()) {
|
|
265
|
+
if (prefix) {
|
|
266
|
+
if (key.startsWith(prefix)) {
|
|
267
|
+
const subKey = key.substring(prefix.length);
|
|
268
|
+
if (!subKey.includes('.')) {
|
|
269
|
+
values[subKey] = this.deserializeValue(value);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
if (!key.includes('.')) {
|
|
275
|
+
values[key] = this.deserializeValue(value);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return values;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Schedule a persist operation (debounced)
|
|
283
|
+
*/
|
|
284
|
+
async schedulePersist() {
|
|
285
|
+
if (this.writeTimer) {
|
|
286
|
+
clearTimeout(this.writeTimer);
|
|
287
|
+
}
|
|
288
|
+
this.pendingWrite = true;
|
|
289
|
+
// Immediate persist for critical data (fabric information)
|
|
290
|
+
const hasCriticalData = Array.from(this.storage.keys()).some(key => key.includes('fabric'));
|
|
291
|
+
if (hasCriticalData) {
|
|
292
|
+
await this.persist();
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
// Debounce non-critical writes
|
|
296
|
+
this.writeTimer = setTimeout(() => {
|
|
297
|
+
void this.persist();
|
|
298
|
+
}, STORAGE_WRITE_DEBOUNCE_MS);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Persist storage to disk with atomic write
|
|
303
|
+
*/
|
|
304
|
+
async persist() {
|
|
305
|
+
// Wait for any in-progress persist operation to complete
|
|
306
|
+
if (this.persistLock) {
|
|
307
|
+
await this.persistLock;
|
|
308
|
+
}
|
|
309
|
+
if (!this.pendingWrite) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
// Create a new lock for this persist operation
|
|
313
|
+
this.persistLock = (async () => {
|
|
314
|
+
try {
|
|
315
|
+
const data = Object.fromEntries(this.storage.entries());
|
|
316
|
+
const dir = path.dirname(this.filePath);
|
|
317
|
+
// Ensure directory exists
|
|
318
|
+
await fsp.mkdir(dir, { recursive: true });
|
|
319
|
+
// Atomic write: write to temp file then rename
|
|
320
|
+
// Use a unique temp file to avoid conflicts
|
|
321
|
+
const tempFile = `${this.filePath}.tmp.${Date.now()}`;
|
|
322
|
+
// Custom replacer to handle BigInt, Uint8Array, and Buffer serialization
|
|
323
|
+
const jsonString = JSON.stringify(data, (_key, value) => {
|
|
324
|
+
if (typeof value === 'bigint') {
|
|
325
|
+
return { __type: 'bigint', value: value.toString() };
|
|
326
|
+
}
|
|
327
|
+
// Handle Buffer before Uint8Array since Buffer extends Uint8Array
|
|
328
|
+
// Note: Buffer.toJSON() returns {type: 'Buffer', data: [...]}, but we want consistent format
|
|
329
|
+
if (Buffer.isBuffer(value)) {
|
|
330
|
+
return { __type: 'Uint8Array', value: Array.from(value) };
|
|
331
|
+
}
|
|
332
|
+
if (value instanceof Uint8Array) {
|
|
333
|
+
return { __type: 'Uint8Array', value: Array.from(value) };
|
|
334
|
+
}
|
|
335
|
+
return value;
|
|
336
|
+
}, 2);
|
|
337
|
+
await fsp.writeFile(tempFile, jsonString, 'utf-8');
|
|
338
|
+
await fsp.rename(tempFile, this.filePath);
|
|
339
|
+
this.pendingWrite = false;
|
|
340
|
+
log.debug(`Persisted ${this.storage.size} entries for namespace: ${this.namespace}`);
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
log.error(`Failed to persist storage for ${this.namespace}:`, error);
|
|
344
|
+
// Don't throw - we don't want to break Matter operations
|
|
345
|
+
}
|
|
346
|
+
finally {
|
|
347
|
+
this.persistLock = null;
|
|
348
|
+
}
|
|
349
|
+
})();
|
|
350
|
+
await this.persistLock;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Force immediate persist (for shutdown)
|
|
354
|
+
*/
|
|
355
|
+
async forcePersist() {
|
|
356
|
+
if (this.writeTimer) {
|
|
357
|
+
clearTimeout(this.writeTimer);
|
|
358
|
+
this.writeTimer = null;
|
|
359
|
+
}
|
|
360
|
+
if (this.pendingWrite) {
|
|
361
|
+
await this.persist();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Close and cleanup storage
|
|
366
|
+
*/
|
|
367
|
+
async close() {
|
|
368
|
+
await this.forcePersist();
|
|
369
|
+
this.storage.clear();
|
|
370
|
+
this.isInitialized = false;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Get storage statistics
|
|
374
|
+
*/
|
|
375
|
+
getStats() {
|
|
376
|
+
return {
|
|
377
|
+
entries: this.storage.size,
|
|
378
|
+
namespace: this.namespace,
|
|
379
|
+
path: this.filePath,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Storage Manager for Matter.js
|
|
385
|
+
* Manages multiple storage contexts for different namespaces
|
|
386
|
+
*/
|
|
387
|
+
export class MatterStorageManager {
|
|
388
|
+
storagePath;
|
|
389
|
+
storages = new Map();
|
|
390
|
+
constructor(storagePath) {
|
|
391
|
+
this.storagePath = storagePath;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Get or create a storage context for a namespace
|
|
395
|
+
*/
|
|
396
|
+
getStorage(namespace) {
|
|
397
|
+
let storage = this.storages.get(namespace);
|
|
398
|
+
if (!storage) {
|
|
399
|
+
storage = new HomebridgeMatterStorage(namespace, this.storagePath);
|
|
400
|
+
this.storages.set(namespace, storage);
|
|
401
|
+
}
|
|
402
|
+
return storage;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Close all storage contexts
|
|
406
|
+
*/
|
|
407
|
+
async closeAll() {
|
|
408
|
+
const promises = Array.from(this.storages.values()).map(storage => storage.close());
|
|
409
|
+
await Promise.all(promises);
|
|
410
|
+
this.storages.clear();
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Get statistics for all storage contexts
|
|
414
|
+
*/
|
|
415
|
+
getAllStats() {
|
|
416
|
+
return Array.from(this.storages.values()).map(storage => storage.getStats());
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
//# sourceMappingURL=matterStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matterStorage.js","sourceRoot":"","sources":["../../src/matter/matterStorage.ts"],"names":[],"mappings":"AAAA,mBAAmB;AAEnB;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAA;AAE/C,kCAAkC;AAClC,MAAM,yBAAyB,GAAG,GAAG,CAAA,CAAC,gCAAgC;AAEtE;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IASxB;IARF,OAAO,GAAqB,IAAI,GAAG,EAAE,CAAA;IAC5B,QAAQ,CAAQ;IACzB,aAAa,GAAG,KAAK,CAAA;IACrB,UAAU,GAA0B,IAAI,CAAA;IACxC,YAAY,GAAG,KAAK,CAAA;IACpB,WAAW,GAAyB,IAAI,CAAA;IAEhD,YACU,SAAiB,EACzB,WAAmB;QADX,cAAS,GAAT,SAAS,CAAQ;QAGzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,SAAS,OAAO,CAAC,CAAA;QAE3D,2EAA2E;QAC3E,wDAAwD;QACxD,IAAI,CAAC,cAAc,EAAE,CAAA;IACvB,CAAC;IAED;;;OAGG;IACK,cAAc;QACpB,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,EAAE,CA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AAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QACvC,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;QACnF,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC3B,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACvB,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC9E,CAAC;CACF"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matter Types for Homebridge Plugin API
|
|
3
|
+
*
|
|
4
|
+
* This module provides types and interfaces for plugin developers
|
|
5
|
+
* to create Matter-compatible accessories.
|
|
6
|
+
*/
|
|
7
|
+
import type { Endpoint, EndpointType } from '@matter/main';
|
|
8
|
+
import * as clusters from '@matter/main/clusters';
|
|
9
|
+
import * as devices from '@matter/main/devices';
|
|
10
|
+
/**
|
|
11
|
+
* Matter command handler function type
|
|
12
|
+
*
|
|
13
|
+
* Handlers can be synchronous or asynchronous (returning a Promise).
|
|
14
|
+
* The args parameter contains the command arguments passed by Matter.js (optional).
|
|
15
|
+
*/
|
|
16
|
+
export type MatterCommandHandler<TArgs = unknown> = (args?: TArgs) => Promise<void> | void;
|
|
17
|
+
/**
|
|
18
|
+
* Matter cluster handlers interface
|
|
19
|
+
*
|
|
20
|
+
* Maps command names to their handler functions.
|
|
21
|
+
* Each command can have custom argument types.
|
|
22
|
+
*/
|
|
23
|
+
export interface MatterClusterHandlers {
|
|
24
|
+
[commandName: string]: MatterCommandHandler<any>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Matter Accessory - Plugin API Interface
|
|
28
|
+
*
|
|
29
|
+
* This is the main interface that plugin developers use to register
|
|
30
|
+
* Matter accessories with Homebridge.
|
|
31
|
+
*/
|
|
32
|
+
export interface MatterAccessory<T = Record<string, any>> {
|
|
33
|
+
/** Unique identifier for this accessory (must be unique across all accessories) */
|
|
34
|
+
uuid: string;
|
|
35
|
+
/** Display name for the accessory */
|
|
36
|
+
displayName: string;
|
|
37
|
+
/** Matter device type (e.g., OnOffLightDevice, DimmableLightDevice, etc.) */
|
|
38
|
+
deviceType: EndpointType;
|
|
39
|
+
/** Serial number for the device */
|
|
40
|
+
serialNumber: string;
|
|
41
|
+
/** Manufacturer name */
|
|
42
|
+
manufacturer: string;
|
|
43
|
+
/** Model name/identifier */
|
|
44
|
+
model: string;
|
|
45
|
+
/** Firmware revision (optional) */
|
|
46
|
+
firmwareRevision?: string;
|
|
47
|
+
/** Hardware revision (optional) */
|
|
48
|
+
hardwareRevision?: string;
|
|
49
|
+
/** Software version (optional) */
|
|
50
|
+
softwareVersion?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Plugin developer storage - persists across restarts
|
|
53
|
+
* This is a way for plugin developers to store custom data with their accessory
|
|
54
|
+
* Similar to `PlatformAccessory.context` for HAP accessories
|
|
55
|
+
*/
|
|
56
|
+
context?: T;
|
|
57
|
+
/**
|
|
58
|
+
* Initial cluster states
|
|
59
|
+
* Key is the cluster name, value is an object of attribute name -> value
|
|
60
|
+
*
|
|
61
|
+
* Example:
|
|
62
|
+
* {
|
|
63
|
+
* onOff: { onOff: true },
|
|
64
|
+
* levelControl: { currentLevel: 127, minLevel: 1, maxLevel: 254 }
|
|
65
|
+
* }
|
|
66
|
+
*/
|
|
67
|
+
clusters: {
|
|
68
|
+
[clusterName: string]: {
|
|
69
|
+
[attributeName: string]: unknown;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Handlers for Matter commands (Home app → Device)
|
|
74
|
+
*
|
|
75
|
+
* These handlers are called when a user controls the accessory via the Home app.
|
|
76
|
+
* Use handlers to send commands to your actual device (cloud API, local network, etc.).
|
|
77
|
+
*/
|
|
78
|
+
handlers?: {
|
|
79
|
+
[clusterName: string]: MatterClusterHandlers;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Optional: Get current state handler
|
|
83
|
+
* Called when a Matter controller reads an attribute
|
|
84
|
+
* If not provided, the last set value is returned
|
|
85
|
+
*/
|
|
86
|
+
getState?: (cluster: string, attribute: string) => Promise<any> | any;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Matter Configuration (for bridge or child bridge)
|
|
90
|
+
*/
|
|
91
|
+
export interface MatterConfig extends Record<string, unknown> {
|
|
92
|
+
/** Port for Matter server (optional, will auto-assign if not specified) */
|
|
93
|
+
port?: number;
|
|
94
|
+
/** Name for the Matter bridge (optional) */
|
|
95
|
+
name?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Matter Fabric Information
|
|
99
|
+
* Represents a commissioned controller (fabric) on the Matter bridge
|
|
100
|
+
*/
|
|
101
|
+
export interface MatterFabricInfo {
|
|
102
|
+
fabricIndex: number;
|
|
103
|
+
fabricId: string;
|
|
104
|
+
nodeId: string;
|
|
105
|
+
rootVendorId: number;
|
|
106
|
+
label?: string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Matter Server Events
|
|
110
|
+
* Event types emitted by the Matter server for commissioning lifecycle
|
|
111
|
+
*/
|
|
112
|
+
export interface MatterServerEvents {
|
|
113
|
+
/** Emitted when the bridge is commissioned for the first time */
|
|
114
|
+
'commissioned': (fabricInfo: MatterFabricInfo) => void;
|
|
115
|
+
/** Emitted when the last fabric is removed (bridge becomes uncommissioned) */
|
|
116
|
+
'decommissioned': () => void;
|
|
117
|
+
/** Emitted when a new fabric (controller) is added */
|
|
118
|
+
'fabric-added': (fabricInfo: MatterFabricInfo) => void;
|
|
119
|
+
/** Emitted when a fabric (controller) is removed */
|
|
120
|
+
'fabric-removed': (fabricInfo: MatterFabricInfo) => void;
|
|
121
|
+
/** Emitted whenever commissioning state changes (any fabric added/removed) */
|
|
122
|
+
'commissioning-changed': (commissioned: boolean, fabricCount: number) => void;
|
|
123
|
+
/** Emitted when an accessory is registered */
|
|
124
|
+
'accessory-registered': (accessory: MatterAccessory) => void;
|
|
125
|
+
/** Emitted when an accessory is unregistered */
|
|
126
|
+
'accessory-unregistered': (uuid: string) => void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Internal Matter accessory representation
|
|
130
|
+
* (Used internally by MatterServer)
|
|
131
|
+
*/
|
|
132
|
+
export interface InternalMatterAccessory extends MatterAccessory {
|
|
133
|
+
_associatedPlugin?: string;
|
|
134
|
+
_associatedPlatform?: string;
|
|
135
|
+
endpoint?: Endpoint;
|
|
136
|
+
registered: boolean;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Matter error type enum (for error handler categorization)
|
|
140
|
+
*/
|
|
141
|
+
export declare enum MatterErrorType {
|
|
142
|
+
INITIALIZATION = "INITIALIZATION",
|
|
143
|
+
NETWORK = "NETWORK",
|
|
144
|
+
COMMISSIONING = "COMMISSIONING",
|
|
145
|
+
DEVICE_SYNC = "DEVICE_SYNC",
|
|
146
|
+
SERVER = "SERVER",
|
|
147
|
+
STORAGE = "STORAGE",
|
|
148
|
+
CONFIGURATION = "CONFIGURATION",
|
|
149
|
+
DEVICE_ERROR = "DEVICE_ERROR",
|
|
150
|
+
UNKNOWN = "UNKNOWN"
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Matter error details interface
|
|
154
|
+
*/
|
|
155
|
+
export interface MatterErrorDetails {
|
|
156
|
+
type?: MatterErrorType;
|
|
157
|
+
recoverable?: boolean;
|
|
158
|
+
code?: string;
|
|
159
|
+
context?: string;
|
|
160
|
+
originalError?: Error;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Matter error types
|
|
164
|
+
*/
|
|
165
|
+
export declare class MatterError extends Error {
|
|
166
|
+
readonly code: string;
|
|
167
|
+
readonly details?: MatterErrorDetails | undefined;
|
|
168
|
+
readonly type: MatterErrorType;
|
|
169
|
+
readonly timestamp: Date;
|
|
170
|
+
readonly recoverable: boolean;
|
|
171
|
+
constructor(message: string, code: string, details?: MatterErrorDetails | undefined, type?: MatterErrorType, recoverable?: boolean);
|
|
172
|
+
}
|
|
173
|
+
export declare class MatterCommissioningError extends MatterError {
|
|
174
|
+
constructor(message: string, details?: MatterErrorDetails);
|
|
175
|
+
}
|
|
176
|
+
export declare class MatterStorageError extends MatterError {
|
|
177
|
+
constructor(message: string, details?: MatterErrorDetails);
|
|
178
|
+
}
|
|
179
|
+
export declare class MatterDeviceError extends MatterError {
|
|
180
|
+
constructor(message: string, details?: MatterErrorDetails);
|
|
181
|
+
}
|
|
182
|
+
export declare class MatterNetworkError extends MatterError {
|
|
183
|
+
constructor(message: string, details?: MatterErrorDetails);
|
|
184
|
+
}
|
|
185
|
+
export { clusters };
|
|
186
|
+
export { devices };
|
|
187
|
+
/**
|
|
188
|
+
* Friendly device type names for the Plugin API
|
|
189
|
+
* Maps simplified names to actual Matter.js device types
|
|
190
|
+
*/
|
|
191
|
+
export declare const deviceTypes: {
|
|
192
|
+
readonly OnOffLight: devices.OnOffLightDevice;
|
|
193
|
+
readonly DimmableLight: devices.DimmableLightDevice;
|
|
194
|
+
readonly ColorTemperatureLight: devices.ColorTemperatureLightDevice;
|
|
195
|
+
readonly ExtendedColorLight: devices.ExtendedColorLightDevice;
|
|
196
|
+
readonly OnOffSwitch: devices.OnOffLightSwitchDevice;
|
|
197
|
+
readonly OnOffOutlet: devices.OnOffPlugInUnitDevice;
|
|
198
|
+
readonly DimmableOutlet: devices.DimmablePlugInUnitDevice;
|
|
199
|
+
readonly TemperatureSensor: devices.TemperatureSensorDevice;
|
|
200
|
+
readonly HumiditySensor: devices.HumiditySensorDevice;
|
|
201
|
+
readonly LightSensor: devices.LightSensorDevice;
|
|
202
|
+
readonly MotionSensor: devices.OccupancySensorDevice;
|
|
203
|
+
readonly ContactSensor: devices.ContactSensorDevice;
|
|
204
|
+
readonly LeakSensor: devices.WaterLeakDetectorDevice;
|
|
205
|
+
readonly SmokeSensor: devices.SmokeCoAlarmDevice;
|
|
206
|
+
readonly Thermostat: devices.ThermostatDevice;
|
|
207
|
+
readonly Fan: devices.FanDevice;
|
|
208
|
+
readonly DoorLock: devices.DoorLockDevice;
|
|
209
|
+
readonly WindowCovering: devices.WindowCoveringDevice;
|
|
210
|
+
readonly GenericSwitch: devices.GenericSwitchDevice;
|
|
211
|
+
readonly Pump: devices.PumpDevice;
|
|
212
|
+
readonly RoomAirConditioner: devices.RoomAirConditionerDevice;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Matter Cluster Names
|
|
216
|
+
* Commonly used cluster names for type safety and autocomplete
|
|
217
|
+
* Use these with api.updateMatterAccessoryState() and api.getAccessoryState()
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* // With autocomplete and type safety:
|
|
222
|
+
* api.updateMatterAccessoryState(uuid, api.matterClusterNames.OnOff, { onOff: true })
|
|
223
|
+
* api.getAccessoryState(uuid, api.matterClusterNames.LevelControl)
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
export declare const clusterNames: {
|
|
227
|
+
readonly OnOff: "onOff";
|
|
228
|
+
readonly LevelControl: "levelControl";
|
|
229
|
+
readonly ColorControl: "colorControl";
|
|
230
|
+
readonly DoorLock: "doorLock";
|
|
231
|
+
readonly WindowCovering: "windowCovering";
|
|
232
|
+
readonly Thermostat: "thermostat";
|
|
233
|
+
readonly FanControl: "fanControl";
|
|
234
|
+
readonly TemperatureMeasurement: "temperatureMeasurement";
|
|
235
|
+
readonly RelativeHumidityMeasurement: "relativeHumidityMeasurement";
|
|
236
|
+
readonly IlluminanceMeasurement: "illuminanceMeasurement";
|
|
237
|
+
readonly OccupancySensing: "occupancySensing";
|
|
238
|
+
readonly BooleanState: "booleanState";
|
|
239
|
+
readonly SmokeCoAlarm: "smokeCoAlarm";
|
|
240
|
+
readonly PumpConfigurationAndControl: "pumpConfigurationAndControl";
|
|
241
|
+
readonly Identify: "identify";
|
|
242
|
+
readonly BasicInformation: "basicInformation";
|
|
243
|
+
readonly BridgedDeviceBasicInformation: "bridgedDeviceBasicInformation";
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Type for Matter cluster names
|
|
247
|
+
* Provides type safety for cluster name strings
|
|
248
|
+
*/
|
|
249
|
+
export type MatterClusterName = typeof clusterNames[keyof typeof clusterNames];
|
|
250
|
+
//# sourceMappingURL=matterTypes.d.ts.map
|