@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.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/CHANGELOG.md +14 -0
- package/dist/device/blindtilt.js +103 -103
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +84 -84
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +97 -97
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +139 -139
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +47 -47
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +91 -89
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +12 -12
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +42 -42
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +95 -95
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +46 -46
- 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 +118 -118
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +74 -74
- 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 +44 -44
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +59 -59
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +73 -73
- 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 +9 -9
- package/src/device/blindtilt.ts +103 -103
- package/src/device/bot.ts +84 -84
- package/src/device/ceilinglight.ts +97 -97
- package/src/device/colorbulb.ts +139 -139
- package/src/device/contact.ts +47 -47
- package/src/device/curtain.ts +91 -89
- package/src/device/device.ts +42 -42
- package/src/device/fan.ts +95 -95
- package/src/device/hub.ts +46 -46
- package/src/device/humidifier.ts +84 -84
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +118 -118
- package/src/device/lock.ts +74 -74
- 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 +44 -44
- package/src/device/plug.ts +61 -61
- package/src/device/robotvacuumcleaner.ts +73 -73
- 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/curtain.ts
CHANGED
|
@@ -278,7 +278,7 @@ export class Curtain extends deviceBase {
|
|
|
278
278
|
if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
279
279
|
return
|
|
280
280
|
}
|
|
281
|
-
|
|
281
|
+
this.debugLog(`Refresh Status When Moving, PositionState: ${this.WindowCovering.PositionState}`)
|
|
282
282
|
await this.refreshStatus()
|
|
283
283
|
})
|
|
284
284
|
|
|
@@ -296,7 +296,7 @@ export class Curtain extends deviceBase {
|
|
|
296
296
|
await this.pushChanges()
|
|
297
297
|
} catch (e: any) {
|
|
298
298
|
await this.apiError(e)
|
|
299
|
-
|
|
299
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
300
300
|
}
|
|
301
301
|
this.curtainUpdateInProgress = false
|
|
302
302
|
})
|
|
@@ -326,7 +326,7 @@ export class Curtain extends deviceBase {
|
|
|
326
326
|
try {
|
|
327
327
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
328
328
|
this.device.bleMac = formattedDeviceId
|
|
329
|
-
|
|
329
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
330
330
|
this.historyService = new this.platform.fakegatoAPI('custom', this.accessory, {
|
|
331
331
|
log: this.platform.log,
|
|
332
332
|
storage: 'fs',
|
|
@@ -360,48 +360,50 @@ export class Curtain extends deviceBase {
|
|
|
360
360
|
})
|
|
361
361
|
this.updateHistory()
|
|
362
362
|
} catch (error) {
|
|
363
|
-
|
|
363
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
|
|
367
|
+
updateHistory(): void {
|
|
368
368
|
const motion = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0
|
|
369
369
|
this.historyService.addEntry({
|
|
370
370
|
time: Math.round(new Date().valueOf() / 1000),
|
|
371
371
|
motion,
|
|
372
372
|
})
|
|
373
|
-
setTimeout(
|
|
374
|
-
|
|
373
|
+
setTimeout(() => {
|
|
374
|
+
this.updateHistory()
|
|
375
375
|
}, 10 * 60 * 1000)
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
async BLEparseStatus(): Promise<void> {
|
|
379
|
-
|
|
380
|
-
|
|
379
|
+
this.debugLog('BLEparseStatus')
|
|
380
|
+
this.debugLog(`(position, battery) = BLE:(${this.serviceData.position}, ${this.serviceData.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`)
|
|
381
381
|
// CurrentPosition
|
|
382
|
-
|
|
383
|
-
|
|
382
|
+
if (this.serviceData.position) {
|
|
383
|
+
this.WindowCovering.CurrentPosition = 100 - this.serviceData.position
|
|
384
|
+
await this.getCurrentPostion()
|
|
385
|
+
}
|
|
384
386
|
// CurrentAmbientLightLevel
|
|
385
|
-
if (!(this.device as curtainConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
387
|
+
if (!(this.device as curtainConfig).hide_lightsensor && this.LightSensor?.Service && this.serviceData.lightLevel) {
|
|
386
388
|
const set_minLux = (this.device as curtainConfig).set_minLux ?? 1
|
|
387
389
|
const set_maxLux = (this.device as curtainConfig).set_maxLux ?? 6001
|
|
388
390
|
const lightLevel = this.serviceData.lightLevel
|
|
389
|
-
this.LightSensor.CurrentAmbientLightLevel =
|
|
391
|
+
this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
390
392
|
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
391
393
|
}
|
|
392
394
|
// BatteryLevel
|
|
393
395
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
394
|
-
|
|
396
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
395
397
|
// StatusLowBattery
|
|
396
398
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
397
399
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
398
400
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
399
|
-
|
|
401
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
400
402
|
}
|
|
401
403
|
|
|
402
404
|
async openAPIparseStatus(): Promise<void> {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
+
this.debugLog('openAPIparseStatus')
|
|
406
|
+
this.debugLog(`(slidePosition, battery, version) = OpenAPI:(${this.deviceStatus.slidePosition}, ${this.deviceStatus.battery}, ${this.deviceStatus.version}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`)
|
|
405
407
|
// CurrentPosition
|
|
406
408
|
this.WindowCovering.CurrentPosition = 100 - this.deviceStatus.slidePosition
|
|
407
409
|
await this.getCurrentPostion()
|
|
@@ -411,24 +413,24 @@ export class Curtain extends deviceBase {
|
|
|
411
413
|
const set_minLux = (this.device as curtainConfig).set_minLux ?? 1
|
|
412
414
|
const set_maxLux = (this.device as curtainConfig).set_maxLux ?? 6001
|
|
413
415
|
const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux
|
|
414
|
-
this.LightSensor.CurrentAmbientLightLevel =
|
|
415
|
-
|
|
416
|
+
this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
417
|
+
this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
416
418
|
}
|
|
417
419
|
|
|
418
420
|
// BatteryLevel
|
|
419
421
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
420
|
-
|
|
422
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
421
423
|
|
|
422
424
|
// StatusLowBattery
|
|
423
425
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
424
426
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
425
427
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
426
|
-
|
|
428
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
427
429
|
|
|
428
430
|
// Firmware Version
|
|
429
431
|
if (this.deviceStatus.version) {
|
|
430
432
|
const version = this.deviceStatus.version.toString()
|
|
431
|
-
|
|
433
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
432
434
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
433
435
|
this.accessory
|
|
434
436
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -437,13 +439,13 @@ export class Curtain extends deviceBase {
|
|
|
437
439
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
438
440
|
.updateValue(deviceVersion)
|
|
439
441
|
this.accessory.context.version = deviceVersion
|
|
440
|
-
|
|
442
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
441
443
|
}
|
|
442
444
|
}
|
|
443
445
|
|
|
444
446
|
async parseStatusWebhook(): Promise<void> {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
+
this.debugLog('parseStatusWebhook')
|
|
448
|
+
this.debugLog(`(slidePosition, battery) = Webhook:(${this.webhookContext.slidePosition}, ${this.webhookContext.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`)
|
|
447
449
|
|
|
448
450
|
// CurrentPosition
|
|
449
451
|
this.WindowCovering.CurrentPosition = 100 - this.webhookContext.slidePosition
|
|
@@ -451,13 +453,13 @@ export class Curtain extends deviceBase {
|
|
|
451
453
|
|
|
452
454
|
// BatteryLevel
|
|
453
455
|
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
454
|
-
|
|
456
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
455
457
|
|
|
456
458
|
// StatusLowBattery
|
|
457
459
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
458
460
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
459
461
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
460
|
-
|
|
462
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
461
463
|
}
|
|
462
464
|
|
|
463
465
|
/**
|
|
@@ -465,19 +467,19 @@ export class Curtain extends deviceBase {
|
|
|
465
467
|
*/
|
|
466
468
|
async refreshStatus(): Promise<void> {
|
|
467
469
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
468
|
-
|
|
470
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
469
471
|
} else if (this.BLE) {
|
|
470
472
|
await this.BLERefreshStatus()
|
|
471
473
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
472
474
|
await this.openAPIRefreshStatus()
|
|
473
475
|
} else {
|
|
474
476
|
await this.offlineOff()
|
|
475
|
-
|
|
477
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
476
478
|
}
|
|
477
479
|
}
|
|
478
480
|
|
|
479
481
|
async BLERefreshStatus(): Promise<void> {
|
|
480
|
-
|
|
482
|
+
this.debugLog('BLERefreshStatus')
|
|
481
483
|
const switchBotBLE = await this.switchbotBLE()
|
|
482
484
|
if (switchBotBLE === undefined) {
|
|
483
485
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -493,7 +495,7 @@ export class Curtain extends deviceBase {
|
|
|
493
495
|
await this.BLEparseStatus()
|
|
494
496
|
await this.updateHomeKitCharacteristics()
|
|
495
497
|
} else {
|
|
496
|
-
|
|
498
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
497
499
|
await this.BLERefreshConnection(switchBotBLE)
|
|
498
500
|
}
|
|
499
501
|
})()
|
|
@@ -501,67 +503,67 @@ export class Curtain extends deviceBase {
|
|
|
501
503
|
}
|
|
502
504
|
|
|
503
505
|
async openAPIRefreshStatus(): Promise<void> {
|
|
504
|
-
|
|
506
|
+
this.debugLog('openAPIRefreshStatus')
|
|
505
507
|
try {
|
|
506
508
|
const { body } = await this.deviceRefreshStatus()
|
|
507
509
|
const deviceStatus: any = body
|
|
508
|
-
|
|
510
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
509
511
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
510
|
-
|
|
512
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
511
513
|
this.deviceStatus = deviceStatus.body
|
|
512
514
|
await this.openAPIparseStatus()
|
|
513
515
|
await this.updateHomeKitCharacteristics()
|
|
514
516
|
} else {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
518
|
+
this.debugWarnLog(deviceStatus)
|
|
517
519
|
}
|
|
518
520
|
} catch (e: any) {
|
|
519
521
|
await this.apiError(e)
|
|
520
|
-
|
|
522
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
521
523
|
}
|
|
522
524
|
}
|
|
523
525
|
|
|
524
526
|
async registerWebhook() {
|
|
525
527
|
if (this.device.webhook) {
|
|
526
|
-
|
|
528
|
+
this.debugLog('is listening webhook.')
|
|
527
529
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: curtainWebhookContext | curtain3WebhookContext) => {
|
|
528
530
|
try {
|
|
529
|
-
|
|
531
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
530
532
|
this.webhookContext = context
|
|
531
533
|
await this.parseStatusWebhook()
|
|
532
534
|
await this.updateHomeKitCharacteristics()
|
|
533
535
|
} catch (e: any) {
|
|
534
|
-
|
|
536
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
535
537
|
}
|
|
536
538
|
}
|
|
537
539
|
} else {
|
|
538
|
-
|
|
540
|
+
this.debugLog('is not listening webhook.')
|
|
539
541
|
}
|
|
540
542
|
}
|
|
541
543
|
|
|
542
544
|
async registerPlatformBLE(): Promise<void> {
|
|
543
|
-
|
|
545
|
+
this.debugLog('registerPlatformBLE')
|
|
544
546
|
if (this.config.options?.BLE) {
|
|
545
|
-
|
|
547
|
+
this.debugLog('is listening to Platform BLE.')
|
|
546
548
|
try {
|
|
547
549
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
548
550
|
this.device.bleMac = formattedDeviceId
|
|
549
|
-
|
|
551
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
550
552
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: curtainServiceData | curtain3ServiceData) => {
|
|
551
553
|
try {
|
|
552
|
-
|
|
554
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
553
555
|
this.serviceData = context
|
|
554
556
|
await this.BLEparseStatus()
|
|
555
557
|
await this.updateHomeKitCharacteristics()
|
|
556
558
|
} catch (e: any) {
|
|
557
|
-
|
|
559
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
558
560
|
}
|
|
559
561
|
}
|
|
560
562
|
} catch (error) {
|
|
561
|
-
|
|
563
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
562
564
|
}
|
|
563
565
|
} else {
|
|
564
|
-
|
|
566
|
+
this.debugLog('is not listening to Platform BLE')
|
|
565
567
|
}
|
|
566
568
|
}
|
|
567
569
|
|
|
@@ -570,14 +572,14 @@ export class Curtain extends deviceBase {
|
|
|
570
572
|
*/
|
|
571
573
|
async pushChanges(): Promise<void> {
|
|
572
574
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
573
|
-
|
|
575
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
574
576
|
} else if (this.BLE) {
|
|
575
577
|
await this.BLEpushChanges()
|
|
576
578
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
577
579
|
await this.openAPIpushChanges()
|
|
578
580
|
} else {
|
|
579
581
|
await this.offlineOff()
|
|
580
|
-
|
|
582
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
581
583
|
}
|
|
582
584
|
// Refresh the status from the API
|
|
583
585
|
interval(15000)
|
|
@@ -589,16 +591,16 @@ export class Curtain extends deviceBase {
|
|
|
589
591
|
}
|
|
590
592
|
|
|
591
593
|
async BLEpushChanges(): Promise<void> {
|
|
592
|
-
|
|
594
|
+
this.debugLog('BLEpushChanges')
|
|
593
595
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
594
596
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
595
597
|
try {
|
|
596
598
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
597
599
|
this.device.bleMac = formattedDeviceId
|
|
598
|
-
|
|
600
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
599
601
|
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
600
602
|
const adjustedMode = setPositionMode === 1 ? 0x01 : 0xFF
|
|
601
|
-
|
|
603
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
602
604
|
if (switchBotBLE !== false) {
|
|
603
605
|
switchBotBLE
|
|
604
606
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
@@ -612,33 +614,33 @@ export class Curtain extends deviceBase {
|
|
|
612
614
|
})
|
|
613
615
|
})
|
|
614
616
|
.then(async () => {
|
|
615
|
-
|
|
617
|
+
this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`)
|
|
616
618
|
await this.updateHomeKitCharacteristics()
|
|
617
619
|
})
|
|
618
620
|
.catch(async (e: any) => {
|
|
619
621
|
await this.apiError(e)
|
|
620
|
-
|
|
622
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
621
623
|
await this.BLEPushConnection()
|
|
622
624
|
})
|
|
623
625
|
} else {
|
|
624
|
-
|
|
626
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
625
627
|
await this.BLEPushConnection()
|
|
626
628
|
}
|
|
627
629
|
} catch (error) {
|
|
628
|
-
|
|
630
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
629
631
|
}
|
|
630
632
|
} else {
|
|
631
|
-
|
|
633
|
+
this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
632
634
|
}
|
|
633
635
|
}
|
|
634
636
|
|
|
635
637
|
async openAPIpushChanges(): Promise<void> {
|
|
636
|
-
|
|
638
|
+
this.debugLog('openAPIpushChanges')
|
|
637
639
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition || this.device.disableCaching) {
|
|
638
|
-
|
|
640
|
+
this.debugLog(`Pushing ${this.WindowCovering.TargetPosition}`)
|
|
639
641
|
const adjustedTargetPosition = 100 - Number(this.WindowCovering.TargetPosition)
|
|
640
642
|
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
641
|
-
|
|
643
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
642
644
|
const adjustedMode = setPositionMode || 'ff'
|
|
643
645
|
let bodyChange: bodyChange
|
|
644
646
|
if (this.WindowCovering.HoldPosition) {
|
|
@@ -654,23 +656,23 @@ export class Curtain extends deviceBase {
|
|
|
654
656
|
commandType: 'command',
|
|
655
657
|
}
|
|
656
658
|
}
|
|
657
|
-
|
|
659
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
658
660
|
try {
|
|
659
|
-
const
|
|
660
|
-
const deviceStatus: any =
|
|
661
|
-
|
|
661
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
662
|
+
const deviceStatus: any = response.body
|
|
663
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
662
664
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
663
|
-
|
|
665
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
664
666
|
await this.updateHomeKitCharacteristics()
|
|
665
667
|
} else {
|
|
666
668
|
await this.statusCode(deviceStatus.statusCode)
|
|
667
669
|
}
|
|
668
670
|
} catch (e: any) {
|
|
669
671
|
await this.apiError(e)
|
|
670
|
-
|
|
672
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
671
673
|
}
|
|
672
674
|
} else {
|
|
673
|
-
|
|
675
|
+
this.debugLog(`No changes (openAPIpushChanges), CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}`)
|
|
674
676
|
}
|
|
675
677
|
}
|
|
676
678
|
|
|
@@ -679,9 +681,9 @@ export class Curtain extends deviceBase {
|
|
|
679
681
|
*/
|
|
680
682
|
async TargetPositionSet(value: CharacteristicValue): Promise<void> {
|
|
681
683
|
if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
|
|
682
|
-
|
|
684
|
+
this.infoLog(`Set TargetPosition: ${value}`)
|
|
683
685
|
} else {
|
|
684
|
-
|
|
686
|
+
this.debugLog(`No Changes, TargetPosition: ${value}`)
|
|
685
687
|
}
|
|
686
688
|
|
|
687
689
|
// Set HoldPosition to false when TargetPosition is changed
|
|
@@ -699,15 +701,15 @@ export class Curtain extends deviceBase {
|
|
|
699
701
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
700
702
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
701
703
|
this.setNewTarget = true
|
|
702
|
-
|
|
704
|
+
this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
703
705
|
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
704
706
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
705
707
|
this.setNewTarget = true
|
|
706
|
-
|
|
708
|
+
this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
707
709
|
} else {
|
|
708
710
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
709
711
|
this.setNewTarget = false
|
|
710
|
-
|
|
712
|
+
this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
711
713
|
}
|
|
712
714
|
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState)
|
|
713
715
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
@@ -717,10 +719,10 @@ export class Curtain extends deviceBase {
|
|
|
717
719
|
* The minimum time depends on the network control latency.
|
|
718
720
|
*/
|
|
719
721
|
clearTimeout(this.setNewTargetTimer)
|
|
720
|
-
|
|
722
|
+
this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`)
|
|
721
723
|
if (this.setNewTarget) {
|
|
722
724
|
this.setNewTargetTimer = setTimeout(async () => {
|
|
723
|
-
|
|
725
|
+
this.debugLog(`setNewTarget ${this.setNewTarget} timeout`)
|
|
724
726
|
this.setNewTarget = false
|
|
725
727
|
}, this.deviceUpdateRate * 1000)
|
|
726
728
|
}
|
|
@@ -789,15 +791,15 @@ export class Curtain extends deviceBase {
|
|
|
789
791
|
|
|
790
792
|
async BLEPushConnection() {
|
|
791
793
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
792
|
-
|
|
794
|
+
this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
793
795
|
await this.openAPIpushChanges()
|
|
794
796
|
}
|
|
795
797
|
}
|
|
796
798
|
|
|
797
799
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
798
|
-
|
|
800
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
799
801
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
800
|
-
|
|
802
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
801
803
|
await this.openAPIRefreshStatus()
|
|
802
804
|
}
|
|
803
805
|
}
|
|
@@ -834,7 +836,7 @@ export class Curtain extends deviceBase {
|
|
|
834
836
|
|
|
835
837
|
async getCurrentPostion(): Promise<void> {
|
|
836
838
|
await this.setMinMax()
|
|
837
|
-
|
|
839
|
+
this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`)
|
|
838
840
|
this.hasLoggedStandby = this.hasLoggedStandby ?? false
|
|
839
841
|
if (this.deviceStatus ? (this.setNewTarget || this.deviceStatus.moving) : this.setNewTarget) {
|
|
840
842
|
this.hasLoggedStandby = false
|
|
@@ -842,33 +844,33 @@ export class Curtain extends deviceBase {
|
|
|
842
844
|
this.curtainMoving = true
|
|
843
845
|
await this.setMinMax()
|
|
844
846
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
845
|
-
|
|
847
|
+
this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
846
848
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
847
849
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
848
|
-
|
|
850
|
+
this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
849
851
|
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
850
|
-
|
|
852
|
+
this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
851
853
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
852
854
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
853
|
-
|
|
855
|
+
this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
854
856
|
} else {
|
|
855
|
-
|
|
857
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
856
858
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
857
859
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
858
|
-
|
|
860
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
859
861
|
}
|
|
860
862
|
} else {
|
|
861
863
|
if (!this.hasLoggedStandby) {
|
|
862
|
-
|
|
864
|
+
this.infoLog('Standby ...')
|
|
863
865
|
this.hasLoggedStandby = true
|
|
864
866
|
}
|
|
865
867
|
this.curtainMoving = false
|
|
866
|
-
|
|
868
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
867
869
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
|
|
868
870
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
869
|
-
|
|
871
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
870
872
|
}
|
|
871
|
-
|
|
873
|
+
this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`)
|
|
872
874
|
}
|
|
873
875
|
|
|
874
876
|
async setMinMax(): Promise<void> {
|