@switchbot/homebridge-switchbot 2.7.1 → 2.8.0-beta.1
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/npm-version-script.js +81 -0
- package/.prettierrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +10 -0
- package/config.schema.json +8 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +49 -59
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +44 -50
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +60 -63
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +68 -70
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -25
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -58
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +6 -0
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +168 -26
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +49 -56
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +18 -20
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +59 -61
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +40 -41
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +65 -68
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -20
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +20 -23
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +30 -33
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +48 -51
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +57 -61
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +29 -31
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +17 -20
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +27 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -26
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +19 -20
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +44 -47
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +17 -20
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +19 -20
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +44 -43
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +106 -72
- package/src/device/bot.ts +94 -58
- package/src/device/ceilinglight.ts +102 -68
- package/src/device/colorbulb.ts +134 -82
- package/src/device/contact.ts +54 -33
- package/src/device/curtain.ts +130 -101
- package/src/device/hub.ts +198 -35
- package/src/device/humidifier.ts +128 -80
- package/src/device/iosensor.ts +43 -27
- package/src/device/lightstrip.ts +108 -67
- package/src/device/lock.ts +73 -45
- package/src/device/meter.ts +94 -75
- package/src/device/meterplus.ts +43 -27
- package/src/device/motion.ts +50 -32
- package/src/device/plug.ts +62 -39
- package/src/device/robotvacuumcleaner.ts +78 -54
- package/src/irdevice/airconditioner.ts +111 -83
- package/src/irdevice/airpurifier.ts +55 -34
- package/src/irdevice/camera.ts +35 -23
- package/src/irdevice/fan.ts +47 -33
- package/src/irdevice/light.ts +43 -29
- package/src/irdevice/other.ts +39 -23
- package/src/irdevice/tv.ts +65 -51
- package/src/irdevice/vacuumcleaner.ts +35 -23
- package/src/irdevice/waterheater.ts +43 -27
- package/src/platform.ts +85 -55
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/device/lightstrip.ts
CHANGED
|
@@ -59,10 +59,14 @@ export class StripLight {
|
|
|
59
59
|
doStripLightUpdate!: Subject<void>;
|
|
60
60
|
|
|
61
61
|
// Connection
|
|
62
|
-
private readonly BLE =
|
|
63
|
-
private readonly OpenAPI =
|
|
64
|
-
|
|
65
|
-
constructor(
|
|
62
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
63
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
64
|
+
|
|
65
|
+
constructor(
|
|
66
|
+
private readonly platform: SwitchBotPlatform,
|
|
67
|
+
private accessory: PlatformAccessory,
|
|
68
|
+
public device: device & devicesConfig,
|
|
69
|
+
) {
|
|
66
70
|
// default placeholders
|
|
67
71
|
this.logs(device);
|
|
68
72
|
this.scan(device);
|
|
@@ -91,7 +95,6 @@ export class StripLight {
|
|
|
91
95
|
(this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
92
96
|
`${accessory.displayName} ${device.deviceType}`;
|
|
93
97
|
|
|
94
|
-
|
|
95
98
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
96
99
|
this.accessory.removeService(this.lightBulbService);
|
|
97
100
|
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
@@ -202,8 +205,10 @@ export class StripLight {
|
|
|
202
205
|
await this.pushChanges();
|
|
203
206
|
} catch (e: any) {
|
|
204
207
|
this.apiError(e);
|
|
205
|
-
this.errorLog(
|
|
206
|
-
|
|
208
|
+
this.errorLog(
|
|
209
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
210
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
211
|
+
);
|
|
207
212
|
}
|
|
208
213
|
this.stripLightUpdateInProgress = false;
|
|
209
214
|
});
|
|
@@ -221,8 +226,9 @@ export class StripLight {
|
|
|
221
226
|
await this.openAPIparseStatus();
|
|
222
227
|
} else {
|
|
223
228
|
await this.offlineOff();
|
|
224
|
-
this.debugWarnLog(
|
|
225
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
229
|
+
this.debugWarnLog(
|
|
230
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
231
|
+
);
|
|
226
232
|
}
|
|
227
233
|
}
|
|
228
234
|
|
|
@@ -263,8 +269,9 @@ export class StripLight {
|
|
|
263
269
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
264
270
|
|
|
265
271
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
266
|
-
this.debugLog(
|
|
267
|
-
+ ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}
|
|
272
|
+
this.debugLog(
|
|
273
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
274
|
+
);
|
|
268
275
|
|
|
269
276
|
// Hue
|
|
270
277
|
this.Hue = hue;
|
|
@@ -288,8 +295,10 @@ export class StripLight {
|
|
|
288
295
|
await this.openAPIRefreshStatus();
|
|
289
296
|
} else {
|
|
290
297
|
await this.offlineOff();
|
|
291
|
-
this.debugWarnLog(
|
|
292
|
-
|
|
298
|
+
this.debugWarnLog(
|
|
299
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
300
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
301
|
+
);
|
|
293
302
|
}
|
|
294
303
|
}
|
|
295
304
|
|
|
@@ -314,8 +323,10 @@ export class StripLight {
|
|
|
314
323
|
// Set an event hander
|
|
315
324
|
switchbot.onadvertisement = async (ad: any) => {
|
|
316
325
|
this.address = ad.address;
|
|
317
|
-
this.debugLog(
|
|
318
|
-
|
|
326
|
+
this.debugLog(
|
|
327
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
328
|
+
` BLE Address Found: ${this.address}`,
|
|
329
|
+
);
|
|
319
330
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
320
331
|
this.serviceData = ad.serviceData;
|
|
321
332
|
//this.state = ad.serviceData.state;
|
|
@@ -350,8 +361,10 @@ export class StripLight {
|
|
|
350
361
|
})
|
|
351
362
|
.catch(async (e: any) => {
|
|
352
363
|
this.apiError(e);
|
|
353
|
-
this.errorLog(
|
|
354
|
-
|
|
364
|
+
this.errorLog(
|
|
365
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
366
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
367
|
+
);
|
|
355
368
|
await this.BLERefreshConnection(switchbot);
|
|
356
369
|
});
|
|
357
370
|
} else {
|
|
@@ -369,10 +382,7 @@ export class StripLight {
|
|
|
369
382
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
370
383
|
this.statusCode(statusCode);
|
|
371
384
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
372
|
-
this.debugLog(
|
|
373
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
374
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
375
|
-
);
|
|
385
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
376
386
|
this.power = deviceStatus.body.power;
|
|
377
387
|
this.color = deviceStatus.body.color;
|
|
378
388
|
this.brightness = deviceStatus.body.brightness;
|
|
@@ -380,8 +390,10 @@ export class StripLight {
|
|
|
380
390
|
this.updateHomeKitCharacteristics();
|
|
381
391
|
} catch (e: any) {
|
|
382
392
|
this.apiError(e);
|
|
383
|
-
this.errorLog(
|
|
384
|
-
|
|
393
|
+
this.errorLog(
|
|
394
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
395
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
396
|
+
);
|
|
385
397
|
}
|
|
386
398
|
}
|
|
387
399
|
|
|
@@ -398,14 +410,15 @@ export class StripLight {
|
|
|
398
410
|
async pushChanges(): Promise<void> {
|
|
399
411
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
400
412
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
401
|
-
}
|
|
413
|
+
} /*if (this.BLE) {
|
|
402
414
|
await this.BLEpushChanges();
|
|
403
|
-
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
415
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
404
416
|
await this.openAPIpushChanges();
|
|
405
417
|
} else {
|
|
406
418
|
await this.offlineOff();
|
|
407
|
-
this.debugWarnLog(
|
|
408
|
-
|
|
419
|
+
this.debugWarnLog(
|
|
420
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
421
|
+
);
|
|
409
422
|
}
|
|
410
423
|
// Refresh the status from the API
|
|
411
424
|
interval(15000)
|
|
@@ -451,8 +464,10 @@ export class StripLight {
|
|
|
451
464
|
})
|
|
452
465
|
.catch(async (e: any) => {
|
|
453
466
|
this.apiError(e);
|
|
454
|
-
this.errorLog(
|
|
455
|
-
|
|
467
|
+
this.errorLog(
|
|
468
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
469
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
470
|
+
);
|
|
456
471
|
await this.BLEPushConnection();
|
|
457
472
|
});
|
|
458
473
|
// Push Brightness Update
|
|
@@ -464,8 +479,9 @@ export class StripLight {
|
|
|
464
479
|
await this.BLEpushRGBChanges();
|
|
465
480
|
}
|
|
466
481
|
} else {
|
|
467
|
-
this.debugLog(
|
|
468
|
-
+ `OnCached: ${this.accessory.context.On}
|
|
482
|
+
this.debugLog(
|
|
483
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, ` + `OnCached: ${this.accessory.context.On}`,
|
|
484
|
+
);
|
|
469
485
|
}
|
|
470
486
|
}
|
|
471
487
|
|
|
@@ -494,13 +510,18 @@ export class StripLight {
|
|
|
494
510
|
})
|
|
495
511
|
.catch(async (e: any) => {
|
|
496
512
|
this.apiError(e);
|
|
497
|
-
this.errorLog(
|
|
498
|
-
|
|
513
|
+
this.errorLog(
|
|
514
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}` +
|
|
515
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
516
|
+
);
|
|
499
517
|
await this.BLEPushConnection();
|
|
500
518
|
});
|
|
501
519
|
} else {
|
|
502
|
-
this.debugLog(
|
|
503
|
-
|
|
520
|
+
this.debugLog(
|
|
521
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` +
|
|
522
|
+
`Brightness: ${this.Brightness}, ` +
|
|
523
|
+
`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
524
|
+
);
|
|
504
525
|
}
|
|
505
526
|
}
|
|
506
527
|
|
|
@@ -526,7 +547,7 @@ export class StripLight {
|
|
|
526
547
|
id: this.device.bleMac,
|
|
527
548
|
})
|
|
528
549
|
.then(async (device_list: any) => {
|
|
529
|
-
this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
|
|
550
|
+
this.infoLog(`${this.accessory.displayName} Target RGB: ${(this.Brightness, red, green, blue)}`);
|
|
530
551
|
return await device_list[0].setRGB(this.Brightness, red, green, blue);
|
|
531
552
|
})
|
|
532
553
|
.then(() => {
|
|
@@ -535,13 +556,17 @@ export class StripLight {
|
|
|
535
556
|
})
|
|
536
557
|
.catch(async (e: any) => {
|
|
537
558
|
this.apiError(e);
|
|
538
|
-
this.errorLog(
|
|
539
|
-
|
|
559
|
+
this.errorLog(
|
|
560
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}` +
|
|
561
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
562
|
+
);
|
|
540
563
|
await this.BLEPushConnection();
|
|
541
564
|
});
|
|
542
565
|
} else {
|
|
543
|
-
this.debugLog(
|
|
544
|
-
|
|
566
|
+
this.debugLog(
|
|
567
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, ` +
|
|
568
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
|
|
569
|
+
);
|
|
545
570
|
}
|
|
546
571
|
}
|
|
547
572
|
|
|
@@ -555,9 +580,9 @@ export class StripLight {
|
|
|
555
580
|
command = 'turnOff';
|
|
556
581
|
}*/
|
|
557
582
|
const bodyChange = JSON.stringify({
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
583
|
+
command: `${command}`,
|
|
584
|
+
parameter: 'default',
|
|
585
|
+
commandType: 'command',
|
|
561
586
|
});
|
|
562
587
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
563
588
|
try {
|
|
@@ -572,13 +597,17 @@ export class StripLight {
|
|
|
572
597
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
573
598
|
} catch (e: any) {
|
|
574
599
|
this.apiError(e);
|
|
575
|
-
this.errorLog(
|
|
576
|
-
|
|
600
|
+
this.errorLog(
|
|
601
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
602
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
577
603
|
);
|
|
578
604
|
}
|
|
579
605
|
} else {
|
|
580
|
-
this.debugLog(
|
|
581
|
-
|
|
606
|
+
this.debugLog(
|
|
607
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
608
|
+
`On: ${this.On}, ` +
|
|
609
|
+
`OnCached: ${this.accessory.context.On}`,
|
|
610
|
+
);
|
|
582
611
|
}
|
|
583
612
|
// Push Hue & Saturation Update
|
|
584
613
|
if (this.On) {
|
|
@@ -599,9 +628,9 @@ export class StripLight {
|
|
|
599
628
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
600
629
|
// Make Push On request to the API
|
|
601
630
|
const bodyChange = JSON.stringify({
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
631
|
+
command: 'setColor',
|
|
632
|
+
parameter: `${red}:${green}:${blue}`,
|
|
633
|
+
commandType: 'command',
|
|
605
634
|
});
|
|
606
635
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
607
636
|
try {
|
|
@@ -616,13 +645,16 @@ export class StripLight {
|
|
|
616
645
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
617
646
|
} catch (e: any) {
|
|
618
647
|
this.apiError(e);
|
|
619
|
-
this.errorLog(
|
|
620
|
-
|
|
648
|
+
this.errorLog(
|
|
649
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}` +
|
|
650
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
621
651
|
);
|
|
622
652
|
}
|
|
623
653
|
} else {
|
|
624
|
-
this.debugLog(
|
|
625
|
-
|
|
654
|
+
this.debugLog(
|
|
655
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, ` +
|
|
656
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`,
|
|
657
|
+
);
|
|
626
658
|
}
|
|
627
659
|
}
|
|
628
660
|
|
|
@@ -630,9 +662,9 @@ export class StripLight {
|
|
|
630
662
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
631
663
|
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
632
664
|
const bodyChange = JSON.stringify({
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
665
|
+
command: 'setBrightness',
|
|
666
|
+
parameter: `${this.Brightness}`,
|
|
667
|
+
commandType: 'command',
|
|
636
668
|
});
|
|
637
669
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
638
670
|
try {
|
|
@@ -647,13 +679,17 @@ export class StripLight {
|
|
|
647
679
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
648
680
|
} catch (e: any) {
|
|
649
681
|
this.apiError(e);
|
|
650
|
-
this.errorLog(
|
|
651
|
-
|
|
682
|
+
this.errorLog(
|
|
683
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}` +
|
|
684
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
652
685
|
);
|
|
653
686
|
}
|
|
654
687
|
} else {
|
|
655
|
-
this.debugLog(
|
|
656
|
-
|
|
688
|
+
this.debugLog(
|
|
689
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges,` +
|
|
690
|
+
`Brightness: ${this.Brightness}, ` +
|
|
691
|
+
`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
692
|
+
);
|
|
657
693
|
}
|
|
658
694
|
}
|
|
659
695
|
|
|
@@ -905,8 +941,10 @@ export class StripLight {
|
|
|
905
941
|
this.offlineOff();
|
|
906
942
|
break;
|
|
907
943
|
case 171:
|
|
908
|
-
this.errorLog(
|
|
909
|
-
|
|
944
|
+
this.errorLog(
|
|
945
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
946
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
947
|
+
);
|
|
910
948
|
this.offlineOff();
|
|
911
949
|
break;
|
|
912
950
|
case 190:
|
|
@@ -922,8 +960,10 @@ export class StripLight {
|
|
|
922
960
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
923
961
|
break;
|
|
924
962
|
default:
|
|
925
|
-
this.infoLog(
|
|
926
|
-
|
|
963
|
+
this.infoLog(
|
|
964
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
965
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
966
|
+
);
|
|
927
967
|
}
|
|
928
968
|
}
|
|
929
969
|
|
|
@@ -943,8 +983,9 @@ export class StripLight {
|
|
|
943
983
|
|
|
944
984
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
945
985
|
let FirmwareRevision: string;
|
|
946
|
-
this.debugLog(
|
|
947
|
-
+ `accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
986
|
+
this.debugLog(
|
|
987
|
+
`${this.device.deviceType}: ${this.accessory.displayName} ` + `accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
988
|
+
);
|
|
948
989
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
949
990
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
950
991
|
if (accessory.context.FirmwareRevision) {
|
package/src/device/lock.ts
CHANGED
|
@@ -38,8 +38,8 @@ export class Lock {
|
|
|
38
38
|
doLockUpdate!: Subject<void>;
|
|
39
39
|
|
|
40
40
|
// Connection
|
|
41
|
-
private readonly BLE =
|
|
42
|
-
private readonly OpenAPI =
|
|
41
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
42
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
43
43
|
battery: any;
|
|
44
44
|
calibration: any;
|
|
45
45
|
status: any;
|
|
@@ -50,7 +50,11 @@ export class Lock {
|
|
|
50
50
|
unlocked_alarm: any;
|
|
51
51
|
auto_lock_paused: any;
|
|
52
52
|
|
|
53
|
-
constructor(
|
|
53
|
+
constructor(
|
|
54
|
+
private readonly platform: SwitchBotPlatform,
|
|
55
|
+
private accessory: PlatformAccessory,
|
|
56
|
+
public device: device & devicesConfig,
|
|
57
|
+
) {
|
|
54
58
|
// default placeholders
|
|
55
59
|
this.logs(device);
|
|
56
60
|
this.scan(device);
|
|
@@ -140,8 +144,10 @@ export class Lock {
|
|
|
140
144
|
await this.pushChanges();
|
|
141
145
|
} catch (e: any) {
|
|
142
146
|
this.apiError(e);
|
|
143
|
-
this.errorLog(
|
|
144
|
-
|
|
147
|
+
this.errorLog(
|
|
148
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
149
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
150
|
+
);
|
|
145
151
|
}
|
|
146
152
|
this.lockUpdateInProgress = false;
|
|
147
153
|
});
|
|
@@ -153,14 +159,15 @@ export class Lock {
|
|
|
153
159
|
async parseStatus(): Promise<void> {
|
|
154
160
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
155
161
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
156
|
-
}
|
|
162
|
+
} /*if (this.BLE) {
|
|
157
163
|
await this.BLEparseStatus();
|
|
158
|
-
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
164
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
159
165
|
await this.openAPIparseStatus();
|
|
160
166
|
} else {
|
|
161
167
|
await this.offlineOff();
|
|
162
|
-
this.debugWarnLog(
|
|
163
|
-
|
|
168
|
+
this.debugWarnLog(
|
|
169
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
170
|
+
);
|
|
164
171
|
}
|
|
165
172
|
}
|
|
166
173
|
|
|
@@ -218,8 +225,10 @@ export class Lock {
|
|
|
218
225
|
await this.openAPIRefreshStatus();
|
|
219
226
|
} else {
|
|
220
227
|
await this.offlineOff();
|
|
221
|
-
this.debugWarnLog(
|
|
222
|
-
|
|
228
|
+
this.debugWarnLog(
|
|
229
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
230
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
231
|
+
);
|
|
223
232
|
}
|
|
224
233
|
}
|
|
225
234
|
|
|
@@ -244,8 +253,10 @@ export class Lock {
|
|
|
244
253
|
// Set an event hander
|
|
245
254
|
switchbot.onadvertisement = async (ad: any) => {
|
|
246
255
|
this.address = ad.address;
|
|
247
|
-
this.debugLog(
|
|
248
|
-
|
|
256
|
+
this.debugLog(
|
|
257
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
258
|
+
` BLE Address Found: ${this.address}`,
|
|
259
|
+
);
|
|
249
260
|
this.serviceData = ad.serviceData;
|
|
250
261
|
this.battery = ad.serviceData.battery;
|
|
251
262
|
this.calibration = ad.serviceData.calibration;
|
|
@@ -260,7 +271,8 @@ export class Lock {
|
|
|
260
271
|
this.debugLog(
|
|
261
272
|
`${this.device.deviceType}: ${this.accessory.displayName} battery: ${ad.serviceData.battery}, ` +
|
|
262
273
|
`calibration: ${ad.serviceData.calibration}, status: ${ad.serviceData.status}, battery: ${ad.serviceData.battery}, ` +
|
|
263
|
-
`door_open: ${ad.serviceData.door_open}
|
|
274
|
+
`door_open: ${ad.serviceData.door_open}`,
|
|
275
|
+
);
|
|
264
276
|
|
|
265
277
|
if (this.serviceData) {
|
|
266
278
|
this.connected = true;
|
|
@@ -280,8 +292,10 @@ export class Lock {
|
|
|
280
292
|
})
|
|
281
293
|
.catch(async (e: any) => {
|
|
282
294
|
this.apiError(e);
|
|
283
|
-
this.errorLog(
|
|
284
|
-
|
|
295
|
+
this.errorLog(
|
|
296
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
297
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
298
|
+
);
|
|
285
299
|
await this.BLERefreshConnection(switchbot);
|
|
286
300
|
});
|
|
287
301
|
} else {
|
|
@@ -299,18 +313,17 @@ export class Lock {
|
|
|
299
313
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
300
314
|
this.statusCode(statusCode);
|
|
301
315
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
302
|
-
this.debugLog(
|
|
303
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
304
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
305
|
-
);
|
|
316
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
306
317
|
this.lockState = deviceStatus.body.lockState;
|
|
307
318
|
this.doorState = deviceStatus.body.doorState;
|
|
308
319
|
this.openAPIparseStatus();
|
|
309
320
|
this.updateHomeKitCharacteristics();
|
|
310
321
|
} catch (e: any) {
|
|
311
322
|
this.apiError(e);
|
|
312
|
-
this.errorLog(
|
|
313
|
-
|
|
323
|
+
this.errorLog(
|
|
324
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
325
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
326
|
+
);
|
|
314
327
|
}
|
|
315
328
|
}
|
|
316
329
|
|
|
@@ -323,14 +336,15 @@ export class Lock {
|
|
|
323
336
|
async pushChanges(): Promise<void> {
|
|
324
337
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
325
338
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
326
|
-
}
|
|
339
|
+
} /*if (this.BLE) {
|
|
327
340
|
await this.BLEpushChanges();
|
|
328
|
-
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
341
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
329
342
|
await this.openAPIpushChanges();
|
|
330
343
|
} else {
|
|
331
344
|
await this.offlineOff();
|
|
332
|
-
this.debugWarnLog(
|
|
333
|
-
|
|
345
|
+
this.debugWarnLog(
|
|
346
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
347
|
+
);
|
|
334
348
|
}
|
|
335
349
|
// Refresh the status from the API
|
|
336
350
|
interval(15000)
|
|
@@ -344,8 +358,10 @@ export class Lock {
|
|
|
344
358
|
async BLEpushChanges(): Promise<void> {
|
|
345
359
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
346
360
|
if (this.LockTargetState !== this.accessory.context.LockTargetState) {
|
|
347
|
-
this.debugLog(
|
|
348
|
-
|
|
361
|
+
this.debugLog(
|
|
362
|
+
`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges LockTargetState: ${this.LockTargetState}` +
|
|
363
|
+
` LockTargetStateCached: ${this.accessory.context.LockTargetState}`,
|
|
364
|
+
);
|
|
349
365
|
const switchbot = await this.platform.connectBLE();
|
|
350
366
|
// Convert to BLE Address
|
|
351
367
|
this.device.bleMac = this.device
|
|
@@ -364,14 +380,17 @@ export class Lock {
|
|
|
364
380
|
})
|
|
365
381
|
.catch(async (e: any) => {
|
|
366
382
|
this.apiError(e);
|
|
367
|
-
this.errorLog(
|
|
368
|
-
|
|
383
|
+
this.errorLog(
|
|
384
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
385
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
386
|
+
);
|
|
369
387
|
await this.BLEPushConnection();
|
|
370
388
|
});
|
|
371
389
|
} else {
|
|
372
390
|
this.debugLog(
|
|
373
|
-
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` +
|
|
374
|
-
|
|
391
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` +
|
|
392
|
+
`LockTargetState: ${this.LockTargetState}, ` +
|
|
393
|
+
`LockTargetStateCached: ${this.accessory.context.LockTargetState}`,
|
|
375
394
|
);
|
|
376
395
|
}
|
|
377
396
|
}
|
|
@@ -386,9 +405,9 @@ export class Lock {
|
|
|
386
405
|
command = 'unlock';
|
|
387
406
|
}
|
|
388
407
|
const bodyChange = JSON.stringify({
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
408
|
+
command: `${command}`,
|
|
409
|
+
parameter: 'default',
|
|
410
|
+
commandType: 'command',
|
|
392
411
|
});
|
|
393
412
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
394
413
|
try {
|
|
@@ -403,13 +422,17 @@ export class Lock {
|
|
|
403
422
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
404
423
|
} catch (e: any) {
|
|
405
424
|
this.apiError(e);
|
|
406
|
-
this.errorLog(
|
|
407
|
-
|
|
425
|
+
this.errorLog(
|
|
426
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
427
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
408
428
|
);
|
|
409
429
|
}
|
|
410
430
|
} else {
|
|
411
|
-
this.debugLog(
|
|
412
|
-
|
|
431
|
+
this.debugLog(
|
|
432
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
433
|
+
`LockTargetState: ${this.LockTargetState}, ` +
|
|
434
|
+
`LockTargetStateCached: ${this.accessory.context.LockTargetState}`,
|
|
435
|
+
);
|
|
413
436
|
}
|
|
414
437
|
}
|
|
415
438
|
|
|
@@ -526,8 +549,10 @@ export class Lock {
|
|
|
526
549
|
this.offlineOff();
|
|
527
550
|
break;
|
|
528
551
|
case 171:
|
|
529
|
-
this.errorLog(
|
|
530
|
-
|
|
552
|
+
this.errorLog(
|
|
553
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
554
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
555
|
+
);
|
|
531
556
|
this.offlineOff();
|
|
532
557
|
break;
|
|
533
558
|
case 190:
|
|
@@ -543,8 +568,10 @@ export class Lock {
|
|
|
543
568
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
544
569
|
break;
|
|
545
570
|
default:
|
|
546
|
-
this.infoLog(
|
|
547
|
-
|
|
571
|
+
this.infoLog(
|
|
572
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
573
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
574
|
+
);
|
|
548
575
|
}
|
|
549
576
|
}
|
|
550
577
|
|
|
@@ -565,8 +592,9 @@ export class Lock {
|
|
|
565
592
|
|
|
566
593
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
567
594
|
let FirmwareRevision: string;
|
|
568
|
-
this.debugLog(
|
|
569
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
595
|
+
this.debugLog(
|
|
596
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
597
|
+
);
|
|
570
598
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
571
599
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
572
600
|
if (accessory.context.FirmwareRevision) {
|