@switchbot/homebridge-switchbot 1.10.2-beta.5 → 1.11.0

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/config.schema.json +49 -0
  3. package/dist/device/bot.d.ts +43 -40
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +29 -26
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +25 -21
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +176 -145
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +15 -15
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +14 -13
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +25 -22
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +50 -37
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts +23 -20
  20. package/dist/device/humidifier.d.ts.map +1 -1
  21. package/dist/device/humidifier.js +41 -41
  22. package/dist/device/humidifier.js.map +1 -1
  23. package/dist/device/lock.d.ts +16 -13
  24. package/dist/device/lock.d.ts.map +1 -1
  25. package/dist/device/lock.js +20 -22
  26. package/dist/device/lock.js.map +1 -1
  27. package/dist/device/meter.d.ts +15 -15
  28. package/dist/device/meter.d.ts.map +1 -1
  29. package/dist/device/meter.js +11 -14
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/motion.d.ts +16 -16
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +16 -17
  34. package/dist/device/motion.js.map +1 -1
  35. package/dist/device/plug.d.ts +10 -7
  36. package/dist/device/plug.d.ts.map +1 -1
  37. package/dist/device/plug.js +22 -21
  38. package/dist/device/plug.js.map +1 -1
  39. package/dist/settings.d.ts +4 -1
  40. package/dist/settings.d.ts.map +1 -1
  41. package/dist/settings.js.map +1 -1
  42. package/package.json +76 -76
  43. package/src/device/bot.ts +53 -50
  44. package/src/device/colorbulb.ts +208 -162
  45. package/src/device/contact.ts +31 -30
  46. package/src/device/curtain.ts +68 -57
  47. package/src/device/humidifier.ts +68 -59
  48. package/src/device/lock.ts +28 -31
  49. package/src/device/meter.ts +25 -31
  50. package/src/device/motion.ts +32 -36
  51. package/src/device/plug.ts +25 -25
  52. package/src/settings.ts +5 -1
package/src/device/bot.ts CHANGED
@@ -12,17 +12,17 @@ import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceSta
12
12
  */
13
13
  export class Bot {
14
14
  // Services
15
- private fanService?: Service;
16
- private doorService?: Service;
17
- private lockService?: Service;
18
- private faucetService?: Service;
19
- private windowService?: Service;
20
- private switchService?: Service;
21
- private outletService?: Service;
22
- private batteryService?: Service;
23
- private garageDoorService?: Service;
24
- private windowCoveringService?: Service;
25
- private statefulProgrammableSwitchService?: Service;
15
+ fanService?: Service;
16
+ doorService?: Service;
17
+ lockService?: Service;
18
+ faucetService?: Service;
19
+ windowService?: Service;
20
+ switchService?: Service;
21
+ outletService?: Service;
22
+ batteryService?: Service;
23
+ garageDoorService?: Service;
24
+ windowCoveringService?: Service;
25
+ statefulProgrammableSwitchService?: Service;
26
26
 
27
27
  // Characteristic Values
28
28
  On!: CharacteristicValue;
@@ -333,8 +333,8 @@ export class Bot {
333
333
  // Start an update interval
334
334
  interval(this.deviceRefreshRate * 1000)
335
335
  .pipe(skipWhile(() => this.botUpdateInProgress))
336
- .subscribe(() => {
337
- this.refreshStatus();
336
+ .subscribe(async () => {
337
+ await this.refreshStatus();
338
338
  });
339
339
 
340
340
  // Watch for Bot change events
@@ -369,7 +369,7 @@ export class Bot {
369
369
  /**
370
370
  * Parse the device status from the SwitchBot api
371
371
  */
372
- async parseStatus() {
372
+ async parseStatus(): Promise<void> {
373
373
  if (this.SwitchToOpenAPI || !this.device.ble) {
374
374
  await this.openAPIparseStatus();
375
375
  } else {
@@ -377,7 +377,7 @@ export class Bot {
377
377
  }
378
378
  }
379
379
 
380
- private async BLEparseStatus() {
380
+ async BLEparseStatus(): Promise<void> {
381
381
  this.debugLog(`Bot: ${this.accessory.displayName} BLE parseStatus`);
382
382
  // BLEmode (true if Switch Mode) | (false if Press Mode)
383
383
  if (this.mode) {
@@ -406,7 +406,7 @@ export class Bot {
406
406
  this.debugLog(`Bot: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
407
407
  }
408
408
 
409
- private async openAPIparseStatus() {
409
+ async openAPIparseStatus(): Promise<void> {
410
410
  if (this.device.ble) {
411
411
  this.SwitchToOpenAPI = false;
412
412
  }
@@ -439,7 +439,7 @@ export class Bot {
439
439
  /**
440
440
  * Asks the SwitchBot API for the latest device information
441
441
  */
442
- async refreshStatus() {
442
+ async refreshStatus(): Promise<void> {
443
443
  if (this.device.ble) {
444
444
  await this.BLERefreshStatus();
445
445
  } else {
@@ -447,7 +447,7 @@ export class Bot {
447
447
  }
448
448
  }
449
449
 
450
- private async BLERefreshStatus() {
450
+ async BLERefreshStatus(): Promise<void> {
451
451
  this.debugLog(`Bot: ${this.accessory.displayName} BLE refreshStatus`);
452
452
  const switchbot = await this.platform.connectBLE();
453
453
  // Convert to BLE Address
@@ -523,7 +523,7 @@ export class Bot {
523
523
  });
524
524
  }
525
525
 
526
- private async openAPIRefreshStatus() {
526
+ async openAPIRefreshStatus(): Promise<void> {
527
527
  if (this.platform.config.credentials?.openToken) {
528
528
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI refreshStatus`);
529
529
  try {
@@ -554,7 +554,7 @@ export class Bot {
554
554
  * Bot - "command" "turnOn" "default" = set to ON state
555
555
  * Bot - "command" "press" "default" = trigger press
556
556
  */
557
- async pushChanges() {
557
+ async pushChanges(): Promise<void> {
558
558
  if (this.device.ble) {
559
559
  await this.BLEpushChanges();
560
560
  } else {
@@ -563,12 +563,12 @@ export class Bot {
563
563
  interval(5000)
564
564
  .pipe(skipWhile(() => this.botUpdateInProgress))
565
565
  .pipe(take(1))
566
- .subscribe(() => {
567
- this.refreshStatus();
566
+ .subscribe(async () => {
567
+ await this.refreshStatus();
568
568
  });
569
569
  }
570
570
 
571
- private async BLEpushChanges() {
571
+ async BLEpushChanges(): Promise<void> {
572
572
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.OnCached}`);
573
573
  if (this.On !== this.OnCached || this.allowPush) {
574
574
  this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`);
@@ -662,7 +662,7 @@ export class Bot {
662
662
  this.accessory.context.On = this.OnCached;
663
663
  }
664
664
 
665
- private turnOnOff(device_list: any) {
665
+ async turnOnOff(device_list: any): Promise<any> {
666
666
  if (this.On) {
667
667
  return device_list[0].turnOn({ id: this.device.bleMac });
668
668
  } else {
@@ -670,7 +670,7 @@ export class Bot {
670
670
  }
671
671
  }
672
672
 
673
- private async openAPIpushChanges() {
673
+ async openAPIpushChanges(): Promise<void> {
674
674
  if (this.platform.config.credentials?.openToken) {
675
675
  try {
676
676
  if (this.On !== this.OnCached || this.allowPush) {
@@ -726,7 +726,7 @@ export class Bot {
726
726
  /**
727
727
  * Updates the status for each of the HomeKit Characteristics
728
728
  */
729
- updateHomeKitCharacteristics() {
729
+ async updateHomeKitCharacteristics(): Promise<void> {
730
730
  if (this.device.bot?.deviceType === 'garagedoor') {
731
731
  if (this.On === undefined) {
732
732
  this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`);
@@ -913,7 +913,7 @@ export class Bot {
913
913
  }
914
914
  }
915
915
 
916
- public apiError(e: any) {
916
+ async apiError(e: any): Promise<void> {
917
917
  if (this.device.bot?.deviceType === 'garagedoor') {
918
918
  this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, e);
919
919
  this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, e);
@@ -952,7 +952,7 @@ export class Bot {
952
952
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
953
953
  }
954
954
 
955
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
955
+ async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
956
956
  switch (push.data.statusCode) {
957
957
  case 151:
958
958
  this.errorLog(`Bot: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -985,7 +985,7 @@ export class Bot {
985
985
  }
986
986
  }
987
987
 
988
- private offlineOff() {
988
+ async offlineOff(): Promise<void> {
989
989
  if (this.device.offline) {
990
990
  this.On = false;
991
991
  if (this.device.bot?.deviceType === 'switch') {
@@ -999,7 +999,7 @@ export class Bot {
999
999
  /**
1000
1000
  * Handle requests to set the "On" characteristic
1001
1001
  */
1002
- private handleOnSet(value: CharacteristicValue) {
1002
+ async handleOnSet(value: CharacteristicValue): Promise<void> {
1003
1003
  if (this.device.bot?.deviceType === 'garagedoor') {
1004
1004
  this.debugLog(`Bot: ${this.accessory.displayName} TargetDoorState: ${value}`);
1005
1005
  if (value === this.platform.Characteristic.TargetDoorState.CLOSED) {
@@ -1046,7 +1046,7 @@ export class Bot {
1046
1046
  this.doBotUpdate.next();
1047
1047
  }
1048
1048
 
1049
- config(device: device & devicesConfig) {
1049
+ async config(device: device & devicesConfig): Promise<void> {
1050
1050
  let config = {};
1051
1051
  if (device.bot) {
1052
1052
  config = device.bot;
@@ -1063,12 +1063,15 @@ export class Bot {
1063
1063
  if (device.scanDuration !== undefined) {
1064
1064
  config['scanDuration'] = device.scanDuration;
1065
1065
  }
1066
+ if (device.offline !== undefined) {
1067
+ config['offline'] = device.offline;
1068
+ }
1066
1069
  if (Object.entries(config).length !== 0) {
1067
1070
  this.warnLog(`Bot: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1068
1071
  }
1069
1072
  }
1070
1073
 
1071
- refreshRate(device: device & devicesConfig) {
1074
+ async refreshRate(device: device & devicesConfig): Promise<void> {
1072
1075
  if (device.refreshRate) {
1073
1076
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
1074
1077
  this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
@@ -1078,7 +1081,7 @@ export class Bot {
1078
1081
  }
1079
1082
  }
1080
1083
 
1081
- scan(device: device & devicesConfig) {
1084
+ async scan(device: device & devicesConfig): Promise<void> {
1082
1085
  if (device.scanDuration) {
1083
1086
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
1084
1087
  if (device.ble) {
@@ -1092,7 +1095,7 @@ export class Bot {
1092
1095
  }
1093
1096
  }
1094
1097
 
1095
- logs(device: device & devicesConfig) {
1098
+ async logs(device: device & devicesConfig): Promise<void> {
1096
1099
  if (this.platform.debugMode) {
1097
1100
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
1098
1101
  this.debugLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -1108,7 +1111,7 @@ export class Bot {
1108
1111
  }
1109
1112
  }
1110
1113
 
1111
- PressOrSwitch(device: device & devicesConfig) {
1114
+ async PressOrSwitch(device: device & devicesConfig): Promise<void> {
1112
1115
  if (!device.bot?.mode) {
1113
1116
  this.botMode = 'switch';
1114
1117
  this.warnLog(`Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`);
@@ -1124,7 +1127,7 @@ export class Bot {
1124
1127
  }
1125
1128
  }
1126
1129
 
1127
- allowPushChanges(device: device & devicesConfig) {
1130
+ async allowPushChanges(device: device & devicesConfig): Promise<void> {
1128
1131
  if (device.bot?.allowPush) {
1129
1132
  this.allowPush = true;
1130
1133
  } else {
@@ -1133,7 +1136,7 @@ export class Bot {
1133
1136
  this.debugLog(`Bot: ${this.accessory.displayName} Allowing Push Changes: ${this.allowPush}`);
1134
1137
  }
1135
1138
 
1136
- public removeOutletService(accessory: PlatformAccessory) {
1139
+ async removeOutletService(accessory: PlatformAccessory): Promise<void> {
1137
1140
  // If outletService still pressent, then remove first
1138
1141
  this.outletService = this.accessory.getService(this.platform.Service.Outlet);
1139
1142
  if (this.outletService) {
@@ -1142,7 +1145,7 @@ export class Bot {
1142
1145
  accessory.removeService(this.outletService!);
1143
1146
  }
1144
1147
 
1145
- public removeGarageDoorService(accessory: PlatformAccessory) {
1148
+ async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
1146
1149
  // If garageDoorService still pressent, then remove first
1147
1150
  this.garageDoorService = this.accessory.getService(this.platform.Service.GarageDoorOpener);
1148
1151
  if (this.garageDoorService) {
@@ -1151,7 +1154,7 @@ export class Bot {
1151
1154
  accessory.removeService(this.garageDoorService!);
1152
1155
  }
1153
1156
 
1154
- public removeDoorService(accessory: PlatformAccessory) {
1157
+ async removeDoorService(accessory: PlatformAccessory): Promise<void> {
1155
1158
  // If doorService still pressent, then remove first
1156
1159
  this.doorService = this.accessory.getService(this.platform.Service.Door);
1157
1160
  if (this.doorService) {
@@ -1160,7 +1163,7 @@ export class Bot {
1160
1163
  accessory.removeService(this.doorService!);
1161
1164
  }
1162
1165
 
1163
- public removeLockService(accessory: PlatformAccessory) {
1166
+ async removeLockService(accessory: PlatformAccessory): Promise<void> {
1164
1167
  // If lockService still pressent, then remove first
1165
1168
  this.lockService = this.accessory.getService(this.platform.Service.LockMechanism);
1166
1169
  if (this.lockService) {
@@ -1169,7 +1172,7 @@ export class Bot {
1169
1172
  accessory.removeService(this.lockService!);
1170
1173
  }
1171
1174
 
1172
- public removeFaucetService(accessory: PlatformAccessory) {
1175
+ async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
1173
1176
  // If faucetService still pressent, then remove first
1174
1177
  this.faucetService = this.accessory.getService(this.platform.Service.Faucet);
1175
1178
  if (this.faucetService) {
@@ -1178,7 +1181,7 @@ export class Bot {
1178
1181
  accessory.removeService(this.faucetService!);
1179
1182
  }
1180
1183
 
1181
- public removeFanService(accessory: PlatformAccessory) {
1184
+ async removeFanService(accessory: PlatformAccessory): Promise<void> {
1182
1185
  // If fanService still pressent, then remove first
1183
1186
  this.fanService = this.accessory.getService(this.platform.Service.Fan);
1184
1187
  if (this.fanService) {
@@ -1187,7 +1190,7 @@ export class Bot {
1187
1190
  accessory.removeService(this.fanService!);
1188
1191
  }
1189
1192
 
1190
- public removeWindowService(accessory: PlatformAccessory) {
1193
+ async removeWindowService(accessory: PlatformAccessory): Promise<void> {
1191
1194
  // If windowService still pressent, then remove first
1192
1195
  this.windowService = this.accessory.getService(this.platform.Service.Window);
1193
1196
  if (this.windowService) {
@@ -1196,7 +1199,7 @@ export class Bot {
1196
1199
  accessory.removeService(this.windowService!);
1197
1200
  }
1198
1201
 
1199
- public removeWindowCoveringService(accessory: PlatformAccessory) {
1202
+ async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
1200
1203
  // If windowCoveringService still pressent, then remove first
1201
1204
  this.windowCoveringService = this.accessory.getService(this.platform.Service.WindowCovering);
1202
1205
  if (this.windowCoveringService) {
@@ -1205,7 +1208,7 @@ export class Bot {
1205
1208
  accessory.removeService(this.windowCoveringService!);
1206
1209
  }
1207
1210
 
1208
- public removeStatefulProgrammableSwitchService(accessory: PlatformAccessory) {
1211
+ async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
1209
1212
  // If statefulProgrammableSwitchService still pressent, then remove first
1210
1213
  this.statefulProgrammableSwitchService = this.accessory.getService(this.platform.Service.StatefulProgrammableSwitch);
1211
1214
  if (this.statefulProgrammableSwitchService) {
@@ -1214,7 +1217,7 @@ export class Bot {
1214
1217
  accessory.removeService(this.statefulProgrammableSwitchService!);
1215
1218
  }
1216
1219
 
1217
- public removeSwitchService(accessory: PlatformAccessory) {
1220
+ async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
1218
1221
  // If switchService still pressent, then remove first
1219
1222
  this.switchService = this.accessory.getService(this.platform.Service.Switch);
1220
1223
  if (this.switchService) {
@@ -1226,25 +1229,25 @@ export class Bot {
1226
1229
  /**
1227
1230
  * Logging for Device
1228
1231
  */
1229
- infoLog(...log: any[]) {
1232
+ infoLog(...log: any[]): void {
1230
1233
  if (this.enablingDeviceLogging()) {
1231
1234
  this.platform.log.info(String(...log));
1232
1235
  }
1233
1236
  }
1234
1237
 
1235
- warnLog(...log: any[]) {
1238
+ warnLog(...log: any[]): void {
1236
1239
  if (this.enablingDeviceLogging()) {
1237
1240
  this.platform.log.warn(String(...log));
1238
1241
  }
1239
1242
  }
1240
1243
 
1241
- errorLog(...log: any[]) {
1244
+ errorLog(...log: any[]): void {
1242
1245
  if (this.enablingDeviceLogging()) {
1243
1246
  this.platform.log.error(String(...log));
1244
1247
  }
1245
1248
  }
1246
1249
 
1247
- debugLog(...log: any[]) {
1250
+ debugLog(...log: any[]): void {
1248
1251
  if (this.enablingDeviceLogging()) {
1249
1252
  if (this.deviceLogging === 'debug') {
1250
1253
  this.platform.log.info('[DEBUG]', String(...log));