@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/src/device/bot.ts
CHANGED
|
@@ -3,12 +3,16 @@
|
|
|
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
|
+
import type { devicesConfig } from '../settings.js';
|
|
10
|
+
import type { device } from '../types/devicelist.js';
|
|
9
11
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
12
|
+
import type { botServiceData } from '../types/bledevicestatus.js';
|
|
13
|
+
import type { botStatus } from '../types/devicestatus.js';
|
|
14
|
+
import type { botWebhookContext } from '../types/devicewebhookstatus.js';
|
|
10
15
|
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
11
|
-
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* Platform Accessory
|
|
@@ -135,7 +139,7 @@ export class Bot extends deviceBase {
|
|
|
135
139
|
On: accessory.context.On ?? false,
|
|
136
140
|
};
|
|
137
141
|
accessory.context.Switch = this.Switch as object;
|
|
138
|
-
this.
|
|
142
|
+
this.debugLog('Displaying as Switch');
|
|
139
143
|
|
|
140
144
|
// Initialize Switch Characteristics
|
|
141
145
|
this.Switch.Service
|
|
@@ -166,7 +170,7 @@ export class Bot extends deviceBase {
|
|
|
166
170
|
On: accessory.context.On ?? false,
|
|
167
171
|
};
|
|
168
172
|
accessory.context.GarageDoor = this.GarageDoor as object;
|
|
169
|
-
this.
|
|
173
|
+
this.debugLog('Displaying as Garage Door Opener');
|
|
170
174
|
|
|
171
175
|
// Initialize GarageDoor Characteristics
|
|
172
176
|
this.GarageDoor.Service
|
|
@@ -202,7 +206,7 @@ export class Bot extends deviceBase {
|
|
|
202
206
|
On: accessory.context.On ?? false,
|
|
203
207
|
};
|
|
204
208
|
accessory.context.Door = this.Door as object;
|
|
205
|
-
this.
|
|
209
|
+
this.debugLog('Displaying as Door');
|
|
206
210
|
|
|
207
211
|
// Initialize Door Characteristics
|
|
208
212
|
this.Door.Service
|
|
@@ -238,7 +242,7 @@ export class Bot extends deviceBase {
|
|
|
238
242
|
On: accessory.context.On ?? false,
|
|
239
243
|
};
|
|
240
244
|
accessory.context.Window = this.Window as object;
|
|
241
|
-
this.
|
|
245
|
+
this.debugLog('Displaying as Window');
|
|
242
246
|
|
|
243
247
|
// Initialize Window Characteristics
|
|
244
248
|
this.Window.Service
|
|
@@ -274,7 +278,7 @@ export class Bot extends deviceBase {
|
|
|
274
278
|
On: accessory.context.On ?? false,
|
|
275
279
|
};
|
|
276
280
|
accessory.context.WindowCovering = this.WindowCovering as object;
|
|
277
|
-
this.
|
|
281
|
+
this.debugLog('Displaying as Window Covering');
|
|
278
282
|
|
|
279
283
|
// Initialize WindowCovering Characteristics
|
|
280
284
|
this.WindowCovering.Service
|
|
@@ -310,7 +314,7 @@ export class Bot extends deviceBase {
|
|
|
310
314
|
On: accessory.context.On ?? false,
|
|
311
315
|
};
|
|
312
316
|
accessory.context.LockMechanism = this.LockMechanism as object;
|
|
313
|
-
this.
|
|
317
|
+
this.debugLog('Displaying as Lock');
|
|
314
318
|
|
|
315
319
|
// Initialize Lock Characteristics
|
|
316
320
|
this.LockMechanism.Service
|
|
@@ -340,7 +344,7 @@ export class Bot extends deviceBase {
|
|
|
340
344
|
On: accessory.context.On ?? false,
|
|
341
345
|
};
|
|
342
346
|
accessory.context.Faucet = this.Faucet as object;
|
|
343
|
-
this.
|
|
347
|
+
this.debugLog('Displaying as Faucet');
|
|
344
348
|
|
|
345
349
|
// Initialize Faucet Characteristics
|
|
346
350
|
this.Faucet.Service
|
|
@@ -370,7 +374,7 @@ export class Bot extends deviceBase {
|
|
|
370
374
|
On: accessory.context.On ?? false,
|
|
371
375
|
};
|
|
372
376
|
accessory.context.Fan = this.Fan as object;
|
|
373
|
-
this.
|
|
377
|
+
this.debugLog('Displaying as Fan');
|
|
374
378
|
|
|
375
379
|
// Initialize Fan Characteristics
|
|
376
380
|
this.Fan.Service
|
|
@@ -401,7 +405,7 @@ export class Bot extends deviceBase {
|
|
|
401
405
|
On: accessory.context.On ?? false,
|
|
402
406
|
};
|
|
403
407
|
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
|
|
404
|
-
this.
|
|
408
|
+
this.debugLog('Displaying as Stateful Programmable Switch');
|
|
405
409
|
|
|
406
410
|
// Initialize StatefulProgrammableSwitch Characteristics
|
|
407
411
|
this.StatefulProgrammableSwitch.Service
|
|
@@ -431,7 +435,7 @@ export class Bot extends deviceBase {
|
|
|
431
435
|
On: accessory.context.On ?? false,
|
|
432
436
|
};
|
|
433
437
|
accessory.context.Outlet = this.Outlet as object;
|
|
434
|
-
this.
|
|
438
|
+
this.debugLog('Displaying as Outlet');
|
|
435
439
|
|
|
436
440
|
// Initialize Outlet Characteristics
|
|
437
441
|
this.Outlet.Service
|
|
@@ -460,6 +464,9 @@ export class Bot extends deviceBase {
|
|
|
460
464
|
// Retrieve initial values and updateHomekit
|
|
461
465
|
this.updateHomeKitCharacteristics();
|
|
462
466
|
|
|
467
|
+
// regisiter webhook event handler
|
|
468
|
+
this.registerWebhook();
|
|
469
|
+
|
|
463
470
|
// Start an update interval
|
|
464
471
|
interval(this.deviceRefreshRate * 1000)
|
|
465
472
|
.pipe(skipWhile(() => this.botUpdateInProgress))
|
|
@@ -467,9 +474,6 @@ export class Bot extends deviceBase {
|
|
|
467
474
|
await this.refreshStatus();
|
|
468
475
|
});
|
|
469
476
|
|
|
470
|
-
// regisiter webhook event handler
|
|
471
|
-
this.registerWebhook(accessory, device);
|
|
472
|
-
|
|
473
477
|
// Watch for Bot change events
|
|
474
478
|
// We put in a debounce of 1000ms so we don't make duplicate calls
|
|
475
479
|
this.doBotUpdate
|
|
@@ -491,9 +495,8 @@ export class Bot extends deviceBase {
|
|
|
491
495
|
await this.pushChanges();
|
|
492
496
|
}
|
|
493
497
|
} catch (e: any) {
|
|
494
|
-
this.apiError(e);
|
|
495
|
-
this.errorLog(
|
|
496
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
498
|
+
await this.apiError(e);
|
|
499
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
497
500
|
}
|
|
498
501
|
this.botUpdateInProgress = false;
|
|
499
502
|
});
|
|
@@ -502,42 +505,37 @@ export class Bot extends deviceBase {
|
|
|
502
505
|
/**
|
|
503
506
|
* Parse the device status from the SwitchBotBLE API
|
|
504
507
|
*/
|
|
505
|
-
async BLEparseStatus(serviceData:
|
|
506
|
-
this.debugLog(
|
|
508
|
+
async BLEparseStatus(serviceData: botServiceData): Promise<void> {
|
|
509
|
+
await this.debugLog('BLEparseStatus');
|
|
507
510
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
508
511
|
if (serviceData.mode) {
|
|
509
512
|
this.accessory.context.On = await this.getOn();
|
|
510
513
|
if (this.getOn() === undefined) {
|
|
511
514
|
this.setOn(Boolean(serviceData.state));
|
|
512
515
|
}
|
|
513
|
-
this.debugLog(
|
|
514
|
-
+ ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
516
|
+
this.debugLog(`Switch Mode, mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
515
517
|
} else {
|
|
516
518
|
this.setOn(false);
|
|
517
519
|
this.accessory.context.On = await this.getOn();
|
|
518
|
-
this.debugLog(
|
|
519
|
-
+ ` mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
520
|
+
this.debugLog(`Press Mode, mode: ${serviceData.mode}, On: ${this.accessory.context.On}`);
|
|
520
521
|
}
|
|
521
522
|
|
|
523
|
+
// BatteryLevel
|
|
522
524
|
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
this.Battery.BatteryLevel = 100;
|
|
530
|
-
}
|
|
531
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
532
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
525
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
526
|
+
|
|
527
|
+
// StatusLowBattery
|
|
528
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
529
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
530
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
533
531
|
}
|
|
534
532
|
|
|
535
533
|
|
|
536
534
|
/**
|
|
537
535
|
* Parse the device status from the SwitchBot OpenAPI
|
|
538
536
|
*/
|
|
539
|
-
async openAPIparseStatus(deviceStatus:
|
|
540
|
-
this.debugLog(
|
|
537
|
+
async openAPIparseStatus(deviceStatus: botStatus): Promise<void> {
|
|
538
|
+
await this.debugLog('openAPIparseStatus');
|
|
541
539
|
if (this.botMode === 'press') {
|
|
542
540
|
this.setOn(false);
|
|
543
541
|
this.accessory.context.On = await this.getOn();
|
|
@@ -547,26 +545,22 @@ export class Bot extends deviceBase {
|
|
|
547
545
|
this.setOn(false);
|
|
548
546
|
}
|
|
549
547
|
}
|
|
550
|
-
this.debugLog(
|
|
548
|
+
await this.debugLog(`On: ${this.accessory.context.On}`);
|
|
551
549
|
|
|
552
|
-
// Battery
|
|
553
|
-
this.Battery.BatteryLevel = Number(deviceStatus.
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
this.Battery.BatteryLevel = 100;
|
|
561
|
-
}
|
|
562
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
563
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
550
|
+
// Battery Level
|
|
551
|
+
this.Battery.BatteryLevel = Number(deviceStatus.battery);
|
|
552
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
553
|
+
|
|
554
|
+
// StatusLowBattery
|
|
555
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
556
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
557
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
564
558
|
|
|
565
559
|
// Firmware Version
|
|
566
|
-
const version = deviceStatus.
|
|
567
|
-
this.debugLog(
|
|
568
|
-
if (deviceStatus.
|
|
569
|
-
const deviceVersion = version
|
|
560
|
+
const version = deviceStatus.version.toString();
|
|
561
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
562
|
+
if (deviceStatus.version) {
|
|
563
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
570
564
|
this.accessory
|
|
571
565
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
572
566
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -574,29 +568,49 @@ export class Bot extends deviceBase {
|
|
|
574
568
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
575
569
|
.updateValue(deviceVersion);
|
|
576
570
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
577
|
-
this.
|
|
571
|
+
await this.debugLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
578
572
|
}
|
|
579
573
|
}
|
|
580
574
|
|
|
575
|
+
async parseStatusWebhook(context: botWebhookContext): Promise<void> {
|
|
576
|
+
await this.debugLog('parseStatusWebhook');
|
|
577
|
+
const getOn = await this.getOn();
|
|
578
|
+
await this.debugLog(`(power, battery, deviceMode) = Webhook:(${context.power}, ${context.battery}, ${context.deviceMode}),`
|
|
579
|
+
+ ` current:(${getOn}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
580
|
+
// On
|
|
581
|
+
const setOn = context.power === 'on' ? true : false;
|
|
582
|
+
await this.setOn(setOn);
|
|
583
|
+
await this.debugLog(`On: ${setOn}`);
|
|
584
|
+
// BatteryLevel
|
|
585
|
+
this.Battery.BatteryLevel = context.battery;
|
|
586
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
587
|
+
// StatusLowBattery
|
|
588
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
589
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
590
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
591
|
+
// Mode
|
|
592
|
+
this.botMode = context.deviceMode;
|
|
593
|
+
await this.debugLog(`Mode: ${this.botMode}`);
|
|
594
|
+
}
|
|
595
|
+
|
|
581
596
|
/**
|
|
582
597
|
* Asks the SwitchBot API for the latest device information
|
|
583
598
|
*/
|
|
584
599
|
async refreshStatus(): Promise<void> {
|
|
585
600
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
586
|
-
this.errorLog(
|
|
601
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
587
602
|
} else if (this.BLE) {
|
|
588
603
|
await this.BLERefreshStatus();
|
|
589
604
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
590
605
|
await this.openAPIRefreshStatus();
|
|
591
606
|
} else {
|
|
592
607
|
await this.offlineOff();
|
|
593
|
-
this.debugWarnLog(
|
|
594
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
608
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
595
609
|
}
|
|
596
610
|
}
|
|
597
611
|
|
|
598
612
|
async BLERefreshStatus(): Promise<void> {
|
|
599
|
-
this.debugLog(
|
|
613
|
+
await this.debugLog('BLERefreshStatus');
|
|
600
614
|
const switchbot = await this.switchbotBLE();
|
|
601
615
|
|
|
602
616
|
if (switchbot === undefined) {
|
|
@@ -605,13 +619,13 @@ export class Bot extends deviceBase {
|
|
|
605
619
|
// Start to monitor advertisement packets
|
|
606
620
|
(async () => {
|
|
607
621
|
// Start to monitor advertisement packets
|
|
608
|
-
const serviceData
|
|
622
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
|
|
609
623
|
// Update HomeKit
|
|
610
|
-
if (serviceData.model
|
|
624
|
+
if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
|
|
611
625
|
await this.BLEparseStatus(serviceData);
|
|
612
626
|
await this.updateHomeKitCharacteristics();
|
|
613
627
|
} else {
|
|
614
|
-
this.errorLog(
|
|
628
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
615
629
|
await this.BLERefreshConnection(switchbot);
|
|
616
630
|
}
|
|
617
631
|
})();
|
|
@@ -619,47 +633,39 @@ export class Bot extends deviceBase {
|
|
|
619
633
|
}
|
|
620
634
|
|
|
621
635
|
async openAPIRefreshStatus(): Promise<void> {
|
|
622
|
-
this.debugLog(
|
|
636
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
623
637
|
try {
|
|
624
638
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
625
639
|
const deviceStatus: any = await body.json();
|
|
626
|
-
await this.
|
|
627
|
-
if (
|
|
628
|
-
await this.
|
|
629
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
640
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
641
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
642
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
643
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
630
644
|
await this.updateHomeKitCharacteristics();
|
|
631
645
|
} else {
|
|
632
|
-
await this.
|
|
646
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
647
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
633
648
|
}
|
|
634
649
|
} catch (e: any) {
|
|
635
|
-
this.apiError(e);
|
|
636
|
-
this.errorLog(
|
|
637
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
650
|
+
await this.apiError(e);
|
|
651
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
638
652
|
}
|
|
639
653
|
}
|
|
640
654
|
|
|
641
|
-
async registerWebhook(
|
|
642
|
-
if (device.webhook) {
|
|
643
|
-
this.debugLog(
|
|
644
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
655
|
+
async registerWebhook() {
|
|
656
|
+
if (this.device.webhook) {
|
|
657
|
+
await this.debugLog('is listening webhook.');
|
|
658
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context: botWebhookContext) => {
|
|
645
659
|
try {
|
|
646
|
-
this.debugLog(
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
const On = await this.getOn();
|
|
650
|
-
const { BatteryLevel } = this.Battery;
|
|
651
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (power, battery, deviceMode) = Webhook:(${power}, ${battery}, ${deviceMode}),`
|
|
652
|
-
+ ` current:(${On}, ${BatteryLevel}, ${botMode})`);
|
|
653
|
-
await this.setOn(power);
|
|
654
|
-
this.Battery.BatteryLevel = battery;
|
|
655
|
-
this.botMode = deviceMode;
|
|
656
|
-
this.updateHomeKitCharacteristics();
|
|
660
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
661
|
+
await this.parseStatusWebhook(context);
|
|
662
|
+
await this.updateHomeKitCharacteristics();
|
|
657
663
|
} catch (e: any) {
|
|
658
|
-
this.errorLog(
|
|
664
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
659
665
|
}
|
|
660
666
|
};
|
|
661
667
|
} else {
|
|
662
|
-
this.debugLog(
|
|
668
|
+
await this.debugLog('is not listening webhook.');
|
|
663
669
|
}
|
|
664
670
|
}
|
|
665
671
|
|
|
@@ -672,15 +678,14 @@ export class Bot extends deviceBase {
|
|
|
672
678
|
*/
|
|
673
679
|
async pushChanges(): Promise<void> {
|
|
674
680
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
675
|
-
this.errorLog(
|
|
681
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
676
682
|
} else if (this.BLE) {
|
|
677
683
|
await this.BLEpushChanges();
|
|
678
684
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
679
685
|
await this.openAPIpushChanges();
|
|
680
686
|
} else {
|
|
681
687
|
await this.offlineOff();
|
|
682
|
-
this.debugWarnLog(
|
|
683
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
688
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
684
689
|
}
|
|
685
690
|
// Refresh the status from the API
|
|
686
691
|
interval(15000)
|
|
@@ -692,48 +697,44 @@ export class Bot extends deviceBase {
|
|
|
692
697
|
}
|
|
693
698
|
|
|
694
699
|
async BLEpushChanges(): Promise<void> {
|
|
695
|
-
this.debugLog(
|
|
700
|
+
await this.debugLog('BLEpushChanges');
|
|
696
701
|
const On = await this.getOn();
|
|
697
702
|
if (On !== this.accessory.context.On || this.allowPush) {
|
|
698
|
-
this.debugLog(
|
|
699
|
-
const switchbot = await this.platform.connectBLE();
|
|
700
|
-
// Convert to BLE Address
|
|
703
|
+
this.debugLog(`BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
704
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
701
705
|
await this.convertBLEAddress();
|
|
702
706
|
//if (switchbot !== false) {
|
|
703
707
|
if (this.botMode === 'press') {
|
|
704
|
-
this.debugLog(
|
|
708
|
+
this.debugLog(`Bot Mode: ${this.botMode}`);
|
|
705
709
|
switchbot
|
|
706
710
|
.discover({ model: 'H', quick: true, id: this.device.bleMac })
|
|
707
711
|
.then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
|
|
708
|
-
this.infoLog(
|
|
712
|
+
this.infoLog(`On: ${On}`);
|
|
709
713
|
return await device_list[0].press({ id: this.device.bleMac });
|
|
710
714
|
})
|
|
711
|
-
.then(() => {
|
|
712
|
-
this.
|
|
713
|
-
this.
|
|
714
|
-
+ `On: ${On} sent over BLE, sent successfully`);
|
|
715
|
-
this.accessory.context.On = On;
|
|
715
|
+
.then(async () => {
|
|
716
|
+
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
717
|
+
await this.updateHomeKitCharacteristics();
|
|
716
718
|
setTimeout(() => {
|
|
717
719
|
if (this.botDeviceType === 'switch') {
|
|
718
720
|
this.Switch?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
719
721
|
} else {
|
|
720
722
|
this.Outlet?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
|
|
721
723
|
}
|
|
722
|
-
this.debugLog(
|
|
724
|
+
this.debugLog(`On: ${On}, Switch Timeout`);
|
|
723
725
|
}, 500);
|
|
724
726
|
})
|
|
725
727
|
.catch(async (e: any) => {
|
|
726
|
-
this.apiError(e);
|
|
727
|
-
this.errorLog(
|
|
728
|
-
+ ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
|
|
728
|
+
await this.apiError(e);
|
|
729
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
729
730
|
await this.BLEPushConnection();
|
|
730
731
|
});
|
|
731
732
|
} else if (this.botMode === 'switch') {
|
|
732
|
-
this.debugLog(
|
|
733
|
+
this.debugLog(`Press Mode: ${this.botMode}`);
|
|
733
734
|
switchbot
|
|
734
735
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
735
736
|
.then(async (device_list: any) => {
|
|
736
|
-
this.infoLog(
|
|
737
|
+
this.infoLog(`On: ${On}`);
|
|
737
738
|
return await this.retryBLE({
|
|
738
739
|
max: await this.maxRetryBLE(),
|
|
739
740
|
fn: async () => {
|
|
@@ -745,29 +746,28 @@ export class Bot extends deviceBase {
|
|
|
745
746
|
},
|
|
746
747
|
});
|
|
747
748
|
})
|
|
748
|
-
.then(() => {
|
|
749
|
-
this.
|
|
750
|
-
this.
|
|
749
|
+
.then(async () => {
|
|
750
|
+
await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
|
|
751
|
+
await this.updateHomeKitCharacteristics();
|
|
751
752
|
})
|
|
752
753
|
.catch(async (e: any) => {
|
|
753
|
-
this.apiError(e);
|
|
754
|
-
this.errorLog(
|
|
755
|
-
+ ` Connection & botMode: ${this.botMode}, Error Message: ${JSON.stringify(e.message)}`);
|
|
754
|
+
await this.apiError(e);
|
|
755
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
756
756
|
await this.BLEPushConnection();
|
|
757
757
|
});
|
|
758
758
|
} else {
|
|
759
|
-
this.errorLog(
|
|
759
|
+
await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`);
|
|
760
760
|
}
|
|
761
761
|
} else {
|
|
762
|
-
this.debugLog(
|
|
762
|
+
await this.debugLog(`No Changes (BLEpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
763
763
|
}
|
|
764
764
|
}
|
|
765
765
|
|
|
766
766
|
async openAPIpushChanges(): Promise<void> {
|
|
767
|
-
this.debugLog(
|
|
767
|
+
await this.debugLog('openAPIpushChanges');
|
|
768
768
|
let On = await this.getOn();
|
|
769
769
|
if (this.multiPressCount > 0) {
|
|
770
|
-
this.debugLog(`${this.
|
|
770
|
+
await this.debugLog(`${this.multiPressCount} request(s) queued.`);
|
|
771
771
|
On = true;
|
|
772
772
|
}
|
|
773
773
|
if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
|
|
@@ -775,30 +775,30 @@ export class Bot extends deviceBase {
|
|
|
775
775
|
if (this.botMode === 'switch' && On) {
|
|
776
776
|
command = 'turnOn';
|
|
777
777
|
On = true;
|
|
778
|
-
this.debugLog(
|
|
778
|
+
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
779
779
|
} else if (this.botMode === 'switch' && !On) {
|
|
780
780
|
command = 'turnOff';
|
|
781
781
|
On = false;
|
|
782
|
-
this.debugLog(
|
|
782
|
+
await this.debugLog(`Switch Mode, Turning ${On}`);
|
|
783
783
|
} else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
784
784
|
command = 'press';
|
|
785
|
-
this.debugLog(
|
|
785
|
+
await this.debugLog('Press Mode');
|
|
786
786
|
On = false;
|
|
787
787
|
} else {
|
|
788
|
-
throw new Error(
|
|
788
|
+
throw new Error('Device Parameters not set for this Bot.');
|
|
789
789
|
}
|
|
790
790
|
const bodyChange = JSON.stringify({
|
|
791
791
|
command: `${command}`,
|
|
792
792
|
parameter: 'default',
|
|
793
793
|
commandType: 'command',
|
|
794
794
|
});
|
|
795
|
-
this.debugLog(
|
|
795
|
+
this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
796
796
|
try {
|
|
797
797
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
798
798
|
const deviceStatus: any = await body.json();
|
|
799
|
-
await this.
|
|
800
|
-
if (
|
|
801
|
-
await this.
|
|
799
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
800
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
801
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
802
802
|
await this.updateHomeKitCharacteristics();
|
|
803
803
|
} else {
|
|
804
804
|
await this.statusCode(statusCode);
|
|
@@ -807,19 +807,17 @@ export class Bot extends deviceBase {
|
|
|
807
807
|
if (this.device.bot?.mode === 'multipress') {
|
|
808
808
|
this.multiPressCount--;
|
|
809
809
|
if (this.multiPressCount > 0) {
|
|
810
|
-
this.debugLog(
|
|
810
|
+
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
811
811
|
On = true;
|
|
812
|
-
this.openAPIpushChanges();
|
|
812
|
+
await this.openAPIpushChanges();
|
|
813
813
|
}
|
|
814
814
|
}
|
|
815
815
|
} catch (e: any) {
|
|
816
|
-
this.apiError(e);
|
|
817
|
-
this.errorLog(
|
|
818
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
816
|
+
await this.apiError(e);
|
|
817
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
819
818
|
}
|
|
820
819
|
} else {
|
|
821
|
-
this.debugLog(
|
|
822
|
-
+ ` On: ${On}, OnCached: ${this.accessory.context.On}`);
|
|
820
|
+
await this.debugLog(`No Changes (openAPIpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
|
|
823
821
|
}
|
|
824
822
|
}
|
|
825
823
|
|
|
@@ -829,7 +827,8 @@ export class Bot extends deviceBase {
|
|
|
829
827
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
830
828
|
if (this.botDeviceType === 'garagedoor') {
|
|
831
829
|
if (this.GarageDoor) {
|
|
832
|
-
this.
|
|
830
|
+
await this.debugLog(`Set TargetDoorState: ${value}`);
|
|
831
|
+
this.infoLog(`Set TargetDoorState: ${value}`);
|
|
833
832
|
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
834
833
|
await this.setOn(false);
|
|
835
834
|
this.GarageDoor.On = false;
|
|
@@ -840,7 +839,7 @@ export class Bot extends deviceBase {
|
|
|
840
839
|
}
|
|
841
840
|
} else if (this.botDeviceType === 'door') {
|
|
842
841
|
if (this.Door) {
|
|
843
|
-
this.
|
|
842
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
844
843
|
if (value === 0) {
|
|
845
844
|
await this.setOn(false);
|
|
846
845
|
this.Door.On = false;
|
|
@@ -851,7 +850,7 @@ export class Bot extends deviceBase {
|
|
|
851
850
|
}
|
|
852
851
|
} else if (this.botDeviceType === 'window') {
|
|
853
852
|
if (this.Window) {
|
|
854
|
-
this.
|
|
853
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
855
854
|
if (value === 0) {
|
|
856
855
|
await this.setOn(false);
|
|
857
856
|
this.Window.On = false;
|
|
@@ -862,7 +861,7 @@ export class Bot extends deviceBase {
|
|
|
862
861
|
}
|
|
863
862
|
} else if (this.botDeviceType === 'windowcovering') {
|
|
864
863
|
if (this.WindowCovering) {
|
|
865
|
-
this.
|
|
864
|
+
await this.debugLog(`Set TargetPosition: ${value}`);
|
|
866
865
|
if (value === 0) {
|
|
867
866
|
await this.setOn(false);
|
|
868
867
|
this.WindowCovering.On = false;
|
|
@@ -873,7 +872,7 @@ export class Bot extends deviceBase {
|
|
|
873
872
|
}
|
|
874
873
|
} else if (this.botDeviceType === 'lock') {
|
|
875
874
|
if (this.LockMechanism) {
|
|
876
|
-
this.
|
|
875
|
+
await this.debugLog(`Set LockTargetState: ${value}`);
|
|
877
876
|
if (value === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
878
877
|
await this.setOn(false);
|
|
879
878
|
this.LockMechanism.On = false;
|
|
@@ -884,7 +883,7 @@ export class Bot extends deviceBase {
|
|
|
884
883
|
}
|
|
885
884
|
} else if (this.botDeviceType === 'faucet') {
|
|
886
885
|
if (this.Faucet) {
|
|
887
|
-
this.
|
|
886
|
+
await this.debugLog(`Set Active: ${value}`);
|
|
888
887
|
if (value === this.hap.Characteristic.Active.INACTIVE) {
|
|
889
888
|
await this.setOn(false);
|
|
890
889
|
this.Faucet.On = false;
|
|
@@ -895,7 +894,7 @@ export class Bot extends deviceBase {
|
|
|
895
894
|
}
|
|
896
895
|
} else if (this.botDeviceType === 'stateful') {
|
|
897
896
|
if (this.StatefulProgrammableSwitch) {
|
|
898
|
-
this.
|
|
897
|
+
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
899
898
|
if (value === 0) {
|
|
900
899
|
await this.setOn(false);
|
|
901
900
|
this.StatefulProgrammableSwitch.On = false;
|
|
@@ -906,7 +905,7 @@ export class Bot extends deviceBase {
|
|
|
906
905
|
}
|
|
907
906
|
} else if (this.botDeviceType === 'switch') {
|
|
908
907
|
if (this.Switch) {
|
|
909
|
-
this.
|
|
908
|
+
await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
|
|
910
909
|
if (value === 0) {
|
|
911
910
|
await this.setOn(false);
|
|
912
911
|
this.Switch.On = false;
|
|
@@ -917,7 +916,7 @@ export class Bot extends deviceBase {
|
|
|
917
916
|
}
|
|
918
917
|
} else {
|
|
919
918
|
if (this.Outlet) {
|
|
920
|
-
this.
|
|
919
|
+
await this.debugLog(`Set On: ${value}`);
|
|
921
920
|
await this.setOn(Boolean(value));
|
|
922
921
|
this.Outlet.On = value;
|
|
923
922
|
}
|
|
@@ -925,7 +924,7 @@ export class Bot extends deviceBase {
|
|
|
925
924
|
if (this.device.bot?.mode === 'multipress') {
|
|
926
925
|
if (value === true) {
|
|
927
926
|
this.multiPressCount++;
|
|
928
|
-
this.debugLog(
|
|
927
|
+
await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
929
928
|
}
|
|
930
929
|
}
|
|
931
930
|
this.doBotUpdate.next();
|
|
@@ -938,186 +937,173 @@ export class Bot extends deviceBase {
|
|
|
938
937
|
// State
|
|
939
938
|
if (this.botDeviceType === 'garagedoor') {
|
|
940
939
|
if (this.GarageDoor?.On === undefined) {
|
|
941
|
-
this.debugLog(
|
|
940
|
+
await this.debugLog(`On: ${this.GarageDoor?.On}`);
|
|
942
941
|
} else {
|
|
943
942
|
if (this.GarageDoor.On) {
|
|
944
943
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
|
|
945
944
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
|
|
946
|
-
this.debugLog(
|
|
947
|
-
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
945
|
+
await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
948
946
|
} else {
|
|
949
947
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
950
948
|
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
951
|
-
this.debugLog(
|
|
952
|
-
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
949
|
+
await this.debugLog(`updateCharacteristicc TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
|
|
953
950
|
}
|
|
954
951
|
}
|
|
955
952
|
await this.setOn(Boolean(this.GarageDoor?.On));
|
|
956
|
-
this.debugLog(
|
|
953
|
+
await this.debugLog(`Garage Door On: ${this.GarageDoor?.On}`);
|
|
957
954
|
} else if (this.botDeviceType === 'door') {
|
|
958
955
|
if (this.Door?.On === undefined) {
|
|
959
|
-
this.debugLog(
|
|
956
|
+
await this.debugLog(`On: ${this.Door?.On}`);
|
|
960
957
|
} else {
|
|
961
958
|
if (this.Door.On) {
|
|
962
959
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
963
960
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
964
961
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
965
|
-
this.debugLog(
|
|
966
|
-
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
|
|
962
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
|
|
967
963
|
} else {
|
|
968
964
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
969
965
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
970
966
|
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
971
|
-
this.debugLog(
|
|
972
|
-
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
|
|
967
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
|
|
973
968
|
}
|
|
974
969
|
}
|
|
975
970
|
await this.setOn(Boolean(this.Door?.On));
|
|
976
|
-
this.debugLog(
|
|
971
|
+
await this.debugLog(`Door On: ${this.Door?.On}`);
|
|
977
972
|
} else if (this.botDeviceType === 'window') {
|
|
978
973
|
if (this.Window?.On === undefined) {
|
|
979
|
-
this.debugLog(
|
|
974
|
+
await this.debugLog(`On: ${this.Window?.On}`);
|
|
980
975
|
} else {
|
|
981
976
|
if (this.Window.On) {
|
|
982
977
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
983
978
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
984
979
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
985
|
-
this.debugLog(
|
|
986
|
-
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
|
|
980
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
|
|
987
981
|
} else {
|
|
988
982
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
989
983
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
990
984
|
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
991
|
-
this.debugLog(
|
|
992
|
-
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
|
|
985
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
|
|
993
986
|
}
|
|
994
987
|
}
|
|
995
988
|
await this.setOn(Boolean(this.Window?.On));
|
|
996
|
-
this.debugLog(
|
|
989
|
+
await this.debugLog(`Window On: ${this.Window?.On}`);
|
|
997
990
|
} else if (this.botDeviceType === 'windowcovering') {
|
|
998
991
|
if (this.WindowCovering?.On === undefined) {
|
|
999
|
-
this.debugLog(
|
|
992
|
+
await this.debugLog(`On: ${this.WindowCovering?.On}`);
|
|
1000
993
|
} else {
|
|
1001
994
|
if (this.WindowCovering.On) {
|
|
1002
995
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
1003
996
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
1004
997
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1005
|
-
this.debugLog(
|
|
1006
|
-
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
|
|
998
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
|
|
1007
999
|
} else {
|
|
1008
1000
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
1009
1001
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
1010
1002
|
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
1011
|
-
this.debugLog(
|
|
1012
|
-
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
|
|
1003
|
+
await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
|
|
1013
1004
|
}
|
|
1014
1005
|
}
|
|
1015
1006
|
await this.setOn(Boolean(this.WindowCovering?.On));
|
|
1016
|
-
this.debugLog(
|
|
1007
|
+
await this.debugLog(`Window Covering On: ${this.WindowCovering?.On}`);
|
|
1017
1008
|
} else if (this.botDeviceType === 'lock') {
|
|
1018
1009
|
if (this.LockMechanism?.On === undefined) {
|
|
1019
|
-
this.debugLog(
|
|
1010
|
+
await this.debugLog(`On: ${this.LockMechanism?.On}`);
|
|
1020
1011
|
} else {
|
|
1021
1012
|
if (this.LockMechanism.On) {
|
|
1022
1013
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
|
|
1023
1014
|
this.hap.Characteristic.LockTargetState.UNSECURED);
|
|
1024
1015
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
|
|
1025
1016
|
this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
1026
|
-
this.debugLog(
|
|
1027
|
-
+ ` LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
|
|
1017
|
+
await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
|
|
1028
1018
|
} else {
|
|
1029
1019
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
|
|
1030
1020
|
this.hap.Characteristic.LockTargetState.SECURED);
|
|
1031
1021
|
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
|
|
1032
1022
|
this.hap.Characteristic.LockCurrentState.SECURED);
|
|
1033
|
-
this.debugLog(
|
|
1034
|
-
+ ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
|
|
1023
|
+
await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
|
|
1035
1024
|
}
|
|
1036
1025
|
}
|
|
1037
1026
|
await this.setOn(Boolean(this.LockMechanism?.On));
|
|
1038
|
-
this.debugLog(
|
|
1027
|
+
await this.debugLog(`Lock On: ${this.LockMechanism?.On}`);
|
|
1039
1028
|
} else if (this.botDeviceType === 'faucet') {
|
|
1040
1029
|
if (this.Faucet?.On === undefined) {
|
|
1041
|
-
this.debugLog(
|
|
1030
|
+
await this.debugLog(`On: ${this.Faucet?.On}`);
|
|
1042
1031
|
} else {
|
|
1043
1032
|
if (this.Faucet.On) {
|
|
1044
1033
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
1045
|
-
this.debugLog(
|
|
1034
|
+
await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
|
|
1046
1035
|
} else {
|
|
1047
1036
|
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
1048
|
-
this.debugLog(
|
|
1037
|
+
await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
|
|
1049
1038
|
}
|
|
1050
1039
|
}
|
|
1051
1040
|
await this.setOn(Boolean(this.Faucet?.On));
|
|
1052
|
-
this.debugLog(
|
|
1041
|
+
await this.debugLog(`Faucet On: ${this.Faucet?.On}`);
|
|
1053
1042
|
} else if (this.botDeviceType === 'fan') {
|
|
1054
1043
|
if (this.Fan?.On === undefined) {
|
|
1055
|
-
this.debugLog(
|
|
1044
|
+
await this.debugLog(`On: ${this.Fan?.On}`);
|
|
1056
1045
|
} else {
|
|
1057
1046
|
if (this.Fan.On) {
|
|
1058
1047
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
|
|
1059
|
-
this.debugLog(
|
|
1048
|
+
await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
|
|
1060
1049
|
} else {
|
|
1061
1050
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
|
|
1062
|
-
this.debugLog(
|
|
1051
|
+
await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
|
|
1063
1052
|
}
|
|
1064
1053
|
}
|
|
1065
1054
|
await this.setOn(Boolean(this.Fan?.On));
|
|
1066
|
-
this.debugLog(
|
|
1055
|
+
await this.debugLog(`Fan On: ${this.Fan?.On}`);
|
|
1067
1056
|
} else if (this.botDeviceType === 'stateful') {
|
|
1068
1057
|
if (this.StatefulProgrammableSwitch?.On === undefined) {
|
|
1069
|
-
this.debugLog(
|
|
1058
|
+
await this.debugLog(`On: ${this.StatefulProgrammableSwitch?.On}`);
|
|
1070
1059
|
} else {
|
|
1071
1060
|
if (this.StatefulProgrammableSwitch.On) {
|
|
1072
1061
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
1073
1062
|
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1074
1063
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
1075
|
-
this.debugLog(
|
|
1076
|
-
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch.On})`);
|
|
1064
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
|
|
1077
1065
|
} else {
|
|
1078
1066
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
1079
1067
|
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
1080
1068
|
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
1081
|
-
this.debugLog(
|
|
1082
|
-
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch.On})`);
|
|
1069
|
+
await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
|
|
1083
1070
|
}
|
|
1084
1071
|
}
|
|
1085
1072
|
await this.setOn(Boolean(this.StatefulProgrammableSwitch?.On));
|
|
1086
|
-
this.debugLog(
|
|
1073
|
+
await this.debugLog(`StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
|
|
1087
1074
|
} else if (this.botDeviceType === 'switch') {
|
|
1088
1075
|
if (this.Switch?.On === undefined) {
|
|
1089
|
-
this.debugLog(
|
|
1076
|
+
await this.debugLog(`On: ${this.Switch?.On}`);
|
|
1090
1077
|
} else {
|
|
1091
1078
|
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
|
|
1092
|
-
this.debugLog(
|
|
1079
|
+
await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
|
|
1093
1080
|
}
|
|
1094
1081
|
await this.setOn(Boolean(this.Switch?.On));
|
|
1095
1082
|
} else {
|
|
1096
1083
|
if (this.Outlet?.On === undefined) {
|
|
1097
|
-
this.debugLog(
|
|
1084
|
+
await this.debugLog(`On: ${this.Outlet?.On}`);
|
|
1098
1085
|
} else {
|
|
1099
1086
|
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet.On);
|
|
1100
|
-
this.debugLog(
|
|
1087
|
+
await this.debugLog(`updateCharacteristic On: ${this.Outlet.On}`);
|
|
1101
1088
|
}
|
|
1102
1089
|
await this.setOn(Boolean(this.Outlet?.On));
|
|
1103
1090
|
}
|
|
1104
1091
|
this.accessory.context.On = await this.getOn();
|
|
1105
1092
|
// BatteryLevel
|
|
1106
1093
|
if (this.Battery.BatteryLevel === undefined) {
|
|
1107
|
-
this.debugLog(
|
|
1094
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1108
1095
|
} else {
|
|
1109
1096
|
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
1110
1097
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
1111
|
-
this.debugLog(
|
|
1098
|
+
await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
1112
1099
|
}
|
|
1113
1100
|
// StatusLowBattery
|
|
1114
1101
|
if (this.Battery.StatusLowBattery === undefined) {
|
|
1115
|
-
this.debugLog(
|
|
1102
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1116
1103
|
} else {
|
|
1117
1104
|
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
1118
1105
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
1119
|
-
this.debugLog(
|
|
1120
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1106
|
+
await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
1121
1107
|
}
|
|
1122
1108
|
}
|
|
1123
1109
|
|
|
@@ -1125,7 +1111,7 @@ export class Bot extends deviceBase {
|
|
|
1125
1111
|
// If outletService still present, then remove first
|
|
1126
1112
|
if (this.Outlet?.Service) {
|
|
1127
1113
|
this.Outlet.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
|
|
1128
|
-
this.warnLog(
|
|
1114
|
+
await this.warnLog('Removing Leftover Outlet Service');
|
|
1129
1115
|
accessory.removeService(this.Outlet.Service);
|
|
1130
1116
|
}
|
|
1131
1117
|
}
|
|
@@ -1134,7 +1120,7 @@ export class Bot extends deviceBase {
|
|
|
1134
1120
|
// If garageDoorService still present, then remove first
|
|
1135
1121
|
if (this.GarageDoor?.Service) {
|
|
1136
1122
|
this.GarageDoor.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
|
|
1137
|
-
this.warnLog(
|
|
1123
|
+
await this.warnLog('Removing Leftover Garage Door Service');
|
|
1138
1124
|
accessory.removeService(this.GarageDoor.Service);
|
|
1139
1125
|
}
|
|
1140
1126
|
}
|
|
@@ -1143,7 +1129,7 @@ export class Bot extends deviceBase {
|
|
|
1143
1129
|
// If doorService still present, then remove first
|
|
1144
1130
|
if (this.Door?.Service) {
|
|
1145
1131
|
this.Door.Service = this.accessory.getService(this.hap.Service.Door) as Service;
|
|
1146
|
-
this.warnLog(
|
|
1132
|
+
await this.warnLog('Removing Leftover Door Service');
|
|
1147
1133
|
accessory.removeService(this.Door.Service);
|
|
1148
1134
|
}
|
|
1149
1135
|
}
|
|
@@ -1152,7 +1138,7 @@ export class Bot extends deviceBase {
|
|
|
1152
1138
|
// If lockService still present, then remove first
|
|
1153
1139
|
if (this.LockMechanism?.Service) {
|
|
1154
1140
|
this.LockMechanism.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
|
|
1155
|
-
this.warnLog(
|
|
1141
|
+
this.warnLog('Removing Leftover Lock Service');
|
|
1156
1142
|
accessory.removeService(this.LockMechanism.Service);
|
|
1157
1143
|
}
|
|
1158
1144
|
}
|
|
@@ -1161,7 +1147,7 @@ export class Bot extends deviceBase {
|
|
|
1161
1147
|
// If faucetService still present, then remove first
|
|
1162
1148
|
if (this.Faucet?.Service) {
|
|
1163
1149
|
this.Faucet.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
|
|
1164
|
-
this.warnLog(
|
|
1150
|
+
await this.warnLog('Removing Leftover Faucet Service');
|
|
1165
1151
|
accessory.removeService(this.Faucet.Service);
|
|
1166
1152
|
}
|
|
1167
1153
|
}
|
|
@@ -1170,7 +1156,7 @@ export class Bot extends deviceBase {
|
|
|
1170
1156
|
// If fanService still present, then remove first
|
|
1171
1157
|
if (this.Fan?.Service) {
|
|
1172
1158
|
this.Fan.Service = this.accessory.getService(this.hap.Service.Fanv2) as Service;
|
|
1173
|
-
this.warnLog(
|
|
1159
|
+
this.warnLog('Removing Leftover Fan Service');
|
|
1174
1160
|
accessory.removeService(this.Fan.Service);
|
|
1175
1161
|
}
|
|
1176
1162
|
}
|
|
@@ -1179,7 +1165,7 @@ export class Bot extends deviceBase {
|
|
|
1179
1165
|
// If windowService still present, then remove first
|
|
1180
1166
|
if (this.Window?.Service) {
|
|
1181
1167
|
this.Window.Service = this.accessory.getService(this.hap.Service.Window) as Service;
|
|
1182
|
-
this.warnLog(
|
|
1168
|
+
await this.warnLog('Removing Leftover Window Service');
|
|
1183
1169
|
accessory.removeService(this.Window.Service);
|
|
1184
1170
|
}
|
|
1185
1171
|
}
|
|
@@ -1188,7 +1174,7 @@ export class Bot extends deviceBase {
|
|
|
1188
1174
|
// If windowCoveringService still present, then remove first
|
|
1189
1175
|
if (this.WindowCovering?.Service) {
|
|
1190
1176
|
this.WindowCovering.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
|
|
1191
|
-
this.warnLog(
|
|
1177
|
+
await this.warnLog('Removing Leftover Window Covering Service');
|
|
1192
1178
|
accessory.removeService(this.WindowCovering.Service);
|
|
1193
1179
|
}
|
|
1194
1180
|
}
|
|
@@ -1197,7 +1183,7 @@ export class Bot extends deviceBase {
|
|
|
1197
1183
|
// If statefulProgrammableSwitchService still present, then remove first
|
|
1198
1184
|
if (this.StatefulProgrammableSwitch?.Service) {
|
|
1199
1185
|
this.StatefulProgrammableSwitch.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
|
|
1200
|
-
this.warnLog(
|
|
1186
|
+
await this.warnLog('Removing Leftover Stateful Programmable Switch Service');
|
|
1201
1187
|
accessory.removeService(this.StatefulProgrammableSwitch.Service);
|
|
1202
1188
|
}
|
|
1203
1189
|
}
|
|
@@ -1206,7 +1192,7 @@ export class Bot extends deviceBase {
|
|
|
1206
1192
|
// If switchService still present, then remove first
|
|
1207
1193
|
if (this.Switch?.Service) {
|
|
1208
1194
|
this.Switch.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
|
|
1209
|
-
this.warnLog(
|
|
1195
|
+
await this.warnLog('Removing Leftover Switch Service');
|
|
1210
1196
|
accessory.removeService(this.Switch.Service);
|
|
1211
1197
|
}
|
|
1212
1198
|
}
|
|
@@ -1285,33 +1271,33 @@ export class Bot extends deviceBase {
|
|
|
1285
1271
|
//Bot Device Type
|
|
1286
1272
|
if (!device.bot?.deviceType && this.accessory.context.deviceType) {
|
|
1287
1273
|
this.botDeviceType = this.accessory.context.deviceType;
|
|
1288
|
-
this.debugWarnLog(
|
|
1274
|
+
await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}, from Accessory Cache.`);
|
|
1289
1275
|
} else if (device.bot?.deviceType) {
|
|
1290
1276
|
this.accessory.context.deviceType = device.bot.deviceType;
|
|
1291
|
-
this.debugWarnLog(
|
|
1277
|
+
await this.debugWarnLog(`Accessory Cache: ${this.accessory.context.deviceType}`);
|
|
1292
1278
|
this.botDeviceType = this.accessory.context.deviceType;
|
|
1293
|
-
this.debugWarnLog(
|
|
1279
|
+
await this.debugWarnLog(`Using Device Type: ${this.botDeviceType}`);
|
|
1294
1280
|
} else {
|
|
1295
1281
|
this.botDeviceType = 'outlet';
|
|
1296
|
-
this.errorLog(
|
|
1297
|
-
this.warnLog(
|
|
1282
|
+
await this.errorLog(`No Device Type Set, deviceType: ${this.device.bot?.deviceType}`);
|
|
1283
|
+
await this.warnLog(`Using default deviceType: ${this.botDeviceType}`);
|
|
1298
1284
|
}
|
|
1299
1285
|
// Bot Mode
|
|
1300
1286
|
if (!device.bot?.mode) {
|
|
1301
1287
|
this.botMode = 'switch';
|
|
1302
|
-
this.warnLog(
|
|
1303
|
-
this.warnLog(
|
|
1288
|
+
await this.warnLog('does not have bot mode set in the Plugin\'s SwitchBot Device Settings,');
|
|
1289
|
+
await this.warnLog(`is defaulting to "${this.botMode}" mode, you may experience issues.`);
|
|
1304
1290
|
} else if (device.bot?.mode === 'switch') {
|
|
1305
1291
|
this.botMode = 'switch';
|
|
1306
|
-
this.debugLog(
|
|
1292
|
+
await this.debugLog(`Using Bot Mode: ${this.botMode}`);
|
|
1307
1293
|
} else if (device.bot?.mode === 'press') {
|
|
1308
1294
|
this.botMode = 'press';
|
|
1309
|
-
this.debugLog(
|
|
1295
|
+
await this.debugLog(`Using Bot Mode: ${this.botMode}`);
|
|
1310
1296
|
} else if (device.bot?.mode === 'multipress') {
|
|
1311
1297
|
this.botMode = 'multipress';
|
|
1312
|
-
this.debugLog(
|
|
1298
|
+
await this.debugLog(`Using Bot Mode: ${this.botMode}`);
|
|
1313
1299
|
} else {
|
|
1314
|
-
throw new Error(
|
|
1300
|
+
throw new Error(`Bot Mode: ${this.botMode}`);
|
|
1315
1301
|
}
|
|
1316
1302
|
|
|
1317
1303
|
// Bot Double Press
|
|
@@ -1325,10 +1311,10 @@ export class Bot extends deviceBase {
|
|
|
1325
1311
|
// Bot Press PushRate
|
|
1326
1312
|
if (device?.bot?.pushRatePress) {
|
|
1327
1313
|
this.pushRatePress = device?.bot?.pushRatePress;
|
|
1328
|
-
this.debugLog(
|
|
1314
|
+
await this.debugLog(`Using Device Config Bot pushRatePress: ${this.pushRatePress}`);
|
|
1329
1315
|
} else {
|
|
1330
1316
|
this.pushRatePress = 15;
|
|
1331
|
-
this.debugLog(
|
|
1317
|
+
await this.debugLog(`Using Default Bot pushRatePress: ${this.pushRatePress}`);
|
|
1332
1318
|
}
|
|
1333
1319
|
|
|
1334
1320
|
// Bot Allow Push
|
|
@@ -1337,23 +1323,22 @@ export class Bot extends deviceBase {
|
|
|
1337
1323
|
} else {
|
|
1338
1324
|
this.allowPush = false;
|
|
1339
1325
|
}
|
|
1340
|
-
this.debugLog(
|
|
1326
|
+
await this.debugLog(`Allowing Push Changes: ${this.allowPush}`);
|
|
1341
1327
|
// Bot Multi Press Count
|
|
1342
1328
|
this.multiPressCount = 0;
|
|
1343
1329
|
}
|
|
1344
1330
|
|
|
1345
1331
|
async BLEPushConnection() {
|
|
1346
1332
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1347
|
-
this.warnLog(
|
|
1333
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
1348
1334
|
await this.openAPIpushChanges();
|
|
1349
1335
|
}
|
|
1350
1336
|
}
|
|
1351
1337
|
|
|
1352
1338
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
1353
|
-
this.errorLog(
|
|
1354
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
1339
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
1355
1340
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
1356
|
-
this.warnLog(
|
|
1341
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
1357
1342
|
await this.openAPIRefreshStatus();
|
|
1358
1343
|
}
|
|
1359
1344
|
}
|