@switchbot/homebridge-switchbot 2.7.1 → 2.8.0-beta.1
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/.github/npm-version-script.js +81 -0
- package/.prettierrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +10 -0
- package/config.schema.json +8 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +49 -59
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +44 -50
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +60 -63
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +68 -70
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -25
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -58
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +6 -0
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +168 -26
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +49 -56
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +18 -20
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +59 -61
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +40 -41
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +65 -68
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -20
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +20 -23
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +30 -33
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +48 -51
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +57 -61
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +29 -31
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +17 -20
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +27 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -26
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +19 -20
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +44 -47
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +17 -20
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +19 -20
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +44 -43
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +106 -72
- package/src/device/bot.ts +94 -58
- package/src/device/ceilinglight.ts +102 -68
- package/src/device/colorbulb.ts +134 -82
- package/src/device/contact.ts +54 -33
- package/src/device/curtain.ts +130 -101
- package/src/device/hub.ts +198 -35
- package/src/device/humidifier.ts +128 -80
- package/src/device/iosensor.ts +43 -27
- package/src/device/lightstrip.ts +108 -67
- package/src/device/lock.ts +73 -45
- package/src/device/meter.ts +94 -75
- package/src/device/meterplus.ts +43 -27
- package/src/device/motion.ts +50 -32
- package/src/device/plug.ts +62 -39
- package/src/device/robotvacuumcleaner.ts +78 -54
- package/src/irdevice/airconditioner.ts +111 -83
- package/src/irdevice/airpurifier.ts +55 -34
- package/src/irdevice/camera.ts +35 -23
- package/src/irdevice/fan.ts +47 -33
- package/src/irdevice/light.ts +43 -29
- package/src/irdevice/other.ts +39 -23
- package/src/irdevice/tv.ts +65 -51
- package/src/irdevice/vacuumcleaner.ts +35 -23
- package/src/irdevice/waterheater.ts +43 -27
- package/src/platform.ts +85 -55
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/device/curtain.ts
CHANGED
|
@@ -68,13 +68,17 @@ export class Curtain {
|
|
|
68
68
|
doCurtainUpdate!: Subject<void>;
|
|
69
69
|
|
|
70
70
|
// Connection
|
|
71
|
-
private readonly BLE =
|
|
72
|
-
private readonly OpenAPI =
|
|
71
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
72
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
73
73
|
|
|
74
74
|
// EVE history service handler
|
|
75
75
|
historyService: any = null;
|
|
76
76
|
|
|
77
|
-
constructor(
|
|
77
|
+
constructor(
|
|
78
|
+
private readonly platform: SwitchBotPlatform,
|
|
79
|
+
private accessory: PlatformAccessory,
|
|
80
|
+
public device: device & devicesConfig,
|
|
81
|
+
) {
|
|
78
82
|
// default placeholders
|
|
79
83
|
this.logs(device);
|
|
80
84
|
this.refreshRate(device);
|
|
@@ -218,8 +222,10 @@ export class Curtain {
|
|
|
218
222
|
await this.pushChanges();
|
|
219
223
|
} catch (e: any) {
|
|
220
224
|
this.apiError(e);
|
|
221
|
-
this.errorLog(
|
|
222
|
-
|
|
225
|
+
this.errorLog(
|
|
226
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
227
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
228
|
+
);
|
|
223
229
|
}
|
|
224
230
|
this.curtainUpdateInProgress = false;
|
|
225
231
|
});
|
|
@@ -229,66 +235,65 @@ export class Curtain {
|
|
|
229
235
|
}
|
|
230
236
|
|
|
231
237
|
/*
|
|
232
|
-
* Setup EVE history features for curtain devices.
|
|
238
|
+
* Setup EVE history features for curtain devices.
|
|
233
239
|
*/
|
|
234
240
|
async setupHistoryService(device: device & devicesConfig): Promise<void> {
|
|
235
241
|
if (device.history !== true) {
|
|
236
242
|
return;
|
|
237
243
|
}
|
|
238
|
-
|
|
244
|
+
|
|
239
245
|
const mac = this.device
|
|
240
246
|
.deviceId!.match(/.{1,2}/g)!
|
|
241
247
|
.join(':')
|
|
242
248
|
.toLowerCase();
|
|
243
|
-
this.historyService =
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
});
|
|
249
|
+
this.historyService = new this.platform.fakegatoAPI('custom', this.accessory, {
|
|
250
|
+
log: this.platform.log,
|
|
251
|
+
storage: 'fs',
|
|
252
|
+
filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
|
|
253
|
+
});
|
|
249
254
|
const motion: Service =
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
`${this.accessory.displayName} Motion`);
|
|
255
|
+
this.accessory.getService(this.platform.Service.MotionSensor) ||
|
|
256
|
+
this.accessory.addService(this.platform.Service.MotionSensor, `${this.accessory.displayName} Motion`);
|
|
253
257
|
motion.addOptionalCharacteristic(this.platform.eve.Characteristics.LastActivation);
|
|
254
|
-
motion.getCharacteristic(this.platform.eve.Characteristics.LastActivation)
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
});
|
|
258
|
+
motion.getCharacteristic(this.platform.eve.Characteristics.LastActivation).onGet(() => {
|
|
259
|
+
const lastActivation = this.accessory.context.lastActivation
|
|
260
|
+
? Math.max(0, this.accessory.context.lastActivation - this.historyService.getInitialTime())
|
|
261
|
+
: 0;
|
|
262
|
+
return lastActivation;
|
|
263
|
+
});
|
|
261
264
|
await this.setMinMax();
|
|
262
|
-
motion.getCharacteristic(this.platform.Characteristic.MotionDetected)
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
});
|
|
265
|
+
motion.getCharacteristic(this.platform.Characteristic.MotionDetected).on('change', (event: CharacteristicChange) => {
|
|
266
|
+
if (event.newValue !== event.oldValue) {
|
|
267
|
+
const sensor = this.accessory.getService(this.platform.Service.MotionSensor);
|
|
268
|
+
const entry = {
|
|
269
|
+
time: Math.round(new Date().valueOf() / 1000),
|
|
270
|
+
motion: event.newValue,
|
|
271
|
+
};
|
|
272
|
+
this.accessory.context.lastActivation = entry.time;
|
|
273
|
+
sensor?.updateCharacteristic(
|
|
274
|
+
this.platform.eve.Characteristics.LastActivation,
|
|
275
|
+
Math.max(0, this.accessory.context.lastActivation - this.historyService.getInitialTime()),
|
|
276
|
+
);
|
|
277
|
+
this.historyService.addEntry(entry);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
278
280
|
this.updateHistory();
|
|
279
281
|
}
|
|
280
282
|
|
|
281
|
-
async updateHistory()
|
|
283
|
+
async updateHistory(): Promise<void> {
|
|
282
284
|
const motion = Number(this.CurrentPosition) > 0 ? 1 : 0;
|
|
283
|
-
this.historyService.addEntry
|
|
284
|
-
time: Math.round(new Date().valueOf()/1000),
|
|
285
|
-
motion: motion
|
|
285
|
+
this.historyService.addEntry({
|
|
286
|
+
time: Math.round(new Date().valueOf() / 1000),
|
|
287
|
+
motion: motion,
|
|
286
288
|
});
|
|
287
|
-
setTimeout(
|
|
288
|
-
|
|
289
|
-
|
|
289
|
+
setTimeout(
|
|
290
|
+
() => {
|
|
291
|
+
this.updateHistory();
|
|
292
|
+
},
|
|
293
|
+
10 * 60 * 1000,
|
|
294
|
+
);
|
|
290
295
|
}
|
|
291
|
-
|
|
296
|
+
|
|
292
297
|
/**
|
|
293
298
|
* Parse the device status from the SwitchBot api
|
|
294
299
|
*/
|
|
@@ -301,8 +306,9 @@ export class Curtain {
|
|
|
301
306
|
await this.openAPIparseStatus();
|
|
302
307
|
} else {
|
|
303
308
|
await this.offlineOff();
|
|
304
|
-
this.debugWarnLog(
|
|
305
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
309
|
+
this.debugWarnLog(
|
|
310
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
311
|
+
);
|
|
306
312
|
}
|
|
307
313
|
}
|
|
308
314
|
|
|
@@ -394,8 +400,8 @@ export class Curtain {
|
|
|
394
400
|
this.debugLog();
|
|
395
401
|
}
|
|
396
402
|
this.debugLog(
|
|
397
|
-
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},`
|
|
398
|
-
|
|
403
|
+
`${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
|
|
404
|
+
` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
399
405
|
);
|
|
400
406
|
}
|
|
401
407
|
// Battery
|
|
@@ -405,8 +411,9 @@ export class Curtain {
|
|
|
405
411
|
} else {
|
|
406
412
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
407
413
|
}
|
|
408
|
-
this.debugLog(
|
|
409
|
-
+ ` StatusLowBattery: ${this.StatusLowBattery}
|
|
414
|
+
this.debugLog(
|
|
415
|
+
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
|
|
416
|
+
);
|
|
410
417
|
}
|
|
411
418
|
|
|
412
419
|
async openAPIparseStatus(): Promise<void> {
|
|
@@ -473,8 +480,10 @@ export class Curtain {
|
|
|
473
480
|
await this.openAPIRefreshStatus();
|
|
474
481
|
} else {
|
|
475
482
|
await this.offlineOff();
|
|
476
|
-
this.debugWarnLog(
|
|
477
|
-
|
|
483
|
+
this.debugWarnLog(
|
|
484
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
485
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
486
|
+
);
|
|
478
487
|
}
|
|
479
488
|
}
|
|
480
489
|
|
|
@@ -499,8 +508,10 @@ export class Curtain {
|
|
|
499
508
|
// Set an event hander
|
|
500
509
|
switchbot.onadvertisement = async (ad: any) => {
|
|
501
510
|
this.address = ad.address;
|
|
502
|
-
this.debugLog(
|
|
503
|
-
|
|
511
|
+
this.debugLog(
|
|
512
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
513
|
+
` BLE Address Found: ${this.address}`,
|
|
514
|
+
);
|
|
504
515
|
this.serviceData = ad.serviceData;
|
|
505
516
|
this.calibration = ad.serviceData.calibration;
|
|
506
517
|
this.battery = ad.serviceData.battery;
|
|
@@ -511,7 +522,8 @@ export class Curtain {
|
|
|
511
522
|
this.debugLog(
|
|
512
523
|
`${this.device.deviceType}: ${this.accessory.displayName} calibration: ${ad.serviceData.calibration}, ` +
|
|
513
524
|
`position: ${ad.serviceData.position}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}, ` +
|
|
514
|
-
`inMotion: ${ad.serviceData.inMotion}
|
|
525
|
+
`inMotion: ${ad.serviceData.inMotion}`,
|
|
526
|
+
);
|
|
515
527
|
|
|
516
528
|
if (this.serviceData) {
|
|
517
529
|
this.connected = true;
|
|
@@ -531,8 +543,10 @@ export class Curtain {
|
|
|
531
543
|
})
|
|
532
544
|
.catch(async (e: any) => {
|
|
533
545
|
this.apiError(e);
|
|
534
|
-
this.errorLog(
|
|
535
|
-
|
|
546
|
+
this.errorLog(
|
|
547
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
548
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
549
|
+
);
|
|
536
550
|
await this.BLERefreshConnection(switchbot);
|
|
537
551
|
});
|
|
538
552
|
} else {
|
|
@@ -550,10 +564,7 @@ export class Curtain {
|
|
|
550
564
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
551
565
|
this.statusCode(statusCode);
|
|
552
566
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
553
|
-
this.debugLog(
|
|
554
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
555
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
556
|
-
);
|
|
567
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
557
568
|
this.slidePosition = deviceStatus.body.slidePosition;
|
|
558
569
|
this.moving = deviceStatus.body.moving;
|
|
559
570
|
this.brightness = deviceStatus.body.brightness;
|
|
@@ -561,8 +572,10 @@ export class Curtain {
|
|
|
561
572
|
this.updateHomeKitCharacteristics();
|
|
562
573
|
} catch (e: any) {
|
|
563
574
|
this.apiError(e);
|
|
564
|
-
this.errorLog(
|
|
565
|
-
|
|
575
|
+
this.errorLog(
|
|
576
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
577
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
578
|
+
);
|
|
566
579
|
}
|
|
567
580
|
}
|
|
568
581
|
|
|
@@ -575,8 +588,9 @@ export class Curtain {
|
|
|
575
588
|
await this.openAPIpushChanges();
|
|
576
589
|
} else {
|
|
577
590
|
await this.offlineOff();
|
|
578
|
-
this.debugWarnLog(
|
|
579
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen
|
|
591
|
+
this.debugWarnLog(
|
|
592
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
593
|
+
);
|
|
580
594
|
}
|
|
581
595
|
// Refresh the status from the API
|
|
582
596
|
interval(15000)
|
|
@@ -618,8 +632,10 @@ export class Curtain {
|
|
|
618
632
|
})
|
|
619
633
|
.catch(async (e: any) => {
|
|
620
634
|
this.apiError(e);
|
|
621
|
-
this.errorLog(
|
|
622
|
-
|
|
635
|
+
this.errorLog(
|
|
636
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
637
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
638
|
+
);
|
|
623
639
|
await this.BLEPushConnection();
|
|
624
640
|
throw new Error('Connection error');
|
|
625
641
|
});
|
|
@@ -630,7 +646,8 @@ export class Curtain {
|
|
|
630
646
|
await this.BLEPushConnection();
|
|
631
647
|
}
|
|
632
648
|
} else {
|
|
633
|
-
this.debugLog(
|
|
649
|
+
this.debugLog(
|
|
650
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges, CurrentPosition & TargetPosition Are the Same.` +
|
|
634
651
|
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
|
|
635
652
|
);
|
|
636
653
|
}
|
|
@@ -658,7 +675,7 @@ export class Curtain {
|
|
|
658
675
|
|
|
659
676
|
async openAPIpushChanges(): Promise<void> {
|
|
660
677
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
661
|
-
if (
|
|
678
|
+
if (this.TargetPosition !== this.CurrentPosition || this.device.disableCaching) {
|
|
662
679
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing ${this.TargetPosition}`);
|
|
663
680
|
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
|
|
664
681
|
if (Number(this.TargetPosition) > 50) {
|
|
@@ -676,9 +693,9 @@ export class Curtain {
|
|
|
676
693
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Mode: ${this.Mode}`);
|
|
677
694
|
const adjustedMode = this.setPositionMode || 'ff';
|
|
678
695
|
const bodyChange = JSON.stringify({
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
696
|
+
command: 'setPosition',
|
|
697
|
+
parameter: `0,${adjustedMode},${adjustedTargetPosition}`,
|
|
698
|
+
commandType: 'command',
|
|
682
699
|
});
|
|
683
700
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
684
701
|
try {
|
|
@@ -693,13 +710,16 @@ export class Curtain {
|
|
|
693
710
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
694
711
|
} catch (e: any) {
|
|
695
712
|
this.apiError(e);
|
|
696
|
-
this.errorLog(
|
|
697
|
-
|
|
713
|
+
this.errorLog(
|
|
714
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
715
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
698
716
|
);
|
|
699
717
|
}
|
|
700
718
|
} else {
|
|
701
|
-
this.debugLog(
|
|
702
|
-
|
|
719
|
+
this.debugLog(
|
|
720
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.` +
|
|
721
|
+
` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`,
|
|
722
|
+
);
|
|
703
723
|
}
|
|
704
724
|
}
|
|
705
725
|
|
|
@@ -791,14 +811,16 @@ export class Curtain {
|
|
|
791
811
|
}
|
|
792
812
|
this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
|
|
793
813
|
this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
|
|
794
|
-
this.debugLog(
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
814
|
+
this.debugLog(
|
|
815
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
816
|
+
` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
|
|
817
|
+
);
|
|
818
|
+
if (this.device.history) {
|
|
819
|
+
this.historyService?.addEntry({
|
|
820
|
+
time: Math.round(new Date().valueOf() / 1000),
|
|
821
|
+
lux: this.CurrentAmbientLightLevel,
|
|
822
|
+
});
|
|
823
|
+
}
|
|
802
824
|
}
|
|
803
825
|
}
|
|
804
826
|
if (this.BLE) {
|
|
@@ -970,8 +992,10 @@ export class Curtain {
|
|
|
970
992
|
if (this.updateRate > device.scanDuration) {
|
|
971
993
|
this.scanDuration = this.updateRate;
|
|
972
994
|
if (this.BLE) {
|
|
973
|
-
this.warnLog(
|
|
974
|
-
|
|
995
|
+
this.warnLog(
|
|
996
|
+
`${this.device.deviceType}: ` +
|
|
997
|
+
`${this.accessory.displayName} scanDuration is less than updateRate, overriding scanDuration with updateRate`,
|
|
998
|
+
);
|
|
975
999
|
}
|
|
976
1000
|
} else {
|
|
977
1001
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
@@ -1007,8 +1031,10 @@ export class Curtain {
|
|
|
1007
1031
|
this.offlineOff();
|
|
1008
1032
|
break;
|
|
1009
1033
|
case 171:
|
|
1010
|
-
this.errorLog(
|
|
1011
|
-
|
|
1034
|
+
this.errorLog(
|
|
1035
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
1036
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
1037
|
+
);
|
|
1012
1038
|
this.offlineOff();
|
|
1013
1039
|
break;
|
|
1014
1040
|
case 190:
|
|
@@ -1024,8 +1050,10 @@ export class Curtain {
|
|
|
1024
1050
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
1025
1051
|
break;
|
|
1026
1052
|
default:
|
|
1027
|
-
this.infoLog(
|
|
1028
|
-
|
|
1053
|
+
this.infoLog(
|
|
1054
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
1055
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
1056
|
+
);
|
|
1029
1057
|
}
|
|
1030
1058
|
}
|
|
1031
1059
|
|
|
@@ -1052,8 +1080,9 @@ export class Curtain {
|
|
|
1052
1080
|
|
|
1053
1081
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
1054
1082
|
let FirmwareRevision: string;
|
|
1055
|
-
this.debugLog(
|
|
1056
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
1083
|
+
this.debugLog(
|
|
1084
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
1085
|
+
);
|
|
1057
1086
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1058
1087
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
1059
1088
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -1087,23 +1116,23 @@ export class Curtain {
|
|
|
1087
1116
|
|
|
1088
1117
|
if (!this.device.curtain?.hide_lightsensor) {
|
|
1089
1118
|
if (this.accessory.context.CurrentAmbientLightLevel !== undefined) {
|
|
1090
|
-
|
|
1119
|
+
this.CurrentAmbientLightLevel = this.accessory.context.CurrentAmbientLightLevel;
|
|
1091
1120
|
}
|
|
1092
1121
|
}
|
|
1093
1122
|
|
|
1094
1123
|
if (this.BLE) {
|
|
1095
1124
|
if (this.accessory.context.BatteryLevel === undefined) {
|
|
1096
|
-
|
|
1125
|
+
this.BatteryLevel = 100;
|
|
1097
1126
|
} else {
|
|
1098
|
-
|
|
1127
|
+
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
1099
1128
|
}
|
|
1100
1129
|
if (this.accessory.context.StatusLowBattery === undefined) {
|
|
1101
|
-
|
|
1130
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
1102
1131
|
} else {
|
|
1103
|
-
|
|
1132
|
+
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
1104
1133
|
}
|
|
1105
1134
|
}
|
|
1106
|
-
|
|
1135
|
+
|
|
1107
1136
|
if (this.device.history === true) {
|
|
1108
1137
|
// initialize when this accessory is newly created.
|
|
1109
1138
|
this.accessory.context.lastActivation = this.accessory.context.lastActivation ?? 0;
|