@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,9 +3,9 @@
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
10
  * Platform Accessory
11
11
  * An instance of this class is created for each accessory your platform registers
@@ -108,14 +108,14 @@ export class Humidifier extends deviceBase {
108
108
  this.refreshStatus();
109
109
  // Retrieve initial values and updateHomekit
110
110
  this.updateHomeKitCharacteristics();
111
+ //regisiter webhook event handler
112
+ this.registerWebhook();
111
113
  // Start an update interval
112
114
  interval(this.deviceRefreshRate * 1000)
113
115
  .pipe(skipWhile(() => this.humidifierUpdateInProgress))
114
116
  .subscribe(async () => {
115
117
  await this.refreshStatus();
116
118
  });
117
- //regisiter webhook event handler
118
- this.registerWebhook(accessory, device);
119
119
  // Watch for Humidifier change events
120
120
  // We put in a debounce of 100ms so we don't make duplicate calls
121
121
  this.doHumidifierUpdate
@@ -127,45 +127,61 @@ export class Humidifier extends deviceBase {
127
127
  await this.pushChanges();
128
128
  }
129
129
  catch (e) {
130
- this.apiError(e);
131
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
132
- + ` 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)}`);
133
132
  }
134
133
  this.humidifierUpdateInProgress = false;
135
134
  });
136
135
  }
137
136
  async BLEparseStatus(serviceData) {
138
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
139
- // Target Humidifier Dehumidifier State
140
- if (serviceData.autoMode) {
141
- this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
142
- }
137
+ await this.debugLog('BLEparseStatus');
138
+ // Active
139
+ this.HumidifierDehumidifier.Active = serviceData.onState ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
140
+ await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`);
143
141
  // Current Relative Humidity
144
142
  this.HumidifierDehumidifier.CurrentRelativeHumidity = serviceData.percentage;
145
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
146
- + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
147
- // Active
148
- if (serviceData.onState) {
149
- this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
150
- }
151
- else {
152
- this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
143
+ await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
144
+ // Target Humidifier Dehumidifier State
145
+ switch (serviceData.autoMode) {
146
+ case true:
147
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
148
+ this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
149
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
150
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.CurrentRelativeHumidity;
151
+ break;
152
+ default:
153
+ this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
154
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = serviceData.percentage > 100 ? 100 : serviceData.percentage;
155
+ if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
156
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
157
+ }
158
+ else if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
159
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
160
+ }
161
+ else {
162
+ this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
163
+ }
153
164
  }
154
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
165
+ await this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState},`
166
+ + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
167
+ + ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
155
168
  }
156
169
  async openAPIparseStatus(deviceStatus) {
157
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
170
+ await this.debugLog('openAPIparseStatus');
171
+ // Active
172
+ this.HumidifierDehumidifier.Active = deviceStatus.power === 'on'
173
+ ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
174
+ await this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`);
158
175
  // Current Relative Humidity
159
- this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.body.temperature;
160
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
161
- + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
176
+ this.HumidifierDehumidifier.CurrentRelativeHumidity = deviceStatus.temperature;
177
+ await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
162
178
  // Current Temperature
163
- if (!this.device.humidifier?.hide_temperature) {
164
- this.TemperatureSensor.CurrentTemperature = deviceStatus.body.temperature;
165
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
179
+ if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
180
+ this.TemperatureSensor.CurrentTemperature = deviceStatus.temperature;
181
+ await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
166
182
  }
167
183
  // Target Humidifier Dehumidifier State
168
- switch (deviceStatus.body.auto) {
184
+ switch (deviceStatus.auto) {
169
185
  case true:
170
186
  this.HumidifierDehumidifier.TargetHumidifierDehumidifierState =
171
187
  this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
@@ -174,12 +190,8 @@ export class Humidifier extends deviceBase {
174
190
  break;
175
191
  default:
176
192
  this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
177
- if (deviceStatus.body.nebulizationEfficiency > 100) {
178
- this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = 100;
179
- }
180
- else {
181
- this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.body.nebulizationEfficiency;
182
- }
193
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = deviceStatus.nebulizationEfficiency > 100
194
+ ? 100 : deviceStatus.nebulizationEfficiency;
183
195
  if (this.HumidifierDehumidifier.CurrentRelativeHumidity > this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold) {
184
196
  this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
185
197
  }
@@ -190,34 +202,22 @@ export class Humidifier extends deviceBase {
190
202
  this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
191
203
  }
192
204
  }
193
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
194
- + ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
195
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
196
- + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
197
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
205
+ await this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState},`
206
+ + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
198
207
  + ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
199
- // Active
200
- switch (deviceStatus.body.power) {
201
- case 'on':
202
- this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
203
- break;
204
- default:
205
- this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.INACTIVE;
206
- }
207
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
208
208
  // Water Level
209
- if (deviceStatus.body.lackWater) {
209
+ if (deviceStatus.lackWater) {
210
210
  this.HumidifierDehumidifier.WaterLevel = 0;
211
211
  }
212
212
  else {
213
213
  this.HumidifierDehumidifier.WaterLevel = 100;
214
214
  }
215
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
215
+ await this.debugLog(`WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
216
216
  // Firmware Version
217
- const version = deviceStatus.body.version?.toString();
218
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
219
- if (deviceStatus.body.version) {
220
- const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
217
+ if (deviceStatus.version) {
218
+ const version = deviceStatus.version.toString();
219
+ await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
220
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
221
221
  this.accessory
222
222
  .getService(this.hap.Service.AccessoryInformation)
223
223
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
@@ -225,12 +225,28 @@ export class Humidifier extends deviceBase {
225
225
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
226
226
  .updateValue(deviceVersion);
227
227
  this.accessory.context.deviceVersion = deviceVersion;
228
- this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceVersion: ${this.accessory.context.deviceVersion}`);
228
+ await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
229
+ }
230
+ }
231
+ async parseStatusWebhook(context) {
232
+ await this.debugLog('parseStatusWebhook');
233
+ await this.debugLog(`(temperature, humidity) = Webhook:(${convertUnits(context.temperature, context.scale, this.device.iosensor?.convertUnitTo)},`
234
+ + ` ${context.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity})`);
235
+ // CurrentRelativeHumidity
236
+ this.HumidifierDehumidifier.CurrentRelativeHumidity = context.humidity;
237
+ await this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
238
+ // CurrentTemperature
239
+ if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
240
+ this.TemperatureSensor.CurrentTemperature = convertUnits(context.temperature, context.scale, this.device.iosensor?.convertUnitTo);
241
+ await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
229
242
  }
230
243
  }
244
+ /**
245
+ * Asks the SwitchBot API for the latest device information
246
+ */
231
247
  async refreshStatus() {
232
248
  if (!this.device.enableCloudService && this.OpenAPI) {
233
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
249
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
234
250
  }
235
251
  else if (this.BLE) {
236
252
  await this.BLERefreshStatus();
@@ -240,12 +256,11 @@ export class Humidifier extends deviceBase {
240
256
  }
241
257
  else {
242
258
  await this.offlineOff();
243
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
244
- + ` ${this.device.connectionType}, refreshStatus will not happen.`);
259
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
245
260
  }
246
261
  }
247
262
  async BLERefreshStatus() {
248
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
263
+ await this.debugLog('BLERefreshStatus');
249
264
  const switchbot = await this.switchbotBLE();
250
265
  if (switchbot === undefined) {
251
266
  await this.BLERefreshConnection(switchbot);
@@ -256,58 +271,50 @@ export class Humidifier extends deviceBase {
256
271
  // Start to monitor advertisement packets
257
272
  const serviceData = await this.monitorAdvertisementPackets(switchbot);
258
273
  // Update HomeKit
259
- if (serviceData.model !== '' && serviceData.modelName !== '') {
274
+ if (serviceData.model === SwitchBotBLEModel.Humidifier && serviceData.modelName === SwitchBotBLEModelName.Humidifier) {
260
275
  await this.BLEparseStatus(serviceData);
261
276
  await this.updateHomeKitCharacteristics();
262
277
  }
263
278
  else {
264
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed to get serviceData, serviceData: ${serviceData}`);
279
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
265
280
  await this.BLERefreshConnection(switchbot);
266
281
  }
267
282
  })();
268
283
  }
269
284
  }
270
285
  async openAPIRefreshStatus() {
271
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
286
+ await this.debugLog('openAPIRefreshStatus');
272
287
  try {
273
288
  const { body, statusCode } = await this.deviceRefreshStatus();
274
289
  const deviceStatus = await body.json();
275
- await this.refreshStatusCodes(statusCode, deviceStatus);
290
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
276
291
  ;
277
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
278
- await this.successfulRefreshStatus(statusCode, deviceStatus);
279
- await this.openAPIparseStatus(deviceStatus);
292
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
293
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
294
+ await this.openAPIparseStatus(deviceStatus.body);
280
295
  await this.updateHomeKitCharacteristics();
281
296
  }
282
297
  else {
283
- await this.statusCodes(statusCode, deviceStatus);
298
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
299
+ await this.debugWarnLog(statusCode, deviceStatus);
284
300
  }
285
301
  }
286
302
  catch (e) {
287
- this.apiError(e);
288
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
289
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
303
+ await this.apiError(e);
304
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
290
305
  }
291
306
  }
292
- async registerWebhook(accessory, device) {
293
- if (device.webhook) {
294
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
295
- this.platform.webhookEventHandler[device.deviceId] = async (context) => {
307
+ async registerWebhook() {
308
+ if (this.device.webhook) {
309
+ await this.debugLog('is listening webhook.');
310
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
296
311
  try {
297
- this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
298
- const { temperature, humidity } = context;
299
- const { CurrentRelativeHumidity } = this.HumidifierDehumidifier;
300
- const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
301
- this.debugLog(`${device.deviceType}: ${accessory.displayName} (temperature, humidity) = Webhook:(${convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo)}, ${humidity}), current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
302
- this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
303
- if (!device.humidifier?.hide_temperature) {
304
- this.TemperatureSensor.CurrentTemperature = convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo);
305
- }
306
- this.updateHomeKitCharacteristics();
312
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
313
+ await this.parseStatusWebhook(context);
314
+ await this.updateHomeKitCharacteristics();
307
315
  }
308
316
  catch (e) {
309
- this.errorLog(`${device.deviceType}: ${accessory.displayName} `
310
- + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
317
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
311
318
  }
312
319
  };
313
320
  }
@@ -317,7 +324,7 @@ export class Humidifier extends deviceBase {
317
324
  */
318
325
  async pushChanges() {
319
326
  if (!this.device.enableCloudService && this.OpenAPI) {
320
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
327
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
321
328
  }
322
329
  else if (this.BLE) {
323
330
  await this.BLEpushChanges();
@@ -327,8 +334,7 @@ export class Humidifier extends deviceBase {
327
334
  }
328
335
  else {
329
336
  await this.offlineOff();
330
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
331
- + ` ${this.device.connectionType}, pushChanges will not happen.`);
337
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
332
338
  }
333
339
  // Refresh the status from the API
334
340
  interval(15000)
@@ -339,46 +345,58 @@ export class Humidifier extends deviceBase {
339
345
  });
340
346
  }
341
347
  async BLEpushChanges() {
342
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
343
- const switchbot = await this.platform.connectBLE();
344
- // Convert to BLE Address
345
- await this.convertBLEAddress();
346
- switchbot
347
- .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
348
- .then(async (device_list) => {
349
- this.infoLog(`${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
350
- return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
351
- })
352
- .then(() => {
353
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
354
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
355
- + `Active: ${this.HumidifierDehumidifier.Active} sent over BLE, sent successfully`);
356
- })
357
- .catch(async (e) => {
358
- this.apiError(e);
359
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
360
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
361
- await this.BLEPushConnection();
362
- });
348
+ await this.debugLog('BLEpushChanges');
349
+ if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
350
+ && (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
351
+ && (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
352
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device);
353
+ await this.convertBLEAddress();
354
+ if (switchbot !== false) {
355
+ switchbot
356
+ .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
357
+ .then(async (device_list) => {
358
+ return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
359
+ })
360
+ .then(async () => {
361
+ await this.successLog(`RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`
362
+ + ' sent over BLE, sent successfully');
363
+ await this.updateHomeKitCharacteristics();
364
+ })
365
+ .catch(async (e) => {
366
+ await this.apiError(e);
367
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
368
+ await this.BLEPushConnection();
369
+ });
370
+ }
371
+ else {
372
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
373
+ await this.BLEPushConnection();
374
+ }
375
+ }
376
+ else {
377
+ await this.debugLog(`No changes (BLEpushChanges), Active: ${this.HumidifierDehumidifier.Active},`
378
+ + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold},`
379
+ + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
380
+ }
363
381
  }
364
382
  async openAPIpushChanges() {
365
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
366
- if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
367
- this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
368
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
369
- + ` Pushing Manual: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
383
+ await this.debugLog('openAPIpushChanges');
384
+ if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
385
+ && (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
386
+ && (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
387
+ await this.debugLog(`Auto Off, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`);
370
388
  const bodyChange = JSON.stringify({
371
389
  command: 'setMode',
372
390
  parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
373
391
  commandType: 'command',
374
392
  });
375
- 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)}`);
376
394
  try {
377
395
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
378
396
  const deviceStatus = await body.json();
379
- await this.pushStatusCodes(statusCode, deviceStatus);
380
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
381
- 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)}`);
382
400
  await this.updateHomeKitCharacteristics();
383
401
  }
384
402
  else {
@@ -387,14 +405,13 @@ export class Humidifier extends deviceBase {
387
405
  }
388
406
  }
389
407
  catch (e) {
390
- this.apiError(e);
391
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
392
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
408
+ await this.apiError(e);
409
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
393
410
  }
394
411
  }
395
- else if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
396
- this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
397
- this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
412
+ else if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
413
+ this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
414
+ && (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
398
415
  await this.pushAutoChanges();
399
416
  }
400
417
  else {
@@ -405,23 +422,23 @@ export class Humidifier extends deviceBase {
405
422
  * Pushes the requested changes to the SwitchBot API
406
423
  */
407
424
  async pushAutoChanges() {
408
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
409
- if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
410
- this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
411
- this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
412
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
425
+ this.debugLog('pushAutoChanges');
426
+ if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
427
+ this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
428
+ && (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
429
+ await this.debugLog('Pushing Auto');
413
430
  const bodyChange = JSON.stringify({
414
431
  command: 'setMode',
415
432
  parameter: 'auto',
416
433
  commandType: 'command',
417
434
  });
418
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
435
+ await this.debugLog(`pushAutoChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
419
436
  try {
420
437
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
421
438
  const deviceStatus = await body.json();
422
- await this.pushStatusCodes(statusCode, deviceStatus);
423
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
424
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
439
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
440
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
441
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
425
442
  await this.updateHomeKitCharacteristics();
426
443
  }
427
444
  else {
@@ -430,13 +447,12 @@ export class Humidifier extends deviceBase {
430
447
  }
431
448
  }
432
449
  catch (e) {
433
- this.apiError(e);
434
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}`
435
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
450
+ await this.apiError(e);
451
+ await this.errorLog(`failed pushAutoChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
436
452
  }
437
453
  }
438
454
  else {
439
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges. TargetHumidifierDehumidifierState:`
455
+ await this.debugLog('No changes (pushAutoChanges), TargetHumidifierDehumidifierState:'
440
456
  + ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
441
457
  }
442
458
  }
@@ -444,21 +460,21 @@ export class Humidifier extends deviceBase {
444
460
  * Pushes the requested changes to the SwitchBot API
445
461
  */
446
462
  async pushActiveChanges() {
447
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
463
+ await this.debugLog('pushActiveChanges');
448
464
  if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
449
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
465
+ await this.debugLog('Pushing Off');
450
466
  const bodyChange = JSON.stringify({
451
467
  command: 'turnOff',
452
468
  parameter: 'default',
453
469
  commandType: 'command',
454
470
  });
455
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
471
+ await this.debugLog(`pushActiveChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
456
472
  try {
457
473
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
458
474
  const deviceStatus = await body.json();
459
- await this.pushStatusCodes(statusCode, deviceStatus);
460
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
461
- await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
475
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
476
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
477
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
462
478
  await this.updateHomeKitCharacteristics();
463
479
  }
464
480
  else {
@@ -467,24 +483,23 @@ export class Humidifier extends deviceBase {
467
483
  }
468
484
  }
469
485
  catch (e) {
470
- this.apiError(e);
471
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
472
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
486
+ await this.apiError(e);
487
+ await this.errorLog(`failed pushActiveChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
473
488
  }
474
489
  }
475
490
  else {
476
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.HumidifierDehumidifier.Active}`);
491
+ await this.debugLog(`No changes (pushActiveChanges), Active: ${this.HumidifierDehumidifier.Active}`);
477
492
  }
478
493
  }
479
494
  /**
480
495
  * Handle requests to set the "Active" characteristic
481
496
  */
482
497
  async ActiveSet(value) {
483
- if (this.HumidifierDehumidifier.Active === this.accessory.context.Active) {
484
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
498
+ if (this.HumidifierDehumidifier.Active !== this.accessory.context.Active) {
499
+ await this.infoLog(`Set Active: ${value}`);
485
500
  }
486
501
  else {
487
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
502
+ await this.debugLog(`No Changes, Active: ${value}`);
488
503
  }
489
504
  this.HumidifierDehumidifier.Active = value;
490
505
  this.doHumidifierUpdate.next();
@@ -494,10 +509,10 @@ export class Humidifier extends deviceBase {
494
509
  */
495
510
  async TargetHumidifierDehumidifierStateSet(value) {
496
511
  if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
497
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
512
+ await this.infoLog(`Set TargetHumidifierDehumidifierState: ${value}`);
498
513
  }
499
514
  else {
500
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
515
+ await this.debugLog(`No Changes, TargetHumidifierDehumidifierState: ${value}`);
501
516
  }
502
517
  this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
503
518
  this.doHumidifierUpdate.next();
@@ -507,109 +522,54 @@ export class Humidifier extends deviceBase {
507
522
  */
508
523
  async RelativeHumidityHumidifierThresholdSet(value) {
509
524
  if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
510
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
525
+ await this.infoLog(`Set RelativeHumidityHumidifierThreshold: ${value}`);
511
526
  }
512
527
  else {
513
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
528
+ await this.debugLog(`No Changes, RelativeHumidityHumidifierThreshold: ${value}`);
514
529
  }
515
- this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
530
+ // If the Humidifier is off, turn it on
516
531
  if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
517
532
  this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
518
533
  this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
519
534
  }
535
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
520
536
  this.doHumidifierUpdate.next();
521
537
  }
522
538
  /**
523
539
  * Updates the status for each of the HomeKit Characteristics
524
540
  */
525
541
  async updateHomeKitCharacteristics() {
526
- if (this.HumidifierDehumidifier.CurrentRelativeHumidity === undefined) {
527
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
528
- + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
529
- }
530
- else {
531
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.HumidifierDehumidifier.CurrentRelativeHumidity);
532
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
533
- + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
534
- this.accessory.context.CurrentRelativeHumidity = this.HumidifierDehumidifier.CurrentRelativeHumidity;
535
- }
536
- if (this.OpenAPI) {
537
- if (this.HumidifierDehumidifier.WaterLevel === undefined) {
538
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
539
- }
540
- else {
541
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel);
542
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
543
- + ` WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
544
- this.accessory.context.WaterLevel = this.HumidifierDehumidifier.WaterLevel;
545
- }
546
- }
547
- if (this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState === undefined) {
548
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
549
- + ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
550
- }
551
- else {
552
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
553
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
554
- + ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
555
- this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
556
- }
557
- if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
558
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
559
- + ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
560
- }
561
- else {
562
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
563
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
564
- + ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
565
- this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
566
- }
567
- if (this.HumidifierDehumidifier.Active === undefined) {
568
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
569
- }
570
- else {
571
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
572
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
573
- this.accessory.context.Active = this.HumidifierDehumidifier.Active;
574
- }
575
- if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
576
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
577
- + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
578
- }
579
- else {
580
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
581
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
582
- + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
583
- this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
584
- }
585
- if (!this.device.humidifier?.hide_temperature && !this.BLE) {
586
- if (this.TemperatureSensor.CurrentTemperature === undefined) {
587
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
588
- }
589
- else {
590
- this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
591
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
592
- + ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
593
- this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
594
- }
542
+ // CurrentRelativeHumidity
543
+ await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.CurrentRelativeHumidity, this.HumidifierDehumidifier.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
544
+ // WaterLevel
545
+ await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel, 'WaterLevel');
546
+ // CurrentHumidifierDehumidifierState
547
+ await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState, 'CurrentHumidifierDehumidifierState');
548
+ // TargetHumidifierDehumidifierState
549
+ await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.TargetHumidifierDehumidifierState, this.HumidifierDehumidifier.TargetHumidifierDehumidifierState, 'TargetHumidifierDehumidifierState');
550
+ // Active
551
+ await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active, 'Active');
552
+ // RelativeHumidityHumidifierThreshold
553
+ await this.updateCharacteristic(this.HumidifierDehumidifier.Service, this.hap.Characteristic.RelativeHumidityHumidifierThreshold, this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold, 'RelativeHumidityHumidifierThreshold');
554
+ // CurrentTemperature
555
+ if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
556
+ await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature');
595
557
  }
596
558
  }
597
559
  async BLEPushConnection() {
598
560
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
599
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
561
+ await this.warnLog('Using OpenAPI Connection to Push Changes');
600
562
  await this.openAPIpushChanges();
601
563
  }
602
564
  }
603
565
  async BLERefreshConnection(switchbot) {
604
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
605
- + ` ${JSON.stringify(switchbot)}`);
566
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
606
567
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
607
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
568
+ await this.warnLog('Using OpenAPI Connection to Refresh Status');
608
569
  await this.openAPIRefreshStatus();
609
570
  }
610
571
  }
611
572
  async offlineOff() {
612
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
613
573
  if (this.device.offline) {
614
574
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
615
575
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
@@ -618,14 +578,12 @@ export class Humidifier extends deviceBase {
618
578
  }
619
579
  async apiError(e) {
620
580
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
621
- if (!this.BLE) {
622
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
623
- }
581
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
624
582
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
625
583
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
626
584
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
627
585
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
628
- if (!this.device.humidifier?.hide_temperature && !this.BLE) {
586
+ if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
629
587
  this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
630
588
  }
631
589
  }