@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.10

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