@switchbot/homebridge-switchbot 2.0.0-beta.0 → 2.0.0-beta.10
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/.github/workflows/{label.yml → labeler.yml} +4 -6
- package/CHANGELOG.md +2 -1
- package/config.schema.json +17 -1
- package/dist/device/bot.d.ts +0 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +14 -29
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -6
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +19 -19
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +0 -1
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/meter.d.ts +0 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +0 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/plug.d.ts +0 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +3 -8
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +16 -5
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +167 -10
- package/dist/device/striplight.js.map +1 -1
- package/dist/platform.d.ts +3 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +93 -79
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +9 -9
- package/src/device/bot.ts +14 -30
- package/src/device/colorbulb.ts +21 -25
- package/src/device/curtain.ts +0 -1
- package/src/device/meter.ts +0 -4
- package/src/device/meterplus.ts +0 -4
- package/src/device/plug.ts +3 -9
- package/src/device/striplight.ts +180 -15
- package/src/platform.ts +88 -73
- package/src/settings.ts +2 -0
- package/.github/labeler.yml +0 -13
package/src/device/striplight.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
6
6
|
import { SwitchBotPlatform } from '../platform';
|
|
7
7
|
import { debounceTime, skipWhile, tap } from 'rxjs/operators';
|
|
8
8
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
9
|
-
import { device, devicesConfig, switchbot, hs2rgb, rgb2hs, deviceStatus, HostDomain, DevicePath } from '../settings';
|
|
9
|
+
import { device, devicesConfig, switchbot, hs2rgb, rgb2hs, deviceStatus, HostDomain, DevicePath, ad, serviceData } from '../settings';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Platform Accessory
|
|
@@ -19,13 +19,9 @@ export class StripLight {
|
|
|
19
19
|
|
|
20
20
|
// Characteristic Values
|
|
21
21
|
On!: CharacteristicValue;
|
|
22
|
-
OnCached!: CharacteristicValue;
|
|
23
22
|
Hue!: CharacteristicValue;
|
|
24
|
-
HueCached!: CharacteristicValue;
|
|
25
23
|
Saturation!: CharacteristicValue;
|
|
26
|
-
SaturationCached!: CharacteristicValue;
|
|
27
24
|
Brightness!: CharacteristicValue;
|
|
28
|
-
BrightnessCached!: CharacteristicValue;
|
|
29
25
|
|
|
30
26
|
// OpenAPI Others
|
|
31
27
|
power: deviceStatus['power'];
|
|
@@ -34,10 +30,18 @@ export class StripLight {
|
|
|
34
30
|
deviceStatus!: any; //deviceStatusResponse;
|
|
35
31
|
|
|
36
32
|
// BLE Others
|
|
33
|
+
connected?: boolean;
|
|
37
34
|
switchbot!: switchbot;
|
|
35
|
+
address!: ad['address'];
|
|
36
|
+
SwitchToOpenAPI?: boolean;
|
|
37
|
+
serviceData!: serviceData;
|
|
38
|
+
state: serviceData['state'];
|
|
39
|
+
delay: serviceData['delay'];
|
|
40
|
+
wifiRssi: serviceData['wifiRssi'];
|
|
38
41
|
|
|
39
42
|
// Config
|
|
40
43
|
set_minStep?: number;
|
|
44
|
+
scanDuration!: number;
|
|
41
45
|
deviceLogging!: string;
|
|
42
46
|
deviceRefreshRate!: number;
|
|
43
47
|
adaptiveLightingShift?: number;
|
|
@@ -57,6 +61,7 @@ export class StripLight {
|
|
|
57
61
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
58
62
|
// default placeholders
|
|
59
63
|
this.logs(device);
|
|
64
|
+
this.scan(device);
|
|
60
65
|
this.refreshRate(device);
|
|
61
66
|
this.config(device);
|
|
62
67
|
if (this.On === undefined) {
|
|
@@ -176,6 +181,27 @@ export class StripLight {
|
|
|
176
181
|
}
|
|
177
182
|
|
|
178
183
|
async parseStatus(): Promise<void> {
|
|
184
|
+
if (this.SwitchToOpenAPI || !this.device.ble) {
|
|
185
|
+
await this.openAPIparseStatus();
|
|
186
|
+
} else {
|
|
187
|
+
await this.BLEparseStatus();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async BLEparseStatus(): Promise<void> {
|
|
192
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} BLE parseStatus`);
|
|
193
|
+
// State
|
|
194
|
+
switch (this.state) {
|
|
195
|
+
case 'on':
|
|
196
|
+
this.On = true;
|
|
197
|
+
break;
|
|
198
|
+
default:
|
|
199
|
+
this.On = false;
|
|
200
|
+
}
|
|
201
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} On: ${this.On}`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async openAPIparseStatus(): Promise<void> {
|
|
179
205
|
switch (this.power) {
|
|
180
206
|
case 'on':
|
|
181
207
|
this.On = true;
|
|
@@ -211,6 +237,130 @@ export class StripLight {
|
|
|
211
237
|
}
|
|
212
238
|
|
|
213
239
|
async refreshStatus(): Promise<void> {
|
|
240
|
+
if (this.device.ble) {
|
|
241
|
+
await this.BLERefreshStatus();
|
|
242
|
+
} else {
|
|
243
|
+
await this.openAPIRefreshStatus();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async BLERefreshStatus(): Promise<void> {
|
|
248
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} BLE refreshStatus`);
|
|
249
|
+
const switchbot = await this.platform.connectBLE();
|
|
250
|
+
// Convert to BLE Address
|
|
251
|
+
this.device.bleMac = this.device
|
|
252
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
253
|
+
.join(':')
|
|
254
|
+
.toLowerCase();
|
|
255
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
256
|
+
this.getCustomBLEAddress(switchbot);
|
|
257
|
+
// Start to monitor advertisement packets
|
|
258
|
+
if (switchbot !== false) {
|
|
259
|
+
switchbot
|
|
260
|
+
.startScan({
|
|
261
|
+
model: 'r',
|
|
262
|
+
id: this.device.bleMac,
|
|
263
|
+
})
|
|
264
|
+
.then(() => {
|
|
265
|
+
// Set an event hander
|
|
266
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
267
|
+
this.address = ad.address;
|
|
268
|
+
if (this.deviceLogging.includes('debug')) {
|
|
269
|
+
this.infoLog(this.address);
|
|
270
|
+
this.infoLog(this.device.bleMac);
|
|
271
|
+
this.infoLog(`Strip Light: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
272
|
+
this.infoLog(`Strip Light: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
273
|
+
}
|
|
274
|
+
this.errorLog(`Strip Light: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
275
|
+
this.serviceData = ad.serviceData;
|
|
276
|
+
//this.state = ad.serviceData.state;
|
|
277
|
+
//this.delay = ad.serviceData.delay;
|
|
278
|
+
//this.timer = ad.serviceData.timer;
|
|
279
|
+
//this.syncUtcTime = ad.serviceData.syncUtcTime;
|
|
280
|
+
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
281
|
+
//this.overload = ad.serviceData.overload;
|
|
282
|
+
//this.currentPower = ad.serviceData.currentPower;
|
|
283
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
284
|
+
/*this.debugLog(
|
|
285
|
+
`Strip Light: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
286
|
+
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
287
|
+
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
288
|
+
);*/
|
|
289
|
+
|
|
290
|
+
if (this.serviceData) {
|
|
291
|
+
this.connected = true;
|
|
292
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
293
|
+
} else {
|
|
294
|
+
this.connected = false;
|
|
295
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
// Wait 2 seconds
|
|
299
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
300
|
+
})
|
|
301
|
+
.then(async () => {
|
|
302
|
+
// Stop to monitor
|
|
303
|
+
switchbot.stopScan();
|
|
304
|
+
if (this.connected) {
|
|
305
|
+
this.parseStatus();
|
|
306
|
+
this.updateHomeKitCharacteristics();
|
|
307
|
+
} else {
|
|
308
|
+
this.errorLog(`Strip Light: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
309
|
+
if (this.platform.config.credentials?.token) {
|
|
310
|
+
this.warnLog(`Strip Light: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
311
|
+
this.SwitchToOpenAPI = true;
|
|
312
|
+
await this.openAPIRefreshStatus();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
})
|
|
316
|
+
.catch(async (e: any) => {
|
|
317
|
+
this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
318
|
+
if (this.deviceLogging.includes('debug')) {
|
|
319
|
+
this.errorLog(
|
|
320
|
+
`Strip Light: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
if (this.platform.config.credentials?.token) {
|
|
324
|
+
this.warnLog(`Strip Light: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
325
|
+
this.SwitchToOpenAPI = true;
|
|
326
|
+
await this.openAPIRefreshStatus();
|
|
327
|
+
}
|
|
328
|
+
this.apiError(e);
|
|
329
|
+
});
|
|
330
|
+
} else {
|
|
331
|
+
await this.BLEconnection(switchbot);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async getCustomBLEAddress(switchbot: any) {
|
|
336
|
+
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
337
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
|
338
|
+
(async () => {
|
|
339
|
+
// Start to monitor advertisement packets
|
|
340
|
+
await switchbot.startScan({
|
|
341
|
+
model: 'r',
|
|
342
|
+
});
|
|
343
|
+
// Set an event handler
|
|
344
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
345
|
+
this.warnLog(`Strip Light: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
346
|
+
};
|
|
347
|
+
await switchbot.wait(10000);
|
|
348
|
+
// Stop to monitor
|
|
349
|
+
switchbot.stopScan();
|
|
350
|
+
})();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async BLEconnection(switchbot: any): Promise<void> {
|
|
355
|
+
this.errorLog(`Strip Light: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
356
|
+
if (this.platform.config.credentials?.token) {
|
|
357
|
+
this.warnLog(`Strip Light: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
358
|
+
this.SwitchToOpenAPI = true;
|
|
359
|
+
await this.openAPIRefreshStatus();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async openAPIRefreshStatus(): Promise<void> {
|
|
214
364
|
try {
|
|
215
365
|
const t = Date.now();
|
|
216
366
|
const nonce = 'requestID';
|
|
@@ -279,7 +429,7 @@ export class StripLight {
|
|
|
279
429
|
*/
|
|
280
430
|
async pushChanges(): Promise<void> {
|
|
281
431
|
try {
|
|
282
|
-
if (this.On !== this.
|
|
432
|
+
if (this.On !== this.accessory.context.On) {
|
|
283
433
|
// Make Push On request to the API
|
|
284
434
|
const t = Date.now();
|
|
285
435
|
const nonce = 'requestID';
|
|
@@ -329,8 +479,6 @@ export class StripLight {
|
|
|
329
479
|
req.write(body);
|
|
330
480
|
req.end();
|
|
331
481
|
this.debugLog(`Strip Light: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
332
|
-
this.OnCached = this.On;
|
|
333
|
-
this.accessory.context.On = this.OnCached;
|
|
334
482
|
}
|
|
335
483
|
// Push Brightness Update
|
|
336
484
|
if (this.On) {
|
|
@@ -354,7 +502,7 @@ export class StripLight {
|
|
|
354
502
|
|
|
355
503
|
async pushHueSaturationChanges(): Promise<void> {
|
|
356
504
|
try {
|
|
357
|
-
if (this.Hue !== this.
|
|
505
|
+
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
358
506
|
this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
359
507
|
this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
360
508
|
|
|
@@ -402,12 +550,11 @@ export class StripLight {
|
|
|
402
550
|
req.write(body);
|
|
403
551
|
req.end();
|
|
404
552
|
this.debugLog(`Strip Light: ${this.accessory.displayName} pushHueSaturationChanges: ${JSON.stringify(req)}`);
|
|
405
|
-
this.HueCached = this.Hue;
|
|
406
|
-
this.SaturationCached = this.Saturation;
|
|
407
553
|
} else {
|
|
408
554
|
this.debugLog(
|
|
409
555
|
`Strip Light: ${this.accessory.displayName} No Changes.` +
|
|
410
|
-
`Hue: ${this.Hue}, HueCached: ${this.
|
|
556
|
+
`Hue: ${this.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, `
|
|
557
|
+
+`SaturationCached: ${this.accessory.context.Saturation}`,
|
|
411
558
|
);
|
|
412
559
|
}
|
|
413
560
|
} catch (e: any) {
|
|
@@ -424,7 +571,7 @@ export class StripLight {
|
|
|
424
571
|
|
|
425
572
|
async pushBrightnessChanges(): Promise<void> {
|
|
426
573
|
try {
|
|
427
|
-
if (this.Brightness !== this.
|
|
574
|
+
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
428
575
|
// Make Push On request to the API
|
|
429
576
|
const t = Date.now();
|
|
430
577
|
const nonce = 'requestID';
|
|
@@ -467,10 +614,10 @@ export class StripLight {
|
|
|
467
614
|
req.write(body);
|
|
468
615
|
req.end();
|
|
469
616
|
this.debugLog(`Strip Light: ${this.accessory.displayName} pushBrightnessChanges: ${JSON.stringify(req)}`);
|
|
470
|
-
this.BrightnessCached = this.Brightness;
|
|
471
617
|
} else {
|
|
472
618
|
this.debugLog(
|
|
473
|
-
`Strip Light: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness},
|
|
619
|
+
`Strip Light: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, `
|
|
620
|
+
+`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
474
621
|
);
|
|
475
622
|
}
|
|
476
623
|
} catch (e: any) {
|
|
@@ -489,24 +636,28 @@ export class StripLight {
|
|
|
489
636
|
if (this.On === undefined) {
|
|
490
637
|
this.debugLog(`Strip Light: ${this.accessory.displayName} On: ${this.On}`);
|
|
491
638
|
} else {
|
|
639
|
+
this.accessory.context.On = this.On;
|
|
492
640
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
493
641
|
this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
494
642
|
}
|
|
495
643
|
if (this.Brightness === undefined) {
|
|
496
644
|
this.debugLog(`Strip Light: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
497
645
|
} else {
|
|
646
|
+
this.accessory.context.Brightness = this.Brightness;
|
|
498
647
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
499
648
|
this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
500
649
|
}
|
|
501
650
|
if (this.Hue === undefined) {
|
|
502
651
|
this.debugLog(`Strip Light: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
503
652
|
} else {
|
|
653
|
+
this.accessory.context.Hue = this.Hue;
|
|
504
654
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
505
655
|
this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
506
656
|
}
|
|
507
657
|
if (this.Saturation === undefined) {
|
|
508
658
|
this.debugLog(`Strip Light: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
509
659
|
} else {
|
|
660
|
+
this.accessory.context.Saturation = this.Saturation;
|
|
510
661
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
511
662
|
this.debugLog(`Strip Light: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
512
663
|
}
|
|
@@ -639,6 +790,20 @@ export class StripLight {
|
|
|
639
790
|
}
|
|
640
791
|
}
|
|
641
792
|
|
|
793
|
+
async scan(device: device & devicesConfig): Promise<void> {
|
|
794
|
+
if (device.scanDuration) {
|
|
795
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
796
|
+
if (device.ble) {
|
|
797
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
798
|
+
}
|
|
799
|
+
} else {
|
|
800
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
801
|
+
if (this.device.ble) {
|
|
802
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
642
807
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
643
808
|
if (this.platform.debugMode) {
|
|
644
809
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
package/src/platform.ts
CHANGED
|
@@ -188,34 +188,34 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
188
188
|
if (this.platformLogging?.includes('debug')) {
|
|
189
189
|
this.debugLog('Using Default Refresh Rate (2 minutes).');
|
|
190
190
|
}
|
|
191
|
+
}
|
|
191
192
|
|
|
192
|
-
|
|
193
|
+
if (!this.config.options.pushRate) {
|
|
193
194
|
// default 100 milliseconds
|
|
194
195
|
this.config.options!.pushRate! = 0.1;
|
|
195
196
|
if (this.platformLogging?.includes('debug')) {
|
|
196
197
|
this.warnLog('Using Default Push Rate.');
|
|
197
198
|
}
|
|
198
|
-
|
|
199
|
+
}
|
|
199
200
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
if (!this.config.credentials) {
|
|
202
|
+
if (this.platformLogging?.includes('debug')) {
|
|
203
|
+
this.debugLog('Missing Credentials');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (!this.config.credentials?.token) {
|
|
207
|
+
if (this.platformLogging?.includes('debug')) {
|
|
208
|
+
this.errorLog('Missing token');
|
|
209
|
+
this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
204
210
|
}
|
|
205
|
-
|
|
211
|
+
}
|
|
212
|
+
if (this.config.credentials?.token) {
|
|
213
|
+
if (!this.config.credentials?.secret) {
|
|
206
214
|
if (this.platformLogging?.includes('debug')) {
|
|
207
|
-
this.errorLog('Missing
|
|
215
|
+
this.errorLog('Missing secret');
|
|
208
216
|
this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
209
217
|
}
|
|
210
|
-
|
|
211
|
-
if (this.config.credentials?.token) {
|
|
212
|
-
if (!this.config.credentials?.secret) {
|
|
213
|
-
if (this.platformLogging?.includes('debug')) {
|
|
214
|
-
this.errorLog('Missing secret');
|
|
215
|
-
this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
216
|
-
}
|
|
217
|
-
throw Error('Missing secret');
|
|
218
|
-
}
|
|
218
|
+
throw Error('Missing secret');
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
}
|
|
@@ -591,23 +591,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
591
591
|
}
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
-
private registerDevice(device: device & devicesConfig) {
|
|
595
|
-
if (!device.hide_device && device.enableCloudService && device.ble) {
|
|
596
|
-
this.registeringDevice = true;
|
|
597
|
-
this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`);
|
|
598
|
-
} else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && !device.enableCloudService) {
|
|
599
|
-
this.registeringDevice = true;
|
|
600
|
-
this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled`);
|
|
601
|
-
} else if (!device.hide_device && device.enableCloudService && !device.ble) {
|
|
602
|
-
this.registeringDevice = true;
|
|
603
|
-
this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
|
|
604
|
-
} else {
|
|
605
|
-
this.registeringDevice = false;
|
|
606
|
-
this.debugLog(`Device: ${device.deviceName} OpenAPI and BLE Are Not Enabled`);
|
|
607
|
-
}
|
|
608
|
-
return this.registeringDevice;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
594
|
private async createHumidifier(device: device & devicesConfig) {
|
|
612
595
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
613
596
|
|
|
@@ -656,8 +639,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
656
639
|
new Humidifier(this, accessory, device);
|
|
657
640
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
658
641
|
|
|
659
|
-
// link the accessory to your platform
|
|
660
|
-
this.
|
|
642
|
+
// publish device externally or link the accessory to your platform
|
|
643
|
+
this.externalOrPlatform(device, accessory);
|
|
661
644
|
this.accessories.push(accessory);
|
|
662
645
|
} else {
|
|
663
646
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -716,8 +699,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
716
699
|
new Bot(this, accessory, device);
|
|
717
700
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
718
701
|
|
|
719
|
-
// link the accessory to your platform
|
|
720
|
-
this.
|
|
702
|
+
// publish device externally or link the accessory to your platform
|
|
703
|
+
this.externalOrPlatform(device, accessory);
|
|
721
704
|
this.accessories.push(accessory);
|
|
722
705
|
} else {
|
|
723
706
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -771,8 +754,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
771
754
|
new Meter(this, accessory, device);
|
|
772
755
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
773
756
|
|
|
774
|
-
// link the accessory to your platform
|
|
775
|
-
this.
|
|
757
|
+
// publish device externally or link the accessory to your platform
|
|
758
|
+
this.externalOrPlatform(device, accessory);
|
|
776
759
|
this.accessories.push(accessory);
|
|
777
760
|
} else {
|
|
778
761
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -826,8 +809,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
826
809
|
new MeterPlus(this, accessory, device);
|
|
827
810
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
828
811
|
|
|
829
|
-
// link the accessory to your platform
|
|
830
|
-
this.
|
|
812
|
+
// publish device externally or link the accessory to your platform
|
|
813
|
+
this.externalOrPlatform(device, accessory);
|
|
831
814
|
this.accessories.push(accessory);
|
|
832
815
|
} else {
|
|
833
816
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -881,8 +864,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
881
864
|
new Motion(this, accessory, device);
|
|
882
865
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
883
866
|
|
|
884
|
-
// link the accessory to your platform
|
|
885
|
-
this.
|
|
867
|
+
// publish device externally or link the accessory to your platform
|
|
868
|
+
this.externalOrPlatform(device, accessory);
|
|
886
869
|
this.accessories.push(accessory);
|
|
887
870
|
} else {
|
|
888
871
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -936,8 +919,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
936
919
|
new Contact(this, accessory, device);
|
|
937
920
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
938
921
|
|
|
939
|
-
// link the accessory to your platform
|
|
940
|
-
this.
|
|
922
|
+
// publish device externally or link the accessory to your platform
|
|
923
|
+
this.externalOrPlatform(device, accessory);
|
|
941
924
|
this.accessories.push(accessory);
|
|
942
925
|
} else {
|
|
943
926
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -1002,8 +985,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1002
985
|
new Curtain(this, accessory, device);
|
|
1003
986
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1004
987
|
|
|
1005
|
-
// link the accessory to your platform
|
|
1006
|
-
this.
|
|
988
|
+
// publish device externally or link the accessory to your platform
|
|
989
|
+
this.externalOrPlatform(device, accessory);
|
|
1007
990
|
this.accessories.push(accessory);
|
|
1008
991
|
} else {
|
|
1009
992
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -1072,8 +1055,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1072
1055
|
new Plug(this, accessory, device);
|
|
1073
1056
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1074
1057
|
|
|
1075
|
-
// link the accessory to your platform
|
|
1076
|
-
this.
|
|
1058
|
+
// publish device externally or link the accessory to your platform
|
|
1059
|
+
this.externalOrPlatform(device, accessory);
|
|
1077
1060
|
this.accessories.push(accessory);
|
|
1078
1061
|
} else {
|
|
1079
1062
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -1127,8 +1110,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1127
1110
|
new Lock(this, accessory, device);
|
|
1128
1111
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1129
1112
|
|
|
1130
|
-
// link the accessory to your platform
|
|
1131
|
-
this.
|
|
1113
|
+
// publish device externally or link the accessory to your platform
|
|
1114
|
+
this.externalOrPlatform(device, accessory);
|
|
1132
1115
|
this.accessories.push(accessory);
|
|
1133
1116
|
} else {
|
|
1134
1117
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -1182,8 +1165,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1182
1165
|
new ColorBulb(this, accessory, device);
|
|
1183
1166
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1184
1167
|
|
|
1185
|
-
// link the accessory to your platform
|
|
1186
|
-
this.
|
|
1168
|
+
// publish device externally or link the accessory to your platform
|
|
1169
|
+
this.externalOrPlatform(device, accessory);
|
|
1187
1170
|
this.accessories.push(accessory);
|
|
1188
1171
|
} else {
|
|
1189
1172
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -1237,8 +1220,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1237
1220
|
new StripLight(this, accessory, device);
|
|
1238
1221
|
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1239
1222
|
|
|
1240
|
-
// link the accessory to your platform
|
|
1241
|
-
this.
|
|
1223
|
+
// publish device externally or link the accessory to your platform
|
|
1224
|
+
this.externalOrPlatform(device, accessory);
|
|
1242
1225
|
this.accessories.push(accessory);
|
|
1243
1226
|
} else {
|
|
1244
1227
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.deviceType} - ${device.deviceId}`);
|
|
@@ -1292,7 +1275,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1292
1275
|
* Only one TV can exist per bridge, to bypass this limitation, you should
|
|
1293
1276
|
* publish your TV as an external accessory.
|
|
1294
1277
|
*/
|
|
1295
|
-
this.
|
|
1278
|
+
this.externalAccessory(accessory);
|
|
1296
1279
|
this.accessories.push(accessory);
|
|
1297
1280
|
} else {
|
|
1298
1281
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
@@ -1347,8 +1330,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1347
1330
|
new Fan(this, accessory, device);
|
|
1348
1331
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1349
1332
|
|
|
1350
|
-
// link the accessory to your platform
|
|
1351
|
-
this.
|
|
1333
|
+
// publish device externally or link the accessory to your platform
|
|
1334
|
+
this.externalOrPlatform(device, accessory);
|
|
1352
1335
|
this.accessories.push(accessory);
|
|
1353
1336
|
} else {
|
|
1354
1337
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
@@ -1402,8 +1385,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1402
1385
|
new Light(this, accessory, device);
|
|
1403
1386
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1404
1387
|
|
|
1405
|
-
// link the accessory to your platform
|
|
1406
|
-
this.
|
|
1388
|
+
// publish device externally or link the accessory to your platform
|
|
1389
|
+
this.externalOrPlatform(device, accessory);
|
|
1407
1390
|
this.accessories.push(accessory);
|
|
1408
1391
|
} else {
|
|
1409
1392
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
@@ -1457,8 +1440,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1457
1440
|
new AirConditioner(this, accessory, device);
|
|
1458
1441
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1459
1442
|
|
|
1460
|
-
// link the accessory to your platform
|
|
1461
|
-
this.
|
|
1443
|
+
// publish device externally or link the accessory to your platform
|
|
1444
|
+
this.externalOrPlatform(device, accessory);
|
|
1462
1445
|
this.accessories.push(accessory);
|
|
1463
1446
|
} else {
|
|
1464
1447
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
@@ -1512,8 +1495,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1512
1495
|
new AirPurifier(this, accessory, device);
|
|
1513
1496
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1514
1497
|
|
|
1515
|
-
// link the accessory to your platform
|
|
1516
|
-
this.
|
|
1498
|
+
// publish device externally or link the accessory to your platform
|
|
1499
|
+
this.externalOrPlatform(device, accessory);
|
|
1517
1500
|
this.accessories.push(accessory);
|
|
1518
1501
|
} else {
|
|
1519
1502
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
@@ -1567,8 +1550,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1567
1550
|
new WaterHeater(this, accessory, device);
|
|
1568
1551
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1569
1552
|
|
|
1570
|
-
// link the accessory to your platform
|
|
1571
|
-
this.
|
|
1553
|
+
// publish device externally or link the accessory to your platform
|
|
1554
|
+
this.externalOrPlatform(device, accessory);
|
|
1572
1555
|
this.accessories.push(accessory);
|
|
1573
1556
|
} else {
|
|
1574
1557
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
@@ -1622,8 +1605,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1622
1605
|
new VacuumCleaner(this, accessory, device);
|
|
1623
1606
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1624
1607
|
|
|
1625
|
-
// link the accessory to your platform
|
|
1626
|
-
this.
|
|
1608
|
+
// publish device externally or link the accessory to your platform
|
|
1609
|
+
this.externalOrPlatform(device, accessory);
|
|
1627
1610
|
this.accessories.push(accessory);
|
|
1628
1611
|
} else {
|
|
1629
1612
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
@@ -1677,8 +1660,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1677
1660
|
new Camera(this, accessory, device);
|
|
1678
1661
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1679
1662
|
|
|
1680
|
-
// link the accessory to your platform
|
|
1681
|
-
this.
|
|
1663
|
+
// publish device externally or link the accessory to your platform
|
|
1664
|
+
this.externalOrPlatform(device, accessory);
|
|
1682
1665
|
this.accessories.push(accessory);
|
|
1683
1666
|
} else {
|
|
1684
1667
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
@@ -1732,14 +1715,46 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1732
1715
|
new Others(this, accessory, device);
|
|
1733
1716
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1734
1717
|
|
|
1735
|
-
// link the accessory to your platform
|
|
1736
|
-
this.
|
|
1718
|
+
// publish device externally or link the accessory to your platform
|
|
1719
|
+
this.externalOrPlatform(device, accessory);
|
|
1737
1720
|
this.accessories.push(accessory);
|
|
1738
1721
|
} else {
|
|
1739
1722
|
this.debugLog(`Unable to Register new device: ${device.deviceName} ${device.remoteType} - ${device.deviceId}`);
|
|
1740
1723
|
}
|
|
1741
1724
|
}
|
|
1742
1725
|
|
|
1726
|
+
private registerDevice(device: device & devicesConfig) {
|
|
1727
|
+
if (!device.hide_device && device.enableCloudService && device.ble) {
|
|
1728
|
+
this.registeringDevice = true;
|
|
1729
|
+
this.debugLog(`Device: ${device.deviceName} Both OpenAPI and BLE Connections Enabled`);
|
|
1730
|
+
} else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
|
|
1731
|
+
&& !device.enableCloudService) {
|
|
1732
|
+
this.registeringDevice = true;
|
|
1733
|
+
this.debugLog(`Device: ${device.deviceName} BLE Connection Enabled`);
|
|
1734
|
+
} else if (!device.hide_device && device.enableCloudService && !device.ble) {
|
|
1735
|
+
this.registeringDevice = true;
|
|
1736
|
+
this.debugLog(`Device: ${device.deviceName} OpenAPI Connection Enabled`);
|
|
1737
|
+
} else {
|
|
1738
|
+
this.registeringDevice = false;
|
|
1739
|
+
this.debugLog(`Device: ${device.deviceName} OpenAPI and BLE Are Not Enabled`);
|
|
1740
|
+
}
|
|
1741
|
+
return this.registeringDevice;
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
public async externalOrPlatform(device: device & devicesConfig, accessory: PlatformAccessory) {
|
|
1745
|
+
this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
1746
|
+
if (device.external) {
|
|
1747
|
+
this.warnLog(`${accessory.displayName} External Accessory Mode`);
|
|
1748
|
+
this.externalAccessory(accessory);
|
|
1749
|
+
} else {
|
|
1750
|
+
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
public async externalAccessory(accessory: PlatformAccessory) {
|
|
1755
|
+
this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1743
1758
|
public async connectionTypeNewAccessory(device: device & devicesConfig, accessory: PlatformAccessory) {
|
|
1744
1759
|
if (device.ble) {
|
|
1745
1760
|
accessory.context.connectionType = 'BLE';
|
package/src/settings.ts
CHANGED
|
@@ -44,6 +44,7 @@ export interface devicesConfig extends device {
|
|
|
44
44
|
configDeviceType: string;
|
|
45
45
|
configDeviceName?: string;
|
|
46
46
|
deviceId: string;
|
|
47
|
+
external?: boolean;
|
|
47
48
|
logging?: string;
|
|
48
49
|
refreshRate?: number;
|
|
49
50
|
firmware?: string;
|
|
@@ -123,6 +124,7 @@ export type lock = {
|
|
|
123
124
|
export interface irDevicesConfig extends irdevice {
|
|
124
125
|
configRemoteType?: string;
|
|
125
126
|
deviceId: string;
|
|
127
|
+
external?: boolean;
|
|
126
128
|
logging?: string;
|
|
127
129
|
irfan?: irfan;
|
|
128
130
|
irair?: irair;
|
package/.github/labeler.yml
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Add 'branding' to any file changes within 'switchbot' folder
|
|
2
|
-
branding: image/*
|
|
3
|
-
|
|
4
|
-
# Add 'enhancement' label to any change to index.js file
|
|
5
|
-
enhancement:
|
|
6
|
-
- src/*
|
|
7
|
-
- package.json
|
|
8
|
-
- pakcage-lock.json
|
|
9
|
-
- config.schema.json
|
|
10
|
-
|
|
11
|
-
# Add 'workflow' to any changes within 'workflow' folder or any subfolders
|
|
12
|
-
workflow:
|
|
13
|
-
- .github/workflows/*
|