homebridge 2.0.0-alpha.40 → 2.0.0-alpha.42
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/config-sample.json +1 -12
- package/dist/api.d.ts +46 -35
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +41 -35
- package/dist/api.js.map +1 -1
- package/dist/bridgeService.d.ts +7 -15
- package/dist/bridgeService.d.ts.map +1 -1
- package/dist/bridgeService.js +10 -7
- package/dist/bridgeService.js.map +1 -1
- package/dist/childBridgeFork.d.ts +19 -0
- package/dist/childBridgeFork.d.ts.map +1 -1
- package/dist/childBridgeFork.js +198 -4
- package/dist/childBridgeFork.js.map +1 -1
- package/dist/childBridgeService.d.ts +28 -1
- package/dist/childBridgeService.d.ts.map +1 -1
- package/dist/childBridgeService.js +43 -0
- package/dist/childBridgeService.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/ipcService.d.ts +21 -3
- package/dist/ipcService.d.ts.map +1 -1
- package/dist/ipcService.js +15 -0
- package/dist/ipcService.js.map +1 -1
- package/dist/matter/index.d.ts +11 -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/matterConfigValidator.d.ts +26 -0
- package/dist/matter/matterConfigValidator.d.ts.map +1 -0
- package/dist/matter/matterConfigValidator.js +171 -0
- package/dist/matter/matterConfigValidator.js.map +1 -0
- package/dist/matter/matterDiagnostics.d.ts +121 -0
- package/dist/matter/matterDiagnostics.d.ts.map +1 -0
- package/dist/matter/matterDiagnostics.js +323 -0
- package/dist/matter/matterDiagnostics.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 +472 -0
- package/dist/matter/matterErrorHandler.js.map +1 -0
- package/dist/matter/matterNetworkMonitor.d.ts +65 -0
- package/dist/matter/matterNetworkMonitor.d.ts.map +1 -0
- package/dist/matter/matterNetworkMonitor.js +227 -0
- package/dist/matter/matterNetworkMonitor.js.map +1 -0
- package/dist/matter/matterServer.d.ts +196 -0
- package/dist/matter/matterServer.d.ts.map +1 -0
- package/dist/matter/matterServer.js +824 -0
- package/dist/matter/matterServer.js.map +1 -0
- package/dist/matter/matterSharedTypes.d.ts +147 -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 +112 -0
- package/dist/matter/matterStorage.d.ts.map +1 -0
- package/dist/matter/matterStorage.js +355 -0
- package/dist/matter/matterStorage.js.map +1 -0
- package/dist/matter/matterTypes.d.ts +163 -0
- package/dist/matter/matterTypes.d.ts.map +1 -0
- package/dist/matter/matterTypes.js +106 -0
- package/dist/matter/matterTypes.js.map +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +4 -2
- package/dist/plugin.js.map +1 -1
- package/dist/server.d.ts +18 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +361 -51
- package/dist/server.js.map +1 -1
- package/dist/user.d.ts +1 -0
- package/dist/user.d.ts.map +1 -1
- package/dist/user.js +3 -0
- package/dist/user.js.map +1 -1
- package/package.json +12 -13
- package/dist/matterConfigValidator.d.ts +0 -34
- package/dist/matterConfigValidator.d.ts.map +0 -1
- package/dist/matterConfigValidator.js +0 -249
- package/dist/matterConfigValidator.js.map +0 -1
- package/dist/matterService.d.ts +0 -168
- package/dist/matterService.d.ts.map +0 -1
- package/dist/matterService.js +0 -677
- package/dist/matterService.js.map +0 -1
- package/dist/matterTypes.d.ts +0 -20
- package/dist/matterTypes.d.ts.map +0 -1
- package/dist/matterTypes.js +0 -278
- package/dist/matterTypes.js.map +0 -1
- package/dist/util/matter-cli.d.ts +0 -3
- package/dist/util/matter-cli.d.ts.map +0 -1
- package/dist/util/matter-cli.js +0 -211
- package/dist/util/matter-cli.js.map +0 -1
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/* global NodeJS */
|
|
2
|
+
/**
|
|
3
|
+
* Matter Network Monitor
|
|
4
|
+
*
|
|
5
|
+
* Monitors network connectivity and handles recovery
|
|
6
|
+
*/
|
|
7
|
+
import * as net from 'node:net';
|
|
8
|
+
import * as os from 'node:os';
|
|
9
|
+
import { Logger } from '../logger.js';
|
|
10
|
+
import { errorHandler, MatterErrorType } from './matterErrorHandler.js';
|
|
11
|
+
const log = Logger.withPrefix('Matter');
|
|
12
|
+
export class MatterNetworkMonitor {
|
|
13
|
+
static instance;
|
|
14
|
+
status;
|
|
15
|
+
checkInterval = null;
|
|
16
|
+
callbacks = new Set();
|
|
17
|
+
checkIntervalMs = 30000; // Check every 30 seconds
|
|
18
|
+
isMonitoring = false;
|
|
19
|
+
stabilityCounter = 0;
|
|
20
|
+
STABILITY_THRESHOLD = 3;
|
|
21
|
+
constructor() {
|
|
22
|
+
this.status = {
|
|
23
|
+
isOnline: true,
|
|
24
|
+
interfaces: [],
|
|
25
|
+
lastCheck: new Date(),
|
|
26
|
+
consecutiveFailures: 0,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
static getInstance() {
|
|
30
|
+
if (!MatterNetworkMonitor.instance) {
|
|
31
|
+
MatterNetworkMonitor.instance = new MatterNetworkMonitor();
|
|
32
|
+
}
|
|
33
|
+
return MatterNetworkMonitor.instance;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Start monitoring network connectivity
|
|
37
|
+
*/
|
|
38
|
+
startMonitoring() {
|
|
39
|
+
if (this.isMonitoring) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.isMonitoring = true;
|
|
43
|
+
log.debug('Starting Matter network monitoring');
|
|
44
|
+
// Initial check (fire-and-forget with error handling)
|
|
45
|
+
this.checkNetworkStatus().catch((error) => {
|
|
46
|
+
log.debug('Error during initial network check:', error);
|
|
47
|
+
});
|
|
48
|
+
// Set up periodic checks
|
|
49
|
+
this.checkInterval = setInterval(() => {
|
|
50
|
+
// Fire-and-forget with error handling
|
|
51
|
+
this.checkNetworkStatus().catch((error) => {
|
|
52
|
+
log.debug('Error during periodic network check:', error);
|
|
53
|
+
});
|
|
54
|
+
}, this.checkIntervalMs);
|
|
55
|
+
// Register recovery callback with error handler
|
|
56
|
+
errorHandler.registerRecoveryCallback(MatterErrorType.NETWORK, async () => this.handleNetworkRecovery());
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Stop monitoring
|
|
60
|
+
*/
|
|
61
|
+
stopMonitoring() {
|
|
62
|
+
if (this.checkInterval) {
|
|
63
|
+
clearInterval(this.checkInterval);
|
|
64
|
+
this.checkInterval = null;
|
|
65
|
+
}
|
|
66
|
+
this.isMonitoring = false;
|
|
67
|
+
log.debug('Stopped Matter network monitoring');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Check network status
|
|
71
|
+
*/
|
|
72
|
+
async checkNetworkStatus() {
|
|
73
|
+
try {
|
|
74
|
+
// Get network interfaces
|
|
75
|
+
const interfaces = this.getActiveInterfaces();
|
|
76
|
+
// Test connectivity with a simple port check
|
|
77
|
+
const isOnline = await this.testConnectivity();
|
|
78
|
+
const previousStatus = this.status.isOnline;
|
|
79
|
+
this.status = {
|
|
80
|
+
isOnline,
|
|
81
|
+
interfaces: interfaces.map(i => i.name),
|
|
82
|
+
primaryInterface: interfaces[0]?.name,
|
|
83
|
+
lastCheck: new Date(),
|
|
84
|
+
consecutiveFailures: isOnline ? 0 : this.status.consecutiveFailures + 1,
|
|
85
|
+
};
|
|
86
|
+
// Notify listeners if status changed
|
|
87
|
+
if (previousStatus !== isOnline) {
|
|
88
|
+
this.notifyStatusChange();
|
|
89
|
+
if (!isOnline) {
|
|
90
|
+
this.stabilityCounter = 0;
|
|
91
|
+
log.warn('Matter network connectivity lost');
|
|
92
|
+
await errorHandler.handleError(new Error('Network connectivity lost'), 'network-monitor');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.stabilityCounter = 0;
|
|
96
|
+
log.info('Matter network connectivity restored');
|
|
97
|
+
errorHandler.resetErrorCount(MatterErrorType.NETWORK);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (isOnline) {
|
|
101
|
+
// Increment stability counter when consistently online
|
|
102
|
+
this.stabilityCounter = Math.min(this.stabilityCounter + 1, this.STABILITY_THRESHOLD);
|
|
103
|
+
}
|
|
104
|
+
// Log warnings for repeated failures
|
|
105
|
+
if (this.status.consecutiveFailures > 3) {
|
|
106
|
+
log.error(`Network has been offline for ${this.status.consecutiveFailures} consecutive checks`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
log.debug('Error checking network status:', error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get active network interfaces
|
|
115
|
+
*/
|
|
116
|
+
getActiveInterfaces() {
|
|
117
|
+
const interfaces = [];
|
|
118
|
+
const networkInterfaces = os.networkInterfaces();
|
|
119
|
+
for (const [name, addrs] of Object.entries(networkInterfaces)) {
|
|
120
|
+
if (!addrs) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
for (const addr of addrs) {
|
|
124
|
+
// Skip internal (loopback) and non-IPv4 addresses
|
|
125
|
+
if (!addr.internal && addr.family === 'IPv4') {
|
|
126
|
+
interfaces.push({ name, address: addr.address });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return interfaces;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Test network connectivity with optimizations
|
|
134
|
+
*/
|
|
135
|
+
async testConnectivity() {
|
|
136
|
+
// If we recently had a successful check, skip the test
|
|
137
|
+
const timeSinceLastCheck = Date.now() - (this.status.lastCheck?.getTime() || 0);
|
|
138
|
+
if (this.status.isOnline && timeSinceLastCheck < 5000 && this.stabilityCounter >= this.STABILITY_THRESHOLD) {
|
|
139
|
+
log.debug('Skipping connectivity test - recent successful check');
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return new Promise((resolve) => {
|
|
143
|
+
const socket = new net.Socket();
|
|
144
|
+
const timeout = 2000; // Reduced timeout for faster failure detection
|
|
145
|
+
const cleanup = () => {
|
|
146
|
+
socket.destroy();
|
|
147
|
+
};
|
|
148
|
+
socket.setTimeout(timeout);
|
|
149
|
+
socket.once('connect', () => {
|
|
150
|
+
cleanup();
|
|
151
|
+
resolve(true);
|
|
152
|
+
});
|
|
153
|
+
socket.once('error', () => {
|
|
154
|
+
cleanup();
|
|
155
|
+
resolve(false);
|
|
156
|
+
});
|
|
157
|
+
socket.once('timeout', () => {
|
|
158
|
+
cleanup();
|
|
159
|
+
resolve(false);
|
|
160
|
+
});
|
|
161
|
+
// Try multiple fallback servers for redundancy
|
|
162
|
+
const servers = [
|
|
163
|
+
{ host: '1.1.1.1', port: 53 }, // Cloudflare DNS
|
|
164
|
+
{ host: '8.8.8.8', port: 53 }, // Google DNS
|
|
165
|
+
{ host: '9.9.9.9', port: 53 }, // Quad9 DNS
|
|
166
|
+
];
|
|
167
|
+
// Try first server, with fallback logic if needed
|
|
168
|
+
const server = servers[this.status.consecutiveFailures % servers.length];
|
|
169
|
+
socket.connect(server.port, server.host);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Handle network recovery
|
|
174
|
+
*/
|
|
175
|
+
async handleNetworkRecovery() {
|
|
176
|
+
log.info('Attempting network recovery...');
|
|
177
|
+
// Force a network check
|
|
178
|
+
await this.checkNetworkStatus();
|
|
179
|
+
if (this.status.isOnline) {
|
|
180
|
+
log.info('Network is online, recovery successful');
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
log.warn('Network still offline, will retry');
|
|
184
|
+
throw new Error('Network recovery failed');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Register a callback for network status changes
|
|
189
|
+
*/
|
|
190
|
+
onStatusChange(callback) {
|
|
191
|
+
this.callbacks.add(callback);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Remove a status change callback
|
|
195
|
+
*/
|
|
196
|
+
removeStatusChangeCallback(callback) {
|
|
197
|
+
this.callbacks.delete(callback);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Notify all listeners of status change
|
|
201
|
+
*/
|
|
202
|
+
notifyStatusChange() {
|
|
203
|
+
for (const callback of this.callbacks) {
|
|
204
|
+
try {
|
|
205
|
+
callback(this.status);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
log.debug('Error in network status callback:', error);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get current network status
|
|
214
|
+
*/
|
|
215
|
+
getStatus() {
|
|
216
|
+
return { ...this.status };
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Check if network is healthy
|
|
220
|
+
*/
|
|
221
|
+
isHealthy() {
|
|
222
|
+
return this.status.isOnline && this.status.consecutiveFailures === 0;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Export singleton instance
|
|
226
|
+
export const networkMonitor = MatterNetworkMonitor.getInstance();
|
|
227
|
+
//# sourceMappingURL=matterNetworkMonitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matterNetworkMonitor.js","sourceRoot":"","sources":["../../src/matter/matterNetworkMonitor.ts"],"names":[],"mappings":"AAAA,mBAAmB;AAEnB;;;;GAIG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;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A;QAC5C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,QAAyC;QACtD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC9B,CAAC;IAED;;OAEG;IACH,0BAA0B,CAAC,QAAyC;QAClE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACjC,CAAC;IAED;;OAEG;IACK,kBAAkB;QACxB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACvB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,GAAG,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAA;YACvD,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;IAC3B,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,KAAK,CAAC,CAAA;IACtE,CAAC;CACF;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matter.js Server Implementation for Homebridge Plugin API
|
|
3
|
+
*
|
|
4
|
+
* This provides a Matter bridge that plugins can use to register
|
|
5
|
+
* Matter accessories via the Homebridge API.
|
|
6
|
+
*/
|
|
7
|
+
import { MatterServerConfig } from './matterSharedTypes.js';
|
|
8
|
+
import { clusters, MatterAccessory } from './matterTypes.js';
|
|
9
|
+
export { MatterServerConfig } from './matterSharedTypes.js';
|
|
10
|
+
/**
|
|
11
|
+
* Matter Server for Homebridge Plugin API
|
|
12
|
+
* Allows plugins to register Matter accessories explicitly
|
|
13
|
+
*/
|
|
14
|
+
export declare class MatterServer {
|
|
15
|
+
private readonly config;
|
|
16
|
+
private serverNode;
|
|
17
|
+
private aggregator;
|
|
18
|
+
private accessories;
|
|
19
|
+
private isRunning;
|
|
20
|
+
private readonly MAX_DEVICES;
|
|
21
|
+
private shutdownHandler;
|
|
22
|
+
private passcode;
|
|
23
|
+
private discriminator;
|
|
24
|
+
private readonly vendorId;
|
|
25
|
+
private readonly productId;
|
|
26
|
+
private commissioningInfo;
|
|
27
|
+
private serialNumber?;
|
|
28
|
+
private cleanupHandlers;
|
|
29
|
+
private storageManager;
|
|
30
|
+
constructor(config?: MatterServerConfig);
|
|
31
|
+
/**
|
|
32
|
+
* Generate a secure random passcode
|
|
33
|
+
* According to Matter spec, passcode must be:
|
|
34
|
+
* - 8 digits (00000001 to 99999998)
|
|
35
|
+
* - Not in the invalid list
|
|
36
|
+
* - Not sequential or repeating patterns
|
|
37
|
+
*/
|
|
38
|
+
private generateSecurePasscode;
|
|
39
|
+
/**
|
|
40
|
+
* Validate a passcode according to Matter specifications
|
|
41
|
+
*/
|
|
42
|
+
private isValidPasscode;
|
|
43
|
+
/**
|
|
44
|
+
* Generate a random discriminator
|
|
45
|
+
* According to Matter spec, discriminator must be:
|
|
46
|
+
* - 12 bits (0-4095)
|
|
47
|
+
* - Should be random for security
|
|
48
|
+
*/
|
|
49
|
+
private generateRandomDiscriminator;
|
|
50
|
+
/**
|
|
51
|
+
* Create ServerNode with automatic recovery from corrupted storage
|
|
52
|
+
* If ServerNode creation fails due to corrupted fabric data, automatically
|
|
53
|
+
* clean up the ServerNodeStore and retry once
|
|
54
|
+
*/
|
|
55
|
+
private createServerNodeWithRecovery;
|
|
56
|
+
/**
|
|
57
|
+
* Start the Matter server
|
|
58
|
+
*/
|
|
59
|
+
start(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Set up and validate storage
|
|
62
|
+
*/
|
|
63
|
+
private setupStorage;
|
|
64
|
+
/**
|
|
65
|
+
* Load or generate commissioning credentials (passcode and discriminator)
|
|
66
|
+
* These must be persistent across restarts to maintain the same QR code
|
|
67
|
+
*/
|
|
68
|
+
private loadOrGenerateCredentials;
|
|
69
|
+
/**
|
|
70
|
+
* Generate serial number for the bridge
|
|
71
|
+
*/
|
|
72
|
+
private generateSerialNumber;
|
|
73
|
+
/**
|
|
74
|
+
* Generate and display commissioning information
|
|
75
|
+
*/
|
|
76
|
+
private generateCommissioningInfo;
|
|
77
|
+
/**
|
|
78
|
+
* Wait for the server to be ready
|
|
79
|
+
*/
|
|
80
|
+
private waitForServerReady;
|
|
81
|
+
/**
|
|
82
|
+
* Register a Matter accessory (Plugin API)
|
|
83
|
+
*/
|
|
84
|
+
registerAccessory(accessory: MatterAccessory): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Unregister a Matter accessory (Plugin API)
|
|
87
|
+
*/
|
|
88
|
+
unregisterAccessory(uuid: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Update a Matter accessory's state (Plugin API)
|
|
91
|
+
*/
|
|
92
|
+
updateAccessoryState(uuid: string, cluster: string, attributes: Record<string, unknown>): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Get all registered accessories (Plugin API)
|
|
95
|
+
*/
|
|
96
|
+
getAccessories(): MatterAccessory[];
|
|
97
|
+
/**
|
|
98
|
+
* Get a specific accessory by UUID (Plugin API)
|
|
99
|
+
*/
|
|
100
|
+
getAccessory(uuid: string): MatterAccessory | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Configure a Matter endpoint after it's been added to the aggregator
|
|
103
|
+
*/
|
|
104
|
+
private configureEndpoint;
|
|
105
|
+
/**
|
|
106
|
+
* Stop the Matter server
|
|
107
|
+
*/
|
|
108
|
+
stop(): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Cleanup resources
|
|
111
|
+
*/
|
|
112
|
+
private cleanup;
|
|
113
|
+
/**
|
|
114
|
+
* Get fabric information for commissioned controllers
|
|
115
|
+
*/
|
|
116
|
+
getFabricInfo(): Array<{
|
|
117
|
+
fabricIndex: number;
|
|
118
|
+
fabricId: string;
|
|
119
|
+
nodeId: string;
|
|
120
|
+
rootVendorId: number;
|
|
121
|
+
label?: string;
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Check if the server is commissioned
|
|
125
|
+
*/
|
|
126
|
+
isCommissioned(): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Get the number of commissioned fabrics
|
|
129
|
+
*/
|
|
130
|
+
getCommissionedFabricCount(): number;
|
|
131
|
+
/**
|
|
132
|
+
* Get server status information
|
|
133
|
+
*/
|
|
134
|
+
getServerInfo(): {
|
|
135
|
+
running: boolean;
|
|
136
|
+
port: number;
|
|
137
|
+
deviceCount: number;
|
|
138
|
+
commissioned: boolean;
|
|
139
|
+
fabricCount: number;
|
|
140
|
+
serialNumber?: string;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Get commissioning information
|
|
144
|
+
*/
|
|
145
|
+
getCommissioningInfo(): {
|
|
146
|
+
qrCode?: string;
|
|
147
|
+
manualPairingCode?: string;
|
|
148
|
+
serialNumber?: string;
|
|
149
|
+
passcode?: number;
|
|
150
|
+
discriminator?: number;
|
|
151
|
+
commissioned: boolean;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Get storage statistics
|
|
155
|
+
*/
|
|
156
|
+
getStorageStats(): Array<{
|
|
157
|
+
entries: number;
|
|
158
|
+
namespace: string;
|
|
159
|
+
path: string;
|
|
160
|
+
}> | null;
|
|
161
|
+
/**
|
|
162
|
+
* Check if server is running
|
|
163
|
+
*/
|
|
164
|
+
isServerRunning(): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Get Matter device types available for plugin use
|
|
167
|
+
*/
|
|
168
|
+
getDeviceTypes(): {
|
|
169
|
+
readonly OnOffLight: import("@matter/node/devices").OnOffLightDevice;
|
|
170
|
+
readonly DimmableLight: import("@matter/node/devices").DimmableLightDevice;
|
|
171
|
+
readonly ColorTemperatureLight: import("@matter/node/devices").ColorTemperatureLightDevice;
|
|
172
|
+
readonly ExtendedColorLight: import("@matter/node/devices").ExtendedColorLightDevice;
|
|
173
|
+
readonly OnOffSwitch: import("@matter/node/devices").OnOffLightSwitchDevice;
|
|
174
|
+
readonly OnOffOutlet: import("@matter/node/devices").OnOffPlugInUnitDevice;
|
|
175
|
+
readonly DimmableOutlet: import("@matter/node/devices").DimmablePlugInUnitDevice;
|
|
176
|
+
readonly TemperatureSensor: import("@matter/node/devices").TemperatureSensorDevice;
|
|
177
|
+
readonly HumiditySensor: import("@matter/node/devices").HumiditySensorDevice;
|
|
178
|
+
readonly LightSensor: import("@matter/node/devices").LightSensorDevice;
|
|
179
|
+
readonly MotionSensor: import("@matter/node/devices").OccupancySensorDevice;
|
|
180
|
+
readonly ContactSensor: import("@matter/node/devices").ContactSensorDevice;
|
|
181
|
+
readonly LeakSensor: import("@matter/node/devices").WaterLeakDetectorDevice;
|
|
182
|
+
readonly SmokeSensor: import("@matter/node/devices").SmokeCoAlarmDevice;
|
|
183
|
+
readonly Thermostat: import("@matter/node/devices").ThermostatDevice;
|
|
184
|
+
readonly Fan: import("@matter/node/devices").FanDevice;
|
|
185
|
+
readonly DoorLock: import("@matter/node/devices").DoorLockDevice;
|
|
186
|
+
readonly WindowCovering: import("@matter/node/devices").WindowCoveringDevice;
|
|
187
|
+
readonly GenericSwitch: import("@matter/node/devices").GenericSwitchDevice;
|
|
188
|
+
readonly Pump: import("@matter/node/devices").PumpDevice;
|
|
189
|
+
readonly RoomAirConditioner: import("@matter/node/devices").RoomAirConditionerDevice;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Get Matter clusters available for plugin use
|
|
193
|
+
*/
|
|
194
|
+
getClusters(): typeof clusters;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=matterServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matterServer.d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