@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/dist/device/curtain.js
CHANGED
|
@@ -209,7 +209,7 @@ export class Curtain extends deviceBase {
|
|
|
209
209
|
if (this.WindowCovering.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
|
|
210
210
|
return;
|
|
211
211
|
}
|
|
212
|
-
|
|
212
|
+
this.debugLog(`Refresh Status When Moving, PositionState: ${this.WindowCovering.PositionState}`);
|
|
213
213
|
await this.refreshStatus();
|
|
214
214
|
});
|
|
215
215
|
// Watch for Curtain change events
|
|
@@ -224,7 +224,7 @@ export class Curtain extends deviceBase {
|
|
|
224
224
|
}
|
|
225
225
|
catch (e) {
|
|
226
226
|
await this.apiError(e);
|
|
227
|
-
|
|
227
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
228
228
|
}
|
|
229
229
|
this.curtainUpdateInProgress = false;
|
|
230
230
|
});
|
|
@@ -251,7 +251,7 @@ export class Curtain extends deviceBase {
|
|
|
251
251
|
try {
|
|
252
252
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
253
253
|
this.device.bleMac = formattedDeviceId;
|
|
254
|
-
|
|
254
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
255
255
|
this.historyService = new this.platform.fakegatoAPI('custom', this.accessory, {
|
|
256
256
|
log: this.platform.log,
|
|
257
257
|
storage: 'fs',
|
|
@@ -282,45 +282,47 @@ export class Curtain extends deviceBase {
|
|
|
282
282
|
this.updateHistory();
|
|
283
283
|
}
|
|
284
284
|
catch (error) {
|
|
285
|
-
|
|
285
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
-
|
|
288
|
+
updateHistory() {
|
|
289
289
|
const motion = Number(this.WindowCovering.CurrentPosition) > 0 ? 1 : 0;
|
|
290
290
|
this.historyService.addEntry({
|
|
291
291
|
time: Math.round(new Date().valueOf() / 1000),
|
|
292
292
|
motion,
|
|
293
293
|
});
|
|
294
|
-
setTimeout(
|
|
295
|
-
|
|
294
|
+
setTimeout(() => {
|
|
295
|
+
this.updateHistory();
|
|
296
296
|
}, 10 * 60 * 1000);
|
|
297
297
|
}
|
|
298
298
|
async BLEparseStatus() {
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
this.debugLog('BLEparseStatus');
|
|
300
|
+
this.debugLog(`(position, battery) = BLE:(${this.serviceData.position}, ${this.serviceData.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`);
|
|
301
301
|
// CurrentPosition
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
if (this.serviceData.position) {
|
|
303
|
+
this.WindowCovering.CurrentPosition = 100 - this.serviceData.position;
|
|
304
|
+
await this.getCurrentPostion();
|
|
305
|
+
}
|
|
304
306
|
// CurrentAmbientLightLevel
|
|
305
|
-
if (!this.device.hide_lightsensor && this.LightSensor?.Service) {
|
|
307
|
+
if (!this.device.hide_lightsensor && this.LightSensor?.Service && this.serviceData.lightLevel) {
|
|
306
308
|
const set_minLux = this.device.set_minLux ?? 1;
|
|
307
309
|
const set_maxLux = this.device.set_maxLux ?? 6001;
|
|
308
310
|
const lightLevel = this.serviceData.lightLevel;
|
|
309
|
-
this.LightSensor.CurrentAmbientLightLevel =
|
|
311
|
+
this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19);
|
|
310
312
|
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
311
313
|
}
|
|
312
314
|
// BatteryLevel
|
|
313
315
|
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
314
|
-
|
|
316
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
315
317
|
// StatusLowBattery
|
|
316
318
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
317
319
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
318
320
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
319
|
-
|
|
321
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
320
322
|
}
|
|
321
323
|
async openAPIparseStatus() {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
+
this.debugLog('openAPIparseStatus');
|
|
325
|
+
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})`);
|
|
324
326
|
// CurrentPosition
|
|
325
327
|
this.WindowCovering.CurrentPosition = 100 - this.deviceStatus.slidePosition;
|
|
326
328
|
await this.getCurrentPostion();
|
|
@@ -329,21 +331,21 @@ export class Curtain extends deviceBase {
|
|
|
329
331
|
const set_minLux = this.device.set_minLux ?? 1;
|
|
330
332
|
const set_maxLux = this.device.set_maxLux ?? 6001;
|
|
331
333
|
const lightLevel = this.deviceStatus.lightLevel === 'bright' ? set_maxLux : set_minLux;
|
|
332
|
-
this.LightSensor.CurrentAmbientLightLevel =
|
|
333
|
-
|
|
334
|
+
this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2);
|
|
335
|
+
this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`);
|
|
334
336
|
}
|
|
335
337
|
// BatteryLevel
|
|
336
338
|
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
337
|
-
|
|
339
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
338
340
|
// StatusLowBattery
|
|
339
341
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
340
342
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
341
343
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
342
|
-
|
|
344
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
343
345
|
// Firmware Version
|
|
344
346
|
if (this.deviceStatus.version) {
|
|
345
347
|
const version = this.deviceStatus.version.toString();
|
|
346
|
-
|
|
348
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
347
349
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
348
350
|
this.accessory
|
|
349
351
|
.getService(this.hap.Service.AccessoryInformation)
|
|
@@ -352,30 +354,30 @@ export class Curtain extends deviceBase {
|
|
|
352
354
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
353
355
|
.updateValue(deviceVersion);
|
|
354
356
|
this.accessory.context.version = deviceVersion;
|
|
355
|
-
|
|
357
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`);
|
|
356
358
|
}
|
|
357
359
|
}
|
|
358
360
|
async parseStatusWebhook() {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
+
this.debugLog('parseStatusWebhook');
|
|
362
|
+
this.debugLog(`(slidePosition, battery) = Webhook:(${this.webhookContext.slidePosition}, ${this.webhookContext.battery}), current:(${this.WindowCovering.CurrentPosition}, ${this.Battery.BatteryLevel})`);
|
|
361
363
|
// CurrentPosition
|
|
362
364
|
this.WindowCovering.CurrentPosition = 100 - this.webhookContext.slidePosition;
|
|
363
365
|
await this.getCurrentPostion();
|
|
364
366
|
// BatteryLevel
|
|
365
367
|
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
366
|
-
|
|
368
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
367
369
|
// StatusLowBattery
|
|
368
370
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
369
371
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
370
372
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
371
|
-
|
|
373
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
372
374
|
}
|
|
373
375
|
/**
|
|
374
376
|
* Asks the SwitchBot API for the latest device information
|
|
375
377
|
*/
|
|
376
378
|
async refreshStatus() {
|
|
377
379
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
378
|
-
|
|
380
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
379
381
|
}
|
|
380
382
|
else if (this.BLE) {
|
|
381
383
|
await this.BLERefreshStatus();
|
|
@@ -385,11 +387,11 @@ export class Curtain extends deviceBase {
|
|
|
385
387
|
}
|
|
386
388
|
else {
|
|
387
389
|
await this.offlineOff();
|
|
388
|
-
|
|
390
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
389
391
|
}
|
|
390
392
|
}
|
|
391
393
|
async BLERefreshStatus() {
|
|
392
|
-
|
|
394
|
+
this.debugLog('BLERefreshStatus');
|
|
393
395
|
const switchBotBLE = await this.switchbotBLE();
|
|
394
396
|
if (switchBotBLE === undefined) {
|
|
395
397
|
await this.BLERefreshConnection(switchBotBLE);
|
|
@@ -407,79 +409,79 @@ export class Curtain extends deviceBase {
|
|
|
407
409
|
await this.updateHomeKitCharacteristics();
|
|
408
410
|
}
|
|
409
411
|
else {
|
|
410
|
-
|
|
412
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`);
|
|
411
413
|
await this.BLERefreshConnection(switchBotBLE);
|
|
412
414
|
}
|
|
413
415
|
})();
|
|
414
416
|
}
|
|
415
417
|
}
|
|
416
418
|
async openAPIRefreshStatus() {
|
|
417
|
-
|
|
419
|
+
this.debugLog('openAPIRefreshStatus');
|
|
418
420
|
try {
|
|
419
421
|
const { body } = await this.deviceRefreshStatus();
|
|
420
422
|
const deviceStatus = body;
|
|
421
|
-
|
|
423
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
422
424
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
423
|
-
|
|
425
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
424
426
|
this.deviceStatus = deviceStatus.body;
|
|
425
427
|
await this.openAPIparseStatus();
|
|
426
428
|
await this.updateHomeKitCharacteristics();
|
|
427
429
|
}
|
|
428
430
|
else {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
432
|
+
this.debugWarnLog(deviceStatus);
|
|
431
433
|
}
|
|
432
434
|
}
|
|
433
435
|
catch (e) {
|
|
434
436
|
await this.apiError(e);
|
|
435
|
-
|
|
437
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
436
438
|
}
|
|
437
439
|
}
|
|
438
440
|
async registerWebhook() {
|
|
439
441
|
if (this.device.webhook) {
|
|
440
|
-
|
|
442
|
+
this.debugLog('is listening webhook.');
|
|
441
443
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
442
444
|
try {
|
|
443
|
-
|
|
445
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
444
446
|
this.webhookContext = context;
|
|
445
447
|
await this.parseStatusWebhook();
|
|
446
448
|
await this.updateHomeKitCharacteristics();
|
|
447
449
|
}
|
|
448
450
|
catch (e) {
|
|
449
|
-
|
|
451
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
450
452
|
}
|
|
451
453
|
};
|
|
452
454
|
}
|
|
453
455
|
else {
|
|
454
|
-
|
|
456
|
+
this.debugLog('is not listening webhook.');
|
|
455
457
|
}
|
|
456
458
|
}
|
|
457
459
|
async registerPlatformBLE() {
|
|
458
|
-
|
|
460
|
+
this.debugLog('registerPlatformBLE');
|
|
459
461
|
if (this.config.options?.BLE) {
|
|
460
|
-
|
|
462
|
+
this.debugLog('is listening to Platform BLE.');
|
|
461
463
|
try {
|
|
462
464
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
463
465
|
this.device.bleMac = formattedDeviceId;
|
|
464
|
-
|
|
466
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
465
467
|
this.platform.bleEventHandler[this.device.bleMac] = async (context) => {
|
|
466
468
|
try {
|
|
467
|
-
|
|
469
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
468
470
|
this.serviceData = context;
|
|
469
471
|
await this.BLEparseStatus();
|
|
470
472
|
await this.updateHomeKitCharacteristics();
|
|
471
473
|
}
|
|
472
474
|
catch (e) {
|
|
473
|
-
|
|
475
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
474
476
|
}
|
|
475
477
|
};
|
|
476
478
|
}
|
|
477
479
|
catch (error) {
|
|
478
|
-
|
|
480
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
479
481
|
}
|
|
480
482
|
}
|
|
481
483
|
else {
|
|
482
|
-
|
|
484
|
+
this.debugLog('is not listening to Platform BLE');
|
|
483
485
|
}
|
|
484
486
|
}
|
|
485
487
|
/**
|
|
@@ -487,7 +489,7 @@ export class Curtain extends deviceBase {
|
|
|
487
489
|
*/
|
|
488
490
|
async pushChanges() {
|
|
489
491
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
490
|
-
|
|
492
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
491
493
|
}
|
|
492
494
|
else if (this.BLE) {
|
|
493
495
|
await this.BLEpushChanges();
|
|
@@ -497,7 +499,7 @@ export class Curtain extends deviceBase {
|
|
|
497
499
|
}
|
|
498
500
|
else {
|
|
499
501
|
await this.offlineOff();
|
|
500
|
-
|
|
502
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
501
503
|
}
|
|
502
504
|
// Refresh the status from the API
|
|
503
505
|
interval(15000)
|
|
@@ -508,16 +510,16 @@ export class Curtain extends deviceBase {
|
|
|
508
510
|
});
|
|
509
511
|
}
|
|
510
512
|
async BLEpushChanges() {
|
|
511
|
-
|
|
513
|
+
this.debugLog('BLEpushChanges');
|
|
512
514
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition) {
|
|
513
515
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
|
|
514
516
|
try {
|
|
515
517
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
516
518
|
this.device.bleMac = formattedDeviceId;
|
|
517
|
-
|
|
519
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
518
520
|
const { setPositionMode, Mode } = await this.setPerformance();
|
|
519
521
|
const adjustedMode = setPositionMode === 1 ? 0x01 : 0xFF;
|
|
520
|
-
|
|
522
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
|
|
521
523
|
if (switchBotBLE !== false) {
|
|
522
524
|
switchBotBLE
|
|
523
525
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
@@ -531,35 +533,35 @@ export class Curtain extends deviceBase {
|
|
|
531
533
|
});
|
|
532
534
|
})
|
|
533
535
|
.then(async () => {
|
|
534
|
-
|
|
536
|
+
this.successLog(`TargetPostion: ${this.WindowCovering.TargetPosition} sent over SwitchBot BLE, sent successfully`);
|
|
535
537
|
await this.updateHomeKitCharacteristics();
|
|
536
538
|
})
|
|
537
539
|
.catch(async (e) => {
|
|
538
540
|
await this.apiError(e);
|
|
539
|
-
|
|
541
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
540
542
|
await this.BLEPushConnection();
|
|
541
543
|
});
|
|
542
544
|
}
|
|
543
545
|
else {
|
|
544
|
-
|
|
546
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
545
547
|
await this.BLEPushConnection();
|
|
546
548
|
}
|
|
547
549
|
}
|
|
548
550
|
catch (error) {
|
|
549
|
-
|
|
551
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
550
552
|
}
|
|
551
553
|
}
|
|
552
554
|
else {
|
|
553
|
-
|
|
555
|
+
this.debugLog(`No changes (BLEpushChanges), TargetPosition: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
554
556
|
}
|
|
555
557
|
}
|
|
556
558
|
async openAPIpushChanges() {
|
|
557
|
-
|
|
559
|
+
this.debugLog('openAPIpushChanges');
|
|
558
560
|
if (this.WindowCovering.TargetPosition !== this.WindowCovering.CurrentPosition || this.device.disableCaching) {
|
|
559
|
-
|
|
561
|
+
this.debugLog(`Pushing ${this.WindowCovering.TargetPosition}`);
|
|
560
562
|
const adjustedTargetPosition = 100 - Number(this.WindowCovering.TargetPosition);
|
|
561
563
|
const { setPositionMode, Mode } = await this.setPerformance();
|
|
562
|
-
|
|
564
|
+
this.debugLog(`Mode: ${Mode}, setPositionMode: ${setPositionMode}`);
|
|
563
565
|
const adjustedMode = setPositionMode || 'ff';
|
|
564
566
|
let bodyChange;
|
|
565
567
|
if (this.WindowCovering.HoldPosition) {
|
|
@@ -576,13 +578,13 @@ export class Curtain extends deviceBase {
|
|
|
576
578
|
commandType: 'command',
|
|
577
579
|
};
|
|
578
580
|
}
|
|
579
|
-
|
|
581
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
580
582
|
try {
|
|
581
|
-
const
|
|
582
|
-
const deviceStatus =
|
|
583
|
-
|
|
583
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
584
|
+
const deviceStatus = response.body;
|
|
585
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
584
586
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
585
|
-
|
|
587
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
586
588
|
await this.updateHomeKitCharacteristics();
|
|
587
589
|
}
|
|
588
590
|
else {
|
|
@@ -591,11 +593,11 @@ export class Curtain extends deviceBase {
|
|
|
591
593
|
}
|
|
592
594
|
catch (e) {
|
|
593
595
|
await this.apiError(e);
|
|
594
|
-
|
|
596
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
595
597
|
}
|
|
596
598
|
}
|
|
597
599
|
else {
|
|
598
|
-
|
|
600
|
+
this.debugLog(`No changes (openAPIpushChanges), CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}`);
|
|
599
601
|
}
|
|
600
602
|
}
|
|
601
603
|
/**
|
|
@@ -603,10 +605,10 @@ export class Curtain extends deviceBase {
|
|
|
603
605
|
*/
|
|
604
606
|
async TargetPositionSet(value) {
|
|
605
607
|
if (this.WindowCovering.TargetPosition !== this.accessory.context.TargetPosition) {
|
|
606
|
-
|
|
608
|
+
this.infoLog(`Set TargetPosition: ${value}`);
|
|
607
609
|
}
|
|
608
610
|
else {
|
|
609
|
-
|
|
611
|
+
this.debugLog(`No Changes, TargetPosition: ${value}`);
|
|
610
612
|
}
|
|
611
613
|
// Set HoldPosition to false when TargetPosition is changed
|
|
612
614
|
this.WindowCovering.HoldPosition = false;
|
|
@@ -621,17 +623,17 @@ export class Curtain extends deviceBase {
|
|
|
621
623
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
622
624
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
623
625
|
this.setNewTarget = true;
|
|
624
|
-
|
|
626
|
+
this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
625
627
|
}
|
|
626
628
|
else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
627
629
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
628
630
|
this.setNewTarget = true;
|
|
629
|
-
|
|
631
|
+
this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
630
632
|
}
|
|
631
633
|
else {
|
|
632
634
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
633
635
|
this.setNewTarget = false;
|
|
634
|
-
|
|
636
|
+
this.debugLog(`value: ${this.WindowCovering.TargetPosition}, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
635
637
|
}
|
|
636
638
|
this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.WindowCovering.PositionState);
|
|
637
639
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
@@ -640,10 +642,10 @@ export class Curtain extends deviceBase {
|
|
|
640
642
|
* The minimum time depends on the network control latency.
|
|
641
643
|
*/
|
|
642
644
|
clearTimeout(this.setNewTargetTimer);
|
|
643
|
-
|
|
645
|
+
this.debugLog(`deviceUpdateRate: ${this.deviceUpdateRate}`);
|
|
644
646
|
if (this.setNewTarget) {
|
|
645
647
|
this.setNewTargetTimer = setTimeout(async () => {
|
|
646
|
-
|
|
648
|
+
this.debugLog(`setNewTarget ${this.setNewTarget} timeout`);
|
|
647
649
|
this.setNewTarget = false;
|
|
648
650
|
}, this.deviceUpdateRate * 1000);
|
|
649
651
|
}
|
|
@@ -707,14 +709,14 @@ export class Curtain extends deviceBase {
|
|
|
707
709
|
}
|
|
708
710
|
async BLEPushConnection() {
|
|
709
711
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
710
|
-
|
|
712
|
+
this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
711
713
|
await this.openAPIpushChanges();
|
|
712
714
|
}
|
|
713
715
|
}
|
|
714
716
|
async BLERefreshConnection(switchbot) {
|
|
715
|
-
|
|
717
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
716
718
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
717
|
-
|
|
719
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
718
720
|
await this.openAPIRefreshStatus();
|
|
719
721
|
}
|
|
720
722
|
}
|
|
@@ -754,7 +756,7 @@ export class Curtain extends deviceBase {
|
|
|
754
756
|
}
|
|
755
757
|
async getCurrentPostion() {
|
|
756
758
|
await this.setMinMax();
|
|
757
|
-
|
|
759
|
+
this.debugLog(`CurrentPosition ${this.WindowCovering.CurrentPosition}`);
|
|
758
760
|
this.hasLoggedStandby = this.hasLoggedStandby ?? false;
|
|
759
761
|
if (this.deviceStatus ? (this.setNewTarget || this.deviceStatus.moving) : this.setNewTarget) {
|
|
760
762
|
this.hasLoggedStandby = false;
|
|
@@ -762,36 +764,36 @@ export class Curtain extends deviceBase {
|
|
|
762
764
|
this.curtainMoving = true;
|
|
763
765
|
await this.setMinMax();
|
|
764
766
|
if (this.WindowCovering.TargetPosition > this.WindowCovering.CurrentPosition) {
|
|
765
|
-
|
|
767
|
+
this.debugLog(`Closing, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
766
768
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.INCREASING;
|
|
767
769
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
768
|
-
|
|
770
|
+
this.debugLog(`Increasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
769
771
|
}
|
|
770
772
|
else if (this.WindowCovering.TargetPosition < this.WindowCovering.CurrentPosition) {
|
|
771
|
-
|
|
773
|
+
this.debugLog(`Opening, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
772
774
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.DECREASING;
|
|
773
775
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
774
|
-
|
|
776
|
+
this.debugLog(`Decreasing, PositionState: ${this.WindowCovering.PositionState}`);
|
|
775
777
|
}
|
|
776
778
|
else {
|
|
777
|
-
|
|
779
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
778
780
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
779
781
|
this.WindowCovering.Service.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.WindowCovering.PositionState);
|
|
780
|
-
|
|
782
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
781
783
|
}
|
|
782
784
|
}
|
|
783
785
|
else {
|
|
784
786
|
if (!this.hasLoggedStandby) {
|
|
785
|
-
|
|
787
|
+
this.infoLog('Standby ...');
|
|
786
788
|
this.hasLoggedStandby = true;
|
|
787
789
|
}
|
|
788
790
|
this.curtainMoving = false;
|
|
789
|
-
|
|
791
|
+
this.debugLog(`Standby, CurrentPosition: ${this.WindowCovering.CurrentPosition}`);
|
|
790
792
|
this.WindowCovering.TargetPosition = this.WindowCovering.CurrentPosition;
|
|
791
793
|
this.WindowCovering.PositionState = this.hap.Characteristic.PositionState.STOPPED;
|
|
792
|
-
|
|
794
|
+
this.debugLog(`Stopped, PositionState: ${this.WindowCovering.PositionState}`);
|
|
793
795
|
}
|
|
794
|
-
|
|
796
|
+
this.debugLog(`CurrentPosition: ${this.WindowCovering.CurrentPosition}, TargetPosition: ${this.WindowCovering.TargetPosition}, PositionState: ${this.WindowCovering.PositionState},`);
|
|
795
797
|
}
|
|
796
798
|
async setMinMax() {
|
|
797
799
|
if (this.device.set_min) {
|