homebridge 2.0.0-alpha.4 → 2.0.0-alpha.41
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 +210 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +140 -0
- package/dist/api.js.map +1 -0
- package/dist/bridgeService.d.ts +122 -0
- package/dist/bridgeService.d.ts.map +1 -0
- package/dist/bridgeService.js +396 -0
- package/dist/bridgeService.js.map +1 -0
- package/dist/childBridgeFork.d.ts +38 -0
- package/dist/childBridgeFork.d.ts.map +1 -0
- package/dist/childBridgeFork.js +241 -2
- package/dist/childBridgeFork.js.map +1 -7
- package/dist/childBridgeService.d.ts +204 -0
- package/dist/childBridgeService.d.ts.map +1 -0
- package/dist/childBridgeService.js +452 -0
- package/dist/childBridgeService.js.map +1 -0
- package/dist/childMatterBridgeFork.d.ts +108 -0
- package/dist/childMatterBridgeFork.d.ts.map +1 -0
- package/dist/childMatterBridgeFork.js +330 -0
- package/dist/childMatterBridgeFork.js.map +1 -0
- package/dist/childMatterBridgeService.d.ts +166 -0
- package/dist/childMatterBridgeService.d.ts.map +1 -0
- package/dist/childMatterBridgeService.js +623 -0
- package/dist/childMatterBridgeService.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +90 -2
- package/dist/cli.js.map +1 -7
- package/dist/externalPortService.d.ts +33 -0
- package/dist/externalPortService.d.ts.map +1 -0
- package/dist/externalPortService.js +59 -0
- package/dist/externalPortService.js.map +1 -0
- package/dist/index.d.ts +90 -1099
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -7
- package/dist/ipcService.d.ts +46 -0
- package/dist/ipcService.d.ts.map +1 -0
- package/dist/ipcService.js +62 -0
- package/dist/ipcService.js.map +1 -0
- package/dist/logger.d.ts +78 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +138 -0
- package/dist/logger.js.map +1 -0
- package/dist/matter/index.d.ts +13 -0
- package/dist/matter/index.d.ts.map +1 -0
- package/dist/matter/index.js +12 -0
- package/dist/matter/index.js.map +1 -0
- package/dist/matter/matterBridge.d.ts +64 -0
- package/dist/matter/matterBridge.d.ts.map +1 -0
- package/dist/matter/matterBridge.js +154 -0
- package/dist/matter/matterBridge.js.map +1 -0
- package/dist/matter/matterConfigValidator.d.ts +27 -0
- package/dist/matter/matterConfigValidator.d.ts.map +1 -0
- package/dist/matter/matterConfigValidator.js +162 -0
- package/dist/matter/matterConfigValidator.js.map +1 -0
- package/dist/matter/matterDevice.d.ts +107 -0
- package/dist/matter/matterDevice.d.ts.map +1 -0
- package/dist/matter/matterDevice.js +913 -0
- package/dist/matter/matterDevice.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 +113 -0
- package/dist/matter/matterErrorHandler.d.ts.map +1 -0
- package/dist/matter/matterErrorHandler.js +482 -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 +110 -0
- package/dist/matter/matterServer.d.ts.map +1 -0
- package/dist/matter/matterServer.js +584 -0
- package/dist/matter/matterServer.js.map +1 -0
- package/dist/matter/matterSharedTypes.d.ts +167 -0
- package/dist/matter/matterSharedTypes.d.ts.map +1 -0
- package/dist/matter/matterSharedTypes.js +55 -0
- package/dist/matter/matterSharedTypes.js.map +1 -0
- package/dist/matter/matterTypes.d.ts +35 -0
- package/dist/matter/matterTypes.d.ts.map +1 -0
- package/dist/matter/matterTypes.js +278 -0
- package/dist/matter/matterTypes.js.map +1 -0
- package/dist/matter/portAllocator.d.ts +85 -0
- package/dist/matter/portAllocator.d.ts.map +1 -0
- package/dist/matter/portAllocator.js +296 -0
- package/dist/matter/portAllocator.js.map +1 -0
- package/dist/platformAccessory.d.ts +56 -0
- package/dist/platformAccessory.d.ts.map +1 -0
- package/dist/platformAccessory.js +105 -0
- package/dist/platformAccessory.js.map +1 -0
- package/dist/plugin.d.ts +30 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +182 -0
- package/dist/plugin.js.map +1 -0
- package/dist/pluginManager.d.ts +77 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +375 -0
- package/dist/pluginManager.js.map +1 -0
- package/dist/server.d.ts +67 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +799 -0
- package/dist/server.js.map +1 -0
- package/dist/storageService.d.ts +13 -0
- package/dist/storageService.d.ts.map +1 -0
- package/dist/storageService.js +41 -0
- package/dist/storageService.js.map +1 -0
- package/dist/user.d.ts +13 -0
- package/dist/user.d.ts.map +1 -0
- package/dist/user.js +29 -0
- package/dist/user.js.map +1 -0
- package/dist/util/mac.d.ts +5 -0
- package/dist/util/mac.d.ts.map +1 -0
- package/dist/util/mac.js +14 -0
- package/dist/util/mac.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +16 -0
- package/dist/version.js.map +1 -0
- package/package.json +31 -34
- package/bin/homebridge +0 -19
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port Allocator for Matter Bridges
|
|
3
|
+
*
|
|
4
|
+
* Thread-safe port allocation with conflict prevention
|
|
5
|
+
* and automatic port discovery
|
|
6
|
+
*/
|
|
7
|
+
import * as net from 'node:net';
|
|
8
|
+
import { Logger } from '../logger.js';
|
|
9
|
+
const log = Logger.withPrefix('Matter');
|
|
10
|
+
/**
|
|
11
|
+
* Simple mutex implementation for synchronization
|
|
12
|
+
*/
|
|
13
|
+
class Mutex {
|
|
14
|
+
queue = [];
|
|
15
|
+
locked = false;
|
|
16
|
+
MAX_QUEUE_SIZE = 100; // Prevent unbounded growth
|
|
17
|
+
/**
|
|
18
|
+
* Acquire the lock
|
|
19
|
+
*/
|
|
20
|
+
async acquire() {
|
|
21
|
+
if (!this.locked) {
|
|
22
|
+
this.locked = true;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Prevent queue from growing unbounded
|
|
26
|
+
if (this.queue.length >= this.MAX_QUEUE_SIZE) {
|
|
27
|
+
throw new Error(`Port allocator queue exceeded maximum size (${this.MAX_QUEUE_SIZE})`);
|
|
28
|
+
}
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
this.queue.push(resolve);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Release the lock
|
|
35
|
+
*/
|
|
36
|
+
release() {
|
|
37
|
+
const next = this.queue.shift();
|
|
38
|
+
if (next) {
|
|
39
|
+
next();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.locked = false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Run a function exclusively with the lock
|
|
47
|
+
*/
|
|
48
|
+
async runExclusive(fn) {
|
|
49
|
+
await this.acquire();
|
|
50
|
+
try {
|
|
51
|
+
return await fn();
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
this.release();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Port allocator with thread-safe allocation and tracking
|
|
60
|
+
*/
|
|
61
|
+
export class PortAllocator {
|
|
62
|
+
static instance;
|
|
63
|
+
allocatedPorts = new Map();
|
|
64
|
+
reservedRanges = new Map();
|
|
65
|
+
mutex = new Mutex();
|
|
66
|
+
defaultMatterStart = 5540;
|
|
67
|
+
defaultMatterEnd = 5580;
|
|
68
|
+
defaultHAPStart = 51826;
|
|
69
|
+
defaultHAPEnd = 51926;
|
|
70
|
+
constructor() {
|
|
71
|
+
// Reserve default ranges
|
|
72
|
+
this.reservedRanges.set('matter', {
|
|
73
|
+
start: this.defaultMatterStart,
|
|
74
|
+
end: this.defaultMatterEnd,
|
|
75
|
+
});
|
|
76
|
+
this.reservedRanges.set('hap', {
|
|
77
|
+
start: this.defaultHAPStart,
|
|
78
|
+
end: this.defaultHAPEnd,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get singleton instance
|
|
83
|
+
*/
|
|
84
|
+
static getInstance() {
|
|
85
|
+
if (!PortAllocator.instance) {
|
|
86
|
+
PortAllocator.instance = new PortAllocator();
|
|
87
|
+
}
|
|
88
|
+
return PortAllocator.instance;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Allocate a port for Matter or HAP
|
|
92
|
+
*/
|
|
93
|
+
async allocatePort(type, identifier, preferredPort) {
|
|
94
|
+
return this.mutex.runExclusive(async () => {
|
|
95
|
+
// Try preferred port first
|
|
96
|
+
if (preferredPort) {
|
|
97
|
+
if (await this.isPortAvailable(preferredPort)) {
|
|
98
|
+
this.allocatedPorts.set(preferredPort, {
|
|
99
|
+
port: preferredPort,
|
|
100
|
+
type,
|
|
101
|
+
identifier,
|
|
102
|
+
allocated: new Date(),
|
|
103
|
+
});
|
|
104
|
+
log.info(`Allocated port ${preferredPort} for ${type} bridge: ${identifier}`);
|
|
105
|
+
return preferredPort;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
log.warn(`Preferred port ${preferredPort} is not available for ${identifier}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Find an available port in the appropriate range
|
|
112
|
+
const range = this.reservedRanges.get(type);
|
|
113
|
+
if (!range) {
|
|
114
|
+
throw new Error(`No port range defined for type: ${type}`);
|
|
115
|
+
}
|
|
116
|
+
for (let port = range.start; port <= range.end; port++) {
|
|
117
|
+
if (!this.allocatedPorts.has(port) && await this.isPortAvailable(port)) {
|
|
118
|
+
this.allocatedPorts.set(port, {
|
|
119
|
+
port,
|
|
120
|
+
type,
|
|
121
|
+
identifier,
|
|
122
|
+
allocated: new Date(),
|
|
123
|
+
});
|
|
124
|
+
log.info(`Allocated port ${port} for ${type} bridge: ${identifier}`);
|
|
125
|
+
return port;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// If no port in range is available, try to find any available port
|
|
129
|
+
const fallbackPort = await this.findAvailablePort();
|
|
130
|
+
this.allocatedPorts.set(fallbackPort, {
|
|
131
|
+
port: fallbackPort,
|
|
132
|
+
type,
|
|
133
|
+
identifier,
|
|
134
|
+
allocated: new Date(),
|
|
135
|
+
});
|
|
136
|
+
log.warn(`Allocated fallback port ${fallbackPort} for ${type} bridge: ${identifier}`);
|
|
137
|
+
return fallbackPort;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Release an allocated port
|
|
142
|
+
*/
|
|
143
|
+
async releasePort(port) {
|
|
144
|
+
return this.mutex.runExclusive(async () => {
|
|
145
|
+
const allocation = this.allocatedPorts.get(port);
|
|
146
|
+
if (allocation) {
|
|
147
|
+
this.allocatedPorts.delete(port);
|
|
148
|
+
log.debug(`Released port ${port} (was allocated to ${allocation.identifier})`);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Release all ports for an identifier
|
|
154
|
+
*/
|
|
155
|
+
async releasePorts(identifier) {
|
|
156
|
+
return this.mutex.runExclusive(async () => {
|
|
157
|
+
const portsToRelease = [];
|
|
158
|
+
for (const [port, allocation] of this.allocatedPorts) {
|
|
159
|
+
if (allocation.identifier === identifier) {
|
|
160
|
+
portsToRelease.push(port);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (const port of portsToRelease) {
|
|
164
|
+
this.allocatedPorts.delete(port);
|
|
165
|
+
log.debug(`Released port ${port} for identifier ${identifier}`);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check if a port is available
|
|
171
|
+
*/
|
|
172
|
+
async isPortAvailable(port) {
|
|
173
|
+
// Check if already allocated by us
|
|
174
|
+
if (this.allocatedPorts.has(port)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
// Check if port is actually available on the system
|
|
178
|
+
return new Promise((resolve) => {
|
|
179
|
+
const server = net.createServer();
|
|
180
|
+
server.once('error', (err) => {
|
|
181
|
+
if (err.code === 'EADDRINUSE') {
|
|
182
|
+
resolve(false);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
// Other errors, assume port is not available
|
|
186
|
+
resolve(false);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
server.once('listening', () => {
|
|
190
|
+
server.close(() => {
|
|
191
|
+
resolve(true);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
server.listen(port, '0.0.0.0');
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Find any available port
|
|
199
|
+
*/
|
|
200
|
+
async findAvailablePort() {
|
|
201
|
+
return new Promise((resolve, reject) => {
|
|
202
|
+
const server = net.createServer();
|
|
203
|
+
server.once('error', (err) => {
|
|
204
|
+
reject(err);
|
|
205
|
+
});
|
|
206
|
+
server.once('listening', () => {
|
|
207
|
+
const address = server.address();
|
|
208
|
+
if (address && typeof address === 'object') {
|
|
209
|
+
const port = address.port;
|
|
210
|
+
server.close(() => {
|
|
211
|
+
resolve(port);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
server.close();
|
|
216
|
+
reject(new Error('Could not determine port'));
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
// Listen on port 0 to get a random available port
|
|
220
|
+
server.listen(0, '0.0.0.0');
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get all allocated ports
|
|
225
|
+
*/
|
|
226
|
+
getAllocatedPorts() {
|
|
227
|
+
return new Map(this.allocatedPorts);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Check for port conflicts
|
|
231
|
+
*/
|
|
232
|
+
async checkForConflicts() {
|
|
233
|
+
const conflicts = [];
|
|
234
|
+
for (const [port, allocation] of this.allocatedPorts) {
|
|
235
|
+
const available = await this.isPortAvailable(port);
|
|
236
|
+
if (!available) {
|
|
237
|
+
conflicts.push({
|
|
238
|
+
port,
|
|
239
|
+
identifier: allocation.identifier,
|
|
240
|
+
available,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return conflicts;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Clear all allocations (use with caution)
|
|
248
|
+
*/
|
|
249
|
+
clearAllocations() {
|
|
250
|
+
this.allocatedPorts.clear();
|
|
251
|
+
log.warn('Cleared all port allocations');
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Set custom port range for a type
|
|
255
|
+
*/
|
|
256
|
+
setPortRange(type, start, end) {
|
|
257
|
+
if (start < 1024 || end > 65535 || start > end) {
|
|
258
|
+
throw new Error('Invalid port range');
|
|
259
|
+
}
|
|
260
|
+
this.reservedRanges.set(type, { start, end });
|
|
261
|
+
log.info(`Set ${type} port range to ${start}-${end}`);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Get statistics about port allocation
|
|
265
|
+
*/
|
|
266
|
+
getStats() {
|
|
267
|
+
let matterPorts = 0;
|
|
268
|
+
let hapPorts = 0;
|
|
269
|
+
let oldest;
|
|
270
|
+
let newest;
|
|
271
|
+
for (const allocation of this.allocatedPorts.values()) {
|
|
272
|
+
if (allocation.type === 'matter') {
|
|
273
|
+
matterPorts++;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
hapPorts++;
|
|
277
|
+
}
|
|
278
|
+
if (!oldest || allocation.allocated < oldest) {
|
|
279
|
+
oldest = allocation.allocated;
|
|
280
|
+
}
|
|
281
|
+
if (!newest || allocation.allocated > newest) {
|
|
282
|
+
newest = allocation.allocated;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
totalAllocated: this.allocatedPorts.size,
|
|
287
|
+
matterPorts,
|
|
288
|
+
hapPorts,
|
|
289
|
+
oldestAllocation: oldest,
|
|
290
|
+
newestAllocation: newest,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// Export singleton instance
|
|
295
|
+
export const portAllocator = PortAllocator.getInstance();
|
|
296
|
+
//# sourceMappingURL=portAllocator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portAllocator.js","sourceRoot":"","sources":["../../src/matter/portAllocator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;AAEvC;;GAEG;AACH,MAAM,KAAK;IACD,KAAK,GAAsB,EAAE,CAAA;IAC7B,MAAM,GAAG,KAAK,CAAA;IACL,cAAc,GAAG,GAAG,CAAA,CAAC,2BAA2B;IAEjE;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;YAClB,OAAM;QACR,CAAC;QAED,uCAAuC;QACvC,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,+CAA+C,IAAI,CAAC,cAAc,GAAG,CAAC,CAAA;QACxF,CAAC;QAED,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACnC,IAAI,C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AI,CAAC,MAAM,IAAI,UAAU,CAAC,SAAS,GAAG,MAAM,EAAE,CAAC;gBAC7C,MAAM,GAAG,UAAU,CAAC,SAAS,CAAA;YAC/B,CAAC;YACD,IAAI,CAAC,MAAM,IAAI,UAAU,CAAC,SAAS,GAAG,MAAM,EAAE,CAAC;gBAC7C,MAAM,GAAG,UAAU,CAAC,SAAS,CAAA;YAC/B,CAAC;QACH,CAAC;QAED,OAAO;YACL,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI;YACxC,WAAW;YACX,QAAQ;YACR,gBAAgB,EAAE,MAAM;YACxB,gBAAgB,EAAE,MAAM;SACzB,CAAA;IACH,CAAC;CACF;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Controller, ControllerConstructor, SerializedAccessory, Service, WithUUID } from 'hap-nodejs';
|
|
2
|
+
import type { ConstructorArgs } from 'hap-nodejs/dist/types.js';
|
|
3
|
+
import type { PlatformName, PluginIdentifier, PluginName } from './api.js';
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
5
|
+
import { Accessory, Categories } from 'hap-nodejs';
|
|
6
|
+
export type UnknownContext = Record<string, any>;
|
|
7
|
+
export interface SerializedPlatformAccessory<T extends UnknownContext = UnknownContext> extends SerializedAccessory {
|
|
8
|
+
plugin: PluginName;
|
|
9
|
+
platform: PlatformName;
|
|
10
|
+
context: T;
|
|
11
|
+
}
|
|
12
|
+
export declare const enum PlatformAccessoryEvent {
|
|
13
|
+
IDENTIFY = "identify"
|
|
14
|
+
}
|
|
15
|
+
export declare interface PlatformAccessory {
|
|
16
|
+
on: (event: 'identify', listener: () => void) => this;
|
|
17
|
+
emit: (event: 'identify') => boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare class PlatformAccessory<T extends UnknownContext = UnknownContext> extends EventEmitter {
|
|
20
|
+
private static injectedAccessory?;
|
|
21
|
+
_associatedPlugin?: PluginIdentifier;
|
|
22
|
+
_associatedPlatform?: PlatformName;
|
|
23
|
+
_associatedHAPAccessory: Accessory;
|
|
24
|
+
displayName: string;
|
|
25
|
+
UUID: string;
|
|
26
|
+
category: Categories;
|
|
27
|
+
services: Service[];
|
|
28
|
+
/**
|
|
29
|
+
* This is a way for Plugin developers to store custom data with their accessory
|
|
30
|
+
*/
|
|
31
|
+
context: T;
|
|
32
|
+
constructor(displayName: string, uuid: string, category?: Categories);
|
|
33
|
+
updateDisplayName(name: string): void;
|
|
34
|
+
addService(service: Service): Service;
|
|
35
|
+
addService<S extends typeof Service>(serviceConstructor: S, ...constructorArgs: ConstructorArgs<S>): Service;
|
|
36
|
+
removeService(service: Service): void;
|
|
37
|
+
getService<T extends WithUUID<typeof Service>>(name: string | T): Service | undefined;
|
|
38
|
+
getServiceById<T extends WithUUID<typeof Service>>(uuid: string | T, subType: string): Service | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Configures a new controller for the given accessory.
|
|
41
|
+
* See {@link https://developers.homebridge.io/HAP-NodeJS/classes/accessory.html#configurecontroller | Accessory.configureController}.
|
|
42
|
+
*
|
|
43
|
+
* @param controller
|
|
44
|
+
*/
|
|
45
|
+
configureController(controller: Controller | ControllerConstructor): void;
|
|
46
|
+
/**
|
|
47
|
+
* Removes a configured controller from the given accessory.
|
|
48
|
+
* See {@link https://developers.homebridge.io/HAP-NodeJS/classes/accessory.html#removecontroller | Accessory.removeController}.
|
|
49
|
+
*
|
|
50
|
+
* @param controller
|
|
51
|
+
*/
|
|
52
|
+
removeController(controller: Controller): void;
|
|
53
|
+
static serialize(accessory: PlatformAccessory): SerializedPlatformAccessory;
|
|
54
|
+
static deserialize(json: SerializedPlatformAccessory): PlatformAccessory;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=platformAccessory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platformAccessory.d.ts","sourceRoot":"","sources":["../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AAE,OAAO,EAAE,CAAK;IAGxB;;OAEG;IACI,OAAO,EAAE,CAAC,CAAU;gBAEf,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAU;IAuB7D,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAOrC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IACrC,UAAU,CAAC,CAAC,SAAS,OAAO,OAAO,EAAE,kBAAkB,EAAE,CAAC,EAAE,GAAG,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO;IAQ5G,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIrC,UAAU,CAAC,CAAC,SAAS,QAAQ,CAAC,OAAO,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,OAAO,GAAG,SAAS;IAIrF,cAAc,CAAC,CAAC,SAAS,QAAQ,CAAC,OAAO,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAIjH;;;;;OAKG;IACI,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,qBAAqB,GAAG,IAAI;IAIhF;;;;;OAKG;IACI,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAKrD,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,iBAAiB,GAAG,2BAA2B;IAU3E,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,2BAA2B,GAAG,iBAAiB;CAczE"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { Accessory } from 'hap-nodejs';
|
|
3
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
4
|
+
export var PlatformAccessoryEvent;
|
|
5
|
+
(function (PlatformAccessoryEvent) {
|
|
6
|
+
PlatformAccessoryEvent["IDENTIFY"] = "identify";
|
|
7
|
+
})(PlatformAccessoryEvent || (PlatformAccessoryEvent = {}));
|
|
8
|
+
// eslint-disable-next-line ts/no-unsafe-declaration-merging
|
|
9
|
+
export class PlatformAccessory extends EventEmitter {
|
|
10
|
+
// somewhat ugly way to inject custom Accessory object, while not changing the publicly exposed constructor signature
|
|
11
|
+
static injectedAccessory;
|
|
12
|
+
_associatedPlugin; // present as soon as it is registered
|
|
13
|
+
_associatedPlatform; // not present for external accessories
|
|
14
|
+
_associatedHAPAccessory;
|
|
15
|
+
// ---------------- HAP Accessory mirror ----------------
|
|
16
|
+
displayName;
|
|
17
|
+
UUID;
|
|
18
|
+
category;
|
|
19
|
+
services = [];
|
|
20
|
+
// ------------------------------------------------------
|
|
21
|
+
/**
|
|
22
|
+
* This is a way for Plugin developers to store custom data with their accessory
|
|
23
|
+
*/
|
|
24
|
+
context = {}; // providing something to store
|
|
25
|
+
constructor(displayName, uuid, category) {
|
|
26
|
+
super();
|
|
27
|
+
this._associatedHAPAccessory = PlatformAccessory.injectedAccessory
|
|
28
|
+
? PlatformAccessory.injectedAccessory
|
|
29
|
+
: new Accessory(displayName, uuid);
|
|
30
|
+
if (category) {
|
|
31
|
+
this._associatedHAPAccessory.category = category;
|
|
32
|
+
}
|
|
33
|
+
this.displayName = this._associatedHAPAccessory.displayName;
|
|
34
|
+
this.UUID = this._associatedHAPAccessory.UUID;
|
|
35
|
+
this.category = category || 1 /* Categories.OTHER */;
|
|
36
|
+
this.services = this._associatedHAPAccessory.services;
|
|
37
|
+
// forward identify event
|
|
38
|
+
this._associatedHAPAccessory.on("identify" /* AccessoryEventTypes.IDENTIFY */, (paired, callback) => {
|
|
39
|
+
// @ts-expect-error: empty callback for backwards compatibility
|
|
40
|
+
this.emit("identify" /* PlatformAccessoryEvent.IDENTIFY */, paired, () => { });
|
|
41
|
+
callback();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
updateDisplayName(name) {
|
|
45
|
+
if (name) {
|
|
46
|
+
this.displayName = name;
|
|
47
|
+
this._associatedHAPAccessory.displayName = name;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
addService(service, ...constructorArgs) {
|
|
51
|
+
// @ts-expect-error: while the HAP-NodeJS interface was refined, the underlying implementation
|
|
52
|
+
// still only operates on an any[] array. Therefore, do not require any additional checks here
|
|
53
|
+
// we force the parameter unpack with expecting a ts-error.
|
|
54
|
+
return this._associatedHAPAccessory.addService(service, ...constructorArgs);
|
|
55
|
+
}
|
|
56
|
+
removeService(service) {
|
|
57
|
+
this._associatedHAPAccessory.removeService(service);
|
|
58
|
+
}
|
|
59
|
+
getService(name) {
|
|
60
|
+
return this._associatedHAPAccessory.getService(name);
|
|
61
|
+
}
|
|
62
|
+
getServiceById(uuid, subType) {
|
|
63
|
+
return this._associatedHAPAccessory.getServiceById(uuid, subType);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Configures a new controller for the given accessory.
|
|
67
|
+
* See {@link https://developers.homebridge.io/HAP-NodeJS/classes/accessory.html#configurecontroller | Accessory.configureController}.
|
|
68
|
+
*
|
|
69
|
+
* @param controller
|
|
70
|
+
*/
|
|
71
|
+
configureController(controller) {
|
|
72
|
+
this._associatedHAPAccessory.configureController(controller);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Removes a configured controller from the given accessory.
|
|
76
|
+
* See {@link https://developers.homebridge.io/HAP-NodeJS/classes/accessory.html#removecontroller | Accessory.removeController}.
|
|
77
|
+
*
|
|
78
|
+
* @param controller
|
|
79
|
+
*/
|
|
80
|
+
removeController(controller) {
|
|
81
|
+
this._associatedHAPAccessory.removeController(controller);
|
|
82
|
+
}
|
|
83
|
+
// private
|
|
84
|
+
static serialize(accessory) {
|
|
85
|
+
accessory._associatedHAPAccessory.displayName = accessory.displayName;
|
|
86
|
+
return {
|
|
87
|
+
plugin: accessory._associatedPlugin,
|
|
88
|
+
platform: accessory._associatedPlatform,
|
|
89
|
+
context: accessory.context,
|
|
90
|
+
...Accessory.serialize(accessory._associatedHAPAccessory),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
static deserialize(json) {
|
|
94
|
+
const accessory = Accessory.deserialize(json);
|
|
95
|
+
PlatformAccessory.injectedAccessory = accessory;
|
|
96
|
+
const platformAccessory = new PlatformAccessory(accessory.displayName, accessory.UUID);
|
|
97
|
+
PlatformAccessory.injectedAccessory = undefined;
|
|
98
|
+
platformAccessory._associatedPlugin = json.plugin;
|
|
99
|
+
platformAccessory._associatedPlatform = json.platform;
|
|
100
|
+
platformAccessory.context = json.context;
|
|
101
|
+
platformAccessory.category = json.category;
|
|
102
|
+
return platformAccessory;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=platformAccessory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platformAccessory.js","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,SAAS,EAAmC,MAAM,YAAY,CAAA;AAUvE,gDAAgD;AAChD,MAAM,CAAN,IAAkB,sBAEjB;AAFD,WAAkB,sBAAsB;IACtC,+CAAqB,CAAA;AACvB,CAAC,EAFiB,sBAAsB,KAAtB,sBAAsB,QAEvC;AAQD,4DAA4D;AAC5D,MAAM,OAAO,iBAA6D,SAAQ,YAAY;IAC5F,qHAAqH;IAC7G,MAAM,CAAC,iBAAiB,CAAY;IAE5C,iBAAiB,CAAmB,CAAC,sCAAsC;IAC3E,mBAAmB,CAAe,CAAC,uCAAuC;IAC1E,uBAAuB,CAAW;IAElC,yDAAyD;IACzD,WAAW,CAAQ;IACnB,IAAI,CAAQ;IACZ,QAAQ,CAAY;IACpB,QAAQ,GAAc,EAAE,CAAA;IACxB,yDAAyD;IAEzD;;OAEG;IACI,OAAO,GAAM,EAAO,CAAA,CAAC,+BAA+B;IAE3D,YAAY,WAAmB,EAAE,IAAY,EAAE,QAAqB;QA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,mBAAmB,GAAG,IAAI,CAAC,QAAQ,CAAA;QACrD,iBAAiB,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QACxC,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;QAE1C,OAAO,iBAAiB,CAAA;IAC1B,CAAC;CACF"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AccessoryIdentifier, AccessoryName, AccessoryPluginConstructor, API, DynamicPlatformPlugin, PlatformIdentifier, PlatformName, PlatformPluginConstructor, PluginIdentifier, PluginName } from './api.js';
|
|
2
|
+
import type { PackageJSON } from './pluginManager.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a loaded Homebridge plugin.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Plugin {
|
|
7
|
+
private readonly pluginName;
|
|
8
|
+
private readonly scope?;
|
|
9
|
+
private readonly pluginPath;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
readonly version: string;
|
|
12
|
+
private readonly main;
|
|
13
|
+
private loadContext?;
|
|
14
|
+
private pluginInitializer?;
|
|
15
|
+
private readonly registeredAccessories;
|
|
16
|
+
private readonly registeredPlatforms;
|
|
17
|
+
private readonly activeDynamicPlatforms;
|
|
18
|
+
constructor(name: PluginName, path: string, packageJSON: PackageJSON, scope?: string);
|
|
19
|
+
getPluginIdentifier(): PluginIdentifier;
|
|
20
|
+
getPluginPath(): string;
|
|
21
|
+
registerAccessory(name: AccessoryName, constructor: AccessoryPluginConstructor): void;
|
|
22
|
+
registerPlatform(name: PlatformName, constructor: PlatformPluginConstructor): void;
|
|
23
|
+
getAccessoryConstructor(accessoryIdentifier: AccessoryIdentifier | AccessoryName): AccessoryPluginConstructor;
|
|
24
|
+
getPlatformConstructor(platformIdentifier: PlatformIdentifier | PlatformName): PlatformPluginConstructor;
|
|
25
|
+
assignDynamicPlatform(platformIdentifier: PlatformIdentifier | PlatformName, platformPlugin: DynamicPlatformPlugin): void;
|
|
26
|
+
getActiveDynamicPlatform(platformName: PlatformName): DynamicPlatformPlugin | undefined;
|
|
27
|
+
load(): Promise<void>;
|
|
28
|
+
initialize(api: API): void | Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EACb,0BAA0B,EAC1B,GAAG,EACH,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,yBAAyB,EACzB,gBAAgB,EAEhB,UAAU,EACX,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAerD;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IAC5B,QAAQ,UAAQ;IAGvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAQ;IAC7B,OAAO,CAAC,WAAW,CAAC,CAGnB;IAGD,OAAO,CAAC,iBAAiB,CAAC,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAA4D;IAClG,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA0D;IAC9F,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAwD;gBAEnF,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,MAAM;IA+C7E,mBAAmB,IAAI,gBAAgB;IAIvC,aAAa,IAAI,MAAM;IAIvB,iBAAiB,CAAC,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,0B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