@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.3

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 (187) hide show
  1. package/dist/device/blindtilt.d.ts +15 -6
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +203 -255
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +9 -4
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +196 -218
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +9 -4
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +202 -247
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +10 -5
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +329 -378
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +9 -4
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +99 -142
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +19 -7
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +203 -264
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/device.d.ts +28 -32
  26. package/dist/device/device.d.ts.map +1 -1
  27. package/dist/device/device.js +186 -225
  28. package/dist/device/device.js.map +1 -1
  29. package/dist/device/fan.d.ts +9 -4
  30. package/dist/device/fan.d.ts.map +1 -1
  31. package/dist/device/fan.js +198 -227
  32. package/dist/device/fan.js.map +1 -1
  33. package/dist/device/hub.d.ts +9 -5
  34. package/dist/device/hub.d.ts.map +1 -1
  35. package/dist/device/hub.js +106 -231
  36. package/dist/device/hub.js.map +1 -1
  37. package/dist/device/humidifier.d.ts +12 -4
  38. package/dist/device/humidifier.d.ts.map +1 -1
  39. package/dist/device/humidifier.js +192 -232
  40. package/dist/device/humidifier.js.map +1 -1
  41. package/dist/device/iosensor.d.ts +9 -4
  42. package/dist/device/iosensor.d.ts.map +1 -1
  43. package/dist/device/iosensor.js +91 -157
  44. package/dist/device/iosensor.js.map +1 -1
  45. package/dist/device/lightstrip.d.ts +10 -5
  46. package/dist/device/lightstrip.d.ts.map +1 -1
  47. package/dist/device/lightstrip.js +287 -367
  48. package/dist/device/lightstrip.js.map +1 -1
  49. package/dist/device/lock.d.ts +10 -5
  50. package/dist/device/lock.d.ts.map +1 -1
  51. package/dist/device/lock.js +171 -216
  52. package/dist/device/lock.js.map +1 -1
  53. package/dist/device/meter.d.ts +9 -4
  54. package/dist/device/meter.d.ts.map +1 -1
  55. package/dist/device/meter.js +93 -158
  56. package/dist/device/meter.js.map +1 -1
  57. package/dist/device/meterplus.d.ts +9 -4
  58. package/dist/device/meterplus.d.ts.map +1 -1
  59. package/dist/device/meterplus.js +94 -155
  60. package/dist/device/meterplus.js.map +1 -1
  61. package/dist/device/motion.d.ts +9 -4
  62. package/dist/device/motion.d.ts.map +1 -1
  63. package/dist/device/motion.js +84 -142
  64. package/dist/device/motion.js.map +1 -1
  65. package/dist/device/plug.d.ts +9 -4
  66. package/dist/device/plug.d.ts.map +1 -1
  67. package/dist/device/plug.js +99 -124
  68. package/dist/device/plug.js.map +1 -1
  69. package/dist/device/robotvacuumcleaner.d.ts +9 -6
  70. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  71. package/dist/device/robotvacuumcleaner.js +170 -253
  72. package/dist/device/robotvacuumcleaner.js.map +1 -1
  73. package/dist/device/waterdetector.d.ts +12 -4
  74. package/dist/device/waterdetector.d.ts.map +1 -1
  75. package/dist/device/waterdetector.js +102 -128
  76. package/dist/device/waterdetector.js.map +1 -1
  77. package/dist/irdevice/airconditioner.d.ts +2 -1
  78. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  79. package/dist/irdevice/airconditioner.js.map +1 -1
  80. package/dist/irdevice/airpurifier.d.ts +2 -1
  81. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  82. package/dist/irdevice/airpurifier.js.map +1 -1
  83. package/dist/irdevice/camera.d.ts +2 -1
  84. package/dist/irdevice/camera.d.ts.map +1 -1
  85. package/dist/irdevice/camera.js.map +1 -1
  86. package/dist/irdevice/fan.d.ts +2 -1
  87. package/dist/irdevice/fan.d.ts.map +1 -1
  88. package/dist/irdevice/fan.js.map +1 -1
  89. package/dist/irdevice/irdevice.d.ts +2 -1
  90. package/dist/irdevice/irdevice.d.ts.map +1 -1
  91. package/dist/irdevice/irdevice.js +1 -1
  92. package/dist/irdevice/irdevice.js.map +1 -1
  93. package/dist/irdevice/light.d.ts +2 -1
  94. package/dist/irdevice/light.d.ts.map +1 -1
  95. package/dist/irdevice/light.js.map +1 -1
  96. package/dist/irdevice/other.d.ts +2 -1
  97. package/dist/irdevice/other.d.ts.map +1 -1
  98. package/dist/irdevice/other.js.map +1 -1
  99. package/dist/irdevice/tv.d.ts +2 -1
  100. package/dist/irdevice/tv.d.ts.map +1 -1
  101. package/dist/irdevice/tv.js.map +1 -1
  102. package/dist/irdevice/vacuumcleaner.d.ts +2 -1
  103. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  104. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  105. package/dist/irdevice/waterheater.d.ts +2 -1
  106. package/dist/irdevice/waterheater.d.ts.map +1 -1
  107. package/dist/irdevice/waterheater.js.map +1 -1
  108. package/dist/platform.d.ts +5 -7
  109. package/dist/platform.d.ts.map +1 -1
  110. package/dist/platform.js +51 -34
  111. package/dist/platform.js.map +1 -1
  112. package/dist/settings.d.ts +49 -191
  113. package/dist/settings.d.ts.map +1 -1
  114. package/dist/settings.js +19 -0
  115. package/dist/settings.js.map +1 -1
  116. package/dist/types/bledevicestatus.d.ts +279 -0
  117. package/dist/types/bledevicestatus.d.ts.map +1 -0
  118. package/dist/types/bledevicestatus.js +2 -0
  119. package/dist/types/bledevicestatus.js.map +1 -0
  120. package/dist/types/devicelist.d.ts +89 -0
  121. package/dist/types/devicelist.d.ts.map +1 -0
  122. package/dist/types/devicelist.js +6 -0
  123. package/dist/types/devicelist.js.map +1 -0
  124. package/dist/types/deviceresponse.d.ts +13 -0
  125. package/dist/types/deviceresponse.d.ts.map +1 -0
  126. package/dist/types/deviceresponse.js +2 -0
  127. package/dist/types/deviceresponse.js.map +1 -0
  128. package/dist/types/devicestatus.d.ts +149 -0
  129. package/dist/types/devicestatus.d.ts.map +1 -0
  130. package/dist/types/devicestatus.js +3 -0
  131. package/dist/types/devicestatus.js.map +1 -0
  132. package/dist/types/devicewebhookstatus.d.ts +156 -0
  133. package/dist/types/devicewebhookstatus.d.ts.map +1 -0
  134. package/dist/types/devicewebhookstatus.js +2 -0
  135. package/dist/types/devicewebhookstatus.js.map +1 -0
  136. package/dist/types/irdevicelist.d.ts +10 -0
  137. package/dist/types/irdevicelist.d.ts.map +1 -0
  138. package/dist/types/irdevicelist.js +2 -0
  139. package/dist/types/irdevicelist.js.map +1 -0
  140. package/dist/types/pushbody.d.ts +6 -0
  141. package/dist/types/pushbody.d.ts.map +1 -0
  142. package/dist/types/pushbody.js +2 -0
  143. package/dist/types/pushbody.js.map +1 -0
  144. package/dist/utils.d.ts +25 -0
  145. package/dist/utils.d.ts.map +1 -1
  146. package/dist/utils.js +28 -0
  147. package/dist/utils.js.map +1 -1
  148. package/package.json +10 -10
  149. package/src/device/blindtilt.ts +223 -263
  150. package/src/device/bot.ts +208 -221
  151. package/src/device/ceilinglight.ts +210 -257
  152. package/src/device/colorbulb.ts +334 -397
  153. package/src/device/contact.ts +111 -146
  154. package/src/device/curtain.ts +220 -283
  155. package/src/device/device.ts +194 -245
  156. package/src/device/fan.ts +214 -230
  157. package/src/device/hub.ts +126 -246
  158. package/src/device/humidifier.ts +216 -243
  159. package/src/device/iosensor.ts +114 -166
  160. package/src/device/lightstrip.ts +302 -377
  161. package/src/device/lock.ts +187 -221
  162. package/src/device/meter.ts +116 -177
  163. package/src/device/meterplus.ts +117 -174
  164. package/src/device/motion.ts +99 -144
  165. package/src/device/plug.ts +110 -128
  166. package/src/device/robotvacuumcleaner.ts +189 -252
  167. package/src/device/waterdetector.ts +120 -138
  168. package/src/irdevice/airconditioner.ts +2 -1
  169. package/src/irdevice/airpurifier.ts +2 -1
  170. package/src/irdevice/camera.ts +2 -1
  171. package/src/irdevice/fan.ts +2 -1
  172. package/src/irdevice/irdevice.ts +3 -2
  173. package/src/irdevice/light.ts +2 -1
  174. package/src/irdevice/other.ts +2 -1
  175. package/src/irdevice/tv.ts +2 -1
  176. package/src/irdevice/vacuumcleaner.ts +2 -1
  177. package/src/irdevice/waterheater.ts +2 -1
  178. package/src/platform.ts +52 -34
  179. package/src/settings.ts +30 -239
  180. package/src/types/bledevicestatus.ts +305 -0
  181. package/src/types/devicelist.ts +124 -0
  182. package/src/types/deviceresponse.ts +15 -0
  183. package/src/types/devicestatus.ts +178 -0
  184. package/src/types/devicewebhookstatus.ts +196 -0
  185. package/src/types/irdevicelist.ts +15 -0
  186. package/src/types/pushbody.ts +9 -0
  187. package/src/utils.ts +33 -0
@@ -3,6 +3,7 @@
3
3
  * plug.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
+ import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
6
7
  import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
7
8
  export class Fan extends deviceBase {
8
9
  platform;
@@ -107,14 +108,14 @@ export class Fan extends deviceBase {
107
108
  this.refreshStatus();
108
109
  // Update Homekit
109
110
  this.updateHomeKitCharacteristics();
111
+ //regisiter webhook event handler
112
+ this.registerWebhook();
110
113
  // Start an update interval
111
114
  interval(this.deviceRefreshRate * 1000)
112
115
  .pipe(skipWhile(() => this.fanUpdateInProgress))
113
116
  .subscribe(async () => {
114
117
  await this.refreshStatus();
115
118
  });
116
- //regisiter webhook event handler
117
- this.registerWebhook(accessory, device);
118
119
  // Watch for Plug change events
119
120
  // We put in a debounce of 100ms so we don't make duplicate calls
120
121
  this.doFanUpdate
@@ -126,56 +127,85 @@ export class Fan extends deviceBase {
126
127
  await this.pushChanges();
127
128
  }
128
129
  catch (e) {
129
- this.apiError(e);
130
- this.errorLog(`${device.deviceType}: ${accessory.displayName} failed pushChanges with ${device.connectionType} Connection,`
131
- + ` Error Message: ${JSON.stringify(e.message)}`);
130
+ await this.apiError(e);
131
+ await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
132
132
  }
133
133
  this.fanUpdateInProgress = false;
134
134
  });
135
135
  }
136
136
  async BLEparseStatus(serviceData) {
137
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
138
- // State
139
- switch (serviceData.state) {
140
- case 'on':
141
- this.Fan.Active = true;
142
- break;
143
- default:
144
- this.Fan.Active = false;
145
- }
146
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Fan.Active}`);
137
+ await this.debugLog('BLEparseStatus');
138
+ // Active
139
+ this.Fan.Active = serviceData.state === 'on' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
140
+ await this.debugLog(`Active: ${this.Fan.Active}`);
147
141
  }
148
142
  async openAPIparseStatus(deviceStatus) {
149
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
143
+ await this.debugLog('openAPIparseStatus');
150
144
  // Active
151
- this.Fan.Active = deviceStatus.body.power === 'on' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
152
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Fan.Active}`);
145
+ this.Fan.Active = deviceStatus.power === 'on' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
146
+ this.debugLog(`Active: ${this.Fan.Active}`);
153
147
  // SwingMode
154
- this.Fan.SwingMode = deviceStatus.body.oscillation === 'on' ?
148
+ this.Fan.SwingMode = deviceStatus.oscillation === 'on' ?
155
149
  this.hap.Characteristic.SwingMode.SWING_ENABLED : this.hap.Characteristic.SwingMode.SWING_DISABLED;
150
+ await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`);
156
151
  // RotationSpeed
157
- this.Fan.RotationSpeed = deviceStatus.body.fanSpeed;
152
+ this.Fan.RotationSpeed = deviceStatus.fanSpeed;
153
+ await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`);
158
154
  // ChargingState
159
- this.Battery.ChargingState = deviceStatus.body.chargingStatus === 'charging' ?
155
+ this.Battery.ChargingState = deviceStatus.chargingStatus === 'charging' ?
160
156
  this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
161
157
  // BatteryLevel
162
- this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
163
- if (this.Battery.BatteryLevel < 10) {
164
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
165
- }
166
- else {
167
- this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
168
- }
169
- if (Number.isNaN(this.Battery.BatteryLevel)) {
170
- this.Battery.BatteryLevel = 100;
171
- }
172
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
173
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
158
+ this.Battery.BatteryLevel = Number(deviceStatus.battery);
159
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
160
+ // StatusLowBattery
161
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
162
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
163
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
174
164
  // Firmware Version
175
- const version = deviceStatus.body.version?.toString();
176
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
177
- if (deviceStatus.body.version) {
178
- const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
165
+ const version = deviceStatus.version.toString();
166
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
167
+ if (deviceStatus.version) {
168
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
169
+ this.accessory
170
+ .getService(this.hap.Service.AccessoryInformation)
171
+ .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
172
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
173
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
174
+ .updateValue(deviceVersion);
175
+ this.accessory.context.deviceVersion = deviceVersion;
176
+ await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
177
+ }
178
+ }
179
+ async parseStatusWebhook(context) {
180
+ await this.debugLog('parseStatusWebhook');
181
+ await this.debugLog(`(version, battery, powerState, oscillation, chargingStatus, fanSpeed) = Webhook:(${context.version}, ${context.battery},`
182
+ + ` ${context.powerState}, ${context.oscillation}, ${context.chargingStatus}, ${context.fanSpeed}),`
183
+ + ` current:(${this.accessory.context.deviceVersion}, ${this.Battery.BatteryLevel}, ${this.Fan.Active}, ${this.Fan.SwingMode},`
184
+ + ` ${this.Battery.ChargingState}, ${this.Fan.RotationSpeed})`);
185
+ // Active
186
+ this.Fan.Active = context.powerState === 'ON' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
187
+ await this.debugLog(`Active: ${this.Fan.Active}`);
188
+ // SwingMode
189
+ this.Fan.SwingMode = context.oscillation === 'on' ?
190
+ this.hap.Characteristic.SwingMode.SWING_ENABLED : this.hap.Characteristic.SwingMode.SWING_DISABLED;
191
+ await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`);
192
+ // RotationSpeed
193
+ this.Fan.RotationSpeed = context.fanSpeed;
194
+ await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`);
195
+ // BatteryLevel
196
+ this.Battery.BatteryLevel = context.battery;
197
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
198
+ // StatusLowBattery
199
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
200
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
201
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
202
+ // ChargingState
203
+ this.Battery.ChargingState = context.chargingStatus === 'charging' ?
204
+ this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
205
+ await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
206
+ // FirmwareVersion
207
+ if (context.version) {
208
+ const deviceVersion = context.version.replace(/^V|-.*$/g, '') ?? '0.0.0';
179
209
  this.accessory
180
210
  .getService(this.hap.Service.AccessoryInformation)
181
211
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
@@ -183,7 +213,7 @@ export class Fan extends deviceBase {
183
213
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
184
214
  .updateValue(deviceVersion);
185
215
  this.accessory.context.deviceVersion = deviceVersion;
186
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
216
+ await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
187
217
  }
188
218
  }
189
219
  /**
@@ -191,7 +221,7 @@ export class Fan extends deviceBase {
191
221
  */
192
222
  async refreshStatus() {
193
223
  if (!this.device.enableCloudService && this.OpenAPI) {
194
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
224
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
195
225
  }
196
226
  else if (this.BLE) {
197
227
  await this.BLERefreshStatus();
@@ -201,12 +231,11 @@ export class Fan extends deviceBase {
201
231
  }
202
232
  else {
203
233
  await this.offlineOff();
204
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
205
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
234
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
206
235
  }
207
236
  }
208
237
  async BLERefreshStatus() {
209
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
238
+ await this.debugLog('BLERefreshStatus');
210
239
  const switchbot = await this.switchbotBLE();
211
240
  if (switchbot === undefined) {
212
241
  await this.BLERefreshConnection(switchbot);
@@ -217,81 +246,55 @@ export class Fan extends deviceBase {
217
246
  // Start to monitor advertisement packets
218
247
  const serviceData = await this.monitorAdvertisementPackets(switchbot);
219
248
  // Update HomeKit
220
- if (serviceData.model !== '' && serviceData.modelName !== '') {
249
+ if (serviceData.model === SwitchBotBLEModel.Unknown && SwitchBotBLEModelName.Unknown) {
221
250
  await this.BLEparseStatus(serviceData);
222
251
  await this.updateHomeKitCharacteristics();
223
252
  }
224
253
  else {
225
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
254
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
226
255
  await this.BLERefreshConnection(switchbot);
227
256
  }
228
257
  })();
229
258
  }
230
259
  }
231
260
  async openAPIRefreshStatus() {
232
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
261
+ await this.debugLog('openAPIRefreshStatus');
233
262
  try {
234
263
  const { body, statusCode } = await this.deviceRefreshStatus();
235
264
  const deviceStatus = await body.json();
236
- await this.refreshStatusCodes(statusCode, deviceStatus);
265
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
237
266
  ;
238
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
239
- await this.successfulRefreshStatus(statusCode, deviceStatus);
240
- await this.openAPIparseStatus(deviceStatus);
267
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
268
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
269
+ await this.openAPIparseStatus(deviceStatus.body);
241
270
  await this.updateHomeKitCharacteristics();
242
271
  }
243
272
  else {
244
- await this.statusCodes(statusCode, deviceStatus);
273
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
274
+ await this.debugWarnLog(statusCode, deviceStatus);
245
275
  }
246
276
  }
247
277
  catch (e) {
248
278
  await this.apiError(e);
249
- await this.openAPIRefreshError(e);
279
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
250
280
  }
251
281
  }
252
- async registerWebhook(accessory, device) {
253
- if (device.webhook) {
254
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
255
- this.platform.webhookEventHandler[device.deviceId] = async (context) => {
282
+ async registerWebhook() {
283
+ if (this.device.webhook) {
284
+ await this.debugLog('is listening webhook.');
285
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
256
286
  try {
257
- this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
258
- const { version, battery, powerState, oscillation, chargingStatus, fanSpeed } = context;
259
- const { Active, SwingMode, RotationSpeed } = this.Fan;
260
- const { BatteryLevel, ChargingState } = this.Battery;
261
- const { FirmwareRevision } = accessory.context;
262
- this.debugLog(`${device.deviceType}: ${accessory.displayName} (version, battery, powerState, oscillation, chargingStatus, fanSpeed) = `
263
- + `Webhook:(${version}, ${battery}, ${powerState}, ${oscillation}, ${chargingStatus}, ${fanSpeed}), `
264
- + `current:(${FirmwareRevision}, ${BatteryLevel}, ${Active}, ${SwingMode}, ${ChargingState}, ${RotationSpeed})`);
265
- // Active
266
- this.Fan.Active = powerState === 'ON' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
267
- // SwingMode
268
- this.Fan.SwingMode = oscillation === 'on' ?
269
- this.hap.Characteristic.SwingMode.SWING_ENABLED : this.hap.Characteristic.SwingMode.SWING_DISABLED;
270
- // RotationSpeed
271
- this.Fan.RotationSpeed = fanSpeed;
272
- // ChargingState
273
- this.Battery.ChargingState = chargingStatus === 'charging' ?
274
- this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
275
- // BatteryLevel
276
- this.Battery.BatteryLevel = battery;
277
- // Firmware Version
278
- if (version) {
279
- accessory.context.version = version;
280
- accessory
281
- .getService(this.hap.Service.AccessoryInformation)
282
- .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.version)
283
- .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
284
- .updateValue(accessory.context.version);
285
- }
286
- this.updateHomeKitCharacteristics();
287
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
288
+ await this.parseStatusWebhook(context);
289
+ await this.updateHomeKitCharacteristics();
287
290
  }
288
291
  catch (e) {
289
- this.errorLog(`${device.deviceType}: ${accessory.displayName} failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
292
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
290
293
  }
291
294
  };
292
295
  }
293
296
  else {
294
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is not listening webhook.`);
297
+ await this.debugLog('is not listening webhook.');
295
298
  }
296
299
  }
297
300
  /**
@@ -305,17 +308,29 @@ export class Fan extends deviceBase {
305
308
  */
306
309
  async pushChanges() {
307
310
  if (!this.device.enableCloudService && this.OpenAPI) {
308
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
311
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
309
312
  }
310
313
  else if (this.BLE) {
311
314
  await this.BLEpushChanges();
312
315
  }
313
316
  else if (this.OpenAPI && this.platform.config.credentials?.token) {
314
317
  await this.openAPIpushChanges();
318
+ if (this.Fan.Active) {
319
+ await this.debugLog(`Active: ${this.Fan.Active}`);
320
+ // Push RotationSpeed Update
321
+ await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`);
322
+ await this.pushRotationSpeedChanges();
323
+ // Push SwingMode Update
324
+ await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`);
325
+ await this.pushSwingModeChanges();
326
+ }
327
+ else {
328
+ await this.debugLog('BLE (RotationSpeed) & (SwingMode) changes will not happen, as the device is Off.');
329
+ }
315
330
  }
316
331
  else {
317
332
  await this.offlineOff();
318
- await this.pushChangeDisabled();
333
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
319
334
  }
320
335
  // Refresh the status from the API
321
336
  interval(15000)
@@ -326,66 +341,62 @@ export class Fan extends deviceBase {
326
341
  });
327
342
  }
328
343
  async BLEpushChanges() {
329
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
344
+ await this.debugLog('BLEpushChanges');
330
345
  if (this.Fan.Active !== this.accessory.context.Active) {
331
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`
332
- + ` On: ${this.Fan.Active} OnCached: ${this.accessory.context.Active}`);
333
- const switchbot = await this.platform.connectBLE();
334
- // Convert to BLE Address
346
+ await this.debugLog(`BLEpushChanges On: ${this.Fan.Active} OnCached: ${this.accessory.context.Active}`);
347
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
335
348
  await this.convertBLEAddress();
336
- switchbot
337
- .discover({ model: this.device.bleModel, id: this.device.bleMac })
338
- .then(async (device_list) => {
339
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Fan.Active}`);
340
- return await this.retryBLE({
341
- max: await this.maxRetryBLE(),
342
- fn: async () => {
343
- if (this.Fan.Active) {
344
- return await device_list[0].turnOn({ id: this.device.bleMac });
345
- }
346
- else {
347
- return await device_list[0].turnOff({ id: this.device.bleMac });
348
- }
349
- },
349
+ if (switchbot !== false) {
350
+ switchbot
351
+ .discover({ model: this.device.bleModel, id: this.device.bleMac })
352
+ .then(async (device_list) => {
353
+ return await this.retryBLE({
354
+ max: await this.maxRetryBLE(),
355
+ fn: async () => {
356
+ if (this.Fan.Active) {
357
+ return await device_list[0].turnOn({ id: this.device.bleMac });
358
+ }
359
+ else {
360
+ return await device_list[0].turnOff({ id: this.device.bleMac });
361
+ }
362
+ },
363
+ });
364
+ })
365
+ .then(async () => {
366
+ await this.successLog(`Active: ${this.Fan.Active} sent over SwitchBot BLE, sent successfully`);
367
+ await this.updateHomeKitCharacteristics();
368
+ })
369
+ .catch(async (e) => {
370
+ await this.apiError(e);
371
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
372
+ await this.BLEPushConnection();
350
373
  });
351
- })
352
- .then(async () => {
353
- await this.successfulPushChange_BLE('Active', this.Fan.Active, 'BLE API');
354
- await this.updateHomeKitCharacteristics();
355
- })
356
- .catch(async (e) => {
357
- await this.apiError(e);
358
- await this.pushChangeError('BLEpushChanges', e);
374
+ }
375
+ else {
376
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
359
377
  await this.BLEPushConnection();
360
- });
378
+ }
361
379
  }
362
380
  else {
363
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges,`
364
- + ` Active: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
381
+ await this.debugLog(`No change (BLEpushChanges), Active: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
365
382
  }
366
383
  }
367
384
  async openAPIpushChanges() {
368
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
385
+ await this.debugLog('openAPIpushChanges');
369
386
  if (this.Fan.Active !== this.accessory.context.Active) {
370
- let command = '';
371
- if (this.Fan.Active) {
372
- command = 'turnOn';
373
- }
374
- else {
375
- command = 'turnOff';
376
- }
387
+ const command = this.Fan.Active ? 'turnOn' : 'turnOff';
377
388
  const bodyChange = JSON.stringify({
378
389
  command: `${command}`,
379
390
  parameter: 'default',
380
391
  commandType: 'command',
381
392
  });
382
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
393
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
383
394
  try {
384
395
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
385
396
  const deviceStatus = await body.json();
386
- await this.pushStatusCodes(statusCode, deviceStatus);
387
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
388
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
397
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
398
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
399
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
389
400
  await this.updateHomeKitCharacteristics();
390
401
  }
391
402
  else {
@@ -394,38 +405,29 @@ export class Fan extends deviceBase {
394
405
  }
395
406
  }
396
407
  catch (e) {
397
- this.apiError(e);
398
- await this.pushChangeError('openAPIpushChanges', e);
408
+ await this.apiError(e);
409
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
399
410
  }
400
411
  }
401
412
  else {
402
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.`
403
- + `On: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
404
- }
405
- // Push RotationSpeed Update
406
- if (this.Fan.Active) {
407
- await this.pushRotationSpeedChanges();
408
- }
409
- // Push SwingMode Update
410
- if (this.Fan.Active) {
411
- await this.pushSwingModeChanges();
413
+ await this.debugLog(`No changes (openAPIpushChanges), Active: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
412
414
  }
413
415
  }
414
416
  async pushRotationSpeedChanges() {
415
- await this.pushChange('pushRotationSpeedChanges');
417
+ await this.debugLog('pushRotationSpeedChanges');
416
418
  if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
417
419
  const bodyChange = JSON.stringify({
418
420
  command: 'setWindSpeed',
419
421
  parameter: `${this.Fan.RotationSpeed}`,
420
422
  commandType: 'command',
421
423
  });
422
- await this.bodyChange(bodyChange, 'SwitchBot OpenAPI');
424
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
423
425
  try {
424
426
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
425
427
  const deviceStatus = await body.json();
426
- await this.pushStatusCodes(statusCode, deviceStatus);
427
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
428
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
428
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
429
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
430
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
429
431
  await this.updateHomeKitCharacteristics();
430
432
  }
431
433
  else {
@@ -434,16 +436,18 @@ export class Fan extends deviceBase {
434
436
  }
435
437
  }
436
438
  catch (e) {
437
- this.apiError(e);
438
- await this.pushChangeError('pushRotationSpeedChanges', e);
439
+ await this.apiError(e);
440
+ await this.errorLog(`failed pushRotationSpeedChanges with ${this.device.connectionType} Connection,`
441
+ + ` Error Message: ${JSON.stringify(e.message)}`);
439
442
  }
440
443
  }
441
444
  else {
442
- await this.noChanges('RotationSpeed', this.Fan.RotationSpeed, this.accessory.context.RotationSpeed);
445
+ await this.debugLog(`No changes (pushRotationSpeedChanges), RotationSpeed: ${this.Fan.RotationSpeed},`
446
+ + ` RotationSpeedCached: ${this.accessory.context.RotationSpeed}`);
443
447
  }
444
448
  }
445
449
  async pushSwingModeChanges() {
446
- await this.pushChange('pushSwingModeChanges');
450
+ await this.debugLog('pushSwingModeChanges');
447
451
  if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
448
452
  const parameter = this.Fan.SwingMode === this.hap.Characteristic.SwingMode.SWING_ENABLED ? 'on' : 'off';
449
453
  const bodyChange = JSON.stringify({
@@ -451,13 +455,13 @@ export class Fan extends deviceBase {
451
455
  parameter: `${parameter}`,
452
456
  commandType: 'command',
453
457
  });
454
- await this.bodyChange(bodyChange, 'SwitchBot OpenAPI');
458
+ await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
455
459
  try {
456
460
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
457
461
  const deviceStatus = await body.json();
458
- await this.pushStatusCodes(statusCode, deviceStatus);
459
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
460
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
462
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
463
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
464
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
461
465
  await this.updateHomeKitCharacteristics();
462
466
  }
463
467
  else {
@@ -466,12 +470,13 @@ export class Fan extends deviceBase {
466
470
  }
467
471
  }
468
472
  catch (e) {
469
- this.apiError(e);
470
- await this.pushChangeError('pushSwingModeChanges', e);
473
+ await this.apiError(e);
474
+ await this.errorLog(`failed pushSwingModeChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
471
475
  }
472
476
  }
473
477
  else {
474
- await this.noChanges('SwingMode', this.Fan.SwingMode, this.accessory.context.SwingMode);
478
+ await this.debugLog(`No changes (pushSwingModeChanges), SwingMode: ${this.Fan.SwingMode},`
479
+ + ` SwingModeCached: ${this.accessory.context.SwingMode}`);
475
480
  }
476
481
  }
477
482
  /**
@@ -479,10 +484,10 @@ export class Fan extends deviceBase {
479
484
  */
480
485
  async ActiveSet(value) {
481
486
  if (this.Fan.Active !== this.accessory.context.Active) {
482
- await this.changeSet(value, 'Active');
487
+ await this.infoLog(`Set Active: ${value}`);
483
488
  }
484
489
  else {
485
- await this.noChangeSet(value, 'Active');
490
+ await this.debugLog(`No Changes, Active: ${value}`);
486
491
  }
487
492
  this.Fan.Active = value;
488
493
  this.doFanUpdate.next();
@@ -492,10 +497,10 @@ export class Fan extends deviceBase {
492
497
  */
493
498
  async RotationSpeedSet(value) {
494
499
  if (this.Fan.RotationSpeed !== this.accessory.context.RotationSpeed) {
495
- await this.changeSet(value, 'RotationSpeed');
500
+ await this.infoLog(`Set RotationSpeed ${value}`);
496
501
  }
497
502
  else {
498
- await this.noChangeSet(value, 'RotationSpeed');
503
+ await this.debugLog(`No Changes, RotationSpeed: ${value}`);
499
504
  }
500
505
  this.Fan.RotationSpeed = value;
501
506
  this.doFanUpdate.next();
@@ -505,10 +510,10 @@ export class Fan extends deviceBase {
505
510
  */
506
511
  async SwingModeSet(value) {
507
512
  if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
508
- await this.changeSet(value, 'SwingMode');
513
+ await this.infoLog(`Set SwingMode ${value}`);
509
514
  }
510
515
  else {
511
- await this.noChangeSet(value, 'SwingMode');
516
+ await this.debugLog(`No Changes, SwingMode: ${value}`);
512
517
  }
513
518
  this.Fan.SwingMode = value;
514
519
  this.doFanUpdate.next();
@@ -518,10 +523,10 @@ export class Fan extends deviceBase {
518
523
  */
519
524
  async OnSet(value) {
520
525
  if (this.LightBulb.On !== this.accessory.context.On) {
521
- await this.changeSet(value, 'On');
526
+ await this.infoLog(`Set On: ${value}`);
522
527
  }
523
528
  else {
524
- await this.noChangeSet(value, 'On');
529
+ await this.debugLog(`No Changes, On: ${value}`);
525
530
  }
526
531
  this.LightBulb.On = value;
527
532
  this.doFanUpdate.next();
@@ -530,86 +535,48 @@ export class Fan extends deviceBase {
530
535
  * Handle requests to set the value of the "Brightness" characteristic
531
536
  */
532
537
  async BrightnessSet(value) {
533
- if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
534
- await this.changeSet(value, 'Brightness');
535
- }
536
- else if (this.LightBulb.On) {
537
- await this.changeSet(value, 'Brightness');
538
+ if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
539
+ await this.infoLog(`Set Brightness: ${value}`);
538
540
  }
539
541
  else {
540
- await this.noChangeSet(value, 'Brightness');
542
+ if (this.LightBulb.On) {
543
+ this.debugLog(`No Changes, Brightness: ${value}`);
544
+ }
545
+ else {
546
+ this.debugLog(`Set Brightness: ${value}, On: ${this.LightBulb.On}`);
547
+ }
541
548
  }
542
549
  this.LightBulb.Brightness = value;
543
550
  this.doFanUpdate.next();
544
551
  }
545
552
  async updateHomeKitCharacteristics() {
546
553
  // Active
547
- if (this.Fan.Active === undefined) {
548
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Fan.Active}`);
549
- }
550
- else {
551
- this.accessory.context.Active = this.Fan.Active;
552
- this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Fan.Active);
553
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Fan.Active}`);
554
- }
554
+ await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.Active, this.Fan.Active, 'Active');
555
555
  // RotationSpeed
556
- if (this.Fan.RotationSpeed === undefined) {
557
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} RotationSpeed: ${this.Fan.RotationSpeed}`);
558
- }
559
- else {
560
- this.accessory.context.RotationSpeed = this.Fan.RotationSpeed;
561
- this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.Fan.RotationSpeed);
562
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.Fan.RotationSpeed}`);
563
- }
556
+ await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.RotationSpeed, this.Fan.RotationSpeed, 'RotationSpeed');
564
557
  // SwingMode
565
- if (this.Fan.SwingMode === undefined) {
566
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} SwingMode: ${this.Fan.SwingMode}`);
567
- }
568
- else {
569
- this.accessory.context.SwingMode = this.Fan.SwingMode;
570
- this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, this.Fan.SwingMode);
571
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.Fan.SwingMode}`);
572
- }
573
- // BateryLevel
574
- if (this.Battery.BatteryLevel === undefined) {
575
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
576
- }
577
- else {
578
- this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
579
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
580
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
581
- }
558
+ await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.SwingMode, this.Fan.SwingMode, 'SwingMode');
559
+ // BatteryLevel
560
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel, 'BatteryLevel');
582
561
  // ChargingState
583
- if (this.Battery.ChargingState === undefined) {
584
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ChargingState: ${this.Battery.ChargingState}`);
585
- }
586
- else {
587
- this.accessory.context.ChargingState = this.Battery.ChargingState;
588
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
589
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ChargingState: ${this.Battery.ChargingState}`);
590
- }
562
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState, this.Battery.ChargingState, 'ChargingState');
591
563
  // StatusLowBattery
592
- if (this.Battery.StatusLowBattery === undefined) {
593
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
594
- }
595
- else {
596
- this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
597
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
598
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
599
- + ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
600
- }
564
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery, 'StatusLowBattery');
565
+ // On
566
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On');
567
+ // Brightness
568
+ await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness, this.LightBulb.Brightness, 'Brightness');
601
569
  }
602
570
  async BLEPushConnection() {
603
571
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
604
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
572
+ await this.warnLog('Using OpenAPI Connection to Push Changes');
605
573
  await this.openAPIpushChanges();
606
574
  }
607
575
  }
608
576
  async BLERefreshConnection(switchbot) {
609
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
610
- + ` ${JSON.stringify(switchbot)}`);
577
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
611
578
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
612
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
579
+ await this.warnLog('Using OpenAPI Connection to Refresh Status');
613
580
  await this.openAPIRefreshStatus();
614
581
  }
615
582
  }
@@ -618,12 +585,16 @@ export class Fan extends deviceBase {
618
585
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
619
586
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, 0);
620
587
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, this.hap.Characteristic.SwingMode.SWING_DISABLED);
588
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false);
589
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, 0);
621
590
  }
622
591
  }
623
592
  async apiError(e) {
624
593
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
625
594
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
626
595
  this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, e);
596
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
597
+ this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);
627
598
  }
628
599
  }
629
600
  //# sourceMappingURL=fan.js.map