@switchbot/homebridge-switchbot 2.2.0-beta.0 → 2.2.0-beta.2
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/CHANGELOG.md +1 -1
- package/config.schema.json +0 -2
- package/dist/device/bot.d.ts +1 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +13 -9
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +11 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +173 -23
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +6 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +23 -16
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +17 -11
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +3 -0
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +13 -9
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/meter.d.ts +6 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +17 -11
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +17 -11
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +21 -12
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +3 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +13 -9
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +3 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +13 -9
- package/dist/device/striplight.js.map +1 -1
- package/dist/settings.d.ts +7 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +4 -4
- package/src/device/bot.ts +13 -8
- package/src/device/colorbulb.ts +190 -25
- package/src/device/contact.ts +28 -16
- package/src/device/curtain.ts +18 -11
- package/src/device/humidifier.ts +13 -8
- package/src/device/meter.ts +20 -11
- package/src/device/meterplus.ts +20 -11
- package/src/device/motion.ts +26 -11
- package/src/device/plug.ts +13 -8
- package/src/device/striplight.ts +13 -8
- package/src/settings.ts +14 -2
package/src/device/colorbulb.ts
CHANGED
|
@@ -37,11 +37,15 @@ export class ColorBulb {
|
|
|
37
37
|
switchbot!: switchbot;
|
|
38
38
|
address!: ad['address'];
|
|
39
39
|
serviceData!: serviceData;
|
|
40
|
+
powerState: serviceData['power'];
|
|
40
41
|
state: serviceData['state'];
|
|
42
|
+
red: serviceData['red'];
|
|
43
|
+
green: serviceData['green'];
|
|
44
|
+
blue: serviceData['blue'];
|
|
41
45
|
delay: serviceData['delay'];
|
|
42
46
|
wifiRssi: serviceData['wifiRssi'];
|
|
43
47
|
brightnessBLE: serviceData['brightness'];
|
|
44
|
-
|
|
48
|
+
color_temperature: serviceData['color_temperature'];
|
|
45
49
|
preset: any;//serviceData['preset'];
|
|
46
50
|
color_mode: any;//serviceData['color_mode'];
|
|
47
51
|
speed: any;//serviceData['speed'];
|
|
@@ -221,9 +225,9 @@ export class ColorBulb {
|
|
|
221
225
|
async parseStatus(): Promise<void> {
|
|
222
226
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
223
227
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
224
|
-
} else
|
|
228
|
+
} else if (this.BLE) {
|
|
225
229
|
await this.BLEparseStatus();
|
|
226
|
-
} else
|
|
230
|
+
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
227
231
|
await this.openAPIparseStatus();
|
|
228
232
|
} else {
|
|
229
233
|
await this.offlineOff();
|
|
@@ -236,13 +240,44 @@ export class ColorBulb {
|
|
|
236
240
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
237
241
|
// State
|
|
238
242
|
switch (this.state) {
|
|
239
|
-
case
|
|
243
|
+
case true:
|
|
240
244
|
this.On = true;
|
|
241
245
|
break;
|
|
242
246
|
default:
|
|
243
247
|
this.On = false;
|
|
244
248
|
}
|
|
245
249
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
// Brightness
|
|
253
|
+
this.Brightness = Number(this.brightnessBLE);
|
|
254
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
255
|
+
|
|
256
|
+
// Color, Hue & Brightness
|
|
257
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${this.red}`);
|
|
258
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${this.green}`);
|
|
259
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.blue}`);
|
|
260
|
+
|
|
261
|
+
const [hue, saturation] = rgb2hs(Number(this.red), Number(this.green), Number(this.blue));
|
|
262
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
263
|
+
+ ` hs: ${superStringify(rgb2hs(Number(this.red), Number(this.green), Number(this.blue)))}`);
|
|
264
|
+
|
|
265
|
+
// Hue
|
|
266
|
+
this.Hue = hue;
|
|
267
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
268
|
+
|
|
269
|
+
// Saturation
|
|
270
|
+
this.Saturation = saturation;
|
|
271
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
272
|
+
|
|
273
|
+
// ColorTemperature
|
|
274
|
+
if (this.color_temperature) {
|
|
275
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE ColorTemperature: ${this.color_temperature}`);
|
|
276
|
+
this.ColorTemperature = this.color_temperature!;
|
|
277
|
+
|
|
278
|
+
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
279
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
280
|
+
}
|
|
246
281
|
}
|
|
247
282
|
|
|
248
283
|
async openAPIparseStatus() {
|
|
@@ -329,14 +364,18 @@ export class ColorBulb {
|
|
|
329
364
|
})
|
|
330
365
|
.then(() => {
|
|
331
366
|
// Set an event hander
|
|
332
|
-
switchbot.onadvertisement = (ad: any) => {
|
|
367
|
+
switchbot.onadvertisement = async (ad: any) => {
|
|
333
368
|
this.address = ad.address;
|
|
334
369
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
335
370
|
+ ` BLE Address Found: ${this.address}`);
|
|
336
371
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
337
372
|
this.serviceData = ad.serviceData;
|
|
373
|
+
this.powerState = ad.serviceData.power;
|
|
338
374
|
this.state = ad.serviceData.state;
|
|
339
|
-
this.
|
|
375
|
+
this.red = ad.serviceData.red;
|
|
376
|
+
this.green = ad.serviceData.green;
|
|
377
|
+
this.blue = ad.serviceData.blue;
|
|
378
|
+
this.color_temperature = ad.serviceData.color_temperature;
|
|
340
379
|
this.brightnessBLE = ad.serviceData.brightness;
|
|
341
380
|
this.delay = ad.serviceData.delay;
|
|
342
381
|
this.preset = ad.serviceData.preset;
|
|
@@ -353,6 +392,7 @@ export class ColorBulb {
|
|
|
353
392
|
if (this.serviceData) {
|
|
354
393
|
this.connected = true;
|
|
355
394
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
395
|
+
await this.stopScanning({ switchbot });
|
|
356
396
|
} else {
|
|
357
397
|
this.connected = false;
|
|
358
398
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
@@ -363,13 +403,7 @@ export class ColorBulb {
|
|
|
363
403
|
})
|
|
364
404
|
.then(async () => {
|
|
365
405
|
// Stop to monitor
|
|
366
|
-
|
|
367
|
-
if (this.connected) {
|
|
368
|
-
this.BLEparseStatus();
|
|
369
|
-
this.updateHomeKitCharacteristics();
|
|
370
|
-
} else {
|
|
371
|
-
await this.BLERefreshConnection(switchbot);
|
|
372
|
-
}
|
|
406
|
+
await this.stopScanning({ switchbot });
|
|
373
407
|
})
|
|
374
408
|
.catch(async (e: any) => {
|
|
375
409
|
this.apiError(e);
|
|
@@ -452,10 +486,9 @@ export class ColorBulb {
|
|
|
452
486
|
async pushChanges(): Promise<void> {
|
|
453
487
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
454
488
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
455
|
-
} else
|
|
456
|
-
/*if (this.BLE) {
|
|
489
|
+
} else/* if (this.BLE) {
|
|
457
490
|
await this.BLEpushChanges();
|
|
458
|
-
} else*/
|
|
491
|
+
} else*/if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
459
492
|
await this.openAPIpushChanges();
|
|
460
493
|
} else {
|
|
461
494
|
await this.offlineOff();
|
|
@@ -473,8 +506,132 @@ export class ColorBulb {
|
|
|
473
506
|
|
|
474
507
|
async BLEpushChanges(): Promise<void> {
|
|
475
508
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
476
|
-
if (this.On !== this.accessory.context.On) {
|
|
477
|
-
|
|
509
|
+
//if (this.On !== this.accessory.context.On) {
|
|
510
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
511
|
+
const switchbot = await this.platform.connectBLE();
|
|
512
|
+
// Convert to BLE Address
|
|
513
|
+
this.device.bleMac = this.device
|
|
514
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
515
|
+
.join(':')
|
|
516
|
+
.toLowerCase();
|
|
517
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
518
|
+
switchbot
|
|
519
|
+
.discover({
|
|
520
|
+
model: 'u',
|
|
521
|
+
id: this.device.bleMac,
|
|
522
|
+
})
|
|
523
|
+
.then((device_list: any) => {
|
|
524
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
525
|
+
return this.turnOnOff(device_list);
|
|
526
|
+
})
|
|
527
|
+
.then(() => {
|
|
528
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
529
|
+
this.On = false;
|
|
530
|
+
})
|
|
531
|
+
.catch(async (e: any) => {
|
|
532
|
+
this.apiError(e);
|
|
533
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
534
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
535
|
+
await this.BLEPushConnection();
|
|
536
|
+
});
|
|
537
|
+
// Push Brightness Update
|
|
538
|
+
if (this.On) {
|
|
539
|
+
await this.BLEpushBrightnessChanges();
|
|
540
|
+
}
|
|
541
|
+
// Push ColorTemperature Update
|
|
542
|
+
if (this.On) {
|
|
543
|
+
await this.BLEpushColorTemperatureChanges();
|
|
544
|
+
}
|
|
545
|
+
// Push Hue & Saturation Update
|
|
546
|
+
if (this.On) {
|
|
547
|
+
await this.BLEpushRGBChanges();
|
|
548
|
+
}
|
|
549
|
+
// } else {
|
|
550
|
+
// this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
551
|
+
// +`OnCached: ${this.accessory.context.On}`);
|
|
552
|
+
// }
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
async BLEpushBrightnessChanges(): Promise<void> {
|
|
556
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushBrightnessChanges`);
|
|
557
|
+
//if (this.Brightness !== this.accessory.context.Brightness) {
|
|
558
|
+
const switchbot = await this.platform.connectBLE();
|
|
559
|
+
// Convert to BLE Address
|
|
560
|
+
this.device.bleMac = this.device
|
|
561
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
562
|
+
.join(':')
|
|
563
|
+
.toLowerCase();
|
|
564
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
565
|
+
switchbot
|
|
566
|
+
.discover({
|
|
567
|
+
model: 'u',
|
|
568
|
+
id: this.device.bleMac,
|
|
569
|
+
})
|
|
570
|
+
.then((device_list: any) => {
|
|
571
|
+
this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.Brightness}`);
|
|
572
|
+
return device_list[0].setBrightness(this.Brightness);
|
|
573
|
+
})
|
|
574
|
+
.then(() => {
|
|
575
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
576
|
+
this.On = false;
|
|
577
|
+
})
|
|
578
|
+
.catch(async (e: any) => {
|
|
579
|
+
this.apiError(e);
|
|
580
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
|
|
581
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
582
|
+
await this.BLEPushConnection();
|
|
583
|
+
});
|
|
584
|
+
// } else {
|
|
585
|
+
// this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
|
|
586
|
+
// +`BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
587
|
+
//}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
async BLEpushColorTemperatureChanges(): Promise<void> {
|
|
591
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushColorTemperatureChanges`);
|
|
592
|
+
if (this.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
593
|
+
const switchbot = await this.platform.connectBLE();
|
|
594
|
+
// Convert to BLE Address
|
|
595
|
+
this.device.bleMac = this.device
|
|
596
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
597
|
+
.join(':')
|
|
598
|
+
.toLowerCase();
|
|
599
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
600
|
+
switchbot
|
|
601
|
+
.discover({
|
|
602
|
+
model: 'u',
|
|
603
|
+
id: this.device.bleMac,
|
|
604
|
+
})
|
|
605
|
+
.then((device_list: any) => {
|
|
606
|
+
this.infoLog(`${this.accessory.displayName} Target ColorTemperature: ${this.ColorTemperature}`);
|
|
607
|
+
return device_list[0].setColorTemperature(this.ColorTemperature);
|
|
608
|
+
})
|
|
609
|
+
.then(() => {
|
|
610
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
611
|
+
this.On = false;
|
|
612
|
+
})
|
|
613
|
+
.catch(async (e: any) => {
|
|
614
|
+
this.apiError(e);
|
|
615
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushColorTemperatureChanges with `
|
|
616
|
+
+ `${this.device.connectionType} Connection, Error Message: ${superStringify(e.message)}`);
|
|
617
|
+
await this.BLEPushConnection();
|
|
618
|
+
});
|
|
619
|
+
} else {
|
|
620
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushColorTemperatureChanges.` +
|
|
621
|
+
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
622
|
+
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
async BLEpushRGBChanges(): Promise<void> {
|
|
627
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushRGBChanges`);
|
|
628
|
+
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
629
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${superStringify(this.Hue)}`);
|
|
630
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${superStringify(this.Saturation)}`);
|
|
631
|
+
|
|
632
|
+
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
633
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${superStringify([red, green, blue])}`);
|
|
634
|
+
|
|
478
635
|
const switchbot = await this.platform.connectBLE();
|
|
479
636
|
// Convert to BLE Address
|
|
480
637
|
this.device.bleMac = this.device
|
|
@@ -488,8 +645,8 @@ export class ColorBulb {
|
|
|
488
645
|
id: this.device.bleMac,
|
|
489
646
|
})
|
|
490
647
|
.then((device_list: any) => {
|
|
491
|
-
this.infoLog(`${this.
|
|
492
|
-
return this.
|
|
648
|
+
this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
|
|
649
|
+
return device_list[0].setRGB(this.Brightness, red, green, blue);
|
|
493
650
|
})
|
|
494
651
|
.then(() => {
|
|
495
652
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
@@ -497,15 +654,13 @@ export class ColorBulb {
|
|
|
497
654
|
})
|
|
498
655
|
.catch(async (e: any) => {
|
|
499
656
|
this.apiError(e);
|
|
500
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed
|
|
657
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}`
|
|
501
658
|
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
502
659
|
await this.BLEPushConnection();
|
|
503
660
|
});
|
|
504
661
|
} else {
|
|
505
|
-
this.debugLog(
|
|
506
|
-
|
|
507
|
-
+`OnCached: ${this.accessory.context.On}`,
|
|
508
|
-
);
|
|
662
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, `
|
|
663
|
+
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
509
664
|
}
|
|
510
665
|
}
|
|
511
666
|
|
|
@@ -910,6 +1065,16 @@ export class ColorBulb {
|
|
|
910
1065
|
}
|
|
911
1066
|
}
|
|
912
1067
|
|
|
1068
|
+
async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
|
|
1069
|
+
switchbot.stopScan();
|
|
1070
|
+
if (this.connected) {
|
|
1071
|
+
this.BLEparseStatus();
|
|
1072
|
+
this.updateHomeKitCharacteristics();
|
|
1073
|
+
} else {
|
|
1074
|
+
await this.BLERefreshConnection(switchbot);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
|
|
913
1078
|
async getCustomBLEAddress(switchbot: any) {
|
|
914
1079
|
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
915
1080
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
package/src/device/contact.ts
CHANGED
|
@@ -42,7 +42,11 @@ export class Contact {
|
|
|
42
42
|
battery!: serviceData['battery'];
|
|
43
43
|
movement!: serviceData['movement'];
|
|
44
44
|
doorState!: serviceData['doorState'];
|
|
45
|
-
|
|
45
|
+
is_light!: any; //serviceData['lightLevel'];
|
|
46
|
+
tested!: any;
|
|
47
|
+
contact_open!: any;
|
|
48
|
+
contact_timeout!: any;
|
|
49
|
+
button_count!: any;
|
|
46
50
|
|
|
47
51
|
// Config
|
|
48
52
|
set_minLux!: number;
|
|
@@ -200,16 +204,15 @@ export class Contact {
|
|
|
200
204
|
if (!this.device.contact?.hide_lightsensor) {
|
|
201
205
|
this.set_minLux = this.minLux();
|
|
202
206
|
this.set_maxLux = this.maxLux();
|
|
203
|
-
switch (this.
|
|
204
|
-
case
|
|
205
|
-
case 0:
|
|
207
|
+
switch (this.is_light) {
|
|
208
|
+
case true:
|
|
206
209
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
207
210
|
break;
|
|
208
211
|
default:
|
|
209
212
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
210
213
|
}
|
|
211
214
|
this.debugLog(
|
|
212
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
215
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.is_light},` +
|
|
213
216
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
214
217
|
);
|
|
215
218
|
}
|
|
@@ -298,24 +301,29 @@ export class Contact {
|
|
|
298
301
|
})
|
|
299
302
|
.then(async () => {
|
|
300
303
|
// Set an event hander
|
|
301
|
-
switchbot.onadvertisement = (ad: any) => {
|
|
304
|
+
switchbot.onadvertisement = async (ad: any) => {
|
|
302
305
|
this.address = ad.address;
|
|
303
306
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
304
307
|
+ ` BLE Address Found: ${this.address}`);
|
|
305
308
|
this.serviceData = ad.serviceData;
|
|
306
309
|
this.movement = ad.serviceData.movement;
|
|
307
|
-
this.
|
|
308
|
-
this.lightLevel = ad.serviceData.lightLevel;
|
|
310
|
+
this.tested = ad.serviceData.tested;
|
|
309
311
|
this.battery = ad.serviceData.battery;
|
|
312
|
+
this.contact_open = ad.serviceData.contact_open;
|
|
313
|
+
this.contact_timeout = ad.serviceData.contact_timeout;
|
|
314
|
+
this.is_light = ad.serviceData.is_light;
|
|
315
|
+
this.button_count = ad.serviceData.button_count;
|
|
316
|
+
this.doorState = ad.serviceData.doorState;
|
|
310
317
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
311
318
|
this.debugLog(
|
|
312
319
|
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
|
|
313
|
-
`${ad.serviceData.doorState},
|
|
320
|
+
`${ad.serviceData.doorState}, is_light: ${ad.serviceData.is_light}, battery: ${ad.serviceData.battery}`,
|
|
314
321
|
);
|
|
315
322
|
|
|
316
323
|
if (this.serviceData) {
|
|
317
324
|
this.connected = true;
|
|
318
325
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
326
|
+
await this.stopScanning(switchbot);
|
|
319
327
|
} else {
|
|
320
328
|
this.connected = false;
|
|
321
329
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
@@ -326,13 +334,7 @@ export class Contact {
|
|
|
326
334
|
})
|
|
327
335
|
.then(async () => {
|
|
328
336
|
// Stop to monitor
|
|
329
|
-
|
|
330
|
-
if (this.connected) {
|
|
331
|
-
this.BLEparseStatus();
|
|
332
|
-
this.updateHomeKitCharacteristics();
|
|
333
|
-
} else {
|
|
334
|
-
await this.BLERefreshConnection(switchbot);
|
|
335
|
-
}
|
|
337
|
+
await this.stopScanning(switchbot);
|
|
336
338
|
})
|
|
337
339
|
.catch(async (e: any) => {
|
|
338
340
|
this.apiError(e);
|
|
@@ -448,6 +450,16 @@ export class Contact {
|
|
|
448
450
|
}
|
|
449
451
|
}
|
|
450
452
|
|
|
453
|
+
async stopScanning(switchbot: any) {
|
|
454
|
+
switchbot.stopScan();
|
|
455
|
+
if (this.connected) {
|
|
456
|
+
this.BLEparseStatus();
|
|
457
|
+
this.updateHomeKitCharacteristics();
|
|
458
|
+
} else {
|
|
459
|
+
await this.BLERefreshConnection(switchbot);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
451
463
|
async getCustomBLEAddress(switchbot: any) {
|
|
452
464
|
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
453
465
|
(async () => {
|
package/src/device/curtain.ts
CHANGED
|
@@ -42,6 +42,7 @@ export class Curtain {
|
|
|
42
42
|
calibration: serviceData['calibration'];
|
|
43
43
|
battery: serviceData['battery'];
|
|
44
44
|
position: serviceData['position'];
|
|
45
|
+
inMotion: serviceData['inMotion'];
|
|
45
46
|
lightLevel: serviceData['lightLevel'];
|
|
46
47
|
|
|
47
48
|
// Target
|
|
@@ -237,7 +238,7 @@ export class Curtain {
|
|
|
237
238
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
if (this.setNewTarget) {
|
|
241
|
+
if (this.setNewTarget && this.inMotion) {
|
|
241
242
|
await this.setMinMax();
|
|
242
243
|
if (this.TargetPosition > this.CurrentPosition) {
|
|
243
244
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
@@ -421,24 +422,26 @@ export class Curtain {
|
|
|
421
422
|
})
|
|
422
423
|
.then(() => {
|
|
423
424
|
// Set an event hander
|
|
424
|
-
switchbot.onadvertisement = (ad: any) => {
|
|
425
|
+
switchbot.onadvertisement = async (ad: any) => {
|
|
425
426
|
this.address = ad.address;
|
|
426
427
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
427
428
|
+ ` BLE Address Found: ${this.address}`);
|
|
428
429
|
this.serviceData = ad.serviceData;
|
|
429
430
|
this.calibration = ad.serviceData.calibration;
|
|
430
431
|
this.battery = ad.serviceData.battery;
|
|
432
|
+
this.inMotion = ad.serviceData.inMotion;
|
|
431
433
|
this.position = ad.serviceData.position;
|
|
432
434
|
this.lightLevel = ad.serviceData.lightLevel;
|
|
433
435
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
434
436
|
this.debugLog(
|
|
435
437
|
`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
436
|
-
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}
|
|
437
|
-
|
|
438
|
+
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}, ` +
|
|
439
|
+
`inMotion: ${ad.serviceData.inMotion}`);
|
|
438
440
|
|
|
439
441
|
if (this.serviceData) {
|
|
440
442
|
this.connected = true;
|
|
441
443
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
444
|
+
await this.stopScanning(switchbot);
|
|
442
445
|
} else {
|
|
443
446
|
this.connected = false;
|
|
444
447
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
@@ -449,13 +452,7 @@ export class Curtain {
|
|
|
449
452
|
})
|
|
450
453
|
.then(async () => {
|
|
451
454
|
// Stop to monitor
|
|
452
|
-
|
|
453
|
-
if (this.connected) {
|
|
454
|
-
this.BLEparseStatus();
|
|
455
|
-
this.updateHomeKitCharacteristics();
|
|
456
|
-
} else {
|
|
457
|
-
await this.BLERefreshConnection(switchbot);
|
|
458
|
-
}
|
|
455
|
+
await this.stopScanning(switchbot);
|
|
459
456
|
})
|
|
460
457
|
.catch(async (e: any) => {
|
|
461
458
|
this.apiError(e);
|
|
@@ -809,6 +806,16 @@ export class Curtain {
|
|
|
809
806
|
}
|
|
810
807
|
}
|
|
811
808
|
|
|
809
|
+
async stopScanning(switchbot: any) {
|
|
810
|
+
switchbot.stopScan();
|
|
811
|
+
if (this.connected) {
|
|
812
|
+
this.BLEparseStatus();
|
|
813
|
+
this.updateHomeKitCharacteristics();
|
|
814
|
+
} else {
|
|
815
|
+
await this.BLERefreshConnection(switchbot);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
812
819
|
async getCustomBLEAddress(switchbot: any) {
|
|
813
820
|
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
814
821
|
(async () => {
|
package/src/device/humidifier.ts
CHANGED
|
@@ -314,7 +314,7 @@ export class Humidifier {
|
|
|
314
314
|
})
|
|
315
315
|
.then(() => {
|
|
316
316
|
// Set an event hander
|
|
317
|
-
switchbot.onadvertisement = (ad: ad) => {
|
|
317
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
318
318
|
this.address = ad.address;
|
|
319
319
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
320
320
|
+ ` BLE Address Found: ${this.address}`);
|
|
@@ -331,6 +331,7 @@ export class Humidifier {
|
|
|
331
331
|
if (this.serviceData) {
|
|
332
332
|
this.connected = true;
|
|
333
333
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
334
|
+
await this.stopScanning(switchbot);
|
|
334
335
|
} else {
|
|
335
336
|
this.connected = false;
|
|
336
337
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
@@ -341,13 +342,7 @@ export class Humidifier {
|
|
|
341
342
|
})
|
|
342
343
|
.then(async () => {
|
|
343
344
|
// Stop to monitor
|
|
344
|
-
|
|
345
|
-
if (this.connected) {
|
|
346
|
-
this.BLEparseStatus();
|
|
347
|
-
this.updateHomeKitCharacteristics();
|
|
348
|
-
} else {
|
|
349
|
-
await this.BLERefreshConnection(switchbot);
|
|
350
|
-
}
|
|
345
|
+
await this.stopScanning(switchbot);
|
|
351
346
|
})
|
|
352
347
|
.catch(async (e: any) => {
|
|
353
348
|
this.apiError(e);
|
|
@@ -770,6 +765,16 @@ export class Humidifier {
|
|
|
770
765
|
}
|
|
771
766
|
}
|
|
772
767
|
|
|
768
|
+
async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
|
|
769
|
+
switchbot.stopScan();
|
|
770
|
+
if (this.connected) {
|
|
771
|
+
this.BLEparseStatus();
|
|
772
|
+
this.updateHomeKitCharacteristics();
|
|
773
|
+
} else {
|
|
774
|
+
await this.BLERefreshConnection(switchbot);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
773
778
|
async getCustomBLEAddress(switchbot: any) {
|
|
774
779
|
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
775
780
|
(async () => {
|
package/src/device/meter.ts
CHANGED
|
@@ -40,7 +40,9 @@ export class Meter {
|
|
|
40
40
|
switchbot!: switchbot;
|
|
41
41
|
serviceData!: serviceData;
|
|
42
42
|
address!: ad['address'];
|
|
43
|
-
temperature!:
|
|
43
|
+
temperature!: serviceData['temperature'];
|
|
44
|
+
celsius!: temperature['c'];
|
|
45
|
+
fahrenheit!: temperature['f'];
|
|
44
46
|
battery!: serviceData['battery'];
|
|
45
47
|
humidity!: serviceData['humidity'];
|
|
46
48
|
|
|
@@ -209,7 +211,7 @@ export class Meter {
|
|
|
209
211
|
|
|
210
212
|
// Current Temperature
|
|
211
213
|
if (!this.device.meter?.hide_temperature) {
|
|
212
|
-
this.
|
|
214
|
+
this.celsius < 0 ? 0 : this.celsius > 100 ? 100 : this.temperature;
|
|
213
215
|
this.CurrentTemperature = this.temperature;
|
|
214
216
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
215
217
|
}
|
|
@@ -266,7 +268,7 @@ export class Meter {
|
|
|
266
268
|
})
|
|
267
269
|
.then(() => {
|
|
268
270
|
// Set an event hander
|
|
269
|
-
switchbot.onadvertisement = (ad: ad) => {
|
|
271
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
270
272
|
this.address = ad.address;
|
|
271
273
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
272
274
|
+ ` BLE Address Found: ${this.address}`);
|
|
@@ -275,7 +277,9 @@ export class Meter {
|
|
|
275
277
|
this.humidity = ad.serviceData.humidity;
|
|
276
278
|
}
|
|
277
279
|
this.serviceData = ad.serviceData;
|
|
278
|
-
this.temperature = ad.serviceData.temperature
|
|
280
|
+
this.temperature = ad.serviceData.temperature;
|
|
281
|
+
this.celsius = ad.serviceData.temperature!.c;
|
|
282
|
+
this.fahrenheit = ad.serviceData.temperature!.f;
|
|
279
283
|
this.battery = ad.serviceData.battery;
|
|
280
284
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
281
285
|
this.debugLog(
|
|
@@ -287,6 +291,7 @@ export class Meter {
|
|
|
287
291
|
if (this.serviceData) {
|
|
288
292
|
this.connected = true;
|
|
289
293
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
294
|
+
await this.stopScanning(switchbot);
|
|
290
295
|
} else {
|
|
291
296
|
this.connected = false;
|
|
292
297
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
@@ -297,13 +302,7 @@ export class Meter {
|
|
|
297
302
|
})
|
|
298
303
|
.then(async () => {
|
|
299
304
|
// Stop to monitor
|
|
300
|
-
|
|
301
|
-
if (this.connected) {
|
|
302
|
-
this.BLEparseStatus();
|
|
303
|
-
this.updateHomeKitCharacteristics();
|
|
304
|
-
} else {
|
|
305
|
-
await this.BLERefreshConnection(switchbot);
|
|
306
|
-
}
|
|
305
|
+
await this.stopScanning(switchbot);
|
|
307
306
|
})
|
|
308
307
|
.catch(async (e: any) => {
|
|
309
308
|
this.apiError(e);
|
|
@@ -489,6 +488,16 @@ export class Meter {
|
|
|
489
488
|
: null;
|
|
490
489
|
}
|
|
491
490
|
|
|
491
|
+
async stopScanning({ switchbot }: { switchbot: any; }): Promise<void> {
|
|
492
|
+
switchbot.stopScan();
|
|
493
|
+
if (this.connected) {
|
|
494
|
+
this.BLEparseStatus();
|
|
495
|
+
this.updateHomeKitCharacteristics();
|
|
496
|
+
} else {
|
|
497
|
+
await this.BLERefreshConnection(switchbot);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
492
501
|
async getCustomBLEAddress(switchbot: any) {
|
|
493
502
|
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
494
503
|
(async () => {
|