@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.10
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/README.md +16 -0
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +224 -370
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +197 -221
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +214 -292
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +335 -421
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +121 -200
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +20 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +229 -403
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +41 -22
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +212 -181
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +204 -249
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +107 -233
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +193 -235
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +92 -159
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +288 -370
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +172 -219
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +94 -160
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +95 -157
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +85 -144
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +100 -127
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +172 -259
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +106 -131
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +2 -3
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +2 -3
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +2 -3
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +2 -3
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +5 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +2 -3
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +2 -3
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +2 -3
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -3
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -3
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +102 -86
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -190
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +11 -11
- package/src/device/blindtilt.ts +254 -376
- package/src/device/bot.ts +209 -224
- package/src/device/ceilinglight.ts +227 -297
- package/src/device/colorbulb.ts +345 -435
- package/src/device/contact.ts +139 -200
- package/src/device/curtain.ts +254 -414
- package/src/device/device.ts +221 -190
- package/src/device/fan.ts +222 -253
- package/src/device/hub.ts +127 -248
- package/src/device/humidifier.ts +217 -246
- package/src/device/iosensor.ts +115 -168
- package/src/device/lightstrip.ts +303 -380
- package/src/device/lock.ts +188 -224
- package/src/device/meter.ts +117 -179
- package/src/device/meterplus.ts +118 -176
- package/src/device/motion.ts +100 -146
- package/src/device/plug.ts +111 -131
- package/src/device/robotvacuumcleaner.ts +191 -258
- package/src/device/waterdetector.ts +124 -141
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/airpurifier.ts +4 -4
- package/src/irdevice/camera.ts +4 -4
- package/src/irdevice/fan.ts +4 -4
- package/src/irdevice/irdevice.ts +8 -2
- package/src/irdevice/light.ts +4 -4
- package/src/irdevice/other.ts +4 -4
- package/src/irdevice/tv.ts +4 -4
- package/src/irdevice/vacuumcleaner.ts +4 -4
- package/src/irdevice/waterheater.ts +4 -4
- package/src/platform.ts +104 -87
- package/src/settings.ts +30 -238
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
package/dist/device/bot.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* bot.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
-
import {
|
|
7
|
-
import { debounceTime, skipWhile, take, tap } from 'rxjs
|
|
6
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
7
|
+
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
8
8
|
/**
|
|
9
9
|
* Platform Accessory
|
|
10
10
|
* An instance of this class is created for each accessory your platform registers
|
|
@@ -66,7 +66,7 @@ export class Bot extends deviceBase {
|
|
|
66
66
|
On: accessory.context.On ?? false,
|
|
67
67
|
};
|
|
68
68
|
accessory.context.Switch = this.Switch;
|
|
69
|
-
this.
|
|
69
|
+
this.debugLog('Displaying as Switch');
|
|
70
70
|
// Initialize Switch Characteristics
|
|
71
71
|
this.Switch.Service
|
|
72
72
|
.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
|
|
@@ -96,7 +96,7 @@ export class Bot extends deviceBase {
|
|
|
96
96
|
On: accessory.context.On ?? false,
|
|
97
97
|
};
|
|
98
98
|
accessory.context.GarageDoor = this.GarageDoor;
|
|
99
|
-
this.
|
|
99
|
+
this.debugLog('Displaying as Garage Door Opener');
|
|
100
100
|
// Initialize GarageDoor Characteristics
|
|
101
101
|
this.GarageDoor.Service
|
|
102
102
|
.setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
|
|
@@ -131,7 +131,7 @@ export class Bot extends deviceBase {
|
|
|
131
131
|
On: accessory.context.On ?? false,
|
|
132
132
|
};
|
|
133
133
|
accessory.context.Door = this.Door;
|
|
134
|
-
this.
|
|
134
|
+
this.debugLog('Displaying as Door');
|
|
135
135
|
// Initialize Door Characteristics
|
|
136
136
|
this.Door.Service
|
|
137
137
|
.setCharacteristic(this.hap.Characteristic.Name, this.Door.Name)
|
|
@@ -166,7 +166,7 @@ export class Bot extends deviceBase {
|
|
|
166
166
|
On: accessory.context.On ?? false,
|
|
167
167
|
};
|
|
168
168
|
accessory.context.Window = this.Window;
|
|
169
|
-
this.
|
|
169
|
+
this.debugLog('Displaying as Window');
|
|
170
170
|
// Initialize Window Characteristics
|
|
171
171
|
this.Window.Service
|
|
172
172
|
.setCharacteristic(this.hap.Characteristic.Name, this.Window.Name)
|
|
@@ -201,7 +201,7 @@ export class Bot extends deviceBase {
|
|
|
201
201
|
On: accessory.context.On ?? false,
|
|
202
202
|
};
|
|
203
203
|
accessory.context.WindowCovering = this.WindowCovering;
|
|
204
|
-
this.
|
|
204
|
+
this.debugLog('Displaying as Window Covering');
|
|
205
205
|
// Initialize WindowCovering Characteristics
|
|
206
206
|
this.WindowCovering.Service
|
|
207
207
|
.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
|
|
@@ -236,7 +236,7 @@ export class Bot extends deviceBase {
|
|
|
236
236
|
On: accessory.context.On ?? false,
|
|
237
237
|
};
|
|
238
238
|
accessory.context.LockMechanism = this.LockMechanism;
|
|
239
|
-
this.
|
|
239
|
+
this.debugLog('Displaying as Lock');
|
|
240
240
|
// Initialize Lock Characteristics
|
|
241
241
|
this.LockMechanism.Service
|
|
242
242
|
.setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
|
|
@@ -265,7 +265,7 @@ export class Bot extends deviceBase {
|
|
|
265
265
|
On: accessory.context.On ?? false,
|
|
266
266
|
};
|
|
267
267
|
accessory.context.Faucet = this.Faucet;
|
|
268
|
-
this.
|
|
268
|
+
this.debugLog('Displaying as Faucet');
|
|
269
269
|
// Initialize Faucet Characteristics
|
|
270
270
|
this.Faucet.Service
|
|
271
271
|
.setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
|
|
@@ -294,7 +294,7 @@ export class Bot extends deviceBase {
|
|
|
294
294
|
On: accessory.context.On ?? false,
|
|
295
295
|
};
|
|
296
296
|
accessory.context.Fan = this.Fan;
|
|
297
|
-
this.
|
|
297
|
+
this.debugLog('Displaying as Fan');
|
|
298
298
|
// Initialize Fan Characteristics
|
|
299
299
|
this.Fan.Service
|
|
300
300
|
.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
|
|
@@ -324,7 +324,7 @@ export class Bot extends deviceBase {
|
|
|
324
324
|
On: accessory.context.On ?? false,
|
|
325
325
|
};
|
|
326
326
|
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch;
|
|
327
|
-
this.
|
|
327
|
+
this.debugLog('Displaying as Stateful Programmable Switch');
|
|
328
328
|
// Initialize StatefulProgrammableSwitch Characteristics
|
|
329
329
|
this.StatefulProgrammableSwitch.Service
|
|
330
330
|
.setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
|
|
@@ -353,7 +353,7 @@ export class Bot extends deviceBase {
|
|
|
353
353
|
On: accessory.context.On ?? false,
|
|
354
354
|
};
|
|
355
355
|
accessory.context.Outlet = this.Outlet;
|
|
356
|
-
this.
|
|
356
|
+
this.debugLog('Displaying as Outlet');
|
|
357
357
|
// Initialize Outlet Characteristics
|
|
358
358
|
this.Outlet.Service
|
|
359
359
|
.setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
|
|
@@ -377,14 +377,14 @@ export class Bot extends deviceBase {
|
|
|
377
377
|
this.refreshStatus();
|
|
378
378
|
// Retrieve initial values and updateHomekit
|
|
379
379
|
this.updateHomeKitCharacteristics();
|
|
380
|
+
// regisiter webhook event handler
|
|
381
|
+
this.registerWebhook();
|
|
380
382
|
// Start an update interval
|
|
381
383
|
interval(this.deviceRefreshRate * 1000)
|
|
382
384
|
.pipe(skipWhile(() => this.botUpdateInProgress))
|
|
383
385
|
.subscribe(async () => {
|
|
384
386
|
await this.refreshStatus();
|
|
385
387
|
});
|
|
386
|
-
// regisiter webhook event handler
|
|
387
|
-
this.registerWebhook(accessory, device);
|
|
388
388
|
// Watch for Bot change events
|
|
389
389
|
// We put in a debounce of 1000ms so we don't make duplicate calls
|
|
390
390
|
this.doBotUpdate
|
|
@@ -405,9 +405,8 @@ export class Bot extends deviceBase {
|
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
catch (e) {
|
|
408
|
-
this.apiError(e);
|
|
409
|
-
this.errorLog(
|
|
410
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
408
|
+
await this.apiError(e);
|
|
409
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
411
410
|
}
|
|
412
411
|
this.botUpdateInProgress = false;
|
|
413
412
|
});
|
|
@@ -416,40 +415,33 @@ export class Bot extends deviceBase {
|
|
|
416
415
|
* Parse the device status from the SwitchBotBLE API
|
|
417
416
|
*/
|
|
418
417
|
async BLEparseStatus(serviceData) {
|
|
419
|
-
this.debugLog(
|
|
418
|
+
await this.debugLog('BLEparseStatus');
|
|
420
419
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
421
420
|
if (serviceData.mode) {
|
|
422
421
|
this.accessory.context.On = await this.getOn();
|
|
423
422
|
if (this.getOn() === undefined) {
|
|
424
423
|
this.setOn(Boolean(serviceData.state));
|
|
425
424
|
}
|
|
426
|
-
this.debugLog(
|
|
427
|
-
+ ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
425
|
+
this.debugLog(`Switch Mode, mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
428
426
|
}
|
|
429
427
|
else {
|
|
430
428
|
this.setOn(false);
|
|
431
429
|
this.accessory.context.On = await this.getOn();
|
|
432
|
-
this.debugLog(
|
|
433
|
-
+ ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
430
|
+
this.debugLog(`Press Mode, mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
434
431
|
}
|
|
432
|
+
// BatteryLevel
|
|
435
433
|
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
443
|
-
this.Battery.BatteryLevel = 100;
|
|
444
|
-
}
|
|
445
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
446
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
434
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
435
|
+
// StatusLowBattery
|
|
436
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
437
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
438
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
447
439
|
}
|
|
448
440
|
/**
|
|
449
441
|
* Parse the device status from the SwitchBot OpenAPI
|
|
450
442
|
*/
|
|
451
443
|
async openAPIparseStatus(deviceStatus) {
|
|
452
|
-
this.debugLog(
|
|
444
|
+
await this.debugLog('openAPIparseStatus');
|
|
453
445
|
if (this.botMode === 'press') {
|
|
454
446
|
this.setOn(false);
|
|
455
447
|
this.accessory.context.On = await this.getOn();
|
|
@@ -460,25 +452,19 @@ export class Bot extends deviceBase {
|
|
|
460
452
|
this.setOn(false);
|
|
461
453
|
}
|
|
462
454
|
}
|
|
463
|
-
this.debugLog(
|
|
464
|
-
// Battery
|
|
465
|
-
this.Battery.BatteryLevel = Number(deviceStatus.
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
473
|
-
this.Battery.BatteryLevel = 100;
|
|
474
|
-
}
|
|
475
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
476
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
455
|
+
await this.debugLog(`On: ${this.accessory.context.On}`);
|
|
456
|
+
// Battery Level
|
|
457
|
+
this.Battery.BatteryLevel = Number(deviceStatus.battery);
|
|
458
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
459
|
+
// StatusLowBattery
|
|
460
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
461
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
462
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
477
463
|
// Firmware Version
|
|
478
|
-
const version = deviceStatus.
|
|
479
|
-
this.debugLog(
|
|
480
|
-
if (deviceStatus.
|
|
481
|
-
const deviceVersion = version
|
|
464
|
+
const version = deviceStatus.version.toString();
|
|
465
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
466
|
+
if (deviceStatus.version) {
|
|
467
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
482
468
|
this.accessory
|
|
483
469
|
.getService(this.hap.Service.AccessoryInformation)
|
|
484
470
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -486,15 +472,35 @@ export class Bot extends deviceBase {
|
|
|
486
472
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
487
473
|
.updateValue(deviceVersion);
|
|
488
474
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
489
|
-
this.
|
|
475
|
+
await this.debugLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
490
476
|
}
|
|
491
477
|
}
|
|
478
|
+
async parseStatusWebhook(context) {
|
|
479
|
+
await this.debugLog('parseStatusWebhook');
|
|
480
|
+
const getOn = await this.getOn();
|
|
481
|
+
await this.debugLog(`(power, battery, deviceMode) = Webhook:(${context.power}, ${context.battery}, ${context.deviceMode}),`
|
|
482
|
+
+ ` current:(${getOn}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
483
|
+
// On
|
|
484
|
+
const setOn = context.power === 'on' ? true : false;
|
|
485
|
+
await this.setOn(setOn);
|
|
486
|
+
await this.debugLog(`On: ${setOn}`);
|
|
487
|
+
// BatteryLevel
|
|
488
|
+
this.Battery.BatteryLevel = context.battery;
|
|
489
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
490
|
+
// StatusLowBattery
|
|
491
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
492
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
493
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
494
|
+
// Mode
|
|
495
|
+
this.botMode = context.deviceMode;
|
|
496
|
+
await this.debugLog(`Mode: ${this.botMode}`);
|
|
497
|
+
}
|
|
492
498
|
/**
|
|
493
499
|
* Asks the SwitchBot API for the latest device information
|
|
494
500
|
*/
|
|
495
501
|
async refreshStatus() {
|
|
496
502
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
497
|
-
this.errorLog(
|
|
503
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
498
504
|
}
|
|
499
505
|
else if (this.BLE) {
|
|
500
506
|
await this.BLERefreshStatus();
|
|
@@ -504,12 +510,11 @@ export class Bot extends deviceBase {
|
|
|
504
510
|
}
|
|
505
511
|
else {
|
|
506
512
|
await this.offlineOff();
|
|
507
|
-
this.debugWarnLog(
|
|
508
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
513
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
509
514
|
}
|
|
510
515
|
}
|
|
511
516
|
async BLERefreshStatus() {
|
|
512
|
-
this.debugLog(
|
|
517
|
+
await this.debugLog('BLERefreshStatus');
|
|
513
518
|
const switchbot = await this.switchbotBLE();
|
|
514
519
|
if (switchbot === undefined) {
|
|
515
520
|
await this.BLERefreshConnection(switchbot);
|
|
@@ -520,63 +525,55 @@ export class Bot extends deviceBase {
|
|
|
520
525
|
// Start to monitor advertisement packets
|
|
521
526
|
const serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
522
527
|
// Update HomeKit
|
|
523
|
-
if (serviceData.model
|
|
528
|
+
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
524
529
|
await this.BLEparseStatus(serviceData);
|
|
525
530
|
await this.updateHomeKitCharacteristics();
|
|
526
531
|
}
|
|
527
532
|
else {
|
|
528
|
-
this.errorLog(
|
|
533
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
529
534
|
await this.BLERefreshConnection(switchbot);
|
|
530
535
|
}
|
|
531
536
|
})();
|
|
532
537
|
}
|
|
533
538
|
}
|
|
534
539
|
async openAPIRefreshStatus() {
|
|
535
|
-
this.debugLog(
|
|
540
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
536
541
|
try {
|
|
537
542
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
538
543
|
const deviceStatus = await body.json();
|
|
539
|
-
await this.
|
|
544
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
540
545
|
;
|
|
541
|
-
if (
|
|
542
|
-
await this.
|
|
543
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
546
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
547
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
548
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
544
549
|
await this.updateHomeKitCharacteristics();
|
|
545
550
|
}
|
|
546
551
|
else {
|
|
547
|
-
await this.
|
|
552
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
553
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
548
554
|
}
|
|
549
555
|
}
|
|
550
556
|
catch (e) {
|
|
551
|
-
this.apiError(e);
|
|
552
|
-
this.errorLog(
|
|
553
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
557
|
+
await this.apiError(e);
|
|
558
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
554
559
|
}
|
|
555
560
|
}
|
|
556
|
-
async registerWebhook(
|
|
557
|
-
if (device.webhook) {
|
|
558
|
-
this.debugLog(
|
|
559
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
561
|
+
async registerWebhook() {
|
|
562
|
+
if (this.device.webhook) {
|
|
563
|
+
await this.debugLog('is listening webhook.');
|
|
564
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
560
565
|
try {
|
|
561
|
-
this.debugLog(
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const On = await this.getOn();
|
|
565
|
-
const { BatteryLevel } = this.Battery;
|
|
566
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (power, battery, deviceMode) = Webhook:(${power}, ${battery}, ${deviceMode}),`
|
|
567
|
-
+ ` current:(${On}, ${BatteryLevel}, ${botMode})`);
|
|
568
|
-
await this.setOn(power);
|
|
569
|
-
this.Battery.BatteryLevel = battery;
|
|
570
|
-
this.botMode = deviceMode;
|
|
571
|
-
this.updateHomeKitCharacteristics();
|
|
566
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
567
|
+
await this.parseStatusWebhook(context);
|
|
568
|
+
await this.updateHomeKitCharacteristics();
|
|
572
569
|
}
|
|
573
570
|
catch (e) {
|
|
574
|
-
this.errorLog(
|
|
571
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
575
572
|
}
|
|
576
573
|
};
|
|
577
574
|
}
|
|
578
575
|
else {
|
|
579
|
-
this.debugLog(
|
|
576
|
+
await this.debugLog('is not listening webhook.');
|
|
580
577
|
}
|
|
581
578
|
}
|
|
582
579
|
/**
|
|
@@ -588,7 +585,7 @@ export class Bot extends deviceBase {
|
|
|
588
585
|
*/
|
|
589
586
|
async pushChanges() {
|
|
590
587
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
591
|
-
this.errorLog(
|
|
588
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
592
589
|
}
|
|
593
590
|
else if (this.BLE) {
|
|
594
591
|
await this.BLEpushChanges();
|
|
@@ -598,8 +595,7 @@ export class Bot extends deviceBase {
|
|
|
598
595
|
}
|
|
599
596
|
else {
|
|
600
597
|
await this.offlineOff();
|
|
601
|
-
this.debugWarnLog(
|
|
602
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
598
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
603
599
|
}
|
|
604
600
|
// Refresh the status from the API
|
|
605
601
|
interval(15000)
|
|
@@ -610,27 +606,24 @@ export class Bot extends deviceBase {
|
|
|
610
606
|
});
|
|
611
607
|
}
|
|
612
608
|
async BLEpushChanges() {
|
|
613
|
-
this.debugLog(
|
|
609
|
+
await this.debugLog('BLEpushChanges');
|
|
614
610
|
const On = await this.getOn();
|
|
615
611
|
if (On !== this.accessory.context.On || this.allowPush) {
|
|
616
|
-
this.debugLog(
|
|
617
|
-
const switchbot = await this.platform.connectBLE();
|
|
618
|
-
// Convert to BLE Address
|
|
612
|
+
this.debugLog(`BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
613
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
619
614
|
await this.convertBLEAddress();
|
|
620
615
|
//if (switchbot !== false) {
|
|
621
616
|
if (this.botMode === 'press') {
|
|
622
|
-
this.debugLog(
|
|
617
|
+
this.debugLog(`Bot Mode: ${this.botMode}`);
|
|
623
618
|
switchbot
|
|
624
619
|
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
625
620
|
.then(async (device_list) => {
|
|
626
|
-
this.infoLog(
|
|
621
|
+
this.infoLog(`On: ${On}`);
|
|
627
622
|
return await device_list[0].press({ id: this.device.bleMac });
|
|
628
623
|
})
|
|
629
|
-
.then(() => {
|
|
630
|
-
this.
|
|
631
|
-
this.
|
|
632
|
-
+ `On: ${On} sent over BLE, sent successfully`);
|
|
633
|
-
this.accessory.context.On = On;
|
|
624
|
+
.then(async () => {
|
|
625
|
+
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
626
|
+
await this.updateHomeKitCharacteristics();
|
|
634
627
|
setTimeout(() => {
|
|
635
628
|
if (this.botDeviceType === 'switch') {
|
|
636
629
|
this.Switch?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
@@ -638,22 +631,21 @@ export class Bot extends deviceBase {
|
|
|
638
631
|
else {
|
|
639
632
|
this.Outlet?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
640
633
|
}
|
|
641
|
-
this.debugLog(
|
|
634
|
+
this.debugLog(`On: ${On}, Switch Timeout`);
|
|
642
635
|
}, 500);
|
|
643
636
|
})
|
|
644
637
|
.catch(async (e) => {
|
|
645
|
-
this.apiError(e);
|
|
646
|
-
this.errorLog(
|
|
647
|
-
+ ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
|
|
638
|
+
await this.apiError(e);
|
|
639
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
648
640
|
await this.BLEPushConnection();
|
|
649
641
|
});
|
|
650
642
|
}
|
|
651
643
|
else if (this.botMode === 'switch') {
|
|
652
|
-
this.debugLog(
|
|
644
|
+
this.debugLog(`Press Mode: ${this.botMode}`);
|
|
653
645
|
switchbot
|
|
654
646
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
655
647
|
.then(async (device_list) => {
|
|
656
|
-
this.infoLog(
|
|
648
|
+
this.infoLog(`On: ${On}`);
|
|
657
649
|
return await this.retryBLE({
|
|
658
650
|
max: await this.maxRetryBLE(),
|
|
659
651
|
fn: async () => {
|
|
@@ -666,30 +658,29 @@ export class Bot extends deviceBase {
|
|
|
666
658
|
},
|
|
667
659
|
});
|
|
668
660
|
})
|
|
669
|
-
.then(() => {
|
|
670
|
-
this.
|
|
671
|
-
this.
|
|
661
|
+
.then(async () => {
|
|
662
|
+
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
663
|
+
await this.updateHomeKitCharacteristics();
|
|
672
664
|
})
|
|
673
665
|
.catch(async (e) => {
|
|
674
|
-
this.apiError(e);
|
|
675
|
-
this.errorLog(
|
|
676
|
-
+ ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
|
|
666
|
+
await this.apiError(e);
|
|
667
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
677
668
|
await this.BLEPushConnection();
|
|
678
669
|
});
|
|
679
670
|
}
|
|
680
671
|
else {
|
|
681
|
-
this.errorLog(
|
|
672
|
+
await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`);
|
|
682
673
|
}
|
|
683
674
|
}
|
|
684
675
|
else {
|
|
685
|
-
this.debugLog(
|
|
676
|
+
await this.debugLog(`No Changes (BLEpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
686
677
|
}
|
|
687
678
|
}
|
|
688
679
|
async openAPIpushChanges() {
|
|
689
|
-
this.debugLog(
|
|
680
|
+
await this.debugLog('openAPIpushChanges');
|
|
690
681
|
let On = await this.getOn();
|
|
691
682
|
if (this.multiPressCount > 0) {
|
|
692
|
-
this.debugLog(`${this.
|
|
683
|
+
await this.debugLog(`${this.multiPressCount} request(s) queued.`);
|
|
693
684
|
On = true;
|
|
694
685
|
}
|
|
695
686
|
if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
|
|
@@ -697,33 +688,33 @@ export class Bot extends deviceBase {
|
|
|
697
688
|
if (this.botMode === 'switch' && On) {
|
|
698
689
|
command = 'turnOn';
|
|
699
690
|
On = true;
|
|
700
|
-
this.debugLog(
|
|
691
|
+
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
701
692
|
}
|
|
702
693
|
else if (this.botMode === 'switch' && !On) {
|
|
703
694
|
command = 'turnOff';
|
|
704
695
|
On = false;
|
|
705
|
-
this.debugLog(
|
|
696
|
+
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
706
697
|
}
|
|
707
698
|
else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
708
699
|
command = 'press';
|
|
709
|
-
this.debugLog(
|
|
700
|
+
await this.debugLog('Press Mode');
|
|
710
701
|
On = false;
|
|
711
702
|
}
|
|
712
703
|
else {
|
|
713
|
-
throw new Error(
|
|
704
|
+
throw new Error('Device Parameters not set for this Bot.');
|
|
714
705
|
}
|
|
715
706
|
const bodyChange = JSON.stringify({
|
|
716
707
|
command: `${command}`,
|
|
717
708
|
parameter: 'default',
|
|
718
709
|
commandType: 'command',
|
|
719
710
|
});
|
|
720
|
-
this.debugLog(
|
|
711
|
+
this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
721
712
|
try {
|
|
722
713
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
723
714
|
const deviceStatus = await body.json();
|
|
724
|
-
await this.
|
|
725
|
-
if (
|
|
726
|
-
await this.
|
|
715
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
716
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
717
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
727
718
|
await this.updateHomeKitCharacteristics();
|
|
728
719
|
}
|
|
729
720
|
else {
|
|
@@ -733,21 +724,19 @@ export class Bot extends deviceBase {
|
|
|
733
724
|
if (this.device.bot?.mode === 'multipress') {
|
|
734
725
|
this.multiPressCount--;
|
|
735
726
|
if (this.multiPressCount > 0) {
|
|
736
|
-
this.debugLog(
|
|
727
|
+
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
737
728
|
On = true;
|
|
738
|
-
this.openAPIpushChanges();
|
|
729
|
+
await this.openAPIpushChanges();
|
|
739
730
|
}
|
|
740
731
|
}
|
|
741
732
|
}
|
|
742
733
|
catch (e) {
|
|
743
|
-
this.apiError(e);
|
|
744
|
-
this.errorLog(
|
|
745
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
734
|
+
await this.apiError(e);
|
|
735
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
746
736
|
}
|
|
747
737
|
}
|
|
748
738
|
else {
|
|
749
|
-
this.debugLog(
|
|
750
|
-
+ ` On: ${On}, OnCached: ${this.accessory.context.On}`);
|
|
739
|
+
await this.debugLog(`No Changes (openAPIpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
751
740
|
}
|
|
752
741
|
}
|
|
753
742
|
/**
|
|
@@ -756,7 +745,8 @@ export class Bot extends deviceBase {
|
|
|
756
745
|
async OnSet(value) {
|
|
757
746
|
if (this.botDeviceType === 'garagedoor') {
|
|
758
747
|
if (this.GarageDoor) {
|
|
759
|
-
this.
|
|
748
|
+
await this.debugLog(`Set TargetDoorState: ${value}`);
|
|
749
|
+
this.infoLog(`Set TargetDoorState: ${value}`);
|
|
760
750
|
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
761
751
|
await this.setOn(false);
|
|
762
752
|
this.GarageDoor.On = false;
|
|
@@ -769,7 +759,7 @@ export class Bot extends deviceBase {
|
|
|
769
759
|
}
|
|
770
760
|
else if (this.botDeviceType === 'door') {
|
|
771
761
|
if (this.Door) {
|
|
772
|
-
this.
|
|
762
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
773
763
|
if (value === 0) {
|
|
774
764
|
await this.setOn(false);
|
|
775
765
|
this.Door.On = false;
|
|
@@ -782,7 +772,7 @@ export class Bot extends deviceBase {
|
|
|
782
772
|
}
|
|
783
773
|
else if (this.botDeviceType === 'window') {
|
|
784
774
|
if (this.Window) {
|
|
785
|
-
this.
|
|
775
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
786
776
|
if (value === 0) {
|
|
787
777
|
await this.setOn(false);
|
|
788
778
|
this.Window.On = false;
|
|
@@ -795,7 +785,7 @@ export class Bot extends deviceBase {
|
|
|
795
785
|
}
|
|
796
786
|
else if (this.botDeviceType === 'windowcovering') {
|
|
797
787
|
if (this.WindowCovering) {
|
|
798
|
-
this.
|
|
788
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
799
789
|
if (value === 0) {
|
|
800
790
|
await this.setOn(false);
|
|
801
791
|
this.WindowCovering.On = false;
|
|
@@ -808,7 +798,7 @@ export class Bot extends deviceBase {
|
|
|
808
798
|
}
|
|
809
799
|
else if (this.botDeviceType === 'lock') {
|
|
810
800
|
if (this.LockMechanism) {
|
|
811
|
-
this.
|
|
801
|
+
await this.debugLog(`Set LockTargetState: ${value}`);
|
|
812
802
|
if (value === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
813
803
|
await this.setOn(false);
|
|
814
804
|
this.LockMechanism.On = false;
|
|
@@ -821,7 +811,7 @@ export class Bot extends deviceBase {
|
|
|
821
811
|
}
|
|
822
812
|
else if (this.botDeviceType === 'faucet') {
|
|
823
813
|
if (this.Faucet) {
|
|
824
|
-
this.
|
|
814
|
+
await this.debugLog(`Set Active: ${value}`);
|
|
825
815
|
if (value === this.hap.Characteristic.Active.INACTIVE) {
|
|
826
816
|
await this.setOn(false);
|
|
827
817
|
this.Faucet.On = false;
|
|
@@ -834,7 +824,7 @@ export class Bot extends deviceBase {
|
|
|
834
824
|
}
|
|
835
825
|
else if (this.botDeviceType === 'stateful') {
|
|
836
826
|
if (this.StatefulProgrammableSwitch) {
|
|
837
|
-
this.
|
|
827
|
+
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
838
828
|
if (value === 0) {
|
|
839
829
|
await this.setOn(false);
|
|
840
830
|
this.StatefulProgrammableSwitch.On = false;
|
|
@@ -847,7 +837,7 @@ export class Bot extends deviceBase {
|
|
|
847
837
|
}
|
|
848
838
|
else if (this.botDeviceType === 'switch') {
|
|
849
839
|
if (this.Switch) {
|
|
850
|
-
this.
|
|
840
|
+
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
851
841
|
if (value === 0) {
|
|
852
842
|
await this.setOn(false);
|
|
853
843
|
this.Switch.On = false;
|
|
@@ -860,7 +850,7 @@ export class Bot extends deviceBase {
|
|
|
860
850
|
}
|
|
861
851
|
else {
|
|
862
852
|
if (this.Outlet) {
|
|
863
|
-
this.
|
|
853
|
+
await this.debugLog(`Set On: ${value}`);
|
|
864
854
|
await this.setOn(Boolean(value));
|
|
865
855
|
this.Outlet.On = value;
|
|
866
856
|
}
|
|
@@ -868,7 +858,7 @@ export class Bot extends deviceBase {
|
|
|
868
858
|
if (this.device.bot?.mode === 'multipress') {
|
|
869
859
|
if (value === true) {
|
|
870
860
|
this.multiPressCount++;
|
|
871
|
-
this.debugLog(
|
|
861
|
+
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
872
862
|
}
|
|
873
863
|
}
|
|
874
864
|
this.doBotUpdate.next();
|
|
@@ -880,216 +870,203 @@ export class Bot extends deviceBase {
|
|
|
880
870
|
// State
|
|
881
871
|
if (this.botDeviceType === 'garagedoor') {
|
|
882
872
|
if (this.GarageDoor?.On === undefined) {
|
|
883
|
-
this.debugLog(
|
|
873
|
+
await this.debugLog(`On: ${this.GarageDoor?.On}`);
|
|
884
874
|
}
|
|
885
875
|
else {
|
|
886
876
|
if (this.GarageDoor.On) {
|
|
887
877
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
|
|
888
878
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
|
|
889
|
-
this.debugLog(
|
|
890
|
-
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
879
|
+
await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
891
880
|
}
|
|
892
881
|
else {
|
|
893
882
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
894
883
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
895
|
-
this.debugLog(
|
|
896
|
-
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
884
|
+
await this.debugLog(`updateCharacteristicc TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
897
885
|
}
|
|
898
886
|
}
|
|
899
887
|
await this.setOn(Boolean(this.GarageDoor?.On));
|
|
900
|
-
this.debugLog(
|
|
888
|
+
await this.debugLog(`Garage Door On: ${this.GarageDoor?.On}`);
|
|
901
889
|
}
|
|
902
890
|
else if (this.botDeviceType === 'door') {
|
|
903
891
|
if (this.Door?.On === undefined) {
|
|
904
|
-
this.debugLog(
|
|
892
|
+
await this.debugLog(`On: ${this.Door?.On}`);
|
|
905
893
|
}
|
|
906
894
|
else {
|
|
907
895
|
if (this.Door.On) {
|
|
908
896
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
909
897
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
910
898
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
911
|
-
this.debugLog(
|
|
912
|
-
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
|
|
899
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
|
|
913
900
|
}
|
|
914
901
|
else {
|
|
915
902
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
916
903
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
917
904
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
918
|
-
this.debugLog(
|
|
919
|
-
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
|
|
905
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
|
|
920
906
|
}
|
|
921
907
|
}
|
|
922
908
|
await this.setOn(Boolean(this.Door?.On));
|
|
923
|
-
this.debugLog(
|
|
909
|
+
await this.debugLog(`Door On: ${this.Door?.On}`);
|
|
924
910
|
}
|
|
925
911
|
else if (this.botDeviceType === 'window') {
|
|
926
912
|
if (this.Window?.On === undefined) {
|
|
927
|
-
this.debugLog(
|
|
913
|
+
await this.debugLog(`On: ${this.Window?.On}`);
|
|
928
914
|
}
|
|
929
915
|
else {
|
|
930
916
|
if (this.Window.On) {
|
|
931
917
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
932
918
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
933
919
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
934
|
-
this.debugLog(
|
|
935
|
-
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
|
|
920
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
|
|
936
921
|
}
|
|
937
922
|
else {
|
|
938
923
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
939
924
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
940
925
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
941
|
-
this.debugLog(
|
|
942
|
-
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
|
|
926
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
|
|
943
927
|
}
|
|
944
928
|
}
|
|
945
929
|
await this.setOn(Boolean(this.Window?.On));
|
|
946
|
-
this.debugLog(
|
|
930
|
+
await this.debugLog(`Window On: ${this.Window?.On}`);
|
|
947
931
|
}
|
|
948
932
|
else if (this.botDeviceType === 'windowcovering') {
|
|
949
933
|
if (this.WindowCovering?.On === undefined) {
|
|
950
|
-
this.debugLog(
|
|
934
|
+
await this.debugLog(`On: ${this.WindowCovering?.On}`);
|
|
951
935
|
}
|
|
952
936
|
else {
|
|
953
937
|
if (this.WindowCovering.On) {
|
|
954
938
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
955
939
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
956
940
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
957
|
-
this.debugLog(
|
|
958
|
-
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
|
|
941
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
|
|
959
942
|
}
|
|
960
943
|
else {
|
|
961
944
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
962
945
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
963
946
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
964
|
-
this.debugLog(
|
|
965
|
-
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
|
|
947
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
|
|
966
948
|
}
|
|
967
949
|
}
|
|
968
950
|
await this.setOn(Boolean(this.WindowCovering?.On));
|
|
969
|
-
this.debugLog(
|
|
951
|
+
await this.debugLog(`Window Covering On: ${this.WindowCovering?.On}`);
|
|
970
952
|
}
|
|
971
953
|
else if (this.botDeviceType === 'lock') {
|
|
972
954
|
if (this.LockMechanism?.On === undefined) {
|
|
973
|
-
this.debugLog(
|
|
955
|
+
await this.debugLog(`On: ${this.LockMechanism?.On}`);
|
|
974
956
|
}
|
|
975
957
|
else {
|
|
976
958
|
if (this.LockMechanism.On) {
|
|
977
959
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
|
|
978
960
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
979
|
-
this.debugLog(
|
|
980
|
-
+ ` LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
|
|
961
|
+
await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
|
|
981
962
|
}
|
|
982
963
|
else {
|
|
983
964
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
|
|
984
965
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
|
|
985
|
-
this.debugLog(
|
|
986
|
-
+ ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
|
|
966
|
+
await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
|
|
987
967
|
}
|
|
988
968
|
}
|
|
989
969
|
await this.setOn(Boolean(this.LockMechanism?.On));
|
|
990
|
-
this.debugLog(
|
|
970
|
+
await this.debugLog(`Lock On: ${this.LockMechanism?.On}`);
|
|
991
971
|
}
|
|
992
972
|
else if (this.botDeviceType === 'faucet') {
|
|
993
973
|
if (this.Faucet?.On === undefined) {
|
|
994
|
-
this.debugLog(
|
|
974
|
+
await this.debugLog(`On: ${this.Faucet?.On}`);
|
|
995
975
|
}
|
|
996
976
|
else {
|
|
997
977
|
if (this.Faucet.On) {
|
|
998
978
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
999
|
-
this.debugLog(
|
|
979
|
+
await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
|
|
1000
980
|
}
|
|
1001
981
|
else {
|
|
1002
982
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
1003
|
-
this.debugLog(
|
|
983
|
+
await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
|
|
1004
984
|
}
|
|
1005
985
|
}
|
|
1006
986
|
await this.setOn(Boolean(this.Faucet?.On));
|
|
1007
|
-
this.debugLog(
|
|
987
|
+
await this.debugLog(`Faucet On: ${this.Faucet?.On}`);
|
|
1008
988
|
}
|
|
1009
989
|
else if (this.botDeviceType === 'fan') {
|
|
1010
990
|
if (this.Fan?.On === undefined) {
|
|
1011
|
-
this.debugLog(
|
|
991
|
+
await this.debugLog(`On: ${this.Fan?.On}`);
|
|
1012
992
|
}
|
|
1013
993
|
else {
|
|
1014
994
|
if (this.Fan.On) {
|
|
1015
995
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
|
|
1016
|
-
this.debugLog(
|
|
996
|
+
await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
|
|
1017
997
|
}
|
|
1018
998
|
else {
|
|
1019
999
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
|
|
1020
|
-
this.debugLog(
|
|
1000
|
+
await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
|
|
1021
1001
|
}
|
|
1022
1002
|
}
|
|
1023
1003
|
await this.setOn(Boolean(this.Fan?.On));
|
|
1024
|
-
this.debugLog(
|
|
1004
|
+
await this.debugLog(`Fan On: ${this.Fan?.On}`);
|
|
1025
1005
|
}
|
|
1026
1006
|
else if (this.botDeviceType === 'stateful') {
|
|
1027
1007
|
if (this.StatefulProgrammableSwitch?.On === undefined) {
|
|
1028
|
-
this.debugLog(
|
|
1008
|
+
await this.debugLog(`On: ${this.StatefulProgrammableSwitch?.On}`);
|
|
1029
1009
|
}
|
|
1030
1010
|
else {
|
|
1031
1011
|
if (this.StatefulProgrammableSwitch.On) {
|
|
1032
1012
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1033
1013
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
1034
|
-
this.debugLog(
|
|
1035
|
-
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch.On})`);
|
|
1014
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
|
|
1036
1015
|
}
|
|
1037
1016
|
else {
|
|
1038
1017
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1039
1018
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
1040
|
-
this.debugLog(
|
|
1041
|
-
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch.On})`);
|
|
1019
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
|
|
1042
1020
|
}
|
|
1043
1021
|
}
|
|
1044
1022
|
await this.setOn(Boolean(this.StatefulProgrammableSwitch?.On));
|
|
1045
|
-
this.debugLog(
|
|
1023
|
+
await this.debugLog(`StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
|
|
1046
1024
|
}
|
|
1047
1025
|
else if (this.botDeviceType === 'switch') {
|
|
1048
1026
|
if (this.Switch?.On === undefined) {
|
|
1049
|
-
this.debugLog(
|
|
1027
|
+
await this.debugLog(`On: ${this.Switch?.On}`);
|
|
1050
1028
|
}
|
|
1051
1029
|
else {
|
|
1052
1030
|
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
|
|
1053
|
-
this.debugLog(
|
|
1031
|
+
await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
|
|
1054
1032
|
}
|
|
1055
1033
|
await this.setOn(Boolean(this.Switch?.On));
|
|
1056
1034
|
}
|
|
1057
1035
|
else {
|
|
1058
1036
|
if (this.Outlet?.On === undefined) {
|
|
1059
|
-
this.debugLog(
|
|
1037
|
+
await this.debugLog(`On: ${this.Outlet?.On}`);
|
|
1060
1038
|
}
|
|
1061
1039
|
else {
|
|
1062
1040
|
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet.On);
|
|
1063
|
-
this.debugLog(
|
|
1041
|
+
await this.debugLog(`updateCharacteristic On: ${this.Outlet.On}`);
|
|
1064
1042
|
}
|
|
1065
1043
|
await this.setOn(Boolean(this.Outlet?.On));
|
|
1066
1044
|
}
|
|
1067
1045
|
this.accessory.context.On = await this.getOn();
|
|
1068
1046
|
// BatteryLevel
|
|
1069
1047
|
if (this.Battery.BatteryLevel === undefined) {
|
|
1070
|
-
this.debugLog(
|
|
1048
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1071
1049
|
}
|
|
1072
1050
|
else {
|
|
1073
1051
|
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
1074
1052
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
1075
|
-
this.debugLog(
|
|
1053
|
+
await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1076
1054
|
}
|
|
1077
1055
|
// StatusLowBattery
|
|
1078
1056
|
if (this.Battery.StatusLowBattery === undefined) {
|
|
1079
|
-
this.debugLog(
|
|
1057
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1080
1058
|
}
|
|
1081
1059
|
else {
|
|
1082
1060
|
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
1083
1061
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
1084
|
-
this.debugLog(
|
|
1085
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1062
|
+
await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1086
1063
|
}
|
|
1087
1064
|
}
|
|
1088
1065
|
async removeOutletService(accessory) {
|
|
1089
1066
|
// If outletService still present, then remove first
|
|
1090
1067
|
if (this.Outlet?.Service) {
|
|
1091
1068
|
this.Outlet.Service = this.accessory.getService(this.hap.Service.Outlet);
|
|
1092
|
-
this.warnLog(
|
|
1069
|
+
await this.warnLog('Removing Leftover Outlet Service');
|
|
1093
1070
|
accessory.removeService(this.Outlet.Service);
|
|
1094
1071
|
}
|
|
1095
1072
|
}
|
|
@@ -1097,7 +1074,7 @@ export class Bot extends deviceBase {
|
|
|
1097
1074
|
// If garageDoorService still present, then remove first
|
|
1098
1075
|
if (this.GarageDoor?.Service) {
|
|
1099
1076
|
this.GarageDoor.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener);
|
|
1100
|
-
this.warnLog(
|
|
1077
|
+
await this.warnLog('Removing Leftover Garage Door Service');
|
|
1101
1078
|
accessory.removeService(this.GarageDoor.Service);
|
|
1102
1079
|
}
|
|
1103
1080
|
}
|
|
@@ -1105,7 +1082,7 @@ export class Bot extends deviceBase {
|
|
|
1105
1082
|
// If doorService still present, then remove first
|
|
1106
1083
|
if (this.Door?.Service) {
|
|
1107
1084
|
this.Door.Service = this.accessory.getService(this.hap.Service.Door);
|
|
1108
|
-
this.warnLog(
|
|
1085
|
+
await this.warnLog('Removing Leftover Door Service');
|
|
1109
1086
|
accessory.removeService(this.Door.Service);
|
|
1110
1087
|
}
|
|
1111
1088
|
}
|
|
@@ -1113,7 +1090,7 @@ export class Bot extends deviceBase {
|
|
|
1113
1090
|
// If lockService still present, then remove first
|
|
1114
1091
|
if (this.LockMechanism?.Service) {
|
|
1115
1092
|
this.LockMechanism.Service = this.accessory.getService(this.hap.Service.LockMechanism);
|
|
1116
|
-
this.warnLog(
|
|
1093
|
+
this.warnLog('Removing Leftover Lock Service');
|
|
1117
1094
|
accessory.removeService(this.LockMechanism.Service);
|
|
1118
1095
|
}
|
|
1119
1096
|
}
|
|
@@ -1121,7 +1098,7 @@ export class Bot extends deviceBase {
|
|
|
1121
1098
|
// If faucetService still present, then remove first
|
|
1122
1099
|
if (this.Faucet?.Service) {
|
|
1123
1100
|
this.Faucet.Service = this.accessory.getService(this.hap.Service.Faucet);
|
|
1124
|
-
this.warnLog(
|
|
1101
|
+
await this.warnLog('Removing Leftover Faucet Service');
|
|
1125
1102
|
accessory.removeService(this.Faucet.Service);
|
|
1126
1103
|
}
|
|
1127
1104
|
}
|
|
@@ -1129,7 +1106,7 @@ export class Bot extends deviceBase {
|
|
|
1129
1106
|
// If fanService still present, then remove first
|
|
1130
1107
|
if (this.Fan?.Service) {
|
|
1131
1108
|
this.Fan.Service = this.accessory.getService(this.hap.Service.Fanv2);
|
|
1132
|
-
this.warnLog(
|
|
1109
|
+
this.warnLog('Removing Leftover Fan Service');
|
|
1133
1110
|
accessory.removeService(this.Fan.Service);
|
|
1134
1111
|
}
|
|
1135
1112
|
}
|
|
@@ -1137,7 +1114,7 @@ export class Bot extends deviceBase {
|
|
|
1137
1114
|
// If windowService still present, then remove first
|
|
1138
1115
|
if (this.Window?.Service) {
|
|
1139
1116
|
this.Window.Service = this.accessory.getService(this.hap.Service.Window);
|
|
1140
|
-
this.warnLog(
|
|
1117
|
+
await this.warnLog('Removing Leftover Window Service');
|
|
1141
1118
|
accessory.removeService(this.Window.Service);
|
|
1142
1119
|
}
|
|
1143
1120
|
}
|
|
@@ -1145,7 +1122,7 @@ export class Bot extends deviceBase {
|
|
|
1145
1122
|
// If windowCoveringService still present, then remove first
|
|
1146
1123
|
if (this.WindowCovering?.Service) {
|
|
1147
1124
|
this.WindowCovering.Service = this.accessory.getService(this.hap.Service.WindowCovering);
|
|
1148
|
-
this.warnLog(
|
|
1125
|
+
await this.warnLog('Removing Leftover Window Covering Service');
|
|
1149
1126
|
accessory.removeService(this.WindowCovering.Service);
|
|
1150
1127
|
}
|
|
1151
1128
|
}
|
|
@@ -1153,7 +1130,7 @@ export class Bot extends deviceBase {
|
|
|
1153
1130
|
// If statefulProgrammableSwitchService still present, then remove first
|
|
1154
1131
|
if (this.StatefulProgrammableSwitch?.Service) {
|
|
1155
1132
|
this.StatefulProgrammableSwitch.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch);
|
|
1156
|
-
this.warnLog(
|
|
1133
|
+
await this.warnLog('Removing Leftover Stateful Programmable Switch Service');
|
|
1157
1134
|
accessory.removeService(this.StatefulProgrammableSwitch.Service);
|
|
1158
1135
|
}
|
|
1159
1136
|
}
|
|
@@ -1161,7 +1138,7 @@ export class Bot extends deviceBase {
|
|
|
1161
1138
|
// If switchService still present, then remove first
|
|
1162
1139
|
if (this.Switch?.Service) {
|
|
1163
1140
|
this.Switch.Service = this.accessory.getService(this.hap.Service.Switch);
|
|
1164
|
-
this.warnLog(
|
|
1141
|
+
await this.warnLog('Removing Leftover Switch Service');
|
|
1165
1142
|
accessory.removeService(this.Switch.Service);
|
|
1166
1143
|
}
|
|
1167
1144
|
}
|
|
@@ -1255,39 +1232,39 @@ export class Bot extends deviceBase {
|
|
|
1255
1232
|
//Bot Device Type
|
|
1256
1233
|
if (!device.bot?.deviceType && this.accessory.context.deviceType) {
|
|
1257
1234
|
this.botDeviceType = this.accessory.context.deviceType;
|
|
1258
|
-
this.debugWarnLog(
|
|
1235
|
+
await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
|
|
1259
1236
|
}
|
|
1260
1237
|
else if (device.bot?.deviceType) {
|
|
1261
1238
|
this.accessory.context.deviceType = device.bot.deviceType;
|
|
1262
|
-
this.debugWarnLog(
|
|
1239
|
+
await this.debugWarnLog(`Accessory Cache: ${this.accessory.context.deviceType}`);
|
|
1263
1240
|
this.botDeviceType = this.accessory.context.deviceType;
|
|
1264
|
-
this.debugWarnLog(
|
|
1241
|
+
await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}`);
|
|
1265
1242
|
}
|
|
1266
1243
|
else {
|
|
1267
1244
|
this.botDeviceType = 'outlet';
|
|
1268
|
-
this.errorLog(
|
|
1269
|
-
this.warnLog(
|
|
1245
|
+
await this.errorLog(`No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
|
|
1246
|
+
await this.warnLog(`Using default deviceType: ${this.botDeviceType}`);
|
|
1270
1247
|
}
|
|
1271
1248
|
// Bot Mode
|
|
1272
1249
|
if (!device.bot?.mode) {
|
|
1273
1250
|
this.botMode = 'switch';
|
|
1274
|
-
this.warnLog(
|
|
1275
|
-
this.warnLog(
|
|
1251
|
+
await this.warnLog('does not have bot mode set in the Plugin\'s SwitchBot Device Settings,');
|
|
1252
|
+
await this.warnLog(`is defaulting to "${this.botMode}" mode, you may experience issues.`);
|
|
1276
1253
|
}
|
|
1277
1254
|
else if (device.bot?.mode === 'switch') {
|
|
1278
1255
|
this.botMode = 'switch';
|
|
1279
|
-
this.debugLog(
|
|
1256
|
+
await this.debugLog(`Using Bot Mode: ${this.botMode}`);
|
|
1280
1257
|
}
|
|
1281
1258
|
else if (device.bot?.mode === 'press') {
|
|
1282
1259
|
this.botMode = 'press';
|
|
1283
|
-
this.debugLog(
|
|
1260
|
+
await this.debugLog(`Using Bot Mode: ${this.botMode}`);
|
|
1284
1261
|
}
|
|
1285
1262
|
else if (device.bot?.mode === 'multipress') {
|
|
1286
1263
|
this.botMode = 'multipress';
|
|
1287
|
-
this.debugLog(
|
|
1264
|
+
await this.debugLog(`Using Bot Mode: ${this.botMode}`);
|
|
1288
1265
|
}
|
|
1289
1266
|
else {
|
|
1290
|
-
throw new Error(
|
|
1267
|
+
throw new Error(`Bot Mode: ${this.botMode}`);
|
|
1291
1268
|
}
|
|
1292
1269
|
// Bot Double Press
|
|
1293
1270
|
if (device.bot?.doublePress) {
|
|
@@ -1300,11 +1277,11 @@ export class Bot extends deviceBase {
|
|
|
1300
1277
|
// Bot Press PushRate
|
|
1301
1278
|
if (device?.bot?.pushRatePress) {
|
|
1302
1279
|
this.pushRatePress = device?.bot?.pushRatePress;
|
|
1303
|
-
this.debugLog(
|
|
1280
|
+
await this.debugLog(`Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
|
|
1304
1281
|
}
|
|
1305
1282
|
else {
|
|
1306
1283
|
this.pushRatePress = 15;
|
|
1307
|
-
this.debugLog(
|
|
1284
|
+
await this.debugLog(`Using Default Bot pushRatePress: ${this.pushRatePress}`);
|
|
1308
1285
|
}
|
|
1309
1286
|
// Bot Allow Push
|
|
1310
1287
|
if (device.bot?.allowPush) {
|
|
@@ -1313,21 +1290,20 @@ export class Bot extends deviceBase {
|
|
|
1313
1290
|
else {
|
|
1314
1291
|
this.allowPush = false;
|
|
1315
1292
|
}
|
|
1316
|
-
this.debugLog(
|
|
1293
|
+
await this.debugLog(`Allowing Push Changes: ${this.allowPush}`);
|
|
1317
1294
|
// Bot Multi Press Count
|
|
1318
1295
|
this.multiPressCount = 0;
|
|
1319
1296
|
}
|
|
1320
1297
|
async BLEPushConnection() {
|
|
1321
1298
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1322
|
-
this.warnLog(
|
|
1299
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
1323
1300
|
await this.openAPIpushChanges();
|
|
1324
1301
|
}
|
|
1325
1302
|
}
|
|
1326
1303
|
async BLERefreshConnection(switchbot) {
|
|
1327
|
-
this.errorLog(
|
|
1328
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
1304
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
1329
1305
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1330
|
-
this.warnLog(
|
|
1306
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
1331
1307
|
await this.openAPIRefreshStatus();
|
|
1332
1308
|
}
|
|
1333
1309
|
}
|