@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/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,29 +31,28 @@ export class Bot {
|
|
|
31
31
|
BatteryLevel!: CharacteristicValue;
|
|
32
32
|
StatusLowBattery!: CharacteristicValue;
|
|
33
33
|
|
|
34
|
-
// OpenAPI
|
|
35
|
-
|
|
36
|
-
deviceStatus
|
|
34
|
+
// OpenAPI Status
|
|
35
|
+
OpenAPI_On: deviceStatus['power'];
|
|
36
|
+
OpenAPI_BatteryLevel: deviceStatus['battery'];
|
|
37
|
+
OpenAPI_FirmwareRevision: deviceStatus['version'];
|
|
37
38
|
|
|
38
|
-
// BLE
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
battery!: serviceData['battery'];
|
|
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;
|
|
46
46
|
|
|
47
47
|
// Config
|
|
48
48
|
botMode!: string;
|
|
49
49
|
allowPush?: boolean;
|
|
50
50
|
doublePress!: number;
|
|
51
|
-
pushRatePress!: number;
|
|
52
51
|
scanDuration!: number;
|
|
52
|
+
pushRatePress!: number;
|
|
53
53
|
deviceLogging!: string;
|
|
54
|
-
deviceRefreshRate!: number;
|
|
55
|
-
// Multi-Press
|
|
56
54
|
multiPressCount!: number;
|
|
55
|
+
deviceRefreshRate!: number;
|
|
57
56
|
|
|
58
57
|
// Updates
|
|
59
58
|
botUpdateInProgress!: boolean;
|
|
@@ -113,7 +112,7 @@ export class Bot {
|
|
|
113
112
|
// Add switchService
|
|
114
113
|
(this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
|
|
115
114
|
`${accessory.displayName} Switch`;
|
|
116
|
-
this.
|
|
115
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`);
|
|
117
116
|
|
|
118
117
|
this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
119
118
|
if (!this.switchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -135,7 +134,7 @@ export class Bot {
|
|
|
135
134
|
(this.garageDoorService =
|
|
136
135
|
accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)),
|
|
137
136
|
`${accessory.displayName} Garage Door Opener`;
|
|
138
|
-
this.
|
|
137
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`);
|
|
139
138
|
|
|
140
139
|
this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
141
140
|
if (!this.garageDoorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -157,7 +156,7 @@ export class Bot {
|
|
|
157
156
|
// Add switchService
|
|
158
157
|
(this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)),
|
|
159
158
|
`${accessory.displayName} Door`;
|
|
160
|
-
this.
|
|
159
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`);
|
|
161
160
|
|
|
162
161
|
this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
163
162
|
if (!this.doorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -187,7 +186,7 @@ export class Bot {
|
|
|
187
186
|
// Add switchService
|
|
188
187
|
(this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)),
|
|
189
188
|
`${accessory.displayName} Window`;
|
|
190
|
-
this.
|
|
189
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`);
|
|
191
190
|
|
|
192
191
|
this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
193
192
|
if (!this.windowService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -218,7 +217,7 @@ export class Bot {
|
|
|
218
217
|
(this.windowCoveringService =
|
|
219
218
|
accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
|
|
220
219
|
`${accessory.displayName} Window Covering`;
|
|
221
|
-
this.
|
|
220
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`);
|
|
222
221
|
|
|
223
222
|
this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
224
223
|
if (!this.windowCoveringService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -248,7 +247,7 @@ export class Bot {
|
|
|
248
247
|
// Add switchService
|
|
249
248
|
(this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
|
|
250
249
|
`${accessory.displayName} Lock`;
|
|
251
|
-
this.
|
|
250
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`);
|
|
252
251
|
|
|
253
252
|
this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
254
253
|
if (!this.lockService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -269,7 +268,7 @@ export class Bot {
|
|
|
269
268
|
// Add switchService
|
|
270
269
|
(this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)),
|
|
271
270
|
`${accessory.displayName} Faucet`;
|
|
272
|
-
this.
|
|
271
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`);
|
|
273
272
|
|
|
274
273
|
this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
275
274
|
if (!this.faucetService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -290,7 +289,7 @@ export class Bot {
|
|
|
290
289
|
// Add switchService
|
|
291
290
|
(this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)),
|
|
292
291
|
`${accessory.displayName} Fan`;
|
|
293
|
-
this.
|
|
292
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`);
|
|
294
293
|
|
|
295
294
|
this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
296
295
|
if (!this.fanService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -313,7 +312,7 @@ export class Bot {
|
|
|
313
312
|
accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
|
|
314
313
|
accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
|
|
315
314
|
`${accessory.displayName} Stateful Programmable Switch`;
|
|
316
|
-
this.
|
|
315
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
|
|
317
316
|
|
|
318
317
|
this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
319
318
|
if (!this.statefulProgrammableSwitchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -336,7 +335,7 @@ export class Bot {
|
|
|
336
335
|
// Add outletService
|
|
337
336
|
(this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
|
|
338
337
|
`${accessory.displayName} Outlet`;
|
|
339
|
-
this.
|
|
338
|
+
this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`);
|
|
340
339
|
|
|
341
340
|
this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
342
341
|
if (!this.outletService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -346,22 +345,14 @@ export class Bot {
|
|
|
346
345
|
}
|
|
347
346
|
|
|
348
347
|
// Battery Service
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
this.
|
|
355
|
-
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
356
|
-
`${accessory.displayName} Battery`;
|
|
357
|
-
|
|
358
|
-
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
359
|
-
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
360
|
-
this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
|
|
361
|
-
}
|
|
362
|
-
} else {
|
|
363
|
-
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`);
|
|
364
354
|
}
|
|
355
|
+
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
365
356
|
|
|
366
357
|
// Retrieve initial values and updateHomekit
|
|
367
358
|
this.updateHomeKitCharacteristics();
|
|
@@ -425,19 +416,19 @@ export class Bot {
|
|
|
425
416
|
async BLEparseStatus(): Promise<void> {
|
|
426
417
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
427
418
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
428
|
-
if (this.
|
|
419
|
+
if (this.BLE_Mode) {
|
|
429
420
|
this.accessory.context.On = this.On;
|
|
430
421
|
if (this.On === undefined) {
|
|
431
|
-
this.On = Boolean(this.
|
|
422
|
+
this.On = Boolean(this.BLE_On);
|
|
432
423
|
}
|
|
433
|
-
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}`);
|
|
434
425
|
} else {
|
|
435
426
|
this.On = false;
|
|
436
427
|
this.accessory.context.On = this.On;
|
|
437
|
-
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}`);
|
|
438
429
|
}
|
|
439
430
|
|
|
440
|
-
this.BatteryLevel = Number(this.
|
|
431
|
+
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
441
432
|
if (this.BatteryLevel < 10) {
|
|
442
433
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
443
434
|
} else {
|
|
@@ -461,6 +452,18 @@ export class Bot {
|
|
|
461
452
|
}
|
|
462
453
|
}
|
|
463
454
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
455
|
+
|
|
456
|
+
// Battery
|
|
457
|
+
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
458
|
+
if (this.BatteryLevel < 10) {
|
|
459
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
460
|
+
} else {
|
|
461
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
462
|
+
}
|
|
463
|
+
if (Number.isNaN(this.BatteryLevel)) {
|
|
464
|
+
this.BatteryLevel = 100;
|
|
465
|
+
}
|
|
466
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
464
467
|
}
|
|
465
468
|
|
|
466
469
|
/**
|
|
@@ -502,28 +505,26 @@ export class Bot {
|
|
|
502
505
|
.then(async () => {
|
|
503
506
|
// Set an event hander
|
|
504
507
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
505
|
-
this.address = ad.address;
|
|
506
508
|
this.debugLog(
|
|
507
509
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
508
|
-
` BLE Address Found: ${
|
|
510
|
+
` BLE Address Found: ${ad.address}`,
|
|
509
511
|
);
|
|
510
|
-
this.
|
|
511
|
-
this.
|
|
512
|
-
this.
|
|
513
|
-
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;
|
|
514
515
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
515
516
|
this.debugLog(
|
|
516
517
|
`${this.device.deviceType}: ${this.accessory.displayName}, model: ${ad.serviceData.model}, modelName: ` +
|
|
517
518
|
`${ad.serviceData.modelName}, mode: ${ad.serviceData.mode}, state: ${ad.serviceData.state}, battery: ${ad.serviceData.battery}`,
|
|
518
519
|
);
|
|
519
520
|
|
|
520
|
-
if (
|
|
521
|
-
this.
|
|
522
|
-
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}`);
|
|
523
524
|
await this.stopScanning(switchbot);
|
|
524
525
|
} else {
|
|
525
|
-
this.
|
|
526
|
-
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}`);
|
|
527
528
|
}
|
|
528
529
|
};
|
|
529
530
|
// Wait
|
|
@@ -552,14 +553,20 @@ export class Bot {
|
|
|
552
553
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
553
554
|
headers: this.platform.generateHeaders(),
|
|
554
555
|
});
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
556
|
+
if (statusCode === 200) {
|
|
557
|
+
const deviceStatus: any = await body.json();
|
|
558
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
559
|
+
this.statusCode(statusCode);
|
|
560
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
561
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
562
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
563
|
+
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
564
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
565
|
+
this.openAPIparseStatus();
|
|
566
|
+
this.updateHomeKitCharacteristics();
|
|
567
|
+
} else {
|
|
568
|
+
this.statusCode(statusCode);
|
|
569
|
+
}
|
|
563
570
|
} catch (e: any) {
|
|
564
571
|
this.apiError(e);
|
|
565
572
|
this.errorLog(
|
|
@@ -712,7 +719,7 @@ export class Bot {
|
|
|
712
719
|
method: 'POST',
|
|
713
720
|
headers: this.platform.generateHeaders(),
|
|
714
721
|
});
|
|
715
|
-
const deviceStatus = await body.json();
|
|
722
|
+
const deviceStatus: any = await body.json();
|
|
716
723
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
717
724
|
this.statusCode(statusCode);
|
|
718
725
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -986,21 +993,30 @@ export class Bot {
|
|
|
986
993
|
}
|
|
987
994
|
}
|
|
988
995
|
this.accessory.context.On = this.On;
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
996
|
+
// Battery
|
|
997
|
+
if (this.BatteryLevel === undefined) {
|
|
998
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
999
|
+
} else {
|
|
1000
|
+
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
1001
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
1002
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
1003
|
+
}
|
|
1004
|
+
if (this.StatusLowBattery === undefined) {
|
|
1005
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
1006
|
+
} else {
|
|
1007
|
+
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
1008
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
1009
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
1010
|
+
}
|
|
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}`);
|
|
1004
1020
|
}
|
|
1005
1021
|
}
|
|
1006
1022
|
|
|
@@ -1105,7 +1121,7 @@ export class Bot {
|
|
|
1105
1121
|
|
|
1106
1122
|
async stopScanning(switchbot: any) {
|
|
1107
1123
|
await switchbot.stopScan();
|
|
1108
|
-
if (this.
|
|
1124
|
+
if (this.BLE_IsConnected) {
|
|
1109
1125
|
await this.BLEparseStatus();
|
|
1110
1126
|
await this.updateHomeKitCharacteristics();
|
|
1111
1127
|
} else {
|
|
@@ -1289,10 +1305,8 @@ export class Bot {
|
|
|
1289
1305
|
} else {
|
|
1290
1306
|
this.outletService?.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
1291
1307
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
1295
|
-
}
|
|
1308
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
|
|
1309
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
1296
1310
|
}
|
|
1297
1311
|
|
|
1298
1312
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
@@ -1302,10 +1316,12 @@ export class Bot {
|
|
|
1302
1316
|
);
|
|
1303
1317
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1304
1318
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
1305
|
-
if (
|
|
1306
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1307
|
-
} else if (device.firmware) {
|
|
1319
|
+
if (device.firmware) {
|
|
1308
1320
|
FirmwareRevision = device.firmware;
|
|
1321
|
+
} else if (device.version) {
|
|
1322
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
1323
|
+
} if (accessory.context.FirmwareRevision) {
|
|
1324
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1309
1325
|
} else {
|
|
1310
1326
|
FirmwareRevision = this.platform.version;
|
|
1311
1327
|
}
|
|
@@ -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,21 +24,20 @@ export class CeilingLight {
|
|
|
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_Delay: serviceData['delay'];
|
|
36
|
+
BLE_On: serviceData['state'];
|
|
37
|
+
BLE_WifiRssi: serviceData['wifiRssi'];
|
|
33
38
|
|
|
34
39
|
// BLE Others
|
|
35
|
-
|
|
36
|
-
switchbot!: switchbot;
|
|
37
|
-
address!: ad['address'];
|
|
38
|
-
serviceData!: serviceData;
|
|
39
|
-
state: serviceData['state'];
|
|
40
|
-
delay: serviceData['delay'];
|
|
41
|
-
wifiRssi: serviceData['wifiRssi'];
|
|
40
|
+
BLE_IsConnected?: boolean;
|
|
42
41
|
|
|
43
42
|
// Config
|
|
44
43
|
set_minStep?: number;
|
|
@@ -251,7 +250,7 @@ export class CeilingLight {
|
|
|
251
250
|
async BLEparseStatus(): Promise<void> {
|
|
252
251
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
253
252
|
// State
|
|
254
|
-
switch (this.
|
|
253
|
+
switch (this.BLE_On) {
|
|
255
254
|
case 'on':
|
|
256
255
|
this.On = true;
|
|
257
256
|
break;
|
|
@@ -263,7 +262,7 @@ export class CeilingLight {
|
|
|
263
262
|
|
|
264
263
|
async openAPIparseStatus() {
|
|
265
264
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
266
|
-
switch (this.
|
|
265
|
+
switch (this.OpenAPI_On) {
|
|
267
266
|
case 'on':
|
|
268
267
|
this.On = true;
|
|
269
268
|
break;
|
|
@@ -273,13 +272,13 @@ export class CeilingLight {
|
|
|
273
272
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
274
273
|
|
|
275
274
|
// Brightness
|
|
276
|
-
this.Brightness = Number(this.
|
|
275
|
+
this.Brightness = Number(this.OpenAPI_Brightness);
|
|
277
276
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
278
277
|
|
|
279
278
|
// Color, Hue & Brightness
|
|
280
|
-
if (this.
|
|
281
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.
|
|
282
|
-
const [red, green, blue] = this.
|
|
279
|
+
if (this.OpenAPI_RGB) {
|
|
280
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.OpenAPI_RGB)}`);
|
|
281
|
+
const [red, green, blue] = this.OpenAPI_RGB!.split(':');
|
|
283
282
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
284
283
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
285
284
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
@@ -299,9 +298,9 @@ export class CeilingLight {
|
|
|
299
298
|
}
|
|
300
299
|
|
|
301
300
|
// ColorTemperature
|
|
302
|
-
if (!Number.isNaN(this.
|
|
303
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.
|
|
304
|
-
const mired = Math.round(1000000 / this.
|
|
301
|
+
if (!Number.isNaN(this.OpenAPI_ColorTemperature)) {
|
|
302
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.OpenAPI_ColorTemperature}`);
|
|
303
|
+
const mired = Math.round(1000000 / this.OpenAPI_ColorTemperature!);
|
|
305
304
|
|
|
306
305
|
this.ColorTemperature = Number(mired);
|
|
307
306
|
|
|
@@ -348,15 +347,13 @@ export class CeilingLight {
|
|
|
348
347
|
})
|
|
349
348
|
.then(async () => {
|
|
350
349
|
// Set an event hander
|
|
351
|
-
switchbot.onadvertisement = async (ad:
|
|
352
|
-
this.address = ad.address;
|
|
350
|
+
switchbot.onadvertisement = async (ad: ad) => {
|
|
353
351
|
this.debugLog(
|
|
354
352
|
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
355
|
-
` BLE Address Found: ${
|
|
353
|
+
` BLE Address Found: ${ad.address}`,
|
|
356
354
|
);
|
|
357
355
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
358
|
-
this.
|
|
359
|
-
//this.state = ad.serviceData.state;
|
|
356
|
+
this.BLE_On = ad.serviceData.state;
|
|
360
357
|
//this.delay = ad.serviceData.delay;
|
|
361
358
|
//this.timer = ad.serviceData.timer;
|
|
362
359
|
//this.syncUtcTime = ad.serviceData.syncUtcTime;
|
|
@@ -370,13 +367,13 @@ export class CeilingLight {
|
|
|
370
367
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
371
368
|
);*/
|
|
372
369
|
|
|
373
|
-
if (
|
|
374
|
-
this.
|
|
375
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
370
|
+
if (ad.serviceData) {
|
|
371
|
+
this.BLE_IsConnected = true;
|
|
372
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
376
373
|
await this.stopScanning(switchbot);
|
|
377
374
|
} else {
|
|
378
|
-
this.
|
|
379
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.
|
|
375
|
+
this.BLE_IsConnected = false;
|
|
376
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
380
377
|
}
|
|
381
378
|
};
|
|
382
379
|
// Wait
|
|
@@ -405,15 +402,16 @@ export class CeilingLight {
|
|
|
405
402
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
406
403
|
headers: this.platform.generateHeaders(),
|
|
407
404
|
});
|
|
408
|
-
const deviceStatus = await body.json();
|
|
405
|
+
const deviceStatus: any = await body.json();
|
|
409
406
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
410
407
|
this.statusCode(statusCode);
|
|
411
408
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
412
409
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
413
|
-
this.
|
|
414
|
-
this.
|
|
415
|
-
this.
|
|
416
|
-
this.
|
|
410
|
+
this.OpenAPI_On = deviceStatus.body.power;
|
|
411
|
+
this.OpenAPI_RGB = deviceStatus.body.color;
|
|
412
|
+
this.OpenAPI_Brightness = deviceStatus.body.brightness;
|
|
413
|
+
this.OpenAPI_ColorTemperature = deviceStatus.body.colorTemperature;
|
|
414
|
+
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
417
415
|
this.openAPIparseStatus();
|
|
418
416
|
this.updateHomeKitCharacteristics();
|
|
419
417
|
} catch (e: any) {
|
|
@@ -527,7 +525,7 @@ export class CeilingLight {
|
|
|
527
525
|
method: 'POST',
|
|
528
526
|
headers: this.platform.generateHeaders(),
|
|
529
527
|
});
|
|
530
|
-
const deviceStatus = await body.json();
|
|
528
|
+
const deviceStatus: any = await body.json();
|
|
531
529
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
532
530
|
this.statusCode(statusCode);
|
|
533
531
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
@@ -578,7 +576,7 @@ export class CeilingLight {
|
|
|
578
576
|
method: 'POST',
|
|
579
577
|
headers: this.platform.generateHeaders(),
|
|
580
578
|
});
|
|
581
|
-
const deviceStatus = await body.json();
|
|
579
|
+
const deviceStatus: any = await body.json();
|
|
582
580
|
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
583
581
|
this.statusCode(statusCode);
|
|
584
582
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
@@ -614,7 +612,7 @@ export class CeilingLight {
|
|
|
614
612
|
method: 'POST',
|
|
615
613
|
headers: this.platform.generateHeaders(),
|
|
616
614
|
});
|
|
617
|
-
const deviceStatus = await body.json();
|
|
615
|
+
const deviceStatus: any = await body.json();
|
|
618
616
|
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
619
617
|
this.statusCode(statusCode);
|
|
620
618
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
@@ -648,7 +646,7 @@ export class CeilingLight {
|
|
|
648
646
|
method: 'POST',
|
|
649
647
|
headers: this.platform.generateHeaders(),
|
|
650
648
|
});
|
|
651
|
-
const deviceStatus = await body.json();
|
|
649
|
+
const deviceStatus: any = await body.json();
|
|
652
650
|
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
653
651
|
this.statusCode(statusCode);
|
|
654
652
|
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
@@ -801,6 +799,16 @@ export class CeilingLight {
|
|
|
801
799
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
802
800
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
803
801
|
}
|
|
802
|
+
// FirmwareRevision
|
|
803
|
+
if (this.OpenAPI_FirmwareRevision === undefined) {
|
|
804
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.OpenAPI_FirmwareRevision}`);
|
|
805
|
+
} else {
|
|
806
|
+
this.accessory.context.OpenAPI_FirmwareRevision = this.OpenAPI_FirmwareRevision;
|
|
807
|
+
this.accessory.getService(this.platform.Service.AccessoryInformation)!
|
|
808
|
+
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.OpenAPI_FirmwareRevision);
|
|
809
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
810
|
+
+ `updateCharacteristic CurrentTemperature: ${this.OpenAPI_FirmwareRevision}`);
|
|
811
|
+
}
|
|
804
812
|
}
|
|
805
813
|
|
|
806
814
|
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
@@ -815,7 +823,7 @@ export class CeilingLight {
|
|
|
815
823
|
|
|
816
824
|
async stopScanning(switchbot: any) {
|
|
817
825
|
await switchbot.stopScan();
|
|
818
|
-
if (this.
|
|
826
|
+
if (this.BLE_IsConnected) {
|
|
819
827
|
await this.BLEparseStatus();
|
|
820
828
|
await this.updateHomeKitCharacteristics();
|
|
821
829
|
} else {
|
|
@@ -964,10 +972,12 @@ export class CeilingLight {
|
|
|
964
972
|
);
|
|
965
973
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
966
974
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
967
|
-
if (
|
|
968
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
969
|
-
} else if (device.firmware) {
|
|
975
|
+
if (device.firmware) {
|
|
970
976
|
FirmwareRevision = device.firmware;
|
|
977
|
+
} else if (device.version) {
|
|
978
|
+
FirmwareRevision = JSON.stringify(device.version);
|
|
979
|
+
} else if (accessory.context.FirmwareRevision) {
|
|
980
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
971
981
|
} else {
|
|
972
982
|
FirmwareRevision = this.platform.version;
|
|
973
983
|
}
|