@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/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,7 +360,7 @@ 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
|
|
|
@@ -376,8 +376,8 @@ export class Curtain extends deviceBase {
|
|
|
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
382
|
this.WindowCovering.CurrentPosition = 100 - this.serviceData.position
|
|
383
383
|
await this.getCurrentPostion()
|
|
@@ -391,17 +391,17 @@ export class Curtain extends deviceBase {
|
|
|
391
391
|
}
|
|
392
392
|
// BatteryLevel
|
|
393
393
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
394
|
-
|
|
394
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
395
395
|
// StatusLowBattery
|
|
396
396
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
397
397
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
398
398
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
399
|
-
|
|
399
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
async openAPIparseStatus(): Promise<void> {
|
|
403
|
-
|
|
404
|
-
|
|
403
|
+
this.debugLog('openAPIparseStatus')
|
|
404
|
+
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
405
|
// CurrentPosition
|
|
406
406
|
this.WindowCovering.CurrentPosition = 100 - this.deviceStatus.slidePosition
|
|
407
407
|
await this.getCurrentPostion()
|
|
@@ -412,23 +412,23 @@ export class Curtain extends deviceBase {
|
|
|
412
412
|
const set_maxLux = (this.device as curtainConfig).set_maxLux ?? 6001
|
|
413
413
|
const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux
|
|
414
414
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
415
|
-
|
|
415
|
+
this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
// BatteryLevel
|
|
419
419
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
420
|
-
|
|
420
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
421
421
|
|
|
422
422
|
// StatusLowBattery
|
|
423
423
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
424
424
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
425
425
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
426
|
-
|
|
426
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
427
427
|
|
|
428
428
|
// Firmware Version
|
|
429
429
|
if (this.deviceStatus.version) {
|
|
430
430
|
const version = this.deviceStatus.version.toString()
|
|
431
|
-
|
|
431
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
432
432
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
433
433
|
this.accessory
|
|
434
434
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -437,13 +437,13 @@ export class Curtain extends deviceBase {
|
|
|
437
437
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
438
438
|
.updateValue(deviceVersion)
|
|
439
439
|
this.accessory.context.version = deviceVersion
|
|
440
|
-
|
|
440
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
async parseStatusWebhook(): Promise<void> {
|
|
445
|
-
|
|
446
|
-
|
|
445
|
+
this.debugLog('parseStatusWebhook')
|
|
446
|
+
this.debugLog(`(slidePosition, battery) = Webhook:(${this.webhookContext.slidePosition}, ${this.webhookContext.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`)
|
|
447
447
|
|
|
448
448
|
// CurrentPosition
|
|
449
449
|
this.WindowCovering.CurrentPosition = 100 - this.webhookContext.slidePosition
|
|
@@ -451,13 +451,13 @@ export class Curtain extends deviceBase {
|
|
|
451
451
|
|
|
452
452
|
// BatteryLevel
|
|
453
453
|
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
454
|
-
|
|
454
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
455
455
|
|
|
456
456
|
// StatusLowBattery
|
|
457
457
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
458
458
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
459
459
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
460
|
-
|
|
460
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
461
461
|
}
|
|
462
462
|
|
|
463
463
|
/**
|
|
@@ -465,19 +465,19 @@ export class Curtain extends deviceBase {
|
|
|
465
465
|
*/
|
|
466
466
|
async refreshStatus(): Promise<void> {
|
|
467
467
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
468
|
-
|
|
468
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
469
469
|
} else if (this.BLE) {
|
|
470
470
|
await this.BLERefreshStatus()
|
|
471
471
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
472
472
|
await this.openAPIRefreshStatus()
|
|
473
473
|
} else {
|
|
474
474
|
await this.offlineOff()
|
|
475
|
-
|
|
475
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
476
476
|
}
|
|
477
477
|
}
|
|
478
478
|
|
|
479
479
|
async BLERefreshStatus(): Promise<void> {
|
|
480
|
-
|
|
480
|
+
this.debugLog('BLERefreshStatus')
|
|
481
481
|
const switchBotBLE = await this.switchbotBLE()
|
|
482
482
|
if (switchBotBLE === undefined) {
|
|
483
483
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -493,7 +493,7 @@ export class Curtain extends deviceBase {
|
|
|
493
493
|
await this.BLEparseStatus()
|
|
494
494
|
await this.updateHomeKitCharacteristics()
|
|
495
495
|
} else {
|
|
496
|
-
|
|
496
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
497
497
|
await this.BLERefreshConnection(switchBotBLE)
|
|
498
498
|
}
|
|
499
499
|
})()
|
|
@@ -501,67 +501,67 @@ export class Curtain extends deviceBase {
|
|
|
501
501
|
}
|
|
502
502
|
|
|
503
503
|
async openAPIRefreshStatus(): Promise<void> {
|
|
504
|
-
|
|
504
|
+
this.debugLog('openAPIRefreshStatus')
|
|
505
505
|
try {
|
|
506
506
|
const { body } = await this.deviceRefreshStatus()
|
|
507
507
|
const deviceStatus: any = body
|
|
508
|
-
|
|
508
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
509
509
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
510
|
-
|
|
510
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
511
511
|
this.deviceStatus = deviceStatus.body
|
|
512
512
|
await this.openAPIparseStatus()
|
|
513
513
|
await this.updateHomeKitCharacteristics()
|
|
514
514
|
} else {
|
|
515
|
-
|
|
516
|
-
|
|
515
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
516
|
+
this.debugWarnLog(deviceStatus)
|
|
517
517
|
}
|
|
518
518
|
} catch (e: any) {
|
|
519
519
|
await this.apiError(e)
|
|
520
|
-
|
|
520
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
521
521
|
}
|
|
522
522
|
}
|
|
523
523
|
|
|
524
524
|
async registerWebhook() {
|
|
525
525
|
if (this.device.webhook) {
|
|
526
|
-
|
|
526
|
+
this.debugLog('is listening webhook.')
|
|
527
527
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: curtainWebhookContext | curtain3WebhookContext) => {
|
|
528
528
|
try {
|
|
529
|
-
|
|
529
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
530
530
|
this.webhookContext = context
|
|
531
531
|
await this.parseStatusWebhook()
|
|
532
532
|
await this.updateHomeKitCharacteristics()
|
|
533
533
|
} catch (e: any) {
|
|
534
|
-
|
|
534
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
537
|
} else {
|
|
538
|
-
|
|
538
|
+
this.debugLog('is not listening webhook.')
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
|
|
542
542
|
async registerPlatformBLE(): Promise<void> {
|
|
543
|
-
|
|
543
|
+
this.debugLog('registerPlatformBLE')
|
|
544
544
|
if (this.config.options?.BLE) {
|
|
545
|
-
|
|
545
|
+
this.debugLog('is listening to Platform BLE.')
|
|
546
546
|
try {
|
|
547
547
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
548
548
|
this.device.bleMac = formattedDeviceId
|
|
549
|
-
|
|
549
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
550
550
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: curtainServiceData | curtain3ServiceData) => {
|
|
551
551
|
try {
|
|
552
|
-
|
|
552
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
553
553
|
this.serviceData = context
|
|
554
554
|
await this.BLEparseStatus()
|
|
555
555
|
await this.updateHomeKitCharacteristics()
|
|
556
556
|
} catch (e: any) {
|
|
557
|
-
|
|
557
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
560
|
} catch (error) {
|
|
561
|
-
|
|
561
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
562
562
|
}
|
|
563
563
|
} else {
|
|
564
|
-
|
|
564
|
+
this.debugLog('is not listening to Platform BLE')
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
567
|
|
|
@@ -570,14 +570,14 @@ export class Curtain extends deviceBase {
|
|
|
570
570
|
*/
|
|
571
571
|
async pushChanges(): Promise<void> {
|
|
572
572
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
573
|
-
|
|
573
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
574
574
|
} else if (this.BLE) {
|
|
575
575
|
await this.BLEpushChanges()
|
|
576
576
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
577
577
|
await this.openAPIpushChanges()
|
|
578
578
|
} else {
|
|
579
579
|
await this.offlineOff()
|
|
580
|
-
|
|
580
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
581
581
|
}
|
|
582
582
|
// Refresh the status from the API
|
|
583
583
|
interval(15000)
|
|
@@ -589,56 +589,56 @@ export class Curtain extends deviceBase {
|
|
|
589
589
|
}
|
|
590
590
|
|
|
591
591
|
async BLEpushChanges(): Promise<void> {
|
|
592
|
-
|
|
592
|
+
this.debugLog('BLEpushChanges')
|
|
593
593
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
594
594
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
595
595
|
try {
|
|
596
596
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
597
597
|
this.device.bleMac = formattedDeviceId
|
|
598
|
-
|
|
598
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
599
599
|
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
600
600
|
const adjustedMode = setPositionMode === 1 ? 0x01 : 0xFF
|
|
601
|
-
|
|
601
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
602
602
|
if (switchBotBLE !== false) {
|
|
603
603
|
switchBotBLE
|
|
604
604
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
605
605
|
.then(async (device_list: SwitchbotDevice[]) => {
|
|
606
606
|
const deviceList = device_list as unknown as WoCurtain[]
|
|
607
607
|
return await this.retryBLE({
|
|
608
|
-
max:
|
|
608
|
+
max: this.maxRetryBLE(),
|
|
609
609
|
fn: async () => {
|
|
610
610
|
return await deviceList[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), adjustedMode)
|
|
611
611
|
},
|
|
612
612
|
})
|
|
613
613
|
})
|
|
614
614
|
.then(async () => {
|
|
615
|
-
|
|
615
|
+
this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`)
|
|
616
616
|
await this.updateHomeKitCharacteristics()
|
|
617
617
|
})
|
|
618
618
|
.catch(async (e: any) => {
|
|
619
619
|
await this.apiError(e)
|
|
620
|
-
|
|
620
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
621
621
|
await this.BLEPushConnection()
|
|
622
622
|
})
|
|
623
623
|
} else {
|
|
624
|
-
|
|
624
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
625
625
|
await this.BLEPushConnection()
|
|
626
626
|
}
|
|
627
627
|
} catch (error) {
|
|
628
|
-
|
|
628
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
629
629
|
}
|
|
630
630
|
} else {
|
|
631
|
-
|
|
631
|
+
this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
632
632
|
}
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
async openAPIpushChanges(): Promise<void> {
|
|
636
|
-
|
|
636
|
+
this.debugLog('openAPIpushChanges')
|
|
637
637
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition || this.device.disableCaching) {
|
|
638
|
-
|
|
638
|
+
this.debugLog(`Pushing ${this.WindowCovering.TargetPosition}`)
|
|
639
639
|
const adjustedTargetPosition = 100 - Number(this.WindowCovering.TargetPosition)
|
|
640
640
|
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
641
|
-
|
|
641
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
642
642
|
const adjustedMode = setPositionMode || 'ff'
|
|
643
643
|
let bodyChange: bodyChange
|
|
644
644
|
if (this.WindowCovering.HoldPosition) {
|
|
@@ -654,23 +654,23 @@ export class Curtain extends deviceBase {
|
|
|
654
654
|
commandType: 'command',
|
|
655
655
|
}
|
|
656
656
|
}
|
|
657
|
-
|
|
657
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
658
658
|
try {
|
|
659
|
-
const
|
|
660
|
-
const deviceStatus: any =
|
|
661
|
-
|
|
659
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
660
|
+
const deviceStatus: any = response.body
|
|
661
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
662
662
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
663
|
-
|
|
663
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
664
664
|
await this.updateHomeKitCharacteristics()
|
|
665
665
|
} else {
|
|
666
666
|
await this.statusCode(deviceStatus.statusCode)
|
|
667
667
|
}
|
|
668
668
|
} catch (e: any) {
|
|
669
669
|
await this.apiError(e)
|
|
670
|
-
|
|
670
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
671
671
|
}
|
|
672
672
|
} else {
|
|
673
|
-
|
|
673
|
+
this.debugLog(`No changes (openAPIpushChanges), CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}`)
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
676
|
|
|
@@ -679,9 +679,9 @@ export class Curtain extends deviceBase {
|
|
|
679
679
|
*/
|
|
680
680
|
async TargetPositionSet(value: CharacteristicValue): Promise<void> {
|
|
681
681
|
if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
|
|
682
|
-
|
|
682
|
+
this.infoLog(`Set TargetPosition: ${value}`)
|
|
683
683
|
} else {
|
|
684
|
-
|
|
684
|
+
this.debugLog(`No Changes, TargetPosition: ${value}`)
|
|
685
685
|
}
|
|
686
686
|
|
|
687
687
|
// Set HoldPosition to false when TargetPosition is changed
|
|
@@ -699,15 +699,15 @@ export class Curtain extends deviceBase {
|
|
|
699
699
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
700
700
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
701
701
|
this.setNewTarget = true
|
|
702
|
-
|
|
702
|
+
this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
703
703
|
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
704
704
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
705
705
|
this.setNewTarget = true
|
|
706
|
-
|
|
706
|
+
this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
707
707
|
} else {
|
|
708
708
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
709
709
|
this.setNewTarget = false
|
|
710
|
-
|
|
710
|
+
this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
711
711
|
}
|
|
712
712
|
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState)
|
|
713
713
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
@@ -717,10 +717,10 @@ export class Curtain extends deviceBase {
|
|
|
717
717
|
* The minimum time depends on the network control latency.
|
|
718
718
|
*/
|
|
719
719
|
clearTimeout(this.setNewTargetTimer)
|
|
720
|
-
|
|
720
|
+
this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`)
|
|
721
721
|
if (this.setNewTarget) {
|
|
722
722
|
this.setNewTargetTimer = setTimeout(async () => {
|
|
723
|
-
|
|
723
|
+
this.debugLog(`setNewTarget ${this.setNewTarget} timeout`)
|
|
724
724
|
this.setNewTarget = false
|
|
725
725
|
}, this.deviceUpdateRate * 1000)
|
|
726
726
|
}
|
|
@@ -789,15 +789,15 @@ export class Curtain extends deviceBase {
|
|
|
789
789
|
|
|
790
790
|
async BLEPushConnection() {
|
|
791
791
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
792
|
-
|
|
792
|
+
this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
793
793
|
await this.openAPIpushChanges()
|
|
794
794
|
}
|
|
795
795
|
}
|
|
796
796
|
|
|
797
797
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
798
|
-
|
|
798
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
799
799
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
800
|
-
|
|
800
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
801
801
|
await this.openAPIRefreshStatus()
|
|
802
802
|
}
|
|
803
803
|
}
|
|
@@ -834,7 +834,7 @@ export class Curtain extends deviceBase {
|
|
|
834
834
|
|
|
835
835
|
async getCurrentPostion(): Promise<void> {
|
|
836
836
|
await this.setMinMax()
|
|
837
|
-
|
|
837
|
+
this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`)
|
|
838
838
|
this.hasLoggedStandby = this.hasLoggedStandby ?? false
|
|
839
839
|
if (this.deviceStatus ? (this.setNewTarget || this.deviceStatus.moving) : this.setNewTarget) {
|
|
840
840
|
this.hasLoggedStandby = false
|
|
@@ -842,33 +842,33 @@ export class Curtain extends deviceBase {
|
|
|
842
842
|
this.curtainMoving = true
|
|
843
843
|
await this.setMinMax()
|
|
844
844
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
845
|
-
|
|
845
|
+
this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
846
846
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
847
847
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
848
|
-
|
|
848
|
+
this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
849
849
|
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
850
|
-
|
|
850
|
+
this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
851
851
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
852
852
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
853
|
-
|
|
853
|
+
this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
854
854
|
} else {
|
|
855
|
-
|
|
855
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
856
856
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
857
857
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
858
|
-
|
|
858
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
859
859
|
}
|
|
860
860
|
} else {
|
|
861
861
|
if (!this.hasLoggedStandby) {
|
|
862
|
-
|
|
862
|
+
this.infoLog('Standby ...')
|
|
863
863
|
this.hasLoggedStandby = true
|
|
864
864
|
}
|
|
865
865
|
this.curtainMoving = false
|
|
866
|
-
|
|
866
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
867
867
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
|
|
868
868
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
869
|
-
|
|
869
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
870
870
|
}
|
|
871
|
-
|
|
871
|
+
this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`)
|
|
872
872
|
}
|
|
873
873
|
|
|
874
874
|
async setMinMax(): Promise<void> {
|