@switchbot/homebridge-switchbot 4.1.1-beta.0 → 4.1.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/CHANGELOG.md +14 -0
- package/config.schema.json +2 -2
- package/dist/device/blindtilt.js +104 -104
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +86 -86
- 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 +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 +95 -93
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +13 -13
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +46 -46
- 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 +46 -46
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +85 -87
- 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 +44 -44
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.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.d.ts.map +1 -1
- package/dist/device/waterdetector.js +54 -56
- 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 +93 -93
- 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/docs/functions/default.html +1 -1
- package/package.json +9 -9
- package/src/device/blindtilt.ts +104 -104
- package/src/device/bot.ts +86 -86
- package/src/device/ceilinglight.ts +98 -98
- package/src/device/colorbulb.ts +140 -140
- package/src/device/contact.ts +47 -47
- package/src/device/curtain.ts +95 -93
- package/src/device/device.ts +46 -46
- package/src/device/fan.ts +96 -96
- package/src/device/hub.ts +46 -46
- package/src/device/humidifier.ts +85 -87
- 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 +44 -44
- package/src/device/plug.ts +62 -62
- package/src/device/robotvacuumcleaner.ts +74 -74
- package/src/device/waterdetector.ts +54 -55
- 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 +93 -93
- 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/blindtilt.ts
CHANGED
|
@@ -293,7 +293,7 @@ export class BlindTilt extends deviceBase {
|
|
|
293
293
|
await this.pushChanges()
|
|
294
294
|
} catch (e: any) {
|
|
295
295
|
await this.apiError(e)
|
|
296
|
-
|
|
296
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
297
297
|
}
|
|
298
298
|
this.blindTiltUpdateInProgress = false
|
|
299
299
|
})
|
|
@@ -303,43 +303,43 @@ export class BlindTilt extends deviceBase {
|
|
|
303
303
|
* Parse the device status from the SwitchBotBLE API
|
|
304
304
|
*/
|
|
305
305
|
async BLEparseStatus(): Promise<void> {
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
this.debugLog('BLEparseStatus')
|
|
307
|
+
this.debugLog(`(direction, slidePosition, battery, version) = BLE:(${this.serviceData.tilt}, ${this.serviceData.tilt}, ${this.serviceData.battery}, ${this.accessory.context.version}), current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`)
|
|
308
308
|
|
|
309
309
|
// CurrentPosition
|
|
310
310
|
this.WindowCovering.CurrentPosition = 100 - Number(this.serviceData.tilt)
|
|
311
311
|
await this.setMinMax()
|
|
312
|
-
|
|
312
|
+
this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`)
|
|
313
313
|
if (this.setNewTarget) {
|
|
314
|
-
|
|
314
|
+
this.infoLog('Checking Status ...')
|
|
315
315
|
}
|
|
316
316
|
if (this.setNewTarget && this.serviceData.inMotion) {
|
|
317
317
|
this.blindTiltMoving = true
|
|
318
318
|
await this.setMinMax()
|
|
319
319
|
if (Number(this.WindowCovering.TargetPosition) > this.WindowCovering.CurrentPosition) {
|
|
320
|
-
|
|
320
|
+
this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
321
321
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
322
322
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
323
|
-
|
|
323
|
+
this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
324
324
|
} else if (Number(this.WindowCovering.TargetPosition) < this.WindowCovering.CurrentPosition) {
|
|
325
|
-
|
|
325
|
+
this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
326
326
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
327
327
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
328
|
-
|
|
328
|
+
this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
329
329
|
} else {
|
|
330
|
-
|
|
330
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
331
331
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
332
332
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
333
|
-
|
|
333
|
+
this.debugLog('Stopped, PositionState', this.WindowCovering.PositionState)
|
|
334
334
|
}
|
|
335
335
|
} else {
|
|
336
336
|
this.blindTiltMoving = false
|
|
337
|
-
|
|
337
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
338
338
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
|
|
339
339
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
340
|
-
|
|
340
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
341
341
|
}
|
|
342
|
-
|
|
342
|
+
this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState}`)
|
|
343
343
|
|
|
344
344
|
// CurrentAmbientLightLevel
|
|
345
345
|
if (!(this.device as blindTiltConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
@@ -347,20 +347,20 @@ export class BlindTilt extends deviceBase {
|
|
|
347
347
|
const set_maxLux = (this.device as blindTiltConfig).set_maxLux ?? 6001
|
|
348
348
|
const spaceBetweenLevels = 9
|
|
349
349
|
|
|
350
|
-
|
|
351
|
-
|
|
350
|
+
this.getLightLevel(this.serviceData.lightLevel, set_minLux, set_maxLux, spaceBetweenLevels)
|
|
351
|
+
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`)
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
// BatteryLevel
|
|
355
355
|
if (this.serviceData?.battery) {
|
|
356
356
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
357
|
-
|
|
357
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
358
358
|
|
|
359
359
|
// StatusLowBattery
|
|
360
360
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
361
361
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
362
362
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
363
|
-
|
|
363
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
364
364
|
}
|
|
365
365
|
};
|
|
366
366
|
|
|
@@ -368,8 +368,8 @@ export class BlindTilt extends deviceBase {
|
|
|
368
368
|
* Parse the device status from the SwitchBot OpenAPI
|
|
369
369
|
*/
|
|
370
370
|
async openAPIparseStatus(): Promise<void> {
|
|
371
|
-
|
|
372
|
-
|
|
371
|
+
this.debugLog('openAPIparseStatus')
|
|
372
|
+
this.debugLog(`(direction, slidePosition, battery, version) = OpenAPI:(${this.deviceStatus.direction}, ${this.deviceStatus.slidePosition}, ${this.deviceStatus.battery}, ${this.deviceStatus.version}), current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`)
|
|
373
373
|
|
|
374
374
|
// CurrentPosition
|
|
375
375
|
await this.getCurrentPosttionDirection(this.deviceStatus.direction, this.deviceStatus.slidePosition)
|
|
@@ -378,23 +378,23 @@ export class BlindTilt extends deviceBase {
|
|
|
378
378
|
const set_minLux = (this.device as blindTiltConfig).set_minLux ?? 1
|
|
379
379
|
const set_maxLux = (this.device as blindTiltConfig).set_maxLux ?? 6001
|
|
380
380
|
const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux
|
|
381
|
-
this.LightSensor.CurrentAmbientLightLevel =
|
|
382
|
-
|
|
381
|
+
this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
382
|
+
this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
383
383
|
}
|
|
384
384
|
|
|
385
385
|
// BatteryLevel
|
|
386
386
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
387
|
-
|
|
387
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
388
388
|
|
|
389
389
|
// StatusLowBattery
|
|
390
390
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
391
391
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
392
392
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
393
|
-
|
|
393
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
394
394
|
|
|
395
395
|
// Firmware Version
|
|
396
396
|
const version = this.deviceStatus.version.toString()
|
|
397
|
-
|
|
397
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
398
398
|
let deviceVersion: string
|
|
399
399
|
if (version?.includes('.') === false) {
|
|
400
400
|
const replace = version?.replace(/^V|-.*$/g, '')
|
|
@@ -411,22 +411,22 @@ export class BlindTilt extends deviceBase {
|
|
|
411
411
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
412
412
|
.updateValue(deviceVersion)
|
|
413
413
|
this.accessory.context.version = deviceVersion
|
|
414
|
-
|
|
414
|
+
this.debugLog(`version: ${this.accessory.context.version}`)
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
async parseStatusWebhook(): Promise<void> {
|
|
418
|
-
|
|
419
|
-
|
|
418
|
+
this.debugLog('parseStatusWebhook')
|
|
419
|
+
this.debugLog(`(slidePosition, battery, version) = Webhook:(${this.webhookContext.direction}, ${this.webhookContext.slidePosition}, ${this.webhookContext.battery}, ${this.webhookContext.version}, current:(${this.WindowCovering.CurrentHorizontalTiltAngle}, ${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel}, ${this.accessory.context.version})`)
|
|
420
420
|
// CurrentPosition and CurrentHorizontalTiltAngle
|
|
421
421
|
await this.getCurrentPosttionDirection(this.webhookContext.direction, this.webhookContext.slidePosition)
|
|
422
422
|
// BatteryLevel
|
|
423
423
|
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
424
|
-
|
|
424
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
425
425
|
// StatusLowBattery
|
|
426
426
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
427
427
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
428
428
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
429
|
-
|
|
429
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
430
430
|
// Firmware Version
|
|
431
431
|
const deviceVersion = this.webhookContext.version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
432
432
|
this.accessory
|
|
@@ -436,7 +436,7 @@ export class BlindTilt extends deviceBase {
|
|
|
436
436
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
437
437
|
.updateValue(deviceVersion)
|
|
438
438
|
this.accessory.context.version = deviceVersion
|
|
439
|
-
|
|
439
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
/**
|
|
@@ -444,19 +444,19 @@ export class BlindTilt extends deviceBase {
|
|
|
444
444
|
*/
|
|
445
445
|
async refreshStatus(): Promise<void> {
|
|
446
446
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
447
|
-
|
|
447
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
448
448
|
} else if (this.BLE) {
|
|
449
449
|
await this.BLERefreshStatus()
|
|
450
450
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
451
451
|
await this.openAPIRefreshStatus()
|
|
452
452
|
} else {
|
|
453
453
|
await this.offlineOff()
|
|
454
|
-
|
|
454
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
async BLERefreshStatus(): Promise<void> {
|
|
459
|
-
|
|
459
|
+
this.debugLog('BLERefreshStatus')
|
|
460
460
|
const switchBotBLE = await this.switchbotBLE()
|
|
461
461
|
if (switchBotBLE === undefined) {
|
|
462
462
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -471,7 +471,7 @@ export class BlindTilt extends deviceBase {
|
|
|
471
471
|
await this.BLEparseStatus()
|
|
472
472
|
await this.updateHomeKitCharacteristics()
|
|
473
473
|
} else {
|
|
474
|
-
|
|
474
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
475
475
|
await this.BLERefreshConnection(switchBotBLE)
|
|
476
476
|
}
|
|
477
477
|
})()
|
|
@@ -479,80 +479,80 @@ export class BlindTilt extends deviceBase {
|
|
|
479
479
|
}
|
|
480
480
|
|
|
481
481
|
async registerPlatformBLE(): Promise<void> {
|
|
482
|
-
|
|
482
|
+
this.debugLog('registerPlatformBLE')
|
|
483
483
|
if (this.config.options?.BLE) {
|
|
484
|
-
|
|
484
|
+
this.debugLog('is listening to Platform BLE.')
|
|
485
485
|
try {
|
|
486
486
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
487
487
|
this.device.bleMac = formattedDeviceId
|
|
488
|
-
|
|
488
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
489
489
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: blindTiltServiceData) => {
|
|
490
490
|
try {
|
|
491
|
-
|
|
491
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
492
492
|
this.serviceData = context
|
|
493
493
|
await this.BLEparseStatus()
|
|
494
494
|
await this.updateHomeKitCharacteristics()
|
|
495
495
|
} catch (e: any) {
|
|
496
|
-
|
|
496
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
} catch (error) {
|
|
500
|
-
|
|
500
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
501
501
|
}
|
|
502
502
|
} else {
|
|
503
|
-
|
|
503
|
+
this.debugLog('is not listening to Platform BLE')
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
506
|
|
|
507
507
|
async openAPIRefreshStatus(): Promise<void> {
|
|
508
|
-
|
|
508
|
+
this.debugLog('openAPIRefreshStatus')
|
|
509
509
|
try {
|
|
510
|
-
const
|
|
511
|
-
const deviceStatus: any =
|
|
512
|
-
|
|
510
|
+
const response = await this.deviceRefreshStatus()
|
|
511
|
+
const deviceStatus: any = response.body
|
|
512
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
513
513
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
514
|
-
|
|
514
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
515
515
|
this.deviceStatus = deviceStatus.body
|
|
516
516
|
await this.openAPIparseStatus()
|
|
517
517
|
await this.updateHomeKitCharacteristics()
|
|
518
518
|
} else {
|
|
519
|
-
|
|
520
|
-
|
|
519
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
520
|
+
this.debugWarnLog(deviceStatus)
|
|
521
521
|
}
|
|
522
522
|
} catch (e: any) {
|
|
523
523
|
await this.apiError(e)
|
|
524
|
-
|
|
524
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
527
|
|
|
528
528
|
async registerWebhook(): Promise<void> {
|
|
529
529
|
if (this.device.webhook) {
|
|
530
|
-
|
|
530
|
+
this.debugLog('is listening webhook.')
|
|
531
531
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: blindTiltWebhookContext) => {
|
|
532
532
|
try {
|
|
533
|
-
|
|
533
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
534
534
|
this.webhookContext = context
|
|
535
535
|
await this.parseStatusWebhook()
|
|
536
536
|
await this.updateHomeKitCharacteristics()
|
|
537
537
|
} catch (e: any) {
|
|
538
|
-
|
|
538
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
} else {
|
|
542
|
-
|
|
542
|
+
this.debugLog('is not listening webhook.')
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
|
|
546
546
|
async pushChanges(): Promise<void> {
|
|
547
547
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
548
|
-
|
|
548
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
549
549
|
} else if (this.BLE) {
|
|
550
550
|
await this.BLEpushChanges()
|
|
551
551
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
552
552
|
await this.openAPIpushChanges()
|
|
553
553
|
} else {
|
|
554
554
|
await this.offlineOff()
|
|
555
|
-
|
|
555
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
556
556
|
}
|
|
557
557
|
// Refresh the status from the API
|
|
558
558
|
interval(15000)
|
|
@@ -564,51 +564,51 @@ export class BlindTilt extends deviceBase {
|
|
|
564
564
|
}
|
|
565
565
|
|
|
566
566
|
async BLEpushChanges(): Promise<void> {
|
|
567
|
-
|
|
567
|
+
this.debugLog('BLEpushChanges')
|
|
568
568
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
569
|
-
|
|
569
|
+
this.debugLog(`BLEpushChanges On: ${this.WindowCovering.TargetPosition} OnCached: ${this.WindowCovering.CurrentPosition}`)
|
|
570
570
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
571
571
|
try {
|
|
572
572
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
573
573
|
this.device.bleMac = formattedDeviceId
|
|
574
|
-
|
|
574
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
575
575
|
const { setPositionMode, Mode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
576
|
-
|
|
576
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
577
577
|
if (switchBotBLE !== false) {
|
|
578
578
|
switchBotBLE
|
|
579
579
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
580
580
|
.then(async (device_list: SwitchbotDevice[]) => {
|
|
581
581
|
const deviceList = device_list as unknown as WoBlindTilt[]
|
|
582
582
|
return await this.retryBLE({
|
|
583
|
-
max:
|
|
583
|
+
max: this.maxRetryBLE(),
|
|
584
584
|
fn: async () => {
|
|
585
585
|
return await deviceList[0].runToPos(100 - Number(this.WindowCovering.TargetPosition), setPositionMode)
|
|
586
586
|
},
|
|
587
587
|
})
|
|
588
588
|
})
|
|
589
589
|
.then(async () => {
|
|
590
|
-
|
|
590
|
+
this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`)
|
|
591
591
|
await this.updateHomeKitCharacteristics()
|
|
592
592
|
})
|
|
593
593
|
.catch(async (e: any) => {
|
|
594
594
|
await this.apiError(e)
|
|
595
|
-
|
|
595
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
596
596
|
await this.BLEPushConnection()
|
|
597
597
|
})
|
|
598
598
|
} else {
|
|
599
|
-
|
|
599
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
600
600
|
await this.BLEPushConnection()
|
|
601
601
|
}
|
|
602
602
|
} catch (error) {
|
|
603
|
-
|
|
603
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
604
604
|
}
|
|
605
605
|
} else {
|
|
606
|
-
|
|
606
|
+
this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
607
607
|
}
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
async openAPIpushChanges(): Promise<void> {
|
|
611
|
-
|
|
611
|
+
this.debugLog('openAPIpushChanges')
|
|
612
612
|
const hasDifferentAndRelevantHorizontalTiltAngle
|
|
613
613
|
= this.mappingMode === BlindTiltMappingMode.UseTiltForDirection
|
|
614
614
|
&& this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle
|
|
@@ -616,8 +616,8 @@ export class BlindTilt extends deviceBase {
|
|
|
616
616
|
|| hasDifferentAndRelevantHorizontalTiltAngle || this.device.disableCaching) {
|
|
617
617
|
const [direction, position] = this.mapHomekitValuesToDeviceValues(Number(this.WindowCovering.TargetPosition), Number(this.WindowCovering.TargetHorizontalTiltAngle))
|
|
618
618
|
const { Mode, setPositionMode }: { setPositionMode: number, Mode: string } = await this.setPerformance()
|
|
619
|
-
|
|
620
|
-
|
|
619
|
+
this.debugLog(`Pushing ${this.WindowCovering.TargetPosition} (device = ${direction};${position})`)
|
|
620
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`)
|
|
621
621
|
let bodyChange: bodyChange
|
|
622
622
|
if (position === 100) {
|
|
623
623
|
bodyChange = {
|
|
@@ -638,24 +638,24 @@ export class BlindTilt extends deviceBase {
|
|
|
638
638
|
commandType: 'command',
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
|
-
|
|
641
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
642
642
|
try {
|
|
643
|
-
const
|
|
644
|
-
const deviceStatus: any =
|
|
645
|
-
|
|
643
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
644
|
+
const deviceStatus: any = response.body
|
|
645
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
646
646
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
647
|
-
|
|
647
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
648
648
|
await this.updateHomeKitCharacteristics()
|
|
649
649
|
} else {
|
|
650
650
|
await this.statusCode(deviceStatus.statusCode)
|
|
651
651
|
}
|
|
652
652
|
} catch (e: any) {
|
|
653
653
|
await this.apiError(e)
|
|
654
|
-
|
|
654
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
655
655
|
}
|
|
656
656
|
} else {
|
|
657
|
-
|
|
658
|
-
|
|
657
|
+
this.debugLog(`No changes (openAPIpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
658
|
+
this.debugLog(`No changes (openAPIpushChanges), TargetHorizontalTiltAngle: ${this.WindowCovering.TargetHorizontalTiltAngle}, CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`)
|
|
659
659
|
}
|
|
660
660
|
}
|
|
661
661
|
|
|
@@ -664,9 +664,9 @@ export class BlindTilt extends deviceBase {
|
|
|
664
664
|
*/
|
|
665
665
|
async TargetHorizontalTiltAngleSet(value: CharacteristicValue): Promise<void> {
|
|
666
666
|
if (this.WindowCovering.TargetHorizontalTiltAngle !== this.accessory.context.TargetHorizontalTiltAngle) {
|
|
667
|
-
|
|
667
|
+
this.debugLog(`Set TargetHorizontalTiltAngle: ${value}`)
|
|
668
668
|
} else {
|
|
669
|
-
|
|
669
|
+
this.debugLog(`No changes, TargetHorizontalTiltAngle: ${value}`)
|
|
670
670
|
}
|
|
671
671
|
|
|
672
672
|
// value = value < 0 ? -90 : 90;
|
|
@@ -680,9 +680,9 @@ export class BlindTilt extends deviceBase {
|
|
|
680
680
|
*/
|
|
681
681
|
async TargetPositionSet(value: CharacteristicValue): Promise<void> {
|
|
682
682
|
if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
|
|
683
|
-
|
|
683
|
+
this.debugLog(`Set TargetPosition: ${value}`)
|
|
684
684
|
} else {
|
|
685
|
-
|
|
685
|
+
this.debugLog(`No changes, TargetPosition: ${value}`)
|
|
686
686
|
}
|
|
687
687
|
|
|
688
688
|
this.WindowCovering.TargetPosition = value
|
|
@@ -692,20 +692,20 @@ export class BlindTilt extends deviceBase {
|
|
|
692
692
|
|
|
693
693
|
async startUpdatingBlindTiltIfNeeded(): Promise<void> {
|
|
694
694
|
await this.setMinMax()
|
|
695
|
-
|
|
695
|
+
this.debugLog('setMinMax')
|
|
696
696
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
697
697
|
|| this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle) {
|
|
698
698
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
699
699
|
this.setNewTarget = true
|
|
700
|
-
|
|
700
|
+
this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
701
701
|
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
702
702
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
703
703
|
this.setNewTarget = true
|
|
704
|
-
|
|
704
|
+
this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
705
705
|
} else {
|
|
706
706
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
707
707
|
this.setNewTarget = false
|
|
708
|
-
|
|
708
|
+
this.debugLog(`value: ${this.WindowCovering.CurrentPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
709
709
|
}
|
|
710
710
|
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState)
|
|
711
711
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
@@ -715,10 +715,10 @@ export class BlindTilt extends deviceBase {
|
|
|
715
715
|
* The minimum time depends on the network control latency.
|
|
716
716
|
*/
|
|
717
717
|
clearTimeout(this.setNewTargetTimer)
|
|
718
|
-
|
|
718
|
+
this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`)
|
|
719
719
|
if (this.setNewTarget) {
|
|
720
720
|
this.setNewTargetTimer = setTimeout(async () => {
|
|
721
|
-
|
|
721
|
+
this.debugLog(`setNewTarget ${this.setNewTarget} timeout`)
|
|
722
722
|
this.setNewTarget = false
|
|
723
723
|
}, this.deviceUpdateRate * 1000)
|
|
724
724
|
}
|
|
@@ -776,15 +776,15 @@ export class BlindTilt extends deviceBase {
|
|
|
776
776
|
|
|
777
777
|
async BLEPushConnection() {
|
|
778
778
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
779
|
-
|
|
779
|
+
this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
780
780
|
await this.openAPIpushChanges()
|
|
781
781
|
}
|
|
782
782
|
}
|
|
783
783
|
|
|
784
784
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
785
|
-
|
|
785
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
786
786
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
787
|
-
|
|
787
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
788
788
|
await this.openAPIRefreshStatus()
|
|
789
789
|
}
|
|
790
790
|
}
|
|
@@ -870,50 +870,50 @@ export class BlindTilt extends deviceBase {
|
|
|
870
870
|
slidePosition: blindTiltStatus['slidePosition'] | blindTiltWebhookContext['slidePosition'],
|
|
871
871
|
) {
|
|
872
872
|
const [homekitPosition, homekitTiltAngle] = this.mapDeviceValuesToHomekitValues(Number(slidePosition), String(direction))
|
|
873
|
-
|
|
874
|
-
|
|
873
|
+
this.debugLog(`Slide Position: ${slidePosition}`)
|
|
874
|
+
this.debugLog(`Homekit Position: ${homekitPosition}`)
|
|
875
875
|
|
|
876
876
|
this.WindowCovering.CurrentPosition = homekitPosition
|
|
877
877
|
await this.setMinMax()
|
|
878
|
-
|
|
878
|
+
this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
879
879
|
|
|
880
880
|
if (homekitTiltAngle) {
|
|
881
881
|
this.WindowCovering.CurrentHorizontalTiltAngle = homekitTiltAngle!
|
|
882
|
-
|
|
882
|
+
this.debugLog(`CurrentHorizontalTiltAngle: ${this.WindowCovering.CurrentHorizontalTiltAngle}`)
|
|
883
883
|
}
|
|
884
884
|
|
|
885
885
|
if (this.setNewTarget) {
|
|
886
886
|
this.blindTiltMoving = true
|
|
887
|
-
|
|
887
|
+
this.infoLog('Checking Status ...')
|
|
888
888
|
await this.setMinMax()
|
|
889
889
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition
|
|
890
890
|
|| (homekitTiltAngle && this.WindowCovering.TargetHorizontalTiltAngle !== this.WindowCovering.CurrentHorizontalTiltAngle)) {
|
|
891
|
-
|
|
891
|
+
this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
892
892
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING
|
|
893
893
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
894
|
-
|
|
894
|
+
this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
895
895
|
} else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
896
|
-
|
|
896
|
+
this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
897
897
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING
|
|
898
898
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
899
|
-
|
|
899
|
+
this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`)
|
|
900
900
|
} else {
|
|
901
|
-
|
|
901
|
+
this.debugLog(`Standby because reached position, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
902
902
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
903
903
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState)
|
|
904
|
-
|
|
904
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
905
905
|
}
|
|
906
906
|
} else {
|
|
907
907
|
this.blindTiltMoving = false
|
|
908
|
-
|
|
908
|
+
this.debugLog(`Standby because device not moving, CurrentPosition: ${this.WindowCovering.CurrentPosition}`)
|
|
909
909
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition
|
|
910
910
|
if (homekitTiltAngle) {
|
|
911
911
|
this.WindowCovering.TargetHorizontalTiltAngle = this.WindowCovering.CurrentHorizontalTiltAngle
|
|
912
912
|
}
|
|
913
913
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED
|
|
914
|
-
|
|
914
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`)
|
|
915
915
|
}
|
|
916
|
-
|
|
916
|
+
this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState}`)
|
|
917
917
|
}
|
|
918
918
|
|
|
919
919
|
/**
|