@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.3
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.js +102 -102
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +85 -85
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +98 -98
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +140 -140
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +44 -44
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +82 -82
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +11 -11
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +41 -41
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +96 -96
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +43 -43
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js +84 -84
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +44 -44
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +119 -119
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +75 -75
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +44 -44
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +42 -42
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/meterpro.js +42 -42
- package/dist/device/meterpro.js.map +1 -1
- package/dist/device/motion.js +42 -42
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +60 -60
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -74
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +44 -44
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -31
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +10 -10
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js +9 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.js +11 -11
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.js +11 -11
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.js +9 -9
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +55 -55
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.js +33 -33
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.js +228 -228
- package/dist/platform.js.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +102 -102
- package/src/device/bot.ts +85 -85
- package/src/device/ceilinglight.ts +98 -98
- package/src/device/colorbulb.ts +140 -140
- package/src/device/contact.ts +44 -44
- package/src/device/curtain.ts +82 -82
- package/src/device/device.ts +41 -41
- package/src/device/fan.ts +96 -96
- package/src/device/hub.ts +43 -43
- package/src/device/humidifier.ts +84 -84
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +119 -119
- package/src/device/lock.ts +75 -75
- package/src/device/meter.ts +44 -44
- package/src/device/meterplus.ts +42 -42
- package/src/device/meterpro.ts +42 -42
- package/src/device/motion.ts +42 -42
- package/src/device/plug.ts +60 -60
- package/src/device/robotvacuumcleaner.ts +74 -74
- package/src/device/waterdetector.ts +44 -44
- package/src/irdevice/airconditioner.ts +31 -31
- package/src/irdevice/airpurifier.ts +10 -10
- package/src/irdevice/camera.ts +9 -9
- package/src/irdevice/fan.ts +11 -11
- package/src/irdevice/irdevice.ts +11 -11
- package/src/irdevice/light.ts +9 -9
- package/src/irdevice/other.ts +55 -55
- package/src/irdevice/tv.ts +33 -33
- package/src/irdevice/vacuumcleaner.ts +9 -9
- package/src/irdevice/waterheater.ts +9 -9
- package/src/platform.ts +228 -228
package/src/device/bot.ts
CHANGED
|
@@ -263,7 +263,7 @@ export class Bot extends deviceBase {
|
|
|
263
263
|
}
|
|
264
264
|
} catch (e: any) {
|
|
265
265
|
await this.apiError(e)
|
|
266
|
-
|
|
266
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
267
267
|
}
|
|
268
268
|
this.botUpdateInProgress = false
|
|
269
269
|
})
|
|
@@ -273,47 +273,47 @@ export class Bot extends deviceBase {
|
|
|
273
273
|
* Parse the device status from the SwitchBotBLE API
|
|
274
274
|
*/
|
|
275
275
|
async BLEparseStatus(): Promise<void> {
|
|
276
|
-
|
|
277
|
-
|
|
276
|
+
this.debugLog('BLEparseStatus')
|
|
277
|
+
this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`)
|
|
278
278
|
|
|
279
279
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
280
280
|
this.On = this.serviceData.mode ? this.serviceData.state : false
|
|
281
281
|
const mode = this.serviceData.mode ? 'Switch' : 'Press'
|
|
282
|
-
|
|
282
|
+
this.debugLog(`${mode} Mode, On: ${this.On}`)
|
|
283
283
|
this.accessory.context.On = this.On
|
|
284
284
|
|
|
285
285
|
// BatteryLevel
|
|
286
286
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
287
|
-
|
|
287
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
288
288
|
|
|
289
289
|
// StatusLowBattery
|
|
290
290
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
291
291
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
292
292
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
293
|
-
|
|
293
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
/**
|
|
297
297
|
* Parse the device status from the SwitchBot OpenAPI
|
|
298
298
|
*/
|
|
299
299
|
async openAPIparseStatus(): Promise<void> {
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
this.debugLog('openAPIparseStatus')
|
|
301
|
+
this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`)
|
|
302
302
|
|
|
303
303
|
// On
|
|
304
304
|
this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on'
|
|
305
|
-
|
|
305
|
+
this.debugLog(`On: ${this.On}`)
|
|
306
306
|
this.accessory.context.On = this.On
|
|
307
307
|
|
|
308
308
|
// Battery Level
|
|
309
309
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
310
|
-
|
|
310
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
311
311
|
|
|
312
312
|
// StatusLowBattery
|
|
313
313
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
314
314
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
315
315
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
316
|
-
|
|
316
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
317
317
|
|
|
318
318
|
// Firmware Version
|
|
319
319
|
if (this.deviceStatus.version) {
|
|
@@ -327,31 +327,31 @@ export class Bot extends deviceBase {
|
|
|
327
327
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
328
328
|
.updateValue(deviceVersion)
|
|
329
329
|
this.accessory.context.version = deviceVersion
|
|
330
|
-
|
|
330
|
+
this.debugLog(`version: ${deviceVersion}`)
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
async parseStatusWebhook(): Promise<void> {
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
this.debugLog('parseStatusWebhook')
|
|
336
|
+
this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery}, ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`)
|
|
337
337
|
|
|
338
338
|
// On
|
|
339
339
|
this.On = this.webhookContext.power === 'on'
|
|
340
|
-
|
|
340
|
+
this.debugLog(`On: ${this.On}`)
|
|
341
341
|
|
|
342
342
|
// BatteryLevel
|
|
343
343
|
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
344
|
-
|
|
344
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
345
345
|
|
|
346
346
|
// StatusLowBattery
|
|
347
347
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
348
348
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
349
349
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
350
|
-
|
|
350
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
351
351
|
|
|
352
352
|
// Mode
|
|
353
353
|
this.botMode = this.webhookContext.deviceMode
|
|
354
|
-
|
|
354
|
+
this.debugLog(`Mode: ${this.botMode}`)
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
/**
|
|
@@ -359,19 +359,19 @@ export class Bot extends deviceBase {
|
|
|
359
359
|
*/
|
|
360
360
|
async refreshStatus(): Promise<void> {
|
|
361
361
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
362
|
-
|
|
362
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
363
363
|
} else if (this.BLE) {
|
|
364
364
|
await this.BLERefreshStatus()
|
|
365
365
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
366
366
|
await this.openAPIRefreshStatus()
|
|
367
367
|
} else {
|
|
368
368
|
await this.offlineOff()
|
|
369
|
-
|
|
369
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
async BLERefreshStatus(): Promise<void> {
|
|
374
|
-
|
|
374
|
+
this.debugLog('BLERefreshStatus')
|
|
375
375
|
const switchBotBLE = await this.switchbotBLE()
|
|
376
376
|
if (switchBotBLE === undefined) {
|
|
377
377
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -386,7 +386,7 @@ export class Bot extends deviceBase {
|
|
|
386
386
|
await this.BLEparseStatus()
|
|
387
387
|
await this.updateHomeKitCharacteristics()
|
|
388
388
|
} else {
|
|
389
|
-
|
|
389
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
390
390
|
await this.BLERefreshConnection(switchBotBLE)
|
|
391
391
|
}
|
|
392
392
|
})()
|
|
@@ -394,67 +394,67 @@ export class Bot extends deviceBase {
|
|
|
394
394
|
}
|
|
395
395
|
|
|
396
396
|
async registerPlatformBLE(): Promise<void> {
|
|
397
|
-
|
|
397
|
+
this.debugLog('registerPlatformBLE')
|
|
398
398
|
if (this.config.options?.BLE) {
|
|
399
|
-
|
|
399
|
+
this.debugLog('is listening to Platform BLE.')
|
|
400
400
|
try {
|
|
401
401
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
402
402
|
this.device.bleMac = formattedDeviceId
|
|
403
|
-
|
|
403
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
404
404
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: botServiceData) => {
|
|
405
405
|
try {
|
|
406
|
-
|
|
406
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
407
407
|
this.serviceData = context
|
|
408
408
|
await this.BLEparseStatus()
|
|
409
409
|
await this.updateHomeKitCharacteristics()
|
|
410
410
|
} catch (e: any) {
|
|
411
|
-
|
|
411
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
} catch (error) {
|
|
415
|
-
|
|
415
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
416
416
|
}
|
|
417
417
|
} else {
|
|
418
|
-
|
|
418
|
+
this.debugLog('is not listening to Platform BLE')
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
async openAPIRefreshStatus(): Promise<void> {
|
|
423
|
-
|
|
423
|
+
this.debugLog('openAPIRefreshStatus')
|
|
424
424
|
try {
|
|
425
|
-
const
|
|
426
|
-
const deviceStatus: any =
|
|
427
|
-
|
|
425
|
+
const response = await this.deviceRefreshStatus()
|
|
426
|
+
const deviceStatus: any = response.body
|
|
427
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
428
428
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
429
|
-
|
|
429
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
430
430
|
this.deviceStatus = deviceStatus.body
|
|
431
431
|
await this.openAPIparseStatus()
|
|
432
432
|
await this.updateHomeKitCharacteristics()
|
|
433
433
|
} else {
|
|
434
|
-
|
|
435
|
-
|
|
434
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
435
|
+
this.debugWarnLog(deviceStatus)
|
|
436
436
|
}
|
|
437
437
|
} catch (e: any) {
|
|
438
438
|
await this.apiError(e)
|
|
439
|
-
|
|
439
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
442
|
|
|
443
443
|
async registerWebhook() {
|
|
444
444
|
if (this.device.webhook) {
|
|
445
|
-
|
|
445
|
+
this.debugLog('is listening webhook.')
|
|
446
446
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: botWebhookContext) => {
|
|
447
447
|
try {
|
|
448
|
-
|
|
448
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
449
449
|
this.webhookContext = context
|
|
450
450
|
await this.parseStatusWebhook()
|
|
451
451
|
await this.updateHomeKitCharacteristics()
|
|
452
452
|
} catch (e: any) {
|
|
453
|
-
|
|
453
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
454
454
|
}
|
|
455
455
|
}
|
|
456
456
|
} else {
|
|
457
|
-
|
|
457
|
+
this.debugLog('is not listening webhook.')
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
460
|
|
|
@@ -467,14 +467,14 @@ export class Bot extends deviceBase {
|
|
|
467
467
|
*/
|
|
468
468
|
async pushChanges(): Promise<void> {
|
|
469
469
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
470
|
-
|
|
470
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
471
471
|
} else if (this.BLE) {
|
|
472
472
|
await this.BLEpushChanges()
|
|
473
473
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
474
474
|
await this.openAPIpushChanges()
|
|
475
475
|
} else {
|
|
476
476
|
await this.offlineOff()
|
|
477
|
-
|
|
477
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
478
478
|
}
|
|
479
479
|
// Refresh the status from the API
|
|
480
480
|
interval(15000)
|
|
@@ -486,26 +486,26 @@ export class Bot extends deviceBase {
|
|
|
486
486
|
}
|
|
487
487
|
|
|
488
488
|
async BLEpushChanges(): Promise<void> {
|
|
489
|
-
|
|
489
|
+
this.debugLog('BLEpushChanges')
|
|
490
490
|
if ((this.On !== this.accessory.context.On) || this.allowPush) {
|
|
491
|
-
|
|
491
|
+
this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
492
492
|
const switchBotBLE = this.platform.switchBotBLE
|
|
493
493
|
try {
|
|
494
494
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
495
495
|
this.device.bleMac = formattedDeviceId
|
|
496
|
-
|
|
496
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
497
497
|
// if (switchBotBLE !== false) {
|
|
498
|
-
|
|
498
|
+
this.debugLog(`Bot Mode: ${this.botMode}`)
|
|
499
499
|
if (this.botMode === 'press') {
|
|
500
500
|
switchBotBLE
|
|
501
501
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
502
502
|
.then(async (device_list: SwitchbotDevice[]) => {
|
|
503
503
|
const deviceList = device_list as unknown as WoHand[]
|
|
504
|
-
|
|
504
|
+
this.infoLog(`On: ${this.On}`)
|
|
505
505
|
return await deviceList[0].press()
|
|
506
506
|
})
|
|
507
507
|
.then(async () => {
|
|
508
|
-
|
|
508
|
+
this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
|
|
509
509
|
await this.updateHomeKitCharacteristics()
|
|
510
510
|
setTimeout(async () => {
|
|
511
511
|
this.On = false
|
|
@@ -515,7 +515,7 @@ export class Bot extends deviceBase {
|
|
|
515
515
|
})
|
|
516
516
|
.catch(async (e: any) => {
|
|
517
517
|
await this.apiError(e)
|
|
518
|
-
|
|
518
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
519
519
|
await this.BLEPushConnection()
|
|
520
520
|
})
|
|
521
521
|
} else if (this.botMode === 'switch') {
|
|
@@ -526,7 +526,7 @@ export class Bot extends deviceBase {
|
|
|
526
526
|
this.infoLog(`On: ${this.On}`)
|
|
527
527
|
this.warnLog(`device_list: ${JSON.stringify(device_list)}`)
|
|
528
528
|
return await this.retryBLE({
|
|
529
|
-
max:
|
|
529
|
+
max: this.maxRetryBLE(),
|
|
530
530
|
fn: async () => {
|
|
531
531
|
if (deviceList.length > 0) {
|
|
532
532
|
if (this.On) {
|
|
@@ -541,38 +541,38 @@ export class Bot extends deviceBase {
|
|
|
541
541
|
})
|
|
542
542
|
})
|
|
543
543
|
.then(async () => {
|
|
544
|
-
|
|
544
|
+
this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
|
|
545
545
|
await this.updateHomeKitCharacteristics()
|
|
546
546
|
})
|
|
547
547
|
.catch(async (e: any) => {
|
|
548
548
|
await this.apiError(e)
|
|
549
|
-
|
|
549
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
550
550
|
await this.BLEPushConnection()
|
|
551
551
|
})
|
|
552
552
|
} else {
|
|
553
|
-
|
|
553
|
+
this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`)
|
|
554
554
|
}
|
|
555
555
|
} catch (error) {
|
|
556
|
-
|
|
556
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
557
557
|
}
|
|
558
558
|
} else {
|
|
559
|
-
|
|
559
|
+
this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
560
560
|
}
|
|
561
561
|
}
|
|
562
562
|
|
|
563
563
|
async openAPIpushChanges(): Promise<void> {
|
|
564
|
-
|
|
564
|
+
this.debugLog('openAPIpushChanges')
|
|
565
565
|
if (this.multiPressCount > 0) {
|
|
566
|
-
|
|
566
|
+
this.debugLog(`${this.multiPressCount} request(s) queued.`)
|
|
567
567
|
}
|
|
568
568
|
if ((this.On !== this.accessory.context.On) || this.allowPush || this.multiPressCount > 0) {
|
|
569
569
|
let command = ''
|
|
570
570
|
if (this.botMode === 'switch') {
|
|
571
571
|
command = this.On ? 'turnOn' : 'turnOff'
|
|
572
|
-
|
|
572
|
+
this.debugLog(`Switch Mode, Command: ${command}`)
|
|
573
573
|
} else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
574
574
|
command = 'press'
|
|
575
|
-
|
|
575
|
+
this.debugLog('Press Mode')
|
|
576
576
|
this.On = false
|
|
577
577
|
} else {
|
|
578
578
|
throw new Error('Device Parameters not set for this Bot.')
|
|
@@ -582,13 +582,13 @@ export class Bot extends deviceBase {
|
|
|
582
582
|
parameter: 'default',
|
|
583
583
|
commandType: 'command',
|
|
584
584
|
}
|
|
585
|
-
|
|
585
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
586
586
|
try {
|
|
587
|
-
const
|
|
588
|
-
const deviceStatus: any =
|
|
589
|
-
|
|
587
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
588
|
+
const deviceStatus: any = response.body
|
|
589
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
590
590
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
591
|
-
|
|
591
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
592
592
|
await this.updateHomeKitCharacteristics()
|
|
593
593
|
} else {
|
|
594
594
|
await this.statusCode(deviceStatus.statusCode)
|
|
@@ -596,17 +596,17 @@ export class Bot extends deviceBase {
|
|
|
596
596
|
if ((this.device as botConfig).mode === 'multipress') {
|
|
597
597
|
this.multiPressCount--
|
|
598
598
|
if (this.multiPressCount > 0) {
|
|
599
|
-
|
|
599
|
+
this.debugLog(`multiPressCount: ${this.multiPressCount}`)
|
|
600
600
|
this.On = true
|
|
601
601
|
await this.openAPIpushChanges()
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
604
|
} catch (e: any) {
|
|
605
605
|
await this.apiError(e)
|
|
606
|
-
|
|
606
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
607
607
|
}
|
|
608
608
|
} else {
|
|
609
|
-
|
|
609
|
+
this.debugLog(`No Changes (openAPIpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
|
|
610
610
|
}
|
|
611
611
|
}
|
|
612
612
|
|
|
@@ -642,27 +642,27 @@ export class Bot extends deviceBase {
|
|
|
642
642
|
* Updates the status for each of the HomeKit Characteristics
|
|
643
643
|
*/
|
|
644
644
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
645
|
-
|
|
645
|
+
this.debugLog('updateHomeKitCharacteristics')
|
|
646
646
|
// BatteryLevel
|
|
647
647
|
if (this.Battery.BatteryLevel === undefined) {
|
|
648
|
-
|
|
648
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
649
649
|
} else {
|
|
650
650
|
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel
|
|
651
651
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel)
|
|
652
|
-
|
|
652
|
+
this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
653
653
|
}
|
|
654
654
|
// StatusLowBattery
|
|
655
655
|
if (this.Battery.StatusLowBattery === undefined) {
|
|
656
|
-
|
|
656
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
657
657
|
} else {
|
|
658
658
|
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery
|
|
659
659
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
|
|
660
|
-
|
|
660
|
+
this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
661
661
|
}
|
|
662
662
|
// State
|
|
663
663
|
const updateCharacteristic = async (service: Service, characteristic: any, value: any, logMessage: string) => {
|
|
664
664
|
service.updateCharacteristic(characteristic, value)
|
|
665
|
-
|
|
665
|
+
this.debugLog(logMessage)
|
|
666
666
|
}
|
|
667
667
|
|
|
668
668
|
const stateActions: { [key: string]: () => Promise<void> } = {
|
|
@@ -716,7 +716,7 @@ export class Bot extends deviceBase {
|
|
|
716
716
|
}
|
|
717
717
|
},
|
|
718
718
|
outlet: async () => this.Outlet && await updateCharacteristic(this.Outlet.Service, this.hap.Characteristic.On, this.On, `updateCharacteristic On: ${this.On}`),
|
|
719
|
-
default: async () =>
|
|
719
|
+
default: async () => this.errorLog(`botDeviceType: ${this.botDeviceType}, On: ${this.On}`),
|
|
720
720
|
}
|
|
721
721
|
|
|
722
722
|
const action = stateActions[this.botDeviceType] || stateActions.default
|
|
@@ -731,7 +731,7 @@ export class Bot extends deviceBase {
|
|
|
731
731
|
Service: accessory.getService(this.hap.Service[serviceType]) as Service,
|
|
732
732
|
}
|
|
733
733
|
accessory.context[contextKey] = this[contextKey] as object
|
|
734
|
-
|
|
734
|
+
this.debugWarnLog(`Removing any leftover ${contextKey} Service`)
|
|
735
735
|
accessory.removeService(this[contextKey].Service)
|
|
736
736
|
}
|
|
737
737
|
|
|
@@ -779,7 +779,7 @@ export class Bot extends deviceBase {
|
|
|
779
779
|
// Bot Device Type
|
|
780
780
|
this.botDeviceType = (device as botConfig).type ?? 'Outlet'
|
|
781
781
|
const botDeviceType = (device as botConfig).type ? 'Device Config' : 'Default'
|
|
782
|
-
|
|
782
|
+
this.debugWarnLog(`Use ${botDeviceType} Device Type: ${this.botDeviceType}`)
|
|
783
783
|
// Bot Mode
|
|
784
784
|
this.botMode = (device as botConfig).mode ?? 'switch'
|
|
785
785
|
if (!(device as botConfig).mode) {
|
|
@@ -794,42 +794,42 @@ export class Bot extends deviceBase {
|
|
|
794
794
|
const botModeLog = (device as botConfig).mode
|
|
795
795
|
? `Using Bot Mode: ${this.botMode}`
|
|
796
796
|
: `No Bot Mode Set, Using default Bot Mode: ${this.botMode}`
|
|
797
|
-
|
|
797
|
+
this.debugWarnLog(botModeLog)
|
|
798
798
|
this.accessory.context.botMode = this.botMode
|
|
799
799
|
// Bot Double Press
|
|
800
800
|
this.doublePress = (device as botConfig).doublePress ?? 1
|
|
801
801
|
const doublePress = (device as botConfig).doublePress
|
|
802
802
|
? `Using Double Press: ${this.doublePress}`
|
|
803
803
|
: `No Double Press Set, Using default Double Press: ${this.doublePress}`
|
|
804
|
-
|
|
804
|
+
this.debugWarnLog(doublePress)
|
|
805
805
|
// Bot Press PushRate
|
|
806
806
|
this.pushRatePress = (device as botConfig).pushRatePress ?? 15
|
|
807
807
|
const pushRatePress = (device as botConfig).pushRatePress
|
|
808
808
|
? `Using Bot Push Rate Press: ${this.pushRatePress}`
|
|
809
809
|
: `No Push Rate Press Set, Using default Push Rate Press: ${this.pushRatePress}`
|
|
810
|
-
|
|
810
|
+
this.debugWarnLog(pushRatePress)
|
|
811
811
|
// Bot Allow Push
|
|
812
812
|
this.allowPush = (device as botConfig).allowPush ?? false
|
|
813
813
|
const allowPush = (device as botConfig).allowPush
|
|
814
814
|
? `Using Allow Push: ${this.allowPush}`
|
|
815
815
|
: `No Allow Push Set, Using default Allow Push: ${this.allowPush}`
|
|
816
|
-
|
|
816
|
+
this.debugWarnLog(allowPush)
|
|
817
817
|
// Bot Multi Press Count
|
|
818
818
|
this.multiPressCount = 0
|
|
819
|
-
|
|
819
|
+
this.debugWarnLog(`Multi Press Count: ${this.multiPressCount}`)
|
|
820
820
|
}
|
|
821
821
|
|
|
822
822
|
async BLEPushConnection() {
|
|
823
823
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
824
|
-
|
|
824
|
+
this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
825
825
|
await this.openAPIpushChanges()
|
|
826
826
|
}
|
|
827
827
|
}
|
|
828
828
|
|
|
829
829
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
830
|
-
|
|
830
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
831
831
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
832
|
-
|
|
832
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
833
833
|
await this.openAPIRefreshStatus()
|
|
834
834
|
}
|
|
835
835
|
}
|