@switchbot/homebridge-switchbot 3.5.0-beta.27 → 3.5.0-beta.29

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 (136) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/config.schema.json +67 -1
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +10 -5
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +10 -5
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts.map +1 -1
  10. package/dist/device/ceilinglight.js +36 -10
  11. package/dist/device/ceilinglight.js.map +1 -1
  12. package/dist/device/colorbulb.d.ts.map +1 -1
  13. package/dist/device/colorbulb.js +24 -5
  14. package/dist/device/colorbulb.js.map +1 -1
  15. package/dist/device/contact.d.ts.map +1 -1
  16. package/dist/device/contact.js +8 -3
  17. package/dist/device/contact.js.map +1 -1
  18. package/dist/device/curtain.d.ts.map +1 -1
  19. package/dist/device/curtain.js +8 -3
  20. package/dist/device/curtain.js.map +1 -1
  21. package/dist/device/device.d.ts +2 -1
  22. package/dist/device/device.d.ts.map +1 -1
  23. package/dist/device/device.js +23 -6
  24. package/dist/device/device.js.map +1 -1
  25. package/dist/device/fan.d.ts +51 -0
  26. package/dist/device/fan.d.ts.map +1 -0
  27. package/dist/device/fan.js +499 -0
  28. package/dist/device/fan.js.map +1 -0
  29. package/dist/device/hub.d.ts.map +1 -1
  30. package/dist/device/hub.js +33 -25
  31. package/dist/device/hub.js.map +1 -1
  32. package/dist/device/humidifier.d.ts.map +1 -1
  33. package/dist/device/humidifier.js +8 -3
  34. package/dist/device/humidifier.js.map +1 -1
  35. package/dist/device/iosensor.d.ts.map +1 -1
  36. package/dist/device/iosensor.js +26 -18
  37. package/dist/device/iosensor.js.map +1 -1
  38. package/dist/device/lightstrip.d.ts.map +1 -1
  39. package/dist/device/lightstrip.js +42 -5
  40. package/dist/device/lightstrip.js.map +1 -1
  41. package/dist/device/lock.d.ts.map +1 -1
  42. package/dist/device/lock.js +8 -3
  43. package/dist/device/lock.js.map +1 -1
  44. package/dist/device/meter.d.ts.map +1 -1
  45. package/dist/device/meter.js +26 -18
  46. package/dist/device/meter.js.map +1 -1
  47. package/dist/device/meterplus.d.ts.map +1 -1
  48. package/dist/device/meterplus.js +8 -3
  49. package/dist/device/meterplus.js.map +1 -1
  50. package/dist/device/motion.d.ts.map +1 -1
  51. package/dist/device/motion.js +8 -3
  52. package/dist/device/motion.js.map +1 -1
  53. package/dist/device/plug.d.ts.map +1 -1
  54. package/dist/device/plug.js +8 -3
  55. package/dist/device/plug.js.map +1 -1
  56. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  57. package/dist/device/robotvacuumcleaner.js +10 -5
  58. package/dist/device/robotvacuumcleaner.js.map +1 -1
  59. package/dist/device/waterdetector.d.ts.map +1 -1
  60. package/dist/device/waterdetector.js +15 -8
  61. package/dist/device/waterdetector.js.map +1 -1
  62. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  63. package/dist/irdevice/airconditioner.js +3 -2
  64. package/dist/irdevice/airconditioner.js.map +1 -1
  65. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  66. package/dist/irdevice/airpurifier.js +3 -2
  67. package/dist/irdevice/airpurifier.js.map +1 -1
  68. package/dist/irdevice/camera.d.ts.map +1 -1
  69. package/dist/irdevice/camera.js +3 -2
  70. package/dist/irdevice/camera.js.map +1 -1
  71. package/dist/irdevice/fan.d.ts +1 -1
  72. package/dist/irdevice/fan.d.ts.map +1 -1
  73. package/dist/irdevice/fan.js +4 -3
  74. package/dist/irdevice/fan.js.map +1 -1
  75. package/dist/irdevice/irdevice.d.ts +2 -1
  76. package/dist/irdevice/irdevice.d.ts.map +1 -1
  77. package/dist/irdevice/irdevice.js +9 -2
  78. package/dist/irdevice/irdevice.js.map +1 -1
  79. package/dist/irdevice/light.d.ts.map +1 -1
  80. package/dist/irdevice/light.js +3 -2
  81. package/dist/irdevice/light.js.map +1 -1
  82. package/dist/irdevice/other.d.ts.map +1 -1
  83. package/dist/irdevice/other.js +3 -2
  84. package/dist/irdevice/other.js.map +1 -1
  85. package/dist/irdevice/tv.d.ts.map +1 -1
  86. package/dist/irdevice/tv.js +3 -2
  87. package/dist/irdevice/tv.js.map +1 -1
  88. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  89. package/dist/irdevice/vacuumcleaner.js +3 -2
  90. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  91. package/dist/irdevice/waterheater.d.ts.map +1 -1
  92. package/dist/irdevice/waterheater.js +3 -2
  93. package/dist/irdevice/waterheater.js.map +1 -1
  94. package/dist/platform.d.ts +2 -1
  95. package/dist/platform.d.ts.map +1 -1
  96. package/dist/platform.js +68 -5
  97. package/dist/platform.js.map +1 -1
  98. package/dist/settings.d.ts +22 -4
  99. package/dist/settings.d.ts.map +1 -1
  100. package/dist/utils.d.ts +10 -5
  101. package/dist/utils.d.ts.map +1 -1
  102. package/dist/utils.js +23 -9
  103. package/dist/utils.js.map +1 -1
  104. package/package.json +3 -3
  105. package/src/device/blindtilt.ts +10 -5
  106. package/src/device/bot.ts +10 -5
  107. package/src/device/ceilinglight.ts +36 -10
  108. package/src/device/colorbulb.ts +26 -7
  109. package/src/device/contact.ts +10 -5
  110. package/src/device/curtain.ts +22 -17
  111. package/src/device/device.ts +24 -6
  112. package/src/device/fan.ts +548 -0
  113. package/src/device/hub.ts +31 -23
  114. package/src/device/humidifier.ts +9 -4
  115. package/src/device/iosensor.ts +28 -20
  116. package/src/device/lightstrip.ts +41 -7
  117. package/src/device/lock.ts +13 -8
  118. package/src/device/meter.ts +30 -22
  119. package/src/device/meterplus.ts +12 -7
  120. package/src/device/motion.ts +9 -4
  121. package/src/device/plug.ts +9 -4
  122. package/src/device/robotvacuumcleaner.ts +15 -10
  123. package/src/device/waterdetector.ts +15 -8
  124. package/src/irdevice/airconditioner.ts +5 -4
  125. package/src/irdevice/airpurifier.ts +5 -4
  126. package/src/irdevice/camera.ts +4 -3
  127. package/src/irdevice/fan.ts +4 -3
  128. package/src/irdevice/irdevice.ts +11 -3
  129. package/src/irdevice/light.ts +3 -2
  130. package/src/irdevice/other.ts +47 -46
  131. package/src/irdevice/tv.ts +3 -2
  132. package/src/irdevice/vacuumcleaner.ts +3 -2
  133. package/src/irdevice/waterheater.ts +3 -2
  134. package/src/platform.ts +71 -5
  135. package/src/settings.ts +34 -9
  136. package/src/utils.ts +24 -9
@@ -101,18 +101,20 @@ export class WaterDetector extends deviceBase {
101
101
  });
102
102
 
103
103
  //regisiter webhook event handler
104
- if (this.device.webhook && !this.device.waterdetector?.hide_leak) {
105
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
104
+ if (device.webhook && !this.device.waterdetector?.hide_leak) {
105
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
106
106
  this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
107
107
  try {
108
108
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
109
- const { status } = context;
109
+ const { detectionState, battery } = context;
110
110
  const { LeakDetected } = this.LeakSensor!;
111
+ const { BatteryLevel } = this.Battery!;
111
112
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
112
- '(status) = ' +
113
- `Webhook:(${status}), ` +
114
- `current:(${LeakDetected})`);
115
- this.LeakSensor!.LeakDetected = status;
113
+ '(detectionState, battery) = ' +
114
+ `Webhook:(${detectionState}, ${battery}), ` +
115
+ `current:(${LeakDetected}, ${BatteryLevel})`);
116
+ this.LeakSensor!.LeakDetected = detectionState;
117
+ this.Battery!.BatteryLevel = battery;
116
118
  this.updateHomeKitCharacteristics();
117
119
  } catch (e: any) {
118
120
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
@@ -165,6 +167,11 @@ export class WaterDetector extends deviceBase {
165
167
 
166
168
  // FirmwareRevision
167
169
  this.accessory.context.FirmwareRevision = deviceStatus.body.version;
170
+ this.accessory
171
+ .getService(this.hap.Service.AccessoryInformation)!
172
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.FirmwareRevision)
173
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
174
+ .updateValue(this.accessory.context.FirmwareRevision);
168
175
  }
169
176
 
170
177
  async refreshStatus(): Promise<void> {
@@ -230,7 +237,7 @@ export class WaterDetector extends deviceBase {
230
237
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
231
238
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
232
239
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
233
- this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
240
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
234
241
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
235
242
  this.openAPIparseStatus(deviceStatus);
236
243
  this.updateHomeKitCharacteristics();
@@ -346,9 +346,10 @@ export class AirConditioner extends irdeviceBase {
346
346
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
347
347
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
348
348
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
349
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
349
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
350
350
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
351
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API, body: ${bodyChange} sent successfully`);
351
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
352
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
352
353
  this.updateHomeKitCharacteristics();
353
354
  } else {
354
355
  this.statusCode(statusCode);
@@ -616,7 +617,7 @@ export class AirConditioner extends irdeviceBase {
616
617
  this.accessory.context.RotationSpeed = this.HeaterCooler.RotationSpeed;
617
618
  this.HeaterCooler.Service?.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.HeaterCooler.RotationSpeed);
618
619
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
619
- + ` RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
620
+ + ` RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
620
621
  }
621
622
  // CurrentTemperature
622
623
  if (this.HeaterCooler.CurrentTemperature === undefined) {
@@ -654,7 +655,7 @@ export class AirConditioner extends irdeviceBase {
654
655
  // CurrentHeaterCoolerState
655
656
  if (this.HeaterCooler.CurrentHeaterCoolerState === undefined) {
656
657
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
657
- + ` CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
658
+ + ` CurrentHeaterCoolerState: ${this.HeaterCooler.CurrentHeaterCoolerState}`);
658
659
  } else {
659
660
  this.accessory.context.CurrentHeaterCoolerState = this.HeaterCooler.CurrentHeaterCoolerState;
660
661
  this.HeaterCooler.Service?.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.HeaterCooler.CurrentHeaterCoolerState);
@@ -222,9 +222,10 @@ export class AirPurifier extends irdeviceBase {
222
222
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
223
223
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
224
224
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
225
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
225
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
226
226
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
227
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API, body: ${bodyChange} sent successfully`);
227
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
228
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
228
229
  this.updateHomeKitCharacteristics();
229
230
  } else {
230
231
  this.statusCode(statusCode);
@@ -261,7 +262,7 @@ export class AirPurifier extends irdeviceBase {
261
262
  this.accessory.context.CurrentAirPurifierState = this.AirPurifier.CurrentAirPurifierState;
262
263
  this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, this.AirPurifier.CurrentAirPurifierState);
263
264
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
264
- + ` CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
265
+ + ` CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
265
266
  }
266
267
  // CurrentHeaterCoolerState
267
268
  if (this.CurrentHeaterCoolerState === undefined) {
@@ -281,7 +282,7 @@ export class AirPurifier extends irdeviceBase {
281
282
  this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
282
283
  this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
283
284
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
284
- + ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
285
+ + ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
285
286
  }
286
287
  }
287
288
 
@@ -68,7 +68,7 @@ export class Camera extends irdeviceBase {
68
68
  */
69
69
  async pushOnChanges(): Promise<void> {
70
70
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.Switch.On},`
71
- + ` disablePushOn: ${this.disablePushOn}`);
71
+ + ` disablePushOn: ${this.disablePushOn}`);
72
72
  if (this.Switch.On && !this.disablePushOn) {
73
73
  const commandType: string = await this.commandType();
74
74
  const command: string = await this.commandOn();
@@ -112,9 +112,10 @@ export class Camera extends irdeviceBase {
112
112
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
113
113
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
114
114
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
115
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
115
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
116
116
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
117
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API, body: ${bodyChange} sent successfully`);
117
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
118
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
118
119
  this.updateHomeKitCharacteristics();
119
120
  } else {
120
121
  this.statusCode(statusCode);
@@ -13,7 +13,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
13
13
  * An instance of this class is created for each accessory your platform registers
14
14
  * Each accessory may expose multiple services of different service types.
15
15
  */
16
- export class Fan extends irdeviceBase {
16
+ export class IRFan extends irdeviceBase {
17
17
  // Services
18
18
  private Fan: {
19
19
  Service: Service;
@@ -231,9 +231,10 @@ export class Fan extends irdeviceBase {
231
231
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
232
232
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
233
233
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
234
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
234
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
235
235
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
236
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API, body: ${bodyChange} sent successfully`);
236
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
237
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
237
238
  this.updateHomeKitCharacteristics();
238
239
  } else {
239
240
  this.statusCode(statusCode);
@@ -455,22 +455,30 @@ export abstract class irdeviceBase {
455
455
  break;
456
456
  default:
457
457
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
458
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
458
+ + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
459
459
  }
460
460
  }
461
461
 
462
462
  /**
463
463
  * Logging for Device
464
464
  */
465
+ infoLog(...log: any[]): void {
466
+ if (this.enablingDeviceLogging()) {
467
+ this.log.info(String(...log));
468
+ }
469
+ }
470
+
465
471
  successLog(...log: any[]): void {
466
472
  if (this.enablingDeviceLogging()) {
467
473
  this.platform.log.success(String(...log));
468
474
  }
469
475
  }
470
476
 
471
- infoLog(...log: any[]): void {
477
+ debugSuccessLog(...log: any[]): void {
472
478
  if (this.enablingDeviceLogging()) {
473
- this.log.info(String(...log));
479
+ if (this.deviceLogging?.includes('debug')) {
480
+ this.log.success('[DEBUG]', String(...log));
481
+ }
474
482
  }
475
483
  }
476
484
 
@@ -223,9 +223,10 @@ export class Light extends irdeviceBase {
223
223
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
224
224
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
225
225
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
226
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
226
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
227
227
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
228
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API, body: ${bodyChange} sent successfully`);
228
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
229
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
229
230
  this.accessory.context.On = this.On;
230
231
  this.updateHomeKitCharacteristics();
231
232
  } else {
@@ -440,7 +440,7 @@ export class Others extends irdeviceBase {
440
440
  */
441
441
  async pushOnChanges(On: boolean): Promise<void> {
442
442
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${On},`
443
- +` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`);
443
+ + ` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`);
444
444
  if (this.device.customize) {
445
445
  if (On === true && !this.disablePushOn) {
446
446
  const commandType: string = await this.commandType();
@@ -491,9 +491,10 @@ export class Others extends irdeviceBase {
491
491
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
492
492
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
493
493
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
494
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
494
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
495
495
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
496
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API, body: ${bodyChange} sent successfully`);
496
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
497
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
497
498
  this.updateHomeKitCharacteristics();
498
499
  } else {
499
500
  this.statusCode(statusCode);
@@ -502,11 +503,11 @@ export class Others extends irdeviceBase {
502
503
  } catch (e: any) {
503
504
  this.apiError(e);
504
505
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
505
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
506
+ + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
506
507
  }
507
508
  } else {
508
509
  this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
509
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
510
+ + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
510
511
  }
511
512
  }
512
513
 
@@ -519,12 +520,12 @@ export class Others extends irdeviceBase {
519
520
  this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
520
521
  this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
521
522
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
522
- + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor!.On})`);
523
+ + ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor!.On})`);
523
524
  } else {
524
525
  this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
525
526
  this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
526
527
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
527
- + ` TargetDoorState: Closed, CurrentDoorState: Closed (${this.GarageDoor!.On})`);
528
+ + ` TargetDoorState: Closed, CurrentDoorState: Closed (${this.GarageDoor!.On})`);
528
529
  }
529
530
  }
530
531
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.GarageDoor!.On}`);
@@ -537,13 +538,13 @@ export class Others extends irdeviceBase {
537
538
  this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
538
539
  this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
539
540
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
540
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Door!.On})`);
541
+ + ` TargetPosition: 100, CurrentPosition: 100 (${this.Door!.On})`);
541
542
  } else {
542
543
  this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
543
544
  this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
544
545
  this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
545
546
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
546
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Door!.On})`);
547
+ + ` TargetPosition: 0, CurrentPosition: 0 (${this.Door!.On})`);
547
548
  }
548
549
  }
549
550
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.Door!.On}`);
@@ -556,13 +557,13 @@ export class Others extends irdeviceBase {
556
557
  this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
557
558
  this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
558
559
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
559
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.Window!.On})`);
560
+ + ` TargetPosition: 100, CurrentPosition: 100 (${this.Window!.On})`);
560
561
  } else {
561
562
  this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
562
563
  this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
563
564
  this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
564
565
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
565
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.Window!.On})`);
566
+ + ` TargetPosition: 0, CurrentPosition: 0 (${this.Window!.On})`);
566
567
  }
567
568
  }
568
569
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.Window!.On}`);
@@ -575,13 +576,13 @@ export class Others extends irdeviceBase {
575
576
  this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
576
577
  this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
577
578
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
578
- + ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering!.On})`);
579
+ + ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering!.On})`);
579
580
  } else {
580
581
  this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
581
582
  this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
582
583
  this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
583
584
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
584
- + ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering!.On})`);
585
+ + ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering!.On})`);
585
586
  }
586
587
  }
587
588
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering!.On}`);
@@ -593,7 +594,7 @@ export class Others extends irdeviceBase {
593
594
  this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
594
595
  this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
595
596
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
596
- + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURE (${this.Lock!.On})`);
597
+ + ` LockTargetState: UNSECURED, LockCurrentState: UNSECURE (${this.Lock!.On})`);
597
598
  } else {
598
599
  this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
599
600
  this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
@@ -637,13 +638,13 @@ export class Others extends irdeviceBase {
637
638
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
638
639
  this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
639
640
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
640
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch!.On})`);
641
+ + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch!.On})`);
641
642
  } else {
642
643
  this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
643
644
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
644
645
  this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
645
646
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
646
- + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch!.On})`);
647
+ + ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch!.On})`);
647
648
  }
648
649
  }
649
650
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch!.On}`);
@@ -701,90 +702,90 @@ export class Others extends irdeviceBase {
701
702
  async removeOutletService(accessory: PlatformAccessory): Promise<void> {
702
703
  // If Outlet.Service still present, then remove first
703
704
  if (this.Outlet?.Service) {
704
- this.Outlet!.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
705
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Outlet Service`);
706
- accessory.removeService(this.Outlet!.Service);
705
+ this.Outlet!.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
706
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Outlet Service`);
707
+ accessory.removeService(this.Outlet!.Service);
707
708
  }
708
709
  }
709
710
 
710
711
  async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
711
712
  // If GarageDoor.Service still present, then remove first
712
713
  if (this.GarageDoor?.Service) {
713
- this.GarageDoor!.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
714
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
715
- accessory.removeService(this.GarageDoor!.Service);
714
+ this.GarageDoor!.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
715
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
716
+ accessory.removeService(this.GarageDoor!.Service);
716
717
  }
717
718
  }
718
719
 
719
720
  async removeDoorService(accessory: PlatformAccessory): Promise<void> {
720
721
  // If Door.Service still present, then remove first
721
722
  if (this.Door?.Service) {
722
- this.Door!.Service = this.accessory.getService(this.hap.Service.Door) as Service;
723
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Door Service`);
724
- accessory.removeService(this.Door!.Service);
723
+ this.Door!.Service = this.accessory.getService(this.hap.Service.Door) as Service;
724
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Door Service`);
725
+ accessory.removeService(this.Door!.Service);
725
726
  }
726
727
  }
727
728
 
728
729
  async removeLockService(accessory: PlatformAccessory): Promise<void> {
729
730
  // If Lock.Service still present, then remove first
730
731
  if (this.Lock?.Service) {
731
- this.Lock!.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
732
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Lock Service`);
733
- accessory.removeService(this.Lock!.Service);
732
+ this.Lock!.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
733
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Lock Service`);
734
+ accessory.removeService(this.Lock!.Service);
734
735
  }
735
736
  }
736
737
 
737
738
  async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
738
739
  // If Faucet.Service still present, then remove first
739
740
  if (this.Faucet?.Service) {
740
- this.Faucet!.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
741
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Faucet Service`);
742
- accessory.removeService(this.Faucet!.Service);
741
+ this.Faucet!.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
742
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Faucet Service`);
743
+ accessory.removeService(this.Faucet!.Service);
743
744
  }
744
745
  }
745
746
 
746
747
  async removeFanService(accessory: PlatformAccessory): Promise<void> {
747
748
  // If Fan Service still present, then remove first
748
749
  if (this.Fan?.Service) {
749
- this.Fan!.Service = this.accessory.getService(this.hap.Service.Fan) as Service;
750
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Fan Service`);
751
- accessory.removeService(this.Fan!.Service);
750
+ this.Fan!.Service = this.accessory.getService(this.hap.Service.Fan) as Service;
751
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Fan Service`);
752
+ accessory.removeService(this.Fan!.Service);
752
753
  }
753
754
  }
754
755
 
755
756
  async removeWindowService(accessory: PlatformAccessory): Promise<void> {
756
757
  // If Window.Service still present, then remove first
757
758
  if (this.Window?.Service) {
758
- this.Window!.Service = this.accessory.getService(this.hap.Service.Window) as Service;
759
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Service`);
760
- accessory.removeService(this.Window!.Service);
759
+ this.Window!.Service = this.accessory.getService(this.hap.Service.Window) as Service;
760
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Service`);
761
+ accessory.removeService(this.Window!.Service);
761
762
  }
762
763
  }
763
764
 
764
765
  async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
765
766
  // If WindowCovering.Service still present, then remove first
766
767
  if (this.WindowCovering?.Service) {
767
- this.WindowCovering!.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
768
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
769
- accessory.removeService(this.WindowCovering!.Service);
768
+ this.WindowCovering!.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
769
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
770
+ accessory.removeService(this.WindowCovering!.Service);
770
771
  }
771
772
  }
772
773
 
773
774
  async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
774
775
  // If StatefulProgrammableSwitch.Service still present, then remove first
775
776
  if (this.StatefulProgrammableSwitch?.Service) {
776
- this.StatefulProgrammableSwitch!.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
777
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
778
- accessory.removeService(this.StatefulProgrammableSwitch!.Service);
777
+ this.StatefulProgrammableSwitch!.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
778
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
779
+ accessory.removeService(this.StatefulProgrammableSwitch!.Service);
779
780
  }
780
781
  }
781
782
 
782
783
  async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
783
784
  // If Switch.Service still present, then remove first
784
785
  if (this.Switch?.Service) {
785
- this.Switch!.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
786
- this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Switch Service`);
787
- accessory.removeService(this.Switch!.Service);
786
+ this.Switch!.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
787
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Switch Service`);
788
+ accessory.removeService(this.Switch!.Service);
788
789
  }
789
790
  }
790
791
 
@@ -388,9 +388,10 @@ export class TV extends irdeviceBase {
388
388
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
389
389
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
390
390
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
391
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
391
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
392
392
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
393
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API, body: ${bodyChange} sent successfully`);
393
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
394
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
394
395
  this.updateHomeKitCharacteristics();
395
396
  } else {
396
397
  this.statusCode(statusCode);
@@ -107,9 +107,10 @@ export class VacuumCleaner extends irdeviceBase {
107
107
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
108
108
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
109
109
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
110
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
110
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
111
111
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
112
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API, body: ${bodyChange} sent successfully`);
112
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
113
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
113
114
  this.updateHomeKitCharacteristics();
114
115
  } else {
115
116
  this.statusCode(statusCode);
@@ -112,9 +112,10 @@ export class WaterHeater extends irdeviceBase {
112
112
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
113
113
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
114
114
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
115
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
115
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
116
116
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
117
- this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API, body: ${bodyChange} sent successfully`);
117
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
118
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
118
119
  this.updateHomeKitCharacteristics();
119
120
  } else {
120
121
  this.statusCode(statusCode);
package/src/platform.ts CHANGED
@@ -20,8 +20,9 @@ import { CeilingLight } from './device/ceilinglight.js';
20
20
  import { StripLight } from './device/lightstrip.js';
21
21
  import { Humidifier } from './device/humidifier.js';
22
22
  import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
23
+ import { Fan } from './device/fan.js';
23
24
  import { TV } from './irdevice/tv.js';
24
- import { Fan } from './irdevice/fan.js';
25
+ import { IRFan } from './irdevice/fan.js';
25
26
  import { Light } from './irdevice/light.js';
26
27
  import { Others } from './irdevice/other.js';
27
28
  import { Camera } from './irdevice/camera.js';
@@ -727,6 +728,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
727
728
  case 'WoSweeperMini':
728
729
  case 'Robot Vacuum Cleaner S1':
729
730
  case 'Robot Vacuum Cleaner S1 Plus':
731
+ case 'Robot Vacuum Cleaner S10':
730
732
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
731
733
  this.createRobotVacuumCleaner(device);
732
734
  break;
@@ -747,6 +749,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
747
749
  case 'remote with screen+':
748
750
  this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
749
751
  break;
752
+ case 'Battery Circulator Fan':
753
+ this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
754
+ this.createFan(device);
755
+ break;
750
756
  default:
751
757
  this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
752
758
  // eslint-disable-next-line max-len
@@ -782,7 +788,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
782
788
  case 'Fan':
783
789
  case 'DIY Fan':
784
790
  this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
785
- this.createFan(device);
791
+ this.createIRFan(device);
786
792
  break;
787
793
  case 'Air Conditioner':
788
794
  case 'DIY Air Conditioner':
@@ -1814,6 +1820,66 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1814
1820
  }
1815
1821
  }
1816
1822
 
1823
+ private async createFan(device: device & devicesConfig) {
1824
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1825
+
1826
+ // see if an accessory with the same uuid has already been registered and restored from
1827
+ // the cached devices we stored in the `configureAccessory` method above
1828
+ const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
1829
+
1830
+ if (existingAccessory) {
1831
+ // the accessory already exists
1832
+ if (await this.registerDevice(device)) {
1833
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1834
+ existingAccessory.context.model = device.deviceType;
1835
+ existingAccessory.context.deviceID = device.deviceId;
1836
+ existingAccessory.displayName = device.configDeviceName || device.deviceName;
1837
+ if (device.firmware) {
1838
+ existingAccessory.context.FirmwareRevision = device.firmware;
1839
+ }
1840
+ existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1841
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
1842
+ existingAccessory.context.connectionType = await this.connectionType(device);
1843
+ this.api.updatePlatformAccessories([existingAccessory]);
1844
+ // create the accessory handler for the restored accessory
1845
+ // this is imported from `platformAccessory.ts`
1846
+ new Fan(this, existingAccessory, device);
1847
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
1848
+ } else {
1849
+ this.unregisterPlatformAccessories(existingAccessory);
1850
+ }
1851
+ } else if (await this.registerDevice(device)) {
1852
+ // the accessory does not yet exist, so we need to create it
1853
+ if (!device.external) {
1854
+ this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1855
+ }
1856
+
1857
+ // create a new accessory
1858
+ const accessory = new this.api.platformAccessory(device.deviceName, uuid);
1859
+
1860
+ // store a copy of the device object in the `accessory.context`
1861
+ // the `context` property can be used to store any data about the accessory you may need
1862
+ accessory.context.device = device;
1863
+ accessory.context.model = device.deviceType;
1864
+ accessory.context.deviceID = device.deviceId;
1865
+ if (device.firmware) {
1866
+ accessory.context.FirmwareRevision = device.firmware;
1867
+ }
1868
+ accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
1869
+ accessory.context.connectionType = await this.connectionType(device);
1870
+ // create the accessory handler for the newly create accessory
1871
+ // this is imported from `platformAccessory.ts`
1872
+ new Fan(this, accessory, device);
1873
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
1874
+
1875
+ // publish device externally or link the accessory to your platform
1876
+ this.externalOrPlatform(device, accessory);
1877
+ this.accessories.push(accessory);
1878
+ } else {
1879
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
1880
+ }
1881
+ }
1882
+
1817
1883
  private async createRobotVacuumCleaner(device: device & devicesConfig) {
1818
1884
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
1819
1885
 
@@ -1926,7 +1992,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1926
1992
  }
1927
1993
  }
1928
1994
 
1929
- private async createFan(device: irdevice & devicesConfig) {
1995
+ private async createIRFan(device: irdevice & devicesConfig) {
1930
1996
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
1931
1997
 
1932
1998
  // see if an accessory with the same uuid has already been registered and restored from
@@ -1949,7 +2015,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1949
2015
  this.api.updatePlatformAccessories([existingAccessory]);
1950
2016
  // create the accessory handler for the restored accessory
1951
2017
  // this is imported from `platformAccessory.ts`
1952
- new Fan(this, existingAccessory, device);
2018
+ new IRFan(this, existingAccessory, device);
1953
2019
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
1954
2020
  } else {
1955
2021
  this.unregisterPlatformAccessories(existingAccessory);
@@ -1975,7 +2041,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1975
2041
  accessory.context.connectionType = device.connectionType;
1976
2042
  // create the accessory handler for the newly create accessory
1977
2043
  // this is imported from `platformAccessory.ts`
1978
- new Fan(this, accessory, device);
2044
+ new IRFan(this, accessory, device);
1979
2045
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
1980
2046
 
1981
2047
  // publish device externally or link the accessory to your platform