@switchbot/homebridge-switchbot 5.0.0-beta.40 → 5.0.0-beta.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/dist/homebridge-ui/server.js +15 -3
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/test/apiRequestTracker.test.d.ts +2 -0
- package/dist/test/apiRequestTracker.test.d.ts.map +1 -0
- package/dist/test/apiRequestTracker.test.js +392 -0
- package/dist/test/apiRequestTracker.test.js.map +1 -0
- package/dist/test/homebridge-ui/server.test.d.ts +2 -0
- package/dist/test/homebridge-ui/server.test.d.ts.map +1 -0
- package/dist/test/homebridge-ui/server.test.js +445 -0
- package/dist/test/homebridge-ui/server.test.js.map +1 -0
- package/docs/variables/default.html +1 -1
- package/package.json +1 -1
- package/src/homebridge-ui/server.ts +16 -3
- package/src/test/apiRequestTracker.test.ts +417 -0
- package/src/test/homebridge-ui/server.test.ts +486 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
/**
|
|
6
|
+
* Test suite for the homebridge-ui server handler logic
|
|
7
|
+
*
|
|
8
|
+
* These tests validate the cached accessory file reading logic that powers
|
|
9
|
+
* the getCachedAccessories and getCachedMatterAccessories handlers.
|
|
10
|
+
*
|
|
11
|
+
* Note: These are integration tests that test the file system logic rather than
|
|
12
|
+
* the UI server infrastructure itself, since HomebridgePluginUiServer is designed
|
|
13
|
+
* to run as a standalone process with IPC communication.
|
|
14
|
+
*/
|
|
15
|
+
// Helper to create isolated test environment
|
|
16
|
+
function createTestEnvironment() {
|
|
17
|
+
const testId = Math.random().toString(36).substring(7);
|
|
18
|
+
const testDir = join(tmpdir(), `switchbot-ui-test-${testId}`);
|
|
19
|
+
const accessoriesDir = join(testDir, 'accessories');
|
|
20
|
+
// Create test directories
|
|
21
|
+
if (!existsSync(testDir)) {
|
|
22
|
+
mkdirSync(testDir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
if (!existsSync(accessoriesDir)) {
|
|
25
|
+
mkdirSync(accessoriesDir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
return { testDir, accessoriesDir };
|
|
28
|
+
}
|
|
29
|
+
// Cleanup helper
|
|
30
|
+
function cleanup(testDir) {
|
|
31
|
+
try {
|
|
32
|
+
if (existsSync(testDir)) {
|
|
33
|
+
const removeRecursive = (dir) => {
|
|
34
|
+
if (!existsSync(dir)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const files = readdirSync(dir);
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
const filePath = join(dir, file);
|
|
40
|
+
try {
|
|
41
|
+
const stat = statSync(filePath);
|
|
42
|
+
if (stat.isDirectory()) {
|
|
43
|
+
removeRecursive(filePath);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
unlinkSync(filePath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// ignore
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
rmdirSync(dir);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// ignore
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
removeRecursive(testDir);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// ignore
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Re-implementation of the getCachedAccessories handler logic for testing
|
|
69
|
+
* This mirrors the actual implementation in server.ts
|
|
70
|
+
*/
|
|
71
|
+
function getCachedAccessories(homebridgeStoragePath) {
|
|
72
|
+
try {
|
|
73
|
+
const pluginNames = ['@switchbot/homebridge-switchbot', 'homebridge-switchbot'];
|
|
74
|
+
const devicesToReturn = [];
|
|
75
|
+
const accFile = `${homebridgeStoragePath}/accessories/cachedAccessories`;
|
|
76
|
+
if (existsSync(accFile)) {
|
|
77
|
+
const cachedAccessories = JSON.parse(readFileSync(accFile, 'utf8'));
|
|
78
|
+
cachedAccessories.forEach((entry) => {
|
|
79
|
+
const pluginName = entry.plugin || entry?.accessory?.plugin || entry?.accessory?.pluginName;
|
|
80
|
+
const acc = entry.accessory ?? entry;
|
|
81
|
+
if (pluginNames.includes(pluginName)) {
|
|
82
|
+
devicesToReturn.push(acc);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return devicesToReturn;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Re-implementation of the getCachedMatterAccessories handler logic for testing
|
|
94
|
+
* This mirrors the actual implementation in server.ts
|
|
95
|
+
*/
|
|
96
|
+
function getCachedMatterAccessories(homebridgeStoragePath) {
|
|
97
|
+
try {
|
|
98
|
+
const pluginNames = ['@switchbot/homebridge-switchbot', 'homebridge-switchbot'];
|
|
99
|
+
const devicesToReturn = [];
|
|
100
|
+
const accFile = `${homebridgeStoragePath}/accessories/cachedAccessories`;
|
|
101
|
+
const matterFile = `${homebridgeStoragePath}/accessories/cachedMatterAccessories`;
|
|
102
|
+
const readAndCollect = (filePath) => {
|
|
103
|
+
if (!existsSync(filePath)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const parsed = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
108
|
+
parsed.forEach((entry) => {
|
|
109
|
+
const pluginName = entry.plugin || entry?.accessory?.plugin || entry?.accessory?.pluginName;
|
|
110
|
+
const acc = entry.accessory ?? entry;
|
|
111
|
+
if (pluginNames.includes(pluginName)) {
|
|
112
|
+
devicesToReturn.push(acc);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// ignore parse errors for a single file
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
readAndCollect(accFile);
|
|
121
|
+
readAndCollect(matterFile);
|
|
122
|
+
return devicesToReturn;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
describe('homebridge-ui server handler logic', () => {
|
|
129
|
+
describe('getCachedAccessories', () => {
|
|
130
|
+
it('should return empty array when no cached accessories file exists', () => {
|
|
131
|
+
const { testDir } = createTestEnvironment();
|
|
132
|
+
try {
|
|
133
|
+
const result = getCachedAccessories(testDir);
|
|
134
|
+
expect(result).toEqual([]);
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
cleanup(testDir);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
it('should return accessories with scoped plugin name', () => {
|
|
141
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
142
|
+
try {
|
|
143
|
+
const cachedAccessories = [
|
|
144
|
+
{
|
|
145
|
+
plugin: '@switchbot/homebridge-switchbot',
|
|
146
|
+
accessory: {
|
|
147
|
+
displayName: 'Test Bot',
|
|
148
|
+
UUID: 'test-uuid-1',
|
|
149
|
+
services: [],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
plugin: 'homebridge-other-plugin',
|
|
154
|
+
accessory: {
|
|
155
|
+
displayName: 'Other Device',
|
|
156
|
+
UUID: 'test-uuid-2',
|
|
157
|
+
services: [],
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
162
|
+
writeFileSync(accFile, JSON.stringify(cachedAccessories), 'utf8');
|
|
163
|
+
const result = getCachedAccessories(testDir);
|
|
164
|
+
expect(result).toHaveLength(1);
|
|
165
|
+
expect(result[0].displayName).toBe('Test Bot');
|
|
166
|
+
expect(result[0].UUID).toBe('test-uuid-1');
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
cleanup(testDir);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
it('should return accessories with unscoped plugin name', () => {
|
|
173
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
174
|
+
try {
|
|
175
|
+
const cachedAccessories = [
|
|
176
|
+
{
|
|
177
|
+
plugin: 'homebridge-switchbot',
|
|
178
|
+
accessory: {
|
|
179
|
+
displayName: 'Test Curtain',
|
|
180
|
+
UUID: 'test-uuid-3',
|
|
181
|
+
services: [],
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
186
|
+
writeFileSync(accFile, JSON.stringify(cachedAccessories), 'utf8');
|
|
187
|
+
const result = getCachedAccessories(testDir);
|
|
188
|
+
expect(result).toHaveLength(1);
|
|
189
|
+
expect(result[0].displayName).toBe('Test Curtain');
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
cleanup(testDir);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
it('should handle entries with plugin name in accessory.plugin', () => {
|
|
196
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
197
|
+
try {
|
|
198
|
+
const cachedAccessories = [
|
|
199
|
+
{
|
|
200
|
+
accessory: {
|
|
201
|
+
plugin: '@switchbot/homebridge-switchbot',
|
|
202
|
+
displayName: 'Test Contact Sensor',
|
|
203
|
+
UUID: 'test-uuid-4',
|
|
204
|
+
services: [],
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
];
|
|
208
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
209
|
+
writeFileSync(accFile, JSON.stringify(cachedAccessories), 'utf8');
|
|
210
|
+
const result = getCachedAccessories(testDir);
|
|
211
|
+
expect(result).toHaveLength(1);
|
|
212
|
+
expect(result[0].displayName).toBe('Test Contact Sensor');
|
|
213
|
+
}
|
|
214
|
+
finally {
|
|
215
|
+
cleanup(testDir);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
it('should handle entries with plugin name in accessory.pluginName', () => {
|
|
219
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
220
|
+
try {
|
|
221
|
+
const cachedAccessories = [
|
|
222
|
+
{
|
|
223
|
+
accessory: {
|
|
224
|
+
pluginName: '@switchbot/homebridge-switchbot',
|
|
225
|
+
displayName: 'Test Motion Sensor',
|
|
226
|
+
UUID: 'test-uuid-5',
|
|
227
|
+
services: [],
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
232
|
+
writeFileSync(accFile, JSON.stringify(cachedAccessories), 'utf8');
|
|
233
|
+
const result = getCachedAccessories(testDir);
|
|
234
|
+
expect(result).toHaveLength(1);
|
|
235
|
+
expect(result[0].displayName).toBe('Test Motion Sensor');
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
cleanup(testDir);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
it('should filter out accessories from other plugins', () => {
|
|
242
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
243
|
+
try {
|
|
244
|
+
const cachedAccessories = [
|
|
245
|
+
{
|
|
246
|
+
plugin: '@switchbot/homebridge-switchbot',
|
|
247
|
+
accessory: { displayName: 'SwitchBot Device 1', UUID: 'uuid-1', services: [] },
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
plugin: 'homebridge-other',
|
|
251
|
+
accessory: { displayName: 'Other Device', UUID: 'uuid-2', services: [] },
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
plugin: 'homebridge-switchbot',
|
|
255
|
+
accessory: { displayName: 'SwitchBot Device 2', UUID: 'uuid-3', services: [] },
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
plugin: 'homebridge-another',
|
|
259
|
+
accessory: { displayName: 'Another Device', UUID: 'uuid-4', services: [] },
|
|
260
|
+
},
|
|
261
|
+
];
|
|
262
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
263
|
+
writeFileSync(accFile, JSON.stringify(cachedAccessories), 'utf8');
|
|
264
|
+
const result = getCachedAccessories(testDir);
|
|
265
|
+
expect(result).toHaveLength(2);
|
|
266
|
+
expect(result[0].displayName).toBe('SwitchBot Device 1');
|
|
267
|
+
expect(result[1].displayName).toBe('SwitchBot Device 2');
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
cleanup(testDir);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
it('should return empty array on malformed JSON', () => {
|
|
274
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
275
|
+
try {
|
|
276
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
277
|
+
writeFileSync(accFile, '{ invalid json }', 'utf8');
|
|
278
|
+
const result = getCachedAccessories(testDir);
|
|
279
|
+
expect(result).toEqual([]);
|
|
280
|
+
}
|
|
281
|
+
finally {
|
|
282
|
+
cleanup(testDir);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
describe('getCachedMatterAccessories', () => {
|
|
287
|
+
it('should return empty array when no cached files exist', () => {
|
|
288
|
+
const { testDir } = createTestEnvironment();
|
|
289
|
+
try {
|
|
290
|
+
const result = getCachedMatterAccessories(testDir);
|
|
291
|
+
expect(result).toEqual([]);
|
|
292
|
+
}
|
|
293
|
+
finally {
|
|
294
|
+
cleanup(testDir);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
it('should read from cachedAccessories file', () => {
|
|
298
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
299
|
+
try {
|
|
300
|
+
const cachedAccessories = [
|
|
301
|
+
{
|
|
302
|
+
plugin: '@switchbot/homebridge-switchbot',
|
|
303
|
+
accessory: {
|
|
304
|
+
displayName: 'HAP Device',
|
|
305
|
+
UUID: 'hap-uuid-1',
|
|
306
|
+
services: [],
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
];
|
|
310
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
311
|
+
writeFileSync(accFile, JSON.stringify(cachedAccessories), 'utf8');
|
|
312
|
+
const result = getCachedMatterAccessories(testDir);
|
|
313
|
+
expect(result).toHaveLength(1);
|
|
314
|
+
expect(result[0].displayName).toBe('HAP Device');
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
cleanup(testDir);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
it('should read from cachedMatterAccessories file', () => {
|
|
321
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
322
|
+
try {
|
|
323
|
+
const matterAccessories = [
|
|
324
|
+
{
|
|
325
|
+
plugin: '@switchbot/homebridge-switchbot',
|
|
326
|
+
accessory: {
|
|
327
|
+
displayName: 'Matter Device',
|
|
328
|
+
UUID: 'matter-uuid-1',
|
|
329
|
+
services: [],
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
];
|
|
333
|
+
const matterFile = join(accessoriesDir, 'cachedMatterAccessories');
|
|
334
|
+
writeFileSync(matterFile, JSON.stringify(matterAccessories), 'utf8');
|
|
335
|
+
const result = getCachedMatterAccessories(testDir);
|
|
336
|
+
expect(result).toHaveLength(1);
|
|
337
|
+
expect(result[0].displayName).toBe('Matter Device');
|
|
338
|
+
}
|
|
339
|
+
finally {
|
|
340
|
+
cleanup(testDir);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
it('should combine accessories from both files', () => {
|
|
344
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
345
|
+
try {
|
|
346
|
+
const cachedAccessories = [
|
|
347
|
+
{
|
|
348
|
+
plugin: '@switchbot/homebridge-switchbot',
|
|
349
|
+
accessory: { displayName: 'HAP Device', UUID: 'hap-uuid', services: [] },
|
|
350
|
+
},
|
|
351
|
+
];
|
|
352
|
+
const matterAccessories = [
|
|
353
|
+
{
|
|
354
|
+
plugin: 'homebridge-switchbot',
|
|
355
|
+
accessory: { displayName: 'Matter Device', UUID: 'matter-uuid', services: [] },
|
|
356
|
+
},
|
|
357
|
+
];
|
|
358
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
359
|
+
const matterFile = join(accessoriesDir, 'cachedMatterAccessories');
|
|
360
|
+
writeFileSync(accFile, JSON.stringify(cachedAccessories), 'utf8');
|
|
361
|
+
writeFileSync(matterFile, JSON.stringify(matterAccessories), 'utf8');
|
|
362
|
+
const result = getCachedMatterAccessories(testDir);
|
|
363
|
+
expect(result).toHaveLength(2);
|
|
364
|
+
expect(result[0].displayName).toBe('HAP Device');
|
|
365
|
+
expect(result[1].displayName).toBe('Matter Device');
|
|
366
|
+
}
|
|
367
|
+
finally {
|
|
368
|
+
cleanup(testDir);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
it('should filter out accessories from other plugins across both files', () => {
|
|
372
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
373
|
+
try {
|
|
374
|
+
const cachedAccessories = [
|
|
375
|
+
{
|
|
376
|
+
plugin: '@switchbot/homebridge-switchbot',
|
|
377
|
+
accessory: { displayName: 'SwitchBot HAP 1', UUID: 'hap-1', services: [] },
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
plugin: 'homebridge-other',
|
|
381
|
+
accessory: { displayName: 'Other HAP', UUID: 'hap-2', services: [] },
|
|
382
|
+
},
|
|
383
|
+
];
|
|
384
|
+
const matterAccessories = [
|
|
385
|
+
{
|
|
386
|
+
plugin: 'homebridge-switchbot',
|
|
387
|
+
accessory: { displayName: 'SwitchBot Matter 1', UUID: 'matter-1', services: [] },
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
plugin: 'homebridge-another',
|
|
391
|
+
accessory: { displayName: 'Another Matter', UUID: 'matter-2', services: [] },
|
|
392
|
+
},
|
|
393
|
+
];
|
|
394
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
395
|
+
const matterFile = join(accessoriesDir, 'cachedMatterAccessories');
|
|
396
|
+
writeFileSync(accFile, JSON.stringify(cachedAccessories), 'utf8');
|
|
397
|
+
writeFileSync(matterFile, JSON.stringify(matterAccessories), 'utf8');
|
|
398
|
+
const result = getCachedMatterAccessories(testDir);
|
|
399
|
+
expect(result).toHaveLength(2);
|
|
400
|
+
expect(result[0].displayName).toBe('SwitchBot HAP 1');
|
|
401
|
+
expect(result[1].displayName).toBe('SwitchBot Matter 1');
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
cleanup(testDir);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
it('should handle malformed JSON in one file gracefully', () => {
|
|
408
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
409
|
+
try {
|
|
410
|
+
const matterAccessories = [
|
|
411
|
+
{
|
|
412
|
+
plugin: '@switchbot/homebridge-switchbot',
|
|
413
|
+
accessory: { displayName: 'Valid Matter', UUID: 'valid', services: [] },
|
|
414
|
+
},
|
|
415
|
+
];
|
|
416
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
417
|
+
const matterFile = join(accessoriesDir, 'cachedMatterAccessories');
|
|
418
|
+
writeFileSync(accFile, '{ invalid json }', 'utf8');
|
|
419
|
+
writeFileSync(matterFile, JSON.stringify(matterAccessories), 'utf8');
|
|
420
|
+
const result = getCachedMatterAccessories(testDir);
|
|
421
|
+
// Should still return the valid Matter accessory
|
|
422
|
+
expect(result).toHaveLength(1);
|
|
423
|
+
expect(result[0].displayName).toBe('Valid Matter');
|
|
424
|
+
}
|
|
425
|
+
finally {
|
|
426
|
+
cleanup(testDir);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
it('should return empty array if both files have malformed JSON', () => {
|
|
430
|
+
const { testDir, accessoriesDir } = createTestEnvironment();
|
|
431
|
+
try {
|
|
432
|
+
const accFile = join(accessoriesDir, 'cachedAccessories');
|
|
433
|
+
const matterFile = join(accessoriesDir, 'cachedMatterAccessories');
|
|
434
|
+
writeFileSync(accFile, '{ bad json', 'utf8');
|
|
435
|
+
writeFileSync(matterFile, 'also bad }', 'utf8');
|
|
436
|
+
const result = getCachedMatterAccessories(testDir);
|
|
437
|
+
expect(result).toEqual([]);
|
|
438
|
+
}
|
|
439
|
+
finally {
|
|
440
|
+
cleanup(testDir);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
//# sourceMappingURL=server.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.test.js","sourceRoot":"","sources":["../../../src/test/homebridge-ui/server.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC1H,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C;;;;;;;;;GASG;AAEH,6CAA6C;AAC7C,SAAS,qBAAqB;IAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACtD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,qBAAqB,MAAM,EAAE,CAAC,CAAA;IAC7D,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;IAEnD,0BAA0B;IAC1B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACzC,C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AmB,CAAC,CAAA;gBACzD,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,EAAE,yBAAyB,CAAC,CAAA;gBAClE,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,CAAA;gBAC5C,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,CAAA;gBAE/C,MAAM,MAAM,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAA;gBAElD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAC5B,CAAC;oBAAS,CAAC;gBACT,OAAO,CAAC,OAAO,CAAC,CAAA;YAClB,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>default | @switchbot/homebridge-switchbot</title><meta name="description" content="Documentation for @switchbot/homebridge-switchbot"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">@switchbot/homebridge-switchbot</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="" aria-current="page">default</a></li></ul><h1>Variable default</h1></div><div class="tsd-signature"><span class="tsd-kind-variable">default</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span></div><div class="tsd-type-declaration"><h4>Type Declaration</h4><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures"><li class="tsd-signature" id="__type"><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">void</span></li><li class="tsd-description"><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">api</span>: <span class="tsd-signature-type">API</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>default | @switchbot/homebridge-switchbot</title><meta name="description" content="Documentation for @switchbot/homebridge-switchbot"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">@switchbot/homebridge-switchbot</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="" aria-current="page">default</a></li></ul><h1>Variable default</h1></div><div class="tsd-signature"><span class="tsd-kind-variable">default</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span></div><div class="tsd-type-declaration"><h4>Type Declaration</h4><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures"><li class="tsd-signature" id="__type"><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">void</span></li><li class="tsd-description"><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">api</span>: <span class="tsd-signature-type">API</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/e68dc3a71ebe3406a869355a0921aa855b0fee73/src/index.ts#L13">index.ts:13</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">@switchbot/homebridge-switchbot</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@switchbot/homebridge-switchbot",
|
|
3
3
|
"displayName": "SwitchBot",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "5.0.0-beta.
|
|
5
|
+
"version": "5.0.0-beta.41",
|
|
6
6
|
"description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
|
|
7
7
|
"author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
|
|
8
8
|
"contributors": [
|
|
@@ -35,9 +35,11 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
35
35
|
})
|
|
36
36
|
}
|
|
37
37
|
// Return the array
|
|
38
|
+
console.warn(`[Homebridge UI] getCachedAccessories returning ${devicesToReturn.length} device(s)`)
|
|
38
39
|
return devicesToReturn
|
|
39
|
-
} catch {
|
|
40
|
+
} catch (e: any) {
|
|
40
41
|
// Just return an empty accessory list in case of any errors
|
|
42
|
+
console.error(`[Homebridge UI] getCachedAccessories error: ${e?.message ?? e}`)
|
|
41
43
|
return []
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -53,22 +55,31 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
53
55
|
const accFile = `${this.homebridgeStoragePath}/accessories/cachedAccessories`
|
|
54
56
|
const matterFile = `${this.homebridgeStoragePath}/accessories/cachedMatterAccessories`
|
|
55
57
|
|
|
58
|
+
console.warn(`[Homebridge UI] Checking for cached files:`)
|
|
59
|
+
console.warn(`[Homebridge UI] - cachedAccessories: ${fs.existsSync(accFile)}`)
|
|
60
|
+
console.warn(`[Homebridge UI] - cachedMatterAccessories: ${fs.existsSync(matterFile)}`)
|
|
61
|
+
|
|
56
62
|
const readAndCollect = (filePath: string) => {
|
|
57
63
|
if (!fs.existsSync(filePath)) {
|
|
58
64
|
return
|
|
59
65
|
}
|
|
60
66
|
try {
|
|
61
67
|
const parsed: any[] = JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
|
68
|
+
console.warn(`[Homebridge UI] - ${filePath}: found ${parsed.length} total entries`)
|
|
69
|
+
let matchCount = 0
|
|
62
70
|
parsed.forEach((entry: any) => {
|
|
63
71
|
// Entry shape varies between Homebridge versions; try common locations
|
|
64
72
|
const pluginName = entry.plugin || entry?.accessory?.plugin || entry?.accessory?.pluginName
|
|
65
73
|
const acc = entry.accessory ?? entry
|
|
66
74
|
if (pluginNames.includes(pluginName)) {
|
|
67
75
|
devicesToReturn.push(acc as never)
|
|
76
|
+
matchCount++
|
|
68
77
|
}
|
|
69
78
|
})
|
|
70
|
-
|
|
79
|
+
console.warn(`[Homebridge UI] - ${filePath}: matched ${matchCount} SwitchBot entries`)
|
|
80
|
+
} catch (e: any) {
|
|
71
81
|
// ignore parse errors for a single file
|
|
82
|
+
console.error(`[Homebridge UI] - ${filePath}: parse error - ${e?.message ?? e}`)
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
85
|
|
|
@@ -76,8 +87,10 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
76
87
|
readAndCollect(accFile)
|
|
77
88
|
readAndCollect(matterFile)
|
|
78
89
|
|
|
90
|
+
console.warn(`[Homebridge UI] getCachedMatterAccessories returning ${devicesToReturn.length} device(s)`)
|
|
79
91
|
return devicesToReturn
|
|
80
|
-
} catch {
|
|
92
|
+
} catch (e: any) {
|
|
93
|
+
console.error(`[Homebridge UI] getCachedMatterAccessories error: ${e?.message ?? e}`)
|
|
81
94
|
return []
|
|
82
95
|
}
|
|
83
96
|
}
|