@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.4
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/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +203 -255
- 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 +196 -218
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +202 -247
- 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 +329 -378
- 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 +99 -142
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +203 -264
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +28 -32
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +186 -225
- 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 +198 -227
- 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 +106 -231
- 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 +192 -232
- 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 +91 -157
- 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 +287 -367
- 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 +171 -216
- 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 +93 -158
- 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 +94 -155
- 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 +84 -142
- 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 +99 -124
- 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 +170 -253
- 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 +102 -128
- 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.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.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.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.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +1 -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.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.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.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.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.map +1 -1
- package/dist/platform.d.ts +5 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +51 -34
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- 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 +10 -10
- package/src/device/blindtilt.ts +224 -264
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +210 -257
- package/src/device/colorbulb.ts +334 -397
- package/src/device/contact.ts +111 -146
- package/src/device/curtain.ts +220 -283
- package/src/device/device.ts +194 -245
- package/src/device/fan.ts +214 -230
- package/src/device/hub.ts +126 -246
- package/src/device/humidifier.ts +216 -243
- package/src/device/iosensor.ts +114 -166
- package/src/device/lightstrip.ts +302 -377
- package/src/device/lock.ts +187 -221
- package/src/device/meter.ts +116 -177
- package/src/device/meterplus.ts +117 -174
- package/src/device/motion.ts +99 -144
- package/src/device/plug.ts +110 -128
- package/src/device/robotvacuumcleaner.ts +189 -252
- package/src/device/waterdetector.ts +120 -138
- package/src/irdevice/airconditioner.ts +2 -1
- package/src/irdevice/airpurifier.ts +2 -1
- package/src/irdevice/camera.ts +2 -1
- package/src/irdevice/fan.ts +2 -1
- package/src/irdevice/irdevice.ts +3 -2
- package/src/irdevice/light.ts +2 -1
- package/src/irdevice/other.ts +2 -1
- package/src/irdevice/tv.ts +2 -1
- package/src/irdevice/vacuumcleaner.ts +2 -1
- package/src/irdevice/waterheater.ts +2 -1
- package/src/platform.ts +52 -34
- package/src/settings.ts +30 -239
- 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,62 +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
557
|
await this.apiError(e);
|
|
552
|
-
await this.
|
|
558
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
553
559
|
}
|
|
554
560
|
}
|
|
555
|
-
async registerWebhook(
|
|
556
|
-
if (device.webhook) {
|
|
557
|
-
this.debugLog(
|
|
558
|
-
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) => {
|
|
559
565
|
try {
|
|
560
|
-
this.debugLog(
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
const On = await this.getOn();
|
|
564
|
-
const { BatteryLevel } = this.Battery;
|
|
565
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (power, battery, deviceMode) = Webhook:(${power}, ${battery}, ${deviceMode}),`
|
|
566
|
-
+ ` current:(${On}, ${BatteryLevel}, ${botMode})`);
|
|
567
|
-
await this.setOn(power);
|
|
568
|
-
this.Battery.BatteryLevel = battery;
|
|
569
|
-
this.botMode = deviceMode;
|
|
570
|
-
this.updateHomeKitCharacteristics();
|
|
566
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
567
|
+
await this.parseStatusWebhook(context);
|
|
568
|
+
await this.updateHomeKitCharacteristics();
|
|
571
569
|
}
|
|
572
570
|
catch (e) {
|
|
573
|
-
this.errorLog(
|
|
571
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
574
572
|
}
|
|
575
573
|
};
|
|
576
574
|
}
|
|
577
575
|
else {
|
|
578
|
-
this.debugLog(
|
|
576
|
+
await this.debugLog('is not listening webhook.');
|
|
579
577
|
}
|
|
580
578
|
}
|
|
581
579
|
/**
|
|
@@ -587,7 +585,7 @@ export class Bot extends deviceBase {
|
|
|
587
585
|
*/
|
|
588
586
|
async pushChanges() {
|
|
589
587
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
590
|
-
this.errorLog(
|
|
588
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
591
589
|
}
|
|
592
590
|
else if (this.BLE) {
|
|
593
591
|
await this.BLEpushChanges();
|
|
@@ -597,7 +595,7 @@ export class Bot extends deviceBase {
|
|
|
597
595
|
}
|
|
598
596
|
else {
|
|
599
597
|
await this.offlineOff();
|
|
600
|
-
await this.
|
|
598
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
601
599
|
}
|
|
602
600
|
// Refresh the status from the API
|
|
603
601
|
interval(15000)
|
|
@@ -608,27 +606,24 @@ export class Bot extends deviceBase {
|
|
|
608
606
|
});
|
|
609
607
|
}
|
|
610
608
|
async BLEpushChanges() {
|
|
611
|
-
this.debugLog(
|
|
609
|
+
await this.debugLog('BLEpushChanges');
|
|
612
610
|
const On = await this.getOn();
|
|
613
611
|
if (On !== this.accessory.context.On || this.allowPush) {
|
|
614
|
-
this.debugLog(
|
|
615
|
-
const switchbot = await this.platform.connectBLE();
|
|
616
|
-
// 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);
|
|
617
614
|
await this.convertBLEAddress();
|
|
618
615
|
//if (switchbot !== false) {
|
|
619
616
|
if (this.botMode === 'press') {
|
|
620
|
-
this.debugLog(
|
|
617
|
+
this.debugLog(`Bot Mode: ${this.botMode}`);
|
|
621
618
|
switchbot
|
|
622
619
|
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
623
620
|
.then(async (device_list) => {
|
|
624
|
-
this.infoLog(
|
|
621
|
+
this.infoLog(`On: ${On}`);
|
|
625
622
|
return await device_list[0].press({ id: this.device.bleMac });
|
|
626
623
|
})
|
|
627
|
-
.then(() => {
|
|
628
|
-
this.
|
|
629
|
-
this.
|
|
630
|
-
+ `On: ${On} sent over BLE, sent successfully`);
|
|
631
|
-
this.accessory.context.On = On;
|
|
624
|
+
.then(async () => {
|
|
625
|
+
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
626
|
+
await this.updateHomeKitCharacteristics();
|
|
632
627
|
setTimeout(() => {
|
|
633
628
|
if (this.botDeviceType === 'switch') {
|
|
634
629
|
this.Switch?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
@@ -636,22 +631,21 @@ export class Bot extends deviceBase {
|
|
|
636
631
|
else {
|
|
637
632
|
this.Outlet?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
638
633
|
}
|
|
639
|
-
this.debugLog(
|
|
634
|
+
this.debugLog(`On: ${On}, Switch Timeout`);
|
|
640
635
|
}, 500);
|
|
641
636
|
})
|
|
642
637
|
.catch(async (e) => {
|
|
643
|
-
this.apiError(e);
|
|
644
|
-
this.errorLog(
|
|
645
|
-
+ ` 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)}`);
|
|
646
640
|
await this.BLEPushConnection();
|
|
647
641
|
});
|
|
648
642
|
}
|
|
649
643
|
else if (this.botMode === 'switch') {
|
|
650
|
-
this.debugLog(
|
|
644
|
+
this.debugLog(`Press Mode: ${this.botMode}`);
|
|
651
645
|
switchbot
|
|
652
646
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
653
647
|
.then(async (device_list) => {
|
|
654
|
-
this.infoLog(
|
|
648
|
+
this.infoLog(`On: ${On}`);
|
|
655
649
|
return await this.retryBLE({
|
|
656
650
|
max: await this.maxRetryBLE(),
|
|
657
651
|
fn: async () => {
|
|
@@ -664,30 +658,29 @@ export class Bot extends deviceBase {
|
|
|
664
658
|
},
|
|
665
659
|
});
|
|
666
660
|
})
|
|
667
|
-
.then(() => {
|
|
668
|
-
this.
|
|
669
|
-
this.
|
|
661
|
+
.then(async () => {
|
|
662
|
+
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
663
|
+
await this.updateHomeKitCharacteristics();
|
|
670
664
|
})
|
|
671
665
|
.catch(async (e) => {
|
|
672
|
-
this.apiError(e);
|
|
673
|
-
this.errorLog(
|
|
674
|
-
+ ` 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)}`);
|
|
675
668
|
await this.BLEPushConnection();
|
|
676
669
|
});
|
|
677
670
|
}
|
|
678
671
|
else {
|
|
679
|
-
this.errorLog(
|
|
672
|
+
await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`);
|
|
680
673
|
}
|
|
681
674
|
}
|
|
682
675
|
else {
|
|
683
|
-
this.debugLog(
|
|
676
|
+
await this.debugLog(`No Changes (BLEpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
684
677
|
}
|
|
685
678
|
}
|
|
686
679
|
async openAPIpushChanges() {
|
|
687
|
-
this.debugLog(
|
|
680
|
+
await this.debugLog('openAPIpushChanges');
|
|
688
681
|
let On = await this.getOn();
|
|
689
682
|
if (this.multiPressCount > 0) {
|
|
690
|
-
this.debugLog(`${this.
|
|
683
|
+
await this.debugLog(`${this.multiPressCount} request(s) queued.`);
|
|
691
684
|
On = true;
|
|
692
685
|
}
|
|
693
686
|
if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
|
|
@@ -695,33 +688,33 @@ export class Bot extends deviceBase {
|
|
|
695
688
|
if (this.botMode === 'switch' && On) {
|
|
696
689
|
command = 'turnOn';
|
|
697
690
|
On = true;
|
|
698
|
-
this.debugLog(
|
|
691
|
+
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
699
692
|
}
|
|
700
693
|
else if (this.botMode === 'switch' && !On) {
|
|
701
694
|
command = 'turnOff';
|
|
702
695
|
On = false;
|
|
703
|
-
this.debugLog(
|
|
696
|
+
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
704
697
|
}
|
|
705
698
|
else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
706
699
|
command = 'press';
|
|
707
|
-
this.debugLog(
|
|
700
|
+
await this.debugLog('Press Mode');
|
|
708
701
|
On = false;
|
|
709
702
|
}
|
|
710
703
|
else {
|
|
711
|
-
throw new Error(
|
|
704
|
+
throw new Error('Device Parameters not set for this Bot.');
|
|
712
705
|
}
|
|
713
706
|
const bodyChange = JSON.stringify({
|
|
714
707
|
command: `${command}`,
|
|
715
708
|
parameter: 'default',
|
|
716
709
|
commandType: 'command',
|
|
717
710
|
});
|
|
718
|
-
this.debugLog(
|
|
711
|
+
this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
719
712
|
try {
|
|
720
713
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
721
714
|
const deviceStatus = await body.json();
|
|
722
|
-
await this.
|
|
723
|
-
if (
|
|
724
|
-
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)}`);
|
|
725
718
|
await this.updateHomeKitCharacteristics();
|
|
726
719
|
}
|
|
727
720
|
else {
|
|
@@ -731,21 +724,19 @@ export class Bot extends deviceBase {
|
|
|
731
724
|
if (this.device.bot?.mode === 'multipress') {
|
|
732
725
|
this.multiPressCount--;
|
|
733
726
|
if (this.multiPressCount > 0) {
|
|
734
|
-
this.debugLog(
|
|
727
|
+
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
735
728
|
On = true;
|
|
736
|
-
this.openAPIpushChanges();
|
|
729
|
+
await this.openAPIpushChanges();
|
|
737
730
|
}
|
|
738
731
|
}
|
|
739
732
|
}
|
|
740
733
|
catch (e) {
|
|
741
|
-
this.apiError(e);
|
|
742
|
-
this.errorLog(
|
|
743
|
-
+ ` 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)}`);
|
|
744
736
|
}
|
|
745
737
|
}
|
|
746
738
|
else {
|
|
747
|
-
this.debugLog(
|
|
748
|
-
+ ` On: ${On}, OnCached: ${this.accessory.context.On}`);
|
|
739
|
+
await this.debugLog(`No Changes (openAPIpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
749
740
|
}
|
|
750
741
|
}
|
|
751
742
|
/**
|
|
@@ -754,7 +745,8 @@ export class Bot extends deviceBase {
|
|
|
754
745
|
async OnSet(value) {
|
|
755
746
|
if (this.botDeviceType === 'garagedoor') {
|
|
756
747
|
if (this.GarageDoor) {
|
|
757
|
-
this.
|
|
748
|
+
await this.debugLog(`Set TargetDoorState: ${value}`);
|
|
749
|
+
this.infoLog(`Set TargetDoorState: ${value}`);
|
|
758
750
|
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
759
751
|
await this.setOn(false);
|
|
760
752
|
this.GarageDoor.On = false;
|
|
@@ -767,7 +759,7 @@ export class Bot extends deviceBase {
|
|
|
767
759
|
}
|
|
768
760
|
else if (this.botDeviceType === 'door') {
|
|
769
761
|
if (this.Door) {
|
|
770
|
-
this.
|
|
762
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
771
763
|
if (value === 0) {
|
|
772
764
|
await this.setOn(false);
|
|
773
765
|
this.Door.On = false;
|
|
@@ -780,7 +772,7 @@ export class Bot extends deviceBase {
|
|
|
780
772
|
}
|
|
781
773
|
else if (this.botDeviceType === 'window') {
|
|
782
774
|
if (this.Window) {
|
|
783
|
-
this.
|
|
775
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
784
776
|
if (value === 0) {
|
|
785
777
|
await this.setOn(false);
|
|
786
778
|
this.Window.On = false;
|
|
@@ -793,7 +785,7 @@ export class Bot extends deviceBase {
|
|
|
793
785
|
}
|
|
794
786
|
else if (this.botDeviceType === 'windowcovering') {
|
|
795
787
|
if (this.WindowCovering) {
|
|
796
|
-
this.
|
|
788
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
797
789
|
if (value === 0) {
|
|
798
790
|
await this.setOn(false);
|
|
799
791
|
this.WindowCovering.On = false;
|
|
@@ -806,7 +798,7 @@ export class Bot extends deviceBase {
|
|
|
806
798
|
}
|
|
807
799
|
else if (this.botDeviceType === 'lock') {
|
|
808
800
|
if (this.LockMechanism) {
|
|
809
|
-
this.
|
|
801
|
+
await this.debugLog(`Set LockTargetState: ${value}`);
|
|
810
802
|
if (value === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
811
803
|
await this.setOn(false);
|
|
812
804
|
this.LockMechanism.On = false;
|
|
@@ -819,7 +811,7 @@ export class Bot extends deviceBase {
|
|
|
819
811
|
}
|
|
820
812
|
else if (this.botDeviceType === 'faucet') {
|
|
821
813
|
if (this.Faucet) {
|
|
822
|
-
this.
|
|
814
|
+
await this.debugLog(`Set Active: ${value}`);
|
|
823
815
|
if (value === this.hap.Characteristic.Active.INACTIVE) {
|
|
824
816
|
await this.setOn(false);
|
|
825
817
|
this.Faucet.On = false;
|
|
@@ -832,7 +824,7 @@ export class Bot extends deviceBase {
|
|
|
832
824
|
}
|
|
833
825
|
else if (this.botDeviceType === 'stateful') {
|
|
834
826
|
if (this.StatefulProgrammableSwitch) {
|
|
835
|
-
this.
|
|
827
|
+
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
836
828
|
if (value === 0) {
|
|
837
829
|
await this.setOn(false);
|
|
838
830
|
this.StatefulProgrammableSwitch.On = false;
|
|
@@ -845,7 +837,7 @@ export class Bot extends deviceBase {
|
|
|
845
837
|
}
|
|
846
838
|
else if (this.botDeviceType === 'switch') {
|
|
847
839
|
if (this.Switch) {
|
|
848
|
-
this.
|
|
840
|
+
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
849
841
|
if (value === 0) {
|
|
850
842
|
await this.setOn(false);
|
|
851
843
|
this.Switch.On = false;
|
|
@@ -858,7 +850,7 @@ export class Bot extends deviceBase {
|
|
|
858
850
|
}
|
|
859
851
|
else {
|
|
860
852
|
if (this.Outlet) {
|
|
861
|
-
this.
|
|
853
|
+
await this.debugLog(`Set On: ${value}`);
|
|
862
854
|
await this.setOn(Boolean(value));
|
|
863
855
|
this.Outlet.On = value;
|
|
864
856
|
}
|
|
@@ -866,7 +858,7 @@ export class Bot extends deviceBase {
|
|
|
866
858
|
if (this.device.bot?.mode === 'multipress') {
|
|
867
859
|
if (value === true) {
|
|
868
860
|
this.multiPressCount++;
|
|
869
|
-
this.debugLog(
|
|
861
|
+
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
870
862
|
}
|
|
871
863
|
}
|
|
872
864
|
this.doBotUpdate.next();
|
|
@@ -878,216 +870,203 @@ export class Bot extends deviceBase {
|
|
|
878
870
|
// State
|
|
879
871
|
if (this.botDeviceType === 'garagedoor') {
|
|
880
872
|
if (this.GarageDoor?.On === undefined) {
|
|
881
|
-
this.debugLog(
|
|
873
|
+
await this.debugLog(`On: ${this.GarageDoor?.On}`);
|
|
882
874
|
}
|
|
883
875
|
else {
|
|
884
876
|
if (this.GarageDoor.On) {
|
|
885
877
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
|
|
886
878
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
|
|
887
|
-
this.debugLog(
|
|
888
|
-
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
879
|
+
await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
889
880
|
}
|
|
890
881
|
else {
|
|
891
882
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
892
883
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
893
|
-
this.debugLog(
|
|
894
|
-
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
884
|
+
await this.debugLog(`updateCharacteristicc TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
895
885
|
}
|
|
896
886
|
}
|
|
897
887
|
await this.setOn(Boolean(this.GarageDoor?.On));
|
|
898
|
-
this.debugLog(
|
|
888
|
+
await this.debugLog(`Garage Door On: ${this.GarageDoor?.On}`);
|
|
899
889
|
}
|
|
900
890
|
else if (this.botDeviceType === 'door') {
|
|
901
891
|
if (this.Door?.On === undefined) {
|
|
902
|
-
this.debugLog(
|
|
892
|
+
await this.debugLog(`On: ${this.Door?.On}`);
|
|
903
893
|
}
|
|
904
894
|
else {
|
|
905
895
|
if (this.Door.On) {
|
|
906
896
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
907
897
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
908
898
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
909
|
-
this.debugLog(
|
|
910
|
-
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
|
|
899
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
|
|
911
900
|
}
|
|
912
901
|
else {
|
|
913
902
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
914
903
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
915
904
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
916
|
-
this.debugLog(
|
|
917
|
-
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
|
|
905
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
|
|
918
906
|
}
|
|
919
907
|
}
|
|
920
908
|
await this.setOn(Boolean(this.Door?.On));
|
|
921
|
-
this.debugLog(
|
|
909
|
+
await this.debugLog(`Door On: ${this.Door?.On}`);
|
|
922
910
|
}
|
|
923
911
|
else if (this.botDeviceType === 'window') {
|
|
924
912
|
if (this.Window?.On === undefined) {
|
|
925
|
-
this.debugLog(
|
|
913
|
+
await this.debugLog(`On: ${this.Window?.On}`);
|
|
926
914
|
}
|
|
927
915
|
else {
|
|
928
916
|
if (this.Window.On) {
|
|
929
917
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
930
918
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
931
919
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
932
|
-
this.debugLog(
|
|
933
|
-
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
|
|
920
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
|
|
934
921
|
}
|
|
935
922
|
else {
|
|
936
923
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
937
924
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
938
925
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
939
|
-
this.debugLog(
|
|
940
|
-
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
|
|
926
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
|
|
941
927
|
}
|
|
942
928
|
}
|
|
943
929
|
await this.setOn(Boolean(this.Window?.On));
|
|
944
|
-
this.debugLog(
|
|
930
|
+
await this.debugLog(`Window On: ${this.Window?.On}`);
|
|
945
931
|
}
|
|
946
932
|
else if (this.botDeviceType === 'windowcovering') {
|
|
947
933
|
if (this.WindowCovering?.On === undefined) {
|
|
948
|
-
this.debugLog(
|
|
934
|
+
await this.debugLog(`On: ${this.WindowCovering?.On}`);
|
|
949
935
|
}
|
|
950
936
|
else {
|
|
951
937
|
if (this.WindowCovering.On) {
|
|
952
938
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
953
939
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
954
940
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
955
|
-
this.debugLog(
|
|
956
|
-
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
|
|
941
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
|
|
957
942
|
}
|
|
958
943
|
else {
|
|
959
944
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
960
945
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
961
946
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
962
|
-
this.debugLog(
|
|
963
|
-
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
|
|
947
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
|
|
964
948
|
}
|
|
965
949
|
}
|
|
966
950
|
await this.setOn(Boolean(this.WindowCovering?.On));
|
|
967
|
-
this.debugLog(
|
|
951
|
+
await this.debugLog(`Window Covering On: ${this.WindowCovering?.On}`);
|
|
968
952
|
}
|
|
969
953
|
else if (this.botDeviceType === 'lock') {
|
|
970
954
|
if (this.LockMechanism?.On === undefined) {
|
|
971
|
-
this.debugLog(
|
|
955
|
+
await this.debugLog(`On: ${this.LockMechanism?.On}`);
|
|
972
956
|
}
|
|
973
957
|
else {
|
|
974
958
|
if (this.LockMechanism.On) {
|
|
975
959
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
|
|
976
960
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
977
|
-
this.debugLog(
|
|
978
|
-
+ ` LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
|
|
961
|
+
await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
|
|
979
962
|
}
|
|
980
963
|
else {
|
|
981
964
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
|
|
982
965
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
|
|
983
|
-
this.debugLog(
|
|
984
|
-
+ ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
|
|
966
|
+
await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
|
|
985
967
|
}
|
|
986
968
|
}
|
|
987
969
|
await this.setOn(Boolean(this.LockMechanism?.On));
|
|
988
|
-
this.debugLog(
|
|
970
|
+
await this.debugLog(`Lock On: ${this.LockMechanism?.On}`);
|
|
989
971
|
}
|
|
990
972
|
else if (this.botDeviceType === 'faucet') {
|
|
991
973
|
if (this.Faucet?.On === undefined) {
|
|
992
|
-
this.debugLog(
|
|
974
|
+
await this.debugLog(`On: ${this.Faucet?.On}`);
|
|
993
975
|
}
|
|
994
976
|
else {
|
|
995
977
|
if (this.Faucet.On) {
|
|
996
978
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
997
|
-
this.debugLog(
|
|
979
|
+
await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
|
|
998
980
|
}
|
|
999
981
|
else {
|
|
1000
982
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
1001
|
-
this.debugLog(
|
|
983
|
+
await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
|
|
1002
984
|
}
|
|
1003
985
|
}
|
|
1004
986
|
await this.setOn(Boolean(this.Faucet?.On));
|
|
1005
|
-
this.debugLog(
|
|
987
|
+
await this.debugLog(`Faucet On: ${this.Faucet?.On}`);
|
|
1006
988
|
}
|
|
1007
989
|
else if (this.botDeviceType === 'fan') {
|
|
1008
990
|
if (this.Fan?.On === undefined) {
|
|
1009
|
-
this.debugLog(
|
|
991
|
+
await this.debugLog(`On: ${this.Fan?.On}`);
|
|
1010
992
|
}
|
|
1011
993
|
else {
|
|
1012
994
|
if (this.Fan.On) {
|
|
1013
995
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
|
|
1014
|
-
this.debugLog(
|
|
996
|
+
await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
|
|
1015
997
|
}
|
|
1016
998
|
else {
|
|
1017
999
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
|
|
1018
|
-
this.debugLog(
|
|
1000
|
+
await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
|
|
1019
1001
|
}
|
|
1020
1002
|
}
|
|
1021
1003
|
await this.setOn(Boolean(this.Fan?.On));
|
|
1022
|
-
this.debugLog(
|
|
1004
|
+
await this.debugLog(`Fan On: ${this.Fan?.On}`);
|
|
1023
1005
|
}
|
|
1024
1006
|
else if (this.botDeviceType === 'stateful') {
|
|
1025
1007
|
if (this.StatefulProgrammableSwitch?.On === undefined) {
|
|
1026
|
-
this.debugLog(
|
|
1008
|
+
await this.debugLog(`On: ${this.StatefulProgrammableSwitch?.On}`);
|
|
1027
1009
|
}
|
|
1028
1010
|
else {
|
|
1029
1011
|
if (this.StatefulProgrammableSwitch.On) {
|
|
1030
1012
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1031
1013
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
1032
|
-
this.debugLog(
|
|
1033
|
-
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch.On})`);
|
|
1014
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
|
|
1034
1015
|
}
|
|
1035
1016
|
else {
|
|
1036
1017
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1037
1018
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
1038
|
-
this.debugLog(
|
|
1039
|
-
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch.On})`);
|
|
1019
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
|
|
1040
1020
|
}
|
|
1041
1021
|
}
|
|
1042
1022
|
await this.setOn(Boolean(this.StatefulProgrammableSwitch?.On));
|
|
1043
|
-
this.debugLog(
|
|
1023
|
+
await this.debugLog(`StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
|
|
1044
1024
|
}
|
|
1045
1025
|
else if (this.botDeviceType === 'switch') {
|
|
1046
1026
|
if (this.Switch?.On === undefined) {
|
|
1047
|
-
this.debugLog(
|
|
1027
|
+
await this.debugLog(`On: ${this.Switch?.On}`);
|
|
1048
1028
|
}
|
|
1049
1029
|
else {
|
|
1050
1030
|
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
|
|
1051
|
-
this.debugLog(
|
|
1031
|
+
await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
|
|
1052
1032
|
}
|
|
1053
1033
|
await this.setOn(Boolean(this.Switch?.On));
|
|
1054
1034
|
}
|
|
1055
1035
|
else {
|
|
1056
1036
|
if (this.Outlet?.On === undefined) {
|
|
1057
|
-
this.debugLog(
|
|
1037
|
+
await this.debugLog(`On: ${this.Outlet?.On}`);
|
|
1058
1038
|
}
|
|
1059
1039
|
else {
|
|
1060
1040
|
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet.On);
|
|
1061
|
-
this.debugLog(
|
|
1041
|
+
await this.debugLog(`updateCharacteristic On: ${this.Outlet.On}`);
|
|
1062
1042
|
}
|
|
1063
1043
|
await this.setOn(Boolean(this.Outlet?.On));
|
|
1064
1044
|
}
|
|
1065
1045
|
this.accessory.context.On = await this.getOn();
|
|
1066
1046
|
// BatteryLevel
|
|
1067
1047
|
if (this.Battery.BatteryLevel === undefined) {
|
|
1068
|
-
this.debugLog(
|
|
1048
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1069
1049
|
}
|
|
1070
1050
|
else {
|
|
1071
1051
|
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
1072
1052
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
1073
|
-
this.debugLog(
|
|
1053
|
+
await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1074
1054
|
}
|
|
1075
1055
|
// StatusLowBattery
|
|
1076
1056
|
if (this.Battery.StatusLowBattery === undefined) {
|
|
1077
|
-
this.debugLog(
|
|
1057
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1078
1058
|
}
|
|
1079
1059
|
else {
|
|
1080
1060
|
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
1081
1061
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
1082
|
-
this.debugLog(
|
|
1083
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1062
|
+
await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1084
1063
|
}
|
|
1085
1064
|
}
|
|
1086
1065
|
async removeOutletService(accessory) {
|
|
1087
1066
|
// If outletService still present, then remove first
|
|
1088
1067
|
if (this.Outlet?.Service) {
|
|
1089
1068
|
this.Outlet.Service = this.accessory.getService(this.hap.Service.Outlet);
|
|
1090
|
-
this.warnLog(
|
|
1069
|
+
await this.warnLog('Removing Leftover Outlet Service');
|
|
1091
1070
|
accessory.removeService(this.Outlet.Service);
|
|
1092
1071
|
}
|
|
1093
1072
|
}
|
|
@@ -1095,7 +1074,7 @@ export class Bot extends deviceBase {
|
|
|
1095
1074
|
// If garageDoorService still present, then remove first
|
|
1096
1075
|
if (this.GarageDoor?.Service) {
|
|
1097
1076
|
this.GarageDoor.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener);
|
|
1098
|
-
this.warnLog(
|
|
1077
|
+
await this.warnLog('Removing Leftover Garage Door Service');
|
|
1099
1078
|
accessory.removeService(this.GarageDoor.Service);
|
|
1100
1079
|
}
|
|
1101
1080
|
}
|
|
@@ -1103,7 +1082,7 @@ export class Bot extends deviceBase {
|
|
|
1103
1082
|
// If doorService still present, then remove first
|
|
1104
1083
|
if (this.Door?.Service) {
|
|
1105
1084
|
this.Door.Service = this.accessory.getService(this.hap.Service.Door);
|
|
1106
|
-
this.warnLog(
|
|
1085
|
+
await this.warnLog('Removing Leftover Door Service');
|
|
1107
1086
|
accessory.removeService(this.Door.Service);
|
|
1108
1087
|
}
|
|
1109
1088
|
}
|
|
@@ -1111,7 +1090,7 @@ export class Bot extends deviceBase {
|
|
|
1111
1090
|
// If lockService still present, then remove first
|
|
1112
1091
|
if (this.LockMechanism?.Service) {
|
|
1113
1092
|
this.LockMechanism.Service = this.accessory.getService(this.hap.Service.LockMechanism);
|
|
1114
|
-
this.warnLog(
|
|
1093
|
+
this.warnLog('Removing Leftover Lock Service');
|
|
1115
1094
|
accessory.removeService(this.LockMechanism.Service);
|
|
1116
1095
|
}
|
|
1117
1096
|
}
|
|
@@ -1119,7 +1098,7 @@ export class Bot extends deviceBase {
|
|
|
1119
1098
|
// If faucetService still present, then remove first
|
|
1120
1099
|
if (this.Faucet?.Service) {
|
|
1121
1100
|
this.Faucet.Service = this.accessory.getService(this.hap.Service.Faucet);
|
|
1122
|
-
this.warnLog(
|
|
1101
|
+
await this.warnLog('Removing Leftover Faucet Service');
|
|
1123
1102
|
accessory.removeService(this.Faucet.Service);
|
|
1124
1103
|
}
|
|
1125
1104
|
}
|
|
@@ -1127,7 +1106,7 @@ export class Bot extends deviceBase {
|
|
|
1127
1106
|
// If fanService still present, then remove first
|
|
1128
1107
|
if (this.Fan?.Service) {
|
|
1129
1108
|
this.Fan.Service = this.accessory.getService(this.hap.Service.Fanv2);
|
|
1130
|
-
this.warnLog(
|
|
1109
|
+
this.warnLog('Removing Leftover Fan Service');
|
|
1131
1110
|
accessory.removeService(this.Fan.Service);
|
|
1132
1111
|
}
|
|
1133
1112
|
}
|
|
@@ -1135,7 +1114,7 @@ export class Bot extends deviceBase {
|
|
|
1135
1114
|
// If windowService still present, then remove first
|
|
1136
1115
|
if (this.Window?.Service) {
|
|
1137
1116
|
this.Window.Service = this.accessory.getService(this.hap.Service.Window);
|
|
1138
|
-
this.warnLog(
|
|
1117
|
+
await this.warnLog('Removing Leftover Window Service');
|
|
1139
1118
|
accessory.removeService(this.Window.Service);
|
|
1140
1119
|
}
|
|
1141
1120
|
}
|
|
@@ -1143,7 +1122,7 @@ export class Bot extends deviceBase {
|
|
|
1143
1122
|
// If windowCoveringService still present, then remove first
|
|
1144
1123
|
if (this.WindowCovering?.Service) {
|
|
1145
1124
|
this.WindowCovering.Service = this.accessory.getService(this.hap.Service.WindowCovering);
|
|
1146
|
-
this.warnLog(
|
|
1125
|
+
await this.warnLog('Removing Leftover Window Covering Service');
|
|
1147
1126
|
accessory.removeService(this.WindowCovering.Service);
|
|
1148
1127
|
}
|
|
1149
1128
|
}
|
|
@@ -1151,7 +1130,7 @@ export class Bot extends deviceBase {
|
|
|
1151
1130
|
// If statefulProgrammableSwitchService still present, then remove first
|
|
1152
1131
|
if (this.StatefulProgrammableSwitch?.Service) {
|
|
1153
1132
|
this.StatefulProgrammableSwitch.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch);
|
|
1154
|
-
this.warnLog(
|
|
1133
|
+
await this.warnLog('Removing Leftover Stateful Programmable Switch Service');
|
|
1155
1134
|
accessory.removeService(this.StatefulProgrammableSwitch.Service);
|
|
1156
1135
|
}
|
|
1157
1136
|
}
|
|
@@ -1159,7 +1138,7 @@ export class Bot extends deviceBase {
|
|
|
1159
1138
|
// If switchService still present, then remove first
|
|
1160
1139
|
if (this.Switch?.Service) {
|
|
1161
1140
|
this.Switch.Service = this.accessory.getService(this.hap.Service.Switch);
|
|
1162
|
-
this.warnLog(
|
|
1141
|
+
await this.warnLog('Removing Leftover Switch Service');
|
|
1163
1142
|
accessory.removeService(this.Switch.Service);
|
|
1164
1143
|
}
|
|
1165
1144
|
}
|
|
@@ -1253,39 +1232,39 @@ export class Bot extends deviceBase {
|
|
|
1253
1232
|
//Bot Device Type
|
|
1254
1233
|
if (!device.bot?.deviceType && this.accessory.context.deviceType) {
|
|
1255
1234
|
this.botDeviceType = this.accessory.context.deviceType;
|
|
1256
|
-
this.debugWarnLog(
|
|
1235
|
+
await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
|
|
1257
1236
|
}
|
|
1258
1237
|
else if (device.bot?.deviceType) {
|
|
1259
1238
|
this.accessory.context.deviceType = device.bot.deviceType;
|
|
1260
|
-
this.debugWarnLog(
|
|
1239
|
+
await this.debugWarnLog(`Accessory Cache: ${this.accessory.context.deviceType}`);
|
|
1261
1240
|
this.botDeviceType = this.accessory.context.deviceType;
|
|
1262
|
-
this.debugWarnLog(
|
|
1241
|
+
await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}`);
|
|
1263
1242
|
}
|
|
1264
1243
|
else {
|
|
1265
1244
|
this.botDeviceType = 'outlet';
|
|
1266
|
-
this.errorLog(
|
|
1267
|
-
this.warnLog(
|
|
1245
|
+
await this.errorLog(`No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
|
|
1246
|
+
await this.warnLog(`Using default deviceType: ${this.botDeviceType}`);
|
|
1268
1247
|
}
|
|
1269
1248
|
// Bot Mode
|
|
1270
1249
|
if (!device.bot?.mode) {
|
|
1271
1250
|
this.botMode = 'switch';
|
|
1272
|
-
this.warnLog(
|
|
1273
|
-
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.`);
|
|
1274
1253
|
}
|
|
1275
1254
|
else if (device.bot?.mode === 'switch') {
|
|
1276
1255
|
this.botMode = 'switch';
|
|
1277
|
-
this.debugLog(
|
|
1256
|
+
await this.debugLog(`Using Bot Mode: ${this.botMode}`);
|
|
1278
1257
|
}
|
|
1279
1258
|
else if (device.bot?.mode === 'press') {
|
|
1280
1259
|
this.botMode = 'press';
|
|
1281
|
-
this.debugLog(
|
|
1260
|
+
await this.debugLog(`Using Bot Mode: ${this.botMode}`);
|
|
1282
1261
|
}
|
|
1283
1262
|
else if (device.bot?.mode === 'multipress') {
|
|
1284
1263
|
this.botMode = 'multipress';
|
|
1285
|
-
this.debugLog(
|
|
1264
|
+
await this.debugLog(`Using Bot Mode: ${this.botMode}`);
|
|
1286
1265
|
}
|
|
1287
1266
|
else {
|
|
1288
|
-
throw new Error(
|
|
1267
|
+
throw new Error(`Bot Mode: ${this.botMode}`);
|
|
1289
1268
|
}
|
|
1290
1269
|
// Bot Double Press
|
|
1291
1270
|
if (device.bot?.doublePress) {
|
|
@@ -1298,11 +1277,11 @@ export class Bot extends deviceBase {
|
|
|
1298
1277
|
// Bot Press PushRate
|
|
1299
1278
|
if (device?.bot?.pushRatePress) {
|
|
1300
1279
|
this.pushRatePress = device?.bot?.pushRatePress;
|
|
1301
|
-
this.debugLog(
|
|
1280
|
+
await this.debugLog(`Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
|
|
1302
1281
|
}
|
|
1303
1282
|
else {
|
|
1304
1283
|
this.pushRatePress = 15;
|
|
1305
|
-
this.debugLog(
|
|
1284
|
+
await this.debugLog(`Using Default Bot pushRatePress: ${this.pushRatePress}`);
|
|
1306
1285
|
}
|
|
1307
1286
|
// Bot Allow Push
|
|
1308
1287
|
if (device.bot?.allowPush) {
|
|
@@ -1311,21 +1290,20 @@ export class Bot extends deviceBase {
|
|
|
1311
1290
|
else {
|
|
1312
1291
|
this.allowPush = false;
|
|
1313
1292
|
}
|
|
1314
|
-
this.debugLog(
|
|
1293
|
+
await this.debugLog(`Allowing Push Changes: ${this.allowPush}`);
|
|
1315
1294
|
// Bot Multi Press Count
|
|
1316
1295
|
this.multiPressCount = 0;
|
|
1317
1296
|
}
|
|
1318
1297
|
async BLEPushConnection() {
|
|
1319
1298
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1320
|
-
this.warnLog(
|
|
1299
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
1321
1300
|
await this.openAPIpushChanges();
|
|
1322
1301
|
}
|
|
1323
1302
|
}
|
|
1324
1303
|
async BLERefreshConnection(switchbot) {
|
|
1325
|
-
this.errorLog(
|
|
1326
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
1304
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
1327
1305
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1328
|
-
this.warnLog(
|
|
1306
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
1329
1307
|
await this.openAPIRefreshStatus();
|
|
1330
1308
|
}
|
|
1331
1309
|
}
|