@switchbot/homebridge-switchbot 2.8.0-beta.9 → 2.8.1-beta.0
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 +4 -2
- package/README.md +1 -1
- package/dist/device/blindtilt.d.ts +21 -22
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +78 -77
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +11 -13
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +93 -75
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +40 -27
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +16 -23
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +55 -46
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +16 -22
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +82 -73
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +21 -24
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +76 -77
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +10 -8
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +50 -35
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +8 -10
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +34 -21
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +16 -20
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +42 -29
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +2 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +9 -8
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -19
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +71 -28
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -9
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +16 -20
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -10
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +16 -20
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +49 -47
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +9 -8
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +6 -8
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +20 -4
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +67 -86
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +0 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +0 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +64 -63
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +3 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +12 -12
- package/src/device/blindtilt.ts +103 -100
- package/src/device/bot.ts +105 -89
- package/src/device/ceilinglight.ts +56 -46
- package/src/device/colorbulb.ts +78 -76
- package/src/device/contact.ts +100 -94
- package/src/device/curtain.ts +101 -101
- package/src/device/hub.ts +61 -43
- package/src/device/humidifier.ts +42 -33
- package/src/device/iosensor.ts +59 -50
- package/src/device/lightstrip.ts +14 -17
- package/src/device/lock.ts +91 -50
- package/src/device/meter.ts +22 -30
- package/src/device/meterplus.ts +23 -32
- package/src/device/motion.ts +55 -53
- package/src/device/plug.ts +12 -15
- package/src/device/robotvacuumcleaner.ts +33 -16
- package/src/irdevice/airconditioner.ts +80 -94
- package/src/irdevice/airpurifier.ts +1 -1
- package/src/irdevice/camera.ts +1 -1
- package/src/irdevice/fan.ts +1 -4
- package/src/irdevice/light.ts +1 -1
- package/src/irdevice/other.ts +1 -1
- package/src/irdevice/tv.ts +1 -4
- package/src/irdevice/vacuumcleaner.ts +1 -1
- package/src/irdevice/waterheater.ts +1 -1
- package/src/platform.ts +73 -73
- package/src/settings.ts +6 -2
package/src/device/colorbulb.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { sleep } from '../utils';
|
|
|
5
5
|
import { interval, Subject } from 'rxjs';
|
|
6
6
|
import { SwitchBotPlatform } from '../platform';
|
|
7
7
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
8
|
-
import { device, devicesConfig, deviceStatus,
|
|
8
|
+
import { device, devicesConfig, deviceStatus, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
|
|
9
9
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -24,31 +24,26 @@ export class ColorBulb {
|
|
|
24
24
|
Brightness!: CharacteristicValue;
|
|
25
25
|
ColorTemperature?: CharacteristicValue;
|
|
26
26
|
|
|
27
|
-
// OpenAPI
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
deviceStatus
|
|
27
|
+
// OpenAPI Status
|
|
28
|
+
OpenAPI_On: deviceStatus['power'];
|
|
29
|
+
OpenAPI_RGB: deviceStatus['color'];
|
|
30
|
+
OpenAPI_Brightness: deviceStatus['brightness'];
|
|
31
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
32
|
+
OpenAPI_ColorTemperature?: deviceStatus['colorTemperature'];
|
|
33
|
+
|
|
34
|
+
// BLE Status
|
|
35
|
+
BLE_Red: serviceData['red'];
|
|
36
|
+
BLE_On: serviceData['state'];
|
|
37
|
+
BLE_Blue: serviceData['blue'];
|
|
38
|
+
BLE_Power: serviceData['power'];
|
|
39
|
+
BLE_Green: serviceData['green'];
|
|
40
|
+
BLE_Delay: serviceData['delay'];
|
|
41
|
+
BLE_WifiRssi: serviceData['wifiRssi'];
|
|
42
|
+
BLE_Brightness: serviceData['brightness'];
|
|
43
|
+
BLE_ColorTemperature: serviceData['color_temperature'];
|
|
33
44
|
|
|
34
45
|
// BLE Others
|
|
35
|
-
|
|
36
|
-
switchbot!: switchbot;
|
|
37
|
-
address!: ad['address'];
|
|
38
|
-
serviceData!: serviceData;
|
|
39
|
-
powerState: serviceData['power'];
|
|
40
|
-
state: serviceData['state'];
|
|
41
|
-
red: serviceData['red'];
|
|
42
|
-
green: serviceData['green'];
|
|
43
|
-
blue: serviceData['blue'];
|
|
44
|
-
delay: serviceData['delay'];
|
|
45
|
-
wifiRssi: serviceData['wifiRssi'];
|
|
46
|
-
brightnessBLE: serviceData['brightness'];
|
|
47
|
-
color_temperature: serviceData['color_temperature'];
|
|
48
|
-
preset: any; //serviceData['preset'];
|
|
49
|
-
color_mode: any; //serviceData['color_mode'];
|
|
50
|
-
speed: any; //serviceData['speed'];
|
|
51
|
-
loop_index: any; //serviceData['loop_index'];
|
|
46
|
+
BLE_IsConnected?: boolean;
|
|
52
47
|
|
|
53
48
|
// Config
|
|
54
49
|
set_minStep?: number;
|
|
@@ -249,7 +244,7 @@ export class ColorBulb {
|
|
|
249
244
|
async BLEparseStatus(): Promise<void> {
|
|
250
245
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
251
246
|
// State
|
|
252
|
-
switch (this.
|
|
247
|
+
switch (this.BLE_On) {
|
|
253
248
|
case true:
|
|
254
249
|
this.On = true;
|
|
255
250
|
break;
|
|
@@ -259,18 +254,18 @@ export class ColorBulb {
|
|
|
259
254
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
260
255
|
|
|
261
256
|
// Brightness
|
|
262
|
-
this.Brightness = Number(this.
|
|
257
|
+
this.Brightness = Number(this.BLE_Brightness);
|
|
263
258
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
264
259
|
|
|
265
260
|
// Color, Hue & Brightness
|
|
266
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${this.
|
|
267
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${this.
|
|
268
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.
|
|
261
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${this.BLE_Red}`);
|
|
262
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${this.BLE_Green}`);
|
|
263
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${this.BLE_Blue}`);
|
|
269
264
|
|
|
270
|
-
const [hue, saturation] = rgb2hs(Number(this.
|
|
265
|
+
const [hue, saturation] = rgb2hs(Number(this.BLE_Red), Number(this.BLE_Green), Number(this.BLE_Blue));
|
|
271
266
|
this.debugLog(
|
|
272
267
|
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
273
|
-
` hs: ${JSON.stringify(rgb2hs(Number(this.
|
|
268
|
+
` hs: ${JSON.stringify(rgb2hs(Number(this.BLE_Red), Number(this.BLE_Green), Number(this.BLE_Blue)))}`,
|
|
274
269
|
);
|
|
275
270
|
|
|
276
271
|
// Hue
|
|
@@ -282,9 +277,9 @@ export class ColorBulb {
|
|
|
282
277
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
283
278
|
|
|
284
279
|
// ColorTemperature
|
|
285
|
-
if (this.
|
|
286
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE ColorTemperature: ${this.
|
|
287
|
-
this.ColorTemperature = this.
|
|
280
|
+
if (this.BLE_ColorTemperature) {
|
|
281
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE ColorTemperature: ${this.BLE_ColorTemperature}`);
|
|
282
|
+
this.ColorTemperature = this.BLE_ColorTemperature!;
|
|
288
283
|
|
|
289
284
|
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
290
285
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
@@ -293,7 +288,7 @@ export class ColorBulb {
|
|
|
293
288
|
|
|
294
289
|
async openAPIparseStatus() {
|
|
295
290
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
296
|
-
switch (this.
|
|
291
|
+
switch (this.OpenAPI_On) {
|
|
297
292
|
case 'on':
|
|
298
293
|
this.On = true;
|
|
299
294
|
break;
|
|
@@ -303,13 +298,13 @@ export class ColorBulb {
|
|
|
303
298
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
304
299
|
|
|
305
300
|
// Brightness
|
|
306
|
-
this.Brightness = Number(this.
|
|
301
|
+
this.Brightness = Number(this.OpenAPI_Brightness);
|
|
307
302
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
308
303
|
|
|
309
304
|
// Color, Hue & Brightness
|
|
310
|
-
if (this.
|
|
311
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.
|
|
312
|
-
const [red, green, blue] = this.
|
|
305
|
+
if (this.OpenAPI_RGB) {
|
|
306
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.OpenAPI_RGB)}`);
|
|
307
|
+
const [red, green, blue] = this.OpenAPI_RGB!.split(':');
|
|
313
308
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
314
309
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
315
310
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
@@ -329,9 +324,9 @@ export class ColorBulb {
|
|
|
329
324
|
}
|
|
330
325
|
|
|
331
326
|
// ColorTemperature
|
|
332
|
-
if (!Number.isNaN(this.
|
|
333
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.
|
|
334
|
-
const mired = Math.round(1000000 / this.
|
|
327
|
+
if (!Number.isNaN(this.OpenAPI_ColorTemperature)) {
|
|
328
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.OpenAPI_ColorTemperature}`);
|
|
329
|
+
const mired = Math.round(1000000 / this.OpenAPI_ColorTemperature!);
|
|
335
330
|
|
|
336
331
|
this.ColorTemperature = Number(mired);
|
|
337
332
|
|
|
@@ -378,26 +373,20 @@ export class ColorBulb {
|
|
|
378
373
|
})
|
|
379
374
|
.then(async () => {
|
|
380
375
|
// Set an event hander
|
|
381
|
-
switchbot.onadvertisement = async (ad:
|
|
382
|
-
this.address = ad.address;
|
|
376
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
383
377
|
this.debugLog(
|
|
384
378
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
385
|
-
` BLE Address Found: ${
|
|
379
|
+
` BLE Address Found: ${ad.address}`,
|
|
386
380
|
);
|
|
387
381
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
388
|
-
this.
|
|
389
|
-
this.
|
|
390
|
-
this.
|
|
391
|
-
this.
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
394
|
-
this.
|
|
395
|
-
this.
|
|
396
|
-
this.delay = ad.serviceData.delay;
|
|
397
|
-
this.preset = ad.serviceData.preset;
|
|
398
|
-
this.color_mode = ad.serviceData.color_mode;
|
|
399
|
-
this.speed = ad.serviceData.speed;
|
|
400
|
-
this.loop_index = ad.serviceData.loop_index;
|
|
382
|
+
this.BLE_Power = ad.serviceData.power;
|
|
383
|
+
this.BLE_On = ad.serviceData.state;
|
|
384
|
+
this.BLE_Red = ad.serviceData.red;
|
|
385
|
+
this.BLE_Green = ad.serviceData.green;
|
|
386
|
+
this.BLE_Blue = ad.serviceData.blue;
|
|
387
|
+
this.BLE_ColorTemperature = ad.serviceData.color_temperature;
|
|
388
|
+
this.BLE_Brightness = ad.serviceData.brightness;
|
|
389
|
+
this.BLE_Delay = ad.serviceData.delay;
|
|
401
390
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
402
391
|
/*this.debugLog(
|
|
403
392
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
@@ -405,13 +394,13 @@ export class ColorBulb {
|
|
|
405
394
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
406
395
|
);*/
|
|
407
396
|
|
|
408
|
-
if (
|
|
409
|
-
this.
|
|
410
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
397
|
+
if (ad.serviceData) {
|
|
398
|
+
this.BLE_IsConnected = true;
|
|
399
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
411
400
|
await this.stopScanning(switchbot);
|
|
412
401
|
} else {
|
|
413
|
-
this.
|
|
414
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
402
|
+
this.BLE_IsConnected = false;
|
|
403
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
415
404
|
}
|
|
416
405
|
};
|
|
417
406
|
// Wait
|
|
@@ -440,15 +429,16 @@ export class ColorBulb {
|
|
|
440
429
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
441
430
|
headers: this.platform.generateHeaders(),
|
|
442
431
|
});
|
|
443
|
-
const deviceStatus = await body.json();
|
|
432
|
+
const deviceStatus: any = await body.json();
|
|
444
433
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
445
434
|
this.statusCode(statusCode);
|
|
446
435
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
447
436
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
448
|
-
this.
|
|
449
|
-
this.
|
|
450
|
-
this.
|
|
451
|
-
this.
|
|
437
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
438
|
+
this.OpenAPI_RGB = deviceStatus.body.color;
|
|
439
|
+
this.OpenAPI_Brightness = deviceStatus.body.brightness;
|
|
440
|
+
this.OpenAPI_ColorTemperature = deviceStatus.body.colorTemperature;
|
|
441
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
452
442
|
this.openAPIparseStatus();
|
|
453
443
|
this.updateHomeKitCharacteristics();
|
|
454
444
|
} catch (e: any) {
|
|
@@ -698,7 +688,7 @@ export class ColorBulb {
|
|
|
698
688
|
method: 'POST',
|
|
699
689
|
headers: this.platform.generateHeaders(),
|
|
700
690
|
});
|
|
701
|
-
const deviceStatus = await body.json();
|
|
691
|
+
const deviceStatus: any = await body.json();
|
|
702
692
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
703
693
|
this.statusCode(statusCode);
|
|
704
694
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -749,7 +739,7 @@ export class ColorBulb {
|
|
|
749
739
|
method: 'POST',
|
|
750
740
|
headers: this.platform.generateHeaders(),
|
|
751
741
|
});
|
|
752
|
-
const deviceStatus = await body.json();
|
|
742
|
+
const deviceStatus: any = await body.json();
|
|
753
743
|
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
754
744
|
this.statusCode(statusCode);
|
|
755
745
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
@@ -785,7 +775,7 @@ export class ColorBulb {
|
|
|
785
775
|
method: 'POST',
|
|
786
776
|
headers: this.platform.generateHeaders(),
|
|
787
777
|
});
|
|
788
|
-
const deviceStatus = await body.json();
|
|
778
|
+
const deviceStatus: any = await body.json();
|
|
789
779
|
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
790
780
|
this.statusCode(statusCode);
|
|
791
781
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
@@ -819,7 +809,7 @@ export class ColorBulb {
|
|
|
819
809
|
method: 'POST',
|
|
820
810
|
headers: this.platform.generateHeaders(),
|
|
821
811
|
});
|
|
822
|
-
const deviceStatus = await body.json();
|
|
812
|
+
const deviceStatus: any = await body.json();
|
|
823
813
|
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
824
814
|
this.statusCode(statusCode);
|
|
825
815
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
@@ -972,6 +962,16 @@ export class ColorBulb {
|
|
|
972
962
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
973
963
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
974
964
|
}
|
|
965
|
+
// FirmwareRevision
|
|
966
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
967
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
968
|
+
} else {
|
|
969
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
970
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
971
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
972
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
973
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
974
|
+
}
|
|
975
975
|
}
|
|
976
976
|
|
|
977
977
|
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
@@ -986,7 +986,7 @@ export class ColorBulb {
|
|
|
986
986
|
|
|
987
987
|
async stopScanning(switchbot: any) {
|
|
988
988
|
await switchbot.stopScan();
|
|
989
|
-
if (this.
|
|
989
|
+
if (this.BLE_IsConnected) {
|
|
990
990
|
await this.BLEparseStatus();
|
|
991
991
|
await this.updateHomeKitCharacteristics();
|
|
992
992
|
} else {
|
|
@@ -1135,10 +1135,12 @@ export class ColorBulb {
|
|
|
1135
1135
|
);
|
|
1136
1136
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1137
1137
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
1138
|
-
if (
|
|
1139
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1140
|
-
} else if (device.firmware) {
|
|
1138
|
+
if (device.firmware) {
|
|
1141
1139
|
FirmwareRevision = device.firmware;
|
|
1140
|
+
} else if (device.version) {
|
|
1141
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
1142
|
+
} if (accessory.context.FirmwareRevision) {
|
|
1143
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1142
1144
|
} else {
|
|
1143
1145
|
FirmwareRevision = this.platform.version;
|
|
1144
1146
|
}
|
package/src/device/contact.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
5
5
|
import { skipWhile } from 'rxjs/operators';
|
|
6
6
|
import { SwitchBotPlatform } from '../platform';
|
|
7
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
8
|
-
import { device, devicesConfig, serviceData,
|
|
8
|
+
import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '../settings';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Platform Accessory
|
|
@@ -14,38 +14,34 @@ import { device, devicesConfig, serviceData, switchbot, deviceStatus, ad, Device
|
|
|
14
14
|
*/
|
|
15
15
|
export class Contact {
|
|
16
16
|
// Services
|
|
17
|
-
contactSensorservice: Service;
|
|
18
17
|
motionService?: Service;
|
|
18
|
+
batteryService: Service;
|
|
19
19
|
lightSensorService?: Service;
|
|
20
|
-
|
|
20
|
+
contactSensorservice: Service;
|
|
21
21
|
|
|
22
22
|
// Characteristic Values
|
|
23
|
-
ContactSensorState!: CharacteristicValue;
|
|
24
|
-
MotionDetected!: CharacteristicValue;
|
|
25
|
-
CurrentAmbientLightLevel!: CharacteristicValue;
|
|
26
23
|
BatteryLevel!: CharacteristicValue;
|
|
24
|
+
MotionDetected!: CharacteristicValue;
|
|
27
25
|
StatusLowBattery!: CharacteristicValue;
|
|
26
|
+
ContactSensorState!: CharacteristicValue;
|
|
27
|
+
CurrentAmbientLightLevel!: CharacteristicValue;
|
|
28
|
+
|
|
29
|
+
// OpenAPI Status
|
|
30
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
31
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
32
|
+
OpenAPI_MotionDetected: deviceStatus['moveDetected'];
|
|
33
|
+
OpenAPI_ContactSensorState: deviceStatus['openState'];
|
|
34
|
+
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
|
|
28
35
|
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
// BLE Status
|
|
37
|
+
BLE_BateryLevel!: serviceData['battery'];
|
|
38
|
+
BLE_MotionDetected!: serviceData['movement'];
|
|
39
|
+
BLE_ContactSensorState!: serviceData['doorState'];
|
|
40
|
+
BLE_CurrentAmbientLightLevel: serviceData['lightLevel'];
|
|
34
41
|
|
|
35
42
|
// BLE Others
|
|
36
|
-
tested!: any;
|
|
37
|
-
contact_open!: any;
|
|
38
|
-
button_count!: any;
|
|
39
43
|
scanning!: boolean;
|
|
40
|
-
|
|
41
|
-
contact_timeout!: any;
|
|
42
|
-
switchbot!: switchbot;
|
|
43
|
-
serviceData!: serviceData;
|
|
44
|
-
address!: ad['address'];
|
|
45
|
-
battery!: serviceData['battery'];
|
|
46
|
-
movement!: serviceData['movement'];
|
|
47
|
-
doorState!: serviceData['doorState'];
|
|
48
|
-
is_light!: any; //serviceData['lightLevel'];
|
|
44
|
+
BLE_IsConnected?: boolean;
|
|
49
45
|
|
|
50
46
|
// Config
|
|
51
47
|
set_minLux!: number;
|
|
@@ -145,20 +141,14 @@ export class Contact {
|
|
|
145
141
|
}
|
|
146
142
|
|
|
147
143
|
// Battery Service
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this.
|
|
154
|
-
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
155
|
-
`${accessory.displayName} Battery`;
|
|
156
|
-
|
|
157
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
158
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
159
|
-
} else {
|
|
160
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
144
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
145
|
+
`${accessory.displayName} Battery`;
|
|
146
|
+
|
|
147
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
148
|
+
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
149
|
+
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
161
150
|
}
|
|
151
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
162
152
|
|
|
163
153
|
// Retrieve initial values and updateHomekit
|
|
164
154
|
this.updateHomeKitCharacteristics();
|
|
@@ -192,7 +182,7 @@ export class Contact {
|
|
|
192
182
|
async BLEparseStatus(): Promise<void> {
|
|
193
183
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
194
184
|
// Door State
|
|
195
|
-
switch (this.
|
|
185
|
+
switch (this.BLE_ContactSensorState) {
|
|
196
186
|
case 'open':
|
|
197
187
|
case 1:
|
|
198
188
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
@@ -202,7 +192,7 @@ export class Contact {
|
|
|
202
192
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
203
193
|
break;
|
|
204
194
|
default:
|
|
205
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.
|
|
195
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.BLE_ContactSensorState}`);
|
|
206
196
|
}
|
|
207
197
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
208
198
|
if (
|
|
@@ -213,7 +203,7 @@ export class Contact {
|
|
|
213
203
|
}
|
|
214
204
|
// Movement
|
|
215
205
|
if (!this.device.contact?.hide_motionsensor) {
|
|
216
|
-
this.MotionDetected = Boolean(this.
|
|
206
|
+
this.MotionDetected = Boolean(this.BLE_MotionDetected);
|
|
217
207
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
218
208
|
if (this.MotionDetected !== this.accessory.context.MotionDetected && this.MotionDetected) {
|
|
219
209
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Detected Motion`);
|
|
@@ -223,7 +213,7 @@ export class Contact {
|
|
|
223
213
|
if (!this.device.contact?.hide_lightsensor) {
|
|
224
214
|
this.set_minLux = this.minLux();
|
|
225
215
|
this.set_maxLux = this.maxLux();
|
|
226
|
-
switch (this.
|
|
216
|
+
switch (this.BLE_CurrentAmbientLightLevel) {
|
|
227
217
|
case true:
|
|
228
218
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
229
219
|
break;
|
|
@@ -231,7 +221,7 @@ export class Contact {
|
|
|
231
221
|
this.CurrentAmbientLightLevel = this.set_maxLux;
|
|
232
222
|
}
|
|
233
223
|
this.debugLog(
|
|
234
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
224
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel},` +
|
|
235
225
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
236
226
|
);
|
|
237
227
|
if (this.CurrentAmbientLightLevel !== this.accessory.context.CurrentAmbientLightLevel) {
|
|
@@ -239,10 +229,10 @@ export class Contact {
|
|
|
239
229
|
}
|
|
240
230
|
}
|
|
241
231
|
// Battery
|
|
242
|
-
if (this.
|
|
243
|
-
this.
|
|
232
|
+
if (this.BLE_BateryLevel === undefined) {
|
|
233
|
+
this.BLE_BateryLevel === 100;
|
|
244
234
|
}
|
|
245
|
-
this.BatteryLevel = Number(this.
|
|
235
|
+
this.BatteryLevel = Number(this.BLE_BateryLevel);
|
|
246
236
|
if (this.BatteryLevel < 10) {
|
|
247
237
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
248
238
|
} else {
|
|
@@ -256,25 +246,25 @@ export class Contact {
|
|
|
256
246
|
async openAPIparseStatus(): Promise<void> {
|
|
257
247
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
258
248
|
// Contact State
|
|
259
|
-
if (this.
|
|
249
|
+
if (this.OpenAPI_ContactSensorState === 'open') {
|
|
260
250
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
261
251
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
262
|
-
} else if (this.
|
|
252
|
+
} else if (this.OpenAPI_ContactSensorState === 'close') {
|
|
263
253
|
this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
264
254
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
265
255
|
} else {
|
|
266
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.
|
|
256
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.OpenAPI_ContactSensorState}`);
|
|
267
257
|
}
|
|
268
258
|
// Motion State
|
|
269
259
|
if (!this.device.contact?.hide_motionsensor) {
|
|
270
|
-
this.MotionDetected = this.
|
|
260
|
+
this.MotionDetected = this.OpenAPI_MotionDetected!;
|
|
271
261
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
|
|
272
262
|
}
|
|
273
263
|
// Light Level
|
|
274
264
|
if (!this.device.contact?.hide_lightsensor) {
|
|
275
265
|
this.set_minLux = this.minLux();
|
|
276
266
|
this.set_maxLux = this.maxLux();
|
|
277
|
-
switch (this.
|
|
267
|
+
switch (this.OpenAPI_CurrentAmbientLightLevel) {
|
|
278
268
|
case 'dim':
|
|
279
269
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
280
270
|
break;
|
|
@@ -284,6 +274,19 @@ export class Contact {
|
|
|
284
274
|
}
|
|
285
275
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
|
|
286
276
|
}
|
|
277
|
+
// Battery
|
|
278
|
+
if (this.OpenAPI_BatteryLevel === undefined) {
|
|
279
|
+
this.OpenAPI_BatteryLevel === 100;
|
|
280
|
+
}
|
|
281
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
282
|
+
if (this.BatteryLevel < 10) {
|
|
283
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
284
|
+
} else {
|
|
285
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
286
|
+
}
|
|
287
|
+
this.debugLog(
|
|
288
|
+
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, ` + `StatusLowBattery: ${this.StatusLowBattery}`,
|
|
289
|
+
);
|
|
287
290
|
}
|
|
288
291
|
|
|
289
292
|
/**
|
|
@@ -327,35 +330,28 @@ export class Contact {
|
|
|
327
330
|
.then(async () => {
|
|
328
331
|
// Set an event hander
|
|
329
332
|
this.scanning = true;
|
|
330
|
-
switchbot.onadvertisement = async (ad:
|
|
331
|
-
this.address = ad.address;
|
|
333
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
332
334
|
this.debugLog(
|
|
333
335
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
334
|
-
` BLE Address Found: ${
|
|
336
|
+
` BLE Address Found: ${ad.address}`,
|
|
335
337
|
);
|
|
336
|
-
this.
|
|
337
|
-
this.
|
|
338
|
-
this.
|
|
339
|
-
this.battery = ad.serviceData.battery;
|
|
340
|
-
this.contact_open = ad.serviceData.contact_open;
|
|
341
|
-
this.contact_timeout = ad.serviceData.contact_timeout;
|
|
342
|
-
this.is_light = ad.serviceData.is_light;
|
|
343
|
-
this.button_count = ad.serviceData.button_count;
|
|
344
|
-
this.doorState = ad.serviceData.doorState;
|
|
338
|
+
this.BLE_MotionDetected = ad.serviceData.movement;
|
|
339
|
+
this.BLE_BateryLevel = ad.serviceData.battery;
|
|
340
|
+
this.BLE_ContactSensorState = ad.serviceData.doorState;
|
|
345
341
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
346
342
|
this.debugLog(
|
|
347
343
|
`${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
|
|
348
|
-
`${ad.serviceData.doorState},
|
|
344
|
+
`${ad.serviceData.doorState}, battery: ${ad.serviceData.battery}`,
|
|
349
345
|
);
|
|
350
346
|
|
|
351
|
-
if (
|
|
352
|
-
this.
|
|
353
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
347
|
+
if (ad.serviceData) {
|
|
348
|
+
this.BLE_IsConnected = true;
|
|
349
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
354
350
|
await this.stopScanning(switchbot);
|
|
355
351
|
this.scanning = false;
|
|
356
352
|
} else {
|
|
357
|
-
this.
|
|
358
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
353
|
+
this.BLE_IsConnected = false;
|
|
354
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
359
355
|
}
|
|
360
356
|
};
|
|
361
357
|
// Wait
|
|
@@ -386,14 +382,16 @@ export class Contact {
|
|
|
386
382
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
387
383
|
headers: this.platform.generateHeaders(),
|
|
388
384
|
});
|
|
389
|
-
const deviceStatus = await body.json();
|
|
385
|
+
const deviceStatus: any = await body.json();
|
|
390
386
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
391
387
|
this.statusCode(statusCode);
|
|
392
388
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
393
389
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
394
|
-
this.
|
|
395
|
-
this.
|
|
396
|
-
this.
|
|
390
|
+
this.OpenAPI_ContactSensorState = deviceStatus.body.openState;
|
|
391
|
+
this.OpenAPI_MotionDetected = deviceStatus.body.moveDetected;
|
|
392
|
+
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
|
|
393
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
394
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
397
395
|
this.openAPIparseStatus();
|
|
398
396
|
this.updateHomeKitCharacteristics();
|
|
399
397
|
} catch (e: any) {
|
|
@@ -437,27 +435,35 @@ export class Contact {
|
|
|
437
435
|
);
|
|
438
436
|
}
|
|
439
437
|
}
|
|
440
|
-
if (this.
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
438
|
+
if (this.BatteryLevel === undefined) {
|
|
439
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
440
|
+
} else {
|
|
441
|
+
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
442
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
443
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
444
|
+
}
|
|
445
|
+
if (this.StatusLowBattery === undefined) {
|
|
446
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
447
|
+
} else {
|
|
448
|
+
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
449
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
450
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
451
|
+
}
|
|
452
|
+
// FirmwareRevision
|
|
453
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
454
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
455
|
+
} else {
|
|
456
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
457
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
458
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
459
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
460
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
455
461
|
}
|
|
456
462
|
}
|
|
457
463
|
|
|
458
464
|
async stopScanning(switchbot: any) {
|
|
459
465
|
await switchbot.stopScan();
|
|
460
|
-
if (this.
|
|
466
|
+
if (this.BLE_IsConnected) {
|
|
461
467
|
await this.BLEparseStatus();
|
|
462
468
|
await this.updateHomeKitCharacteristics();
|
|
463
469
|
} else {
|
|
@@ -580,10 +586,8 @@ export class Contact {
|
|
|
580
586
|
if (!this.device.contact?.hide_lightsensor) {
|
|
581
587
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
|
|
582
588
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
586
|
-
}
|
|
589
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
|
|
590
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
587
591
|
}
|
|
588
592
|
|
|
589
593
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
@@ -593,10 +597,12 @@ export class Contact {
|
|
|
593
597
|
);
|
|
594
598
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
595
599
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
596
|
-
if (
|
|
597
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
598
|
-
} else if (device.firmware) {
|
|
600
|
+
if (device.firmware) {
|
|
599
601
|
FirmwareRevision = device.firmware;
|
|
602
|
+
} else if (device.version) {
|
|
603
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
604
|
+
} else if (accessory.context.FirmwareRevision) {
|
|
605
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
600
606
|
} else {
|
|
601
607
|
FirmwareRevision = this.platform.version;
|
|
602
608
|
}
|