@switchbot/homebridge-switchbot 2.8.0 → 2.8.1-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/dist/device/blindtilt.d.ts +21 -23
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +71 -73
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +11 -15
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +38 -34
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -14
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +33 -23
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +16 -24
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +49 -43
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +16 -24
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +49 -51
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +21 -26
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +49 -47
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -8
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +42 -30
- 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 +27 -17
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +16 -21
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +35 -26
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +8 -13
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +28 -25
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -21
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +75 -26
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +16 -21
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +40 -37
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +16 -21
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +40 -37
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +12 -21
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +44 -46
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +5 -15
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +22 -19
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -13
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +30 -28
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +4 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/fan.d.ts +3 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/other.d.ts +2 -2
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.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 +5 -5
- package/src/device/blindtilt.ts +96 -95
- package/src/device/bot.ts +54 -54
- package/src/device/ceilinglight.ts +46 -39
- package/src/device/colorbulb.ts +68 -69
- package/src/device/contact.ts +69 -77
- package/src/device/curtain.ts +75 -74
- package/src/device/hub.ts +53 -38
- package/src/device/humidifier.ts +33 -26
- package/src/device/iosensor.ts +53 -48
- package/src/device/lightstrip.ts +39 -40
- package/src/device/lock.ts +94 -49
- package/src/device/meter.ts +59 -59
- package/src/device/meterplus.ts +59 -60
- package/src/device/motion.ts +61 -65
- package/src/device/plug.ts +27 -35
- package/src/device/robotvacuumcleaner.ts +43 -43
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/camera.ts +1 -1
- package/src/irdevice/fan.ts +3 -6
- package/src/irdevice/light.ts +1 -1
- package/src/irdevice/other.ts +2 -2
- package/src/irdevice/tv.ts +1 -4
- package/src/irdevice/vacuumcleaner.ts +1 -1
- package/src/irdevice/waterheater.ts +1 -1
- package/src/settings.ts +5 -1
package/src/device/blindtilt.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { connectAsync } from 'async-mqtt';
|
|
|
7
7
|
import { SwitchBotPlatform } from '../platform';
|
|
8
8
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
9
9
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
10
|
-
import { device, devicesConfig, serviceData,
|
|
10
|
+
import { device, devicesConfig, serviceData, deviceStatus, ad, Devices } from '../settings';
|
|
11
11
|
|
|
12
12
|
enum BlindTiltMappingMode {
|
|
13
13
|
OnlyUp = 'only_up',
|
|
@@ -19,43 +19,44 @@ enum BlindTiltMappingMode {
|
|
|
19
19
|
|
|
20
20
|
export class BlindTilt {
|
|
21
21
|
// Services
|
|
22
|
-
|
|
22
|
+
batteryService: Service;
|
|
23
23
|
lightSensorService?: Service;
|
|
24
|
-
|
|
24
|
+
windowCoveringService: Service;
|
|
25
25
|
|
|
26
26
|
// Characteristic Values
|
|
27
|
-
|
|
27
|
+
BatteryLevel!: CharacteristicValue;
|
|
28
28
|
PositionState!: CharacteristicValue;
|
|
29
29
|
TargetPosition!: CharacteristicValue;
|
|
30
|
+
CurrentPosition!: CharacteristicValue;
|
|
31
|
+
StatusLowBattery!: CharacteristicValue;
|
|
30
32
|
CurrentAmbientLightLevel?: CharacteristicValue;
|
|
31
|
-
BatteryLevel?: CharacteristicValue;
|
|
32
|
-
StatusLowBattery?: CharacteristicValue;
|
|
33
|
-
CurrentHorizontalTiltAngle!: CharacteristicValue;
|
|
34
33
|
TargetHorizontalTiltAngle!: CharacteristicValue;
|
|
34
|
+
CurrentHorizontalTiltAngle!: CharacteristicValue;
|
|
35
|
+
|
|
36
|
+
// OpenAPI Status
|
|
37
|
+
OpenAPI_InMotion: deviceStatus['moving'];
|
|
38
|
+
OpenAPI_BatteryLevel: serviceData['battery'];
|
|
39
|
+
OpenAPI_Direction: deviceStatus['direction'];
|
|
40
|
+
OpenAPI_Calibration: serviceData['calibration'];
|
|
41
|
+
OpenAPI_CurrentPosition: serviceData['position'];
|
|
42
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
43
|
+
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];
|
|
35
44
|
|
|
36
45
|
// OpenAPI Others
|
|
37
|
-
Version: deviceStatus['version'];
|
|
38
|
-
deviceStatus!: any; //deviceStatusResponse;
|
|
39
|
-
slidePosition: deviceStatus['slidePosition'];
|
|
40
|
-
direction: deviceStatus['direction'];
|
|
41
|
-
moving: deviceStatus['moving'];
|
|
42
|
-
brightness: deviceStatus['brightness'];
|
|
43
|
-
setPositionMode?: string | number;
|
|
44
46
|
Mode!: string;
|
|
45
|
-
|
|
47
|
+
setPositionMode?: string | number;
|
|
46
48
|
mappingMode: BlindTiltMappingMode = BlindTiltMappingMode.OnlyUp;
|
|
47
49
|
|
|
50
|
+
// BLE Status
|
|
51
|
+
BLE_InMotion: serviceData['inMotion'];
|
|
52
|
+
BLE_BatteryLevel: serviceData['battery'];
|
|
53
|
+
BLE_Calibration: serviceData['calibration'];
|
|
54
|
+
BLE_CurrentPosition: serviceData['position'];
|
|
55
|
+
BLE_CurrentAmbientLightLevel: serviceData['lightLevel'];
|
|
56
|
+
|
|
48
57
|
// BLE Others
|
|
49
|
-
|
|
50
|
-
switchbot!: switchbot;
|
|
51
|
-
serviceData!: serviceData;
|
|
58
|
+
BLE_IsConnected?: boolean;
|
|
52
59
|
spaceBetweenLevels!: number;
|
|
53
|
-
address!: ad['address'];
|
|
54
|
-
calibration: serviceData['calibration'];
|
|
55
|
-
battery: serviceData['battery'];
|
|
56
|
-
position: serviceData['position'];
|
|
57
|
-
inMotion: serviceData['inMotion'];
|
|
58
|
-
lightLevel: serviceData['lightLevel'];
|
|
59
60
|
|
|
60
61
|
// Target
|
|
61
62
|
setNewTarget!: boolean;
|
|
@@ -188,21 +189,12 @@ export class BlindTilt {
|
|
|
188
189
|
.onSet(this.TargetHorizontalTiltAngleSet.bind(this));
|
|
189
190
|
|
|
190
191
|
// Battery Service
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.
|
|
197
|
-
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
198
|
-
`${accessory.displayName} Battery`;
|
|
199
|
-
|
|
200
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
201
|
-
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
202
|
-
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
203
|
-
}
|
|
204
|
-
} else {
|
|
205
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
192
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
193
|
+
`${accessory.displayName} Battery`;
|
|
194
|
+
|
|
195
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
196
|
+
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
197
|
+
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
206
198
|
}
|
|
207
199
|
|
|
208
200
|
// Update Homekit
|
|
@@ -270,14 +262,14 @@ export class BlindTilt {
|
|
|
270
262
|
async BLEparseStatus(): Promise<void> {
|
|
271
263
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
272
264
|
// CurrentPosition
|
|
273
|
-
this.CurrentPosition = 100 - Number(this.
|
|
265
|
+
this.CurrentPosition = 100 - Number(this.BLE_CurrentPosition);
|
|
274
266
|
await this.setMinMax();
|
|
275
267
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`);
|
|
276
268
|
if (this.setNewTarget) {
|
|
277
269
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
278
270
|
}
|
|
279
271
|
|
|
280
|
-
if (this.setNewTarget && this.
|
|
272
|
+
if (this.setNewTarget && this.BLE_InMotion) {
|
|
281
273
|
await this.setMinMax();
|
|
282
274
|
if (Number(this.TargetPosition) > this.CurrentPosition) {
|
|
283
275
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
|
|
@@ -312,45 +304,45 @@ export class BlindTilt {
|
|
|
312
304
|
this.spaceBetweenLevels = 9;
|
|
313
305
|
|
|
314
306
|
// Brightness
|
|
315
|
-
switch (this.
|
|
307
|
+
switch (this.BLE_CurrentAmbientLightLevel) {
|
|
316
308
|
case 1:
|
|
317
309
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
318
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
310
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
319
311
|
break;
|
|
320
312
|
case 2:
|
|
321
313
|
this.CurrentAmbientLightLevel = (this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels;
|
|
322
314
|
this.debugLog(
|
|
323
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
315
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel},` +
|
|
324
316
|
` Calculation: ${(this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels}`,
|
|
325
317
|
);
|
|
326
318
|
break;
|
|
327
319
|
case 3:
|
|
328
320
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 2;
|
|
329
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
321
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
330
322
|
break;
|
|
331
323
|
case 4:
|
|
332
324
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 3;
|
|
333
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
325
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
334
326
|
break;
|
|
335
327
|
case 5:
|
|
336
328
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 4;
|
|
337
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
329
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
338
330
|
break;
|
|
339
331
|
case 6:
|
|
340
332
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 5;
|
|
341
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
333
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
342
334
|
break;
|
|
343
335
|
case 7:
|
|
344
336
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 6;
|
|
345
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
337
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
346
338
|
break;
|
|
347
339
|
case 8:
|
|
348
340
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 7;
|
|
349
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
341
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
350
342
|
break;
|
|
351
343
|
case 9:
|
|
352
344
|
this.CurrentAmbientLightLevel = ((this.set_maxLux - this.set_minLux) / this.spaceBetweenLevels) * 8;
|
|
353
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
345
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel}`);
|
|
354
346
|
break;
|
|
355
347
|
case 10:
|
|
356
348
|
default:
|
|
@@ -358,12 +350,12 @@ export class BlindTilt {
|
|
|
358
350
|
this.debugLog();
|
|
359
351
|
}
|
|
360
352
|
this.debugLog(
|
|
361
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.
|
|
353
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.BLE_CurrentAmbientLightLevel},` +
|
|
362
354
|
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
363
355
|
);
|
|
364
356
|
}
|
|
365
357
|
// Battery
|
|
366
|
-
this.BatteryLevel = Number(this.
|
|
358
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
367
359
|
if (this.BatteryLevel < 10) {
|
|
368
360
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
369
361
|
} else {
|
|
@@ -377,8 +369,9 @@ export class BlindTilt {
|
|
|
377
369
|
async openAPIparseStatus(): Promise<void> {
|
|
378
370
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
379
371
|
|
|
380
|
-
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(this.
|
|
381
|
-
|
|
372
|
+
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(this.OpenAPI_CurrentPosition),
|
|
373
|
+
String(this.OpenAPI_Direction));
|
|
374
|
+
this.debugLog(` device: ${this.OpenAPI_CurrentPosition} => HK: ${homekitPosition}`);
|
|
382
375
|
|
|
383
376
|
this.CurrentPosition = homekitPosition;
|
|
384
377
|
// CurrentPosition
|
|
@@ -394,7 +387,7 @@ export class BlindTilt {
|
|
|
394
387
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`);
|
|
395
388
|
}
|
|
396
389
|
|
|
397
|
-
if (this.setNewTarget && this.
|
|
390
|
+
if (this.setNewTarget && this.OpenAPI_InMotion) {
|
|
398
391
|
await this.setMinMax();
|
|
399
392
|
if (this.TargetPosition > this.CurrentPosition || (homekitTiltAngle && this.TargetHorizontalTiltAngle !== this.CurrentHorizontalTiltAngle)) {
|
|
400
393
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
|
|
@@ -434,7 +427,7 @@ export class BlindTilt {
|
|
|
434
427
|
this.set_minLux = this.minLux();
|
|
435
428
|
this.set_maxLux = this.maxLux();
|
|
436
429
|
// Brightness
|
|
437
|
-
switch (this.
|
|
430
|
+
switch (this.OpenAPI_CurrentAmbientLightLevel) {
|
|
438
431
|
case 'dim':
|
|
439
432
|
this.CurrentAmbientLightLevel = this.set_minLux;
|
|
440
433
|
break;
|
|
@@ -481,18 +474,16 @@ export class BlindTilt {
|
|
|
481
474
|
})
|
|
482
475
|
.then(async () => {
|
|
483
476
|
// Set an event hander
|
|
484
|
-
switchbot.onadvertisement = async (ad:
|
|
485
|
-
this.address = ad.address;
|
|
477
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
486
478
|
this.debugLog(
|
|
487
479
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
488
|
-
` BLE Address Found: ${
|
|
480
|
+
` BLE Address Found: ${ad.address}`,
|
|
489
481
|
);
|
|
490
|
-
this.
|
|
491
|
-
this.
|
|
492
|
-
this.
|
|
493
|
-
this.
|
|
494
|
-
this.
|
|
495
|
-
this.lightLevel = ad.serviceData.lightLevel;
|
|
482
|
+
this.BLE_Calibration = ad.serviceData.calibration;
|
|
483
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
484
|
+
this.BLE_InMotion = ad.serviceData.inMotion;
|
|
485
|
+
this.BLE_CurrentPosition = ad.serviceData.position;
|
|
486
|
+
this.BLE_CurrentAmbientLightLevel = ad.serviceData.lightLevel;
|
|
496
487
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
497
488
|
this.debugLog(
|
|
498
489
|
`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
@@ -500,13 +491,13 @@ export class BlindTilt {
|
|
|
500
491
|
`inMotion: ${ad.serviceData.inMotion}`,
|
|
501
492
|
);
|
|
502
493
|
|
|
503
|
-
if (
|
|
504
|
-
this.
|
|
505
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
494
|
+
if (ad.serviceData) {
|
|
495
|
+
this.BLE_IsConnected = true;
|
|
496
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
506
497
|
await this.stopScanning(switchbot);
|
|
507
498
|
} else {
|
|
508
|
-
this.
|
|
509
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
499
|
+
this.BLE_IsConnected = false;
|
|
500
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
510
501
|
}
|
|
511
502
|
};
|
|
512
503
|
// Wait
|
|
@@ -540,10 +531,12 @@ export class BlindTilt {
|
|
|
540
531
|
this.statusCode(statusCode);
|
|
541
532
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
542
533
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
543
|
-
this.
|
|
544
|
-
this.
|
|
545
|
-
this.
|
|
546
|
-
this.
|
|
534
|
+
this.OpenAPI_CurrentPosition = deviceStatus.body.slidePosition;
|
|
535
|
+
this.OpenAPI_Direction = deviceStatus.body.direction;
|
|
536
|
+
this.OpenAPI_InMotion = deviceStatus.body.moving;
|
|
537
|
+
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
|
|
538
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
539
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
547
540
|
this.openAPIparseStatus();
|
|
548
541
|
this.updateHomeKitCharacteristics();
|
|
549
542
|
} catch (e: any) {
|
|
@@ -842,27 +835,35 @@ export class BlindTilt {
|
|
|
842
835
|
);
|
|
843
836
|
}
|
|
844
837
|
}
|
|
845
|
-
if (this.
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
851
|
-
}
|
|
852
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
853
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
854
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
838
|
+
if (this.BatteryLevel === undefined) {
|
|
839
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
840
|
+
} else {
|
|
841
|
+
if (this.device.mqttURL) {
|
|
842
|
+
this.mqttPublish('BatteryLevel', this.BatteryLevel);
|
|
855
843
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
this.
|
|
844
|
+
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
845
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
846
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
847
|
+
}
|
|
848
|
+
if (this.StatusLowBattery === undefined) {
|
|
849
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
850
|
+
} else {
|
|
851
|
+
if (this.device.mqttURL) {
|
|
852
|
+
this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
|
|
865
853
|
}
|
|
854
|
+
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
855
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
856
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
857
|
+
}
|
|
858
|
+
// FirmwareRevision
|
|
859
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
860
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
861
|
+
} else {
|
|
862
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
863
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
864
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
865
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
866
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
866
867
|
}
|
|
867
868
|
}
|
|
868
869
|
|
|
@@ -900,7 +901,7 @@ export class BlindTilt {
|
|
|
900
901
|
|
|
901
902
|
async stopScanning(switchbot: any) {
|
|
902
903
|
await switchbot.stopScan();
|
|
903
|
-
if (this.
|
|
904
|
+
if (this.BLE_IsConnected) {
|
|
904
905
|
await this.BLEparseStatus();
|
|
905
906
|
await this.updateHomeKitCharacteristics();
|
|
906
907
|
} else {
|
package/src/device/bot.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
5
5
|
import { SwitchBotPlatform } from '../platform';
|
|
6
6
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
7
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
8
|
-
import { device, devicesConfig, deviceStatus, ad, serviceData,
|
|
8
|
+
import { device, devicesConfig, deviceStatus, ad, serviceData, Devices } from '../settings';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Platform Accessory
|
|
@@ -21,7 +21,7 @@ export class Bot {
|
|
|
21
21
|
windowService?: Service;
|
|
22
22
|
switchService?: Service;
|
|
23
23
|
outletService?: Service;
|
|
24
|
-
batteryService
|
|
24
|
+
batteryService: Service;
|
|
25
25
|
garageDoorService?: Service;
|
|
26
26
|
windowCoveringService?: Service;
|
|
27
27
|
statefulProgrammableSwitchService?: Service;
|
|
@@ -31,31 +31,28 @@ export class Bot {
|
|
|
31
31
|
BatteryLevel!: CharacteristicValue;
|
|
32
32
|
StatusLowBattery!: CharacteristicValue;
|
|
33
33
|
|
|
34
|
-
// OpenAPI
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
state!: serviceData['state'];
|
|
47
|
-
battery!: serviceData['battery'];
|
|
34
|
+
// OpenAPI Status
|
|
35
|
+
OpenAPI_On: deviceStatus['power'];
|
|
36
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
37
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
38
|
+
|
|
39
|
+
// BLE Status
|
|
40
|
+
BLE_On!: serviceData['state'];
|
|
41
|
+
BLE_Mode!: serviceData['mode'];
|
|
42
|
+
BLE_BatteryLevel!: serviceData['battery'];
|
|
43
|
+
|
|
44
|
+
//BLE Others
|
|
45
|
+
BLE_IsConnected?: boolean;
|
|
48
46
|
|
|
49
47
|
// Config
|
|
50
48
|
botMode!: string;
|
|
51
49
|
allowPush?: boolean;
|
|
52
50
|
doublePress!: number;
|
|
53
|
-
pushRatePress!: number;
|
|
54
51
|
scanDuration!: number;
|
|
52
|
+
pushRatePress!: number;
|
|
55
53
|
deviceLogging!: string;
|
|
56
|
-
deviceRefreshRate!: number;
|
|
57
|
-
// Multi-Press
|
|
58
54
|
multiPressCount!: number;
|
|
55
|
+
deviceRefreshRate!: number;
|
|
59
56
|
|
|
60
57
|
// Updates
|
|
61
58
|
botUpdateInProgress!: boolean;
|
|
@@ -348,19 +345,14 @@ export class Bot {
|
|
|
348
345
|
}
|
|
349
346
|
|
|
350
347
|
// Battery Service
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
this.batteryService.
|
|
357
|
-
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
358
|
-
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
359
|
-
}
|
|
360
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
361
|
-
} else {
|
|
362
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
348
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)),
|
|
349
|
+
`${accessory.displayName} Battery`;
|
|
350
|
+
|
|
351
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
352
|
+
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
353
|
+
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
363
354
|
}
|
|
355
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
364
356
|
|
|
365
357
|
// Retrieve initial values and updateHomekit
|
|
366
358
|
this.updateHomeKitCharacteristics();
|
|
@@ -424,19 +416,19 @@ export class Bot {
|
|
|
424
416
|
async BLEparseStatus(): Promise<void> {
|
|
425
417
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
426
418
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
427
|
-
if (this.
|
|
419
|
+
if (this.BLE_Mode) {
|
|
428
420
|
this.accessory.context.On = this.On;
|
|
429
421
|
if (this.On === undefined) {
|
|
430
|
-
this.On = Boolean(this.
|
|
422
|
+
this.On = Boolean(this.BLE_On);
|
|
431
423
|
}
|
|
432
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, mode: ${this.
|
|
424
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Switch Mode, mode: ${this.BLE_Mode}, On: ${this.On}`);
|
|
433
425
|
} else {
|
|
434
426
|
this.On = false;
|
|
435
427
|
this.accessory.context.On = this.On;
|
|
436
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode, mode: ${this.
|
|
428
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Press Mode, mode: ${this.BLE_Mode}, On: ${this.On}`);
|
|
437
429
|
}
|
|
438
430
|
|
|
439
|
-
this.BatteryLevel = Number(this.
|
|
431
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
440
432
|
if (this.BatteryLevel < 10) {
|
|
441
433
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
442
434
|
} else {
|
|
@@ -462,7 +454,7 @@ export class Bot {
|
|
|
462
454
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
463
455
|
|
|
464
456
|
// Battery
|
|
465
|
-
this.BatteryLevel = Number(this.
|
|
457
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
466
458
|
if (this.BatteryLevel < 10) {
|
|
467
459
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
468
460
|
} else {
|
|
@@ -513,28 +505,26 @@ export class Bot {
|
|
|
513
505
|
.then(async () => {
|
|
514
506
|
// Set an event hander
|
|
515
507
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
516
|
-
this.address = ad.address;
|
|
517
508
|
this.debugLog(
|
|
518
509
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
519
|
-
` BLE Address Found: ${
|
|
510
|
+
` BLE Address Found: ${ad.address}`,
|
|
520
511
|
);
|
|
521
|
-
this.
|
|
522
|
-
this.
|
|
523
|
-
this.
|
|
524
|
-
this.battery = ad.serviceData.battery;
|
|
512
|
+
this.BLE_Mode = ad.serviceData.mode;
|
|
513
|
+
this.BLE_On = ad.serviceData.state;
|
|
514
|
+
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
525
515
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
526
516
|
this.debugLog(
|
|
527
517
|
`${this.device.deviceType}: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ` +
|
|
528
518
|
`${ad.serviceData.modelName}, mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`,
|
|
529
519
|
);
|
|
530
520
|
|
|
531
|
-
if (
|
|
532
|
-
this.
|
|
533
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
521
|
+
if (ad.serviceData) {
|
|
522
|
+
this.BLE_IsConnected = true;
|
|
523
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
534
524
|
await this.stopScanning(switchbot);
|
|
535
525
|
} else {
|
|
536
|
-
this.
|
|
537
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
526
|
+
this.BLE_IsConnected = false;
|
|
527
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
538
528
|
}
|
|
539
529
|
};
|
|
540
530
|
// Wait
|
|
@@ -569,9 +559,9 @@ export class Bot {
|
|
|
569
559
|
this.statusCode(statusCode);
|
|
570
560
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
571
561
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
572
|
-
this.
|
|
573
|
-
this.
|
|
574
|
-
this.
|
|
562
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
563
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
564
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
575
565
|
this.openAPIparseStatus();
|
|
576
566
|
this.updateHomeKitCharacteristics();
|
|
577
567
|
} else {
|
|
@@ -1002,6 +992,8 @@ export class Bot {
|
|
|
1002
992
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
1003
993
|
}
|
|
1004
994
|
}
|
|
995
|
+
this.accessory.context.On = this.On;
|
|
996
|
+
// Battery
|
|
1005
997
|
if (this.BatteryLevel === undefined) {
|
|
1006
998
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
1007
999
|
} else {
|
|
@@ -1016,8 +1008,16 @@ export class Bot {
|
|
|
1016
1008
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
1017
1009
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
1018
1010
|
}
|
|
1019
|
-
|
|
1020
|
-
this.
|
|
1011
|
+
// FirmwareRevision
|
|
1012
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
1013
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
1014
|
+
} else {
|
|
1015
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
1016
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
1017
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
1018
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
1019
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
1020
|
+
}
|
|
1021
1021
|
}
|
|
1022
1022
|
|
|
1023
1023
|
async removeOutletService(accessory: PlatformAccessory): Promise<void> {
|
|
@@ -1121,7 +1121,7 @@ export class Bot {
|
|
|
1121
1121
|
|
|
1122
1122
|
async stopScanning(switchbot: any) {
|
|
1123
1123
|
await switchbot.stopScan();
|
|
1124
|
-
if (this.
|
|
1124
|
+
if (this.BLE_IsConnected) {
|
|
1125
1125
|
await this.BLEparseStatus();
|
|
1126
1126
|
await this.updateHomeKitCharacteristics();
|
|
1127
1127
|
} else {
|