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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/device/blindtilt.d.ts +15 -6
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +203 -255
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +9 -4
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +196 -218
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +9 -4
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +202 -247
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +10 -5
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +329 -378
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +9 -4
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +99 -142
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +19 -7
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +203 -264
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/device.d.ts +28 -32
  26. package/dist/device/device.d.ts.map +1 -1
  27. package/dist/device/device.js +186 -225
  28. package/dist/device/device.js.map +1 -1
  29. package/dist/device/fan.d.ts +9 -4
  30. package/dist/device/fan.d.ts.map +1 -1
  31. package/dist/device/fan.js +198 -227
  32. package/dist/device/fan.js.map +1 -1
  33. package/dist/device/hub.d.ts +9 -5
  34. package/dist/device/hub.d.ts.map +1 -1
  35. package/dist/device/hub.js +106 -231
  36. package/dist/device/hub.js.map +1 -1
  37. package/dist/device/humidifier.d.ts +12 -4
  38. package/dist/device/humidifier.d.ts.map +1 -1
  39. package/dist/device/humidifier.js +192 -232
  40. package/dist/device/humidifier.js.map +1 -1
  41. package/dist/device/iosensor.d.ts +9 -4
  42. package/dist/device/iosensor.d.ts.map +1 -1
  43. package/dist/device/iosensor.js +91 -157
  44. package/dist/device/iosensor.js.map +1 -1
  45. package/dist/device/lightstrip.d.ts +10 -5
  46. package/dist/device/lightstrip.d.ts.map +1 -1
  47. package/dist/device/lightstrip.js +287 -367
  48. package/dist/device/lightstrip.js.map +1 -1
  49. package/dist/device/lock.d.ts +10 -5
  50. package/dist/device/lock.d.ts.map +1 -1
  51. package/dist/device/lock.js +171 -216
  52. package/dist/device/lock.js.map +1 -1
  53. package/dist/device/meter.d.ts +9 -4
  54. package/dist/device/meter.d.ts.map +1 -1
  55. package/dist/device/meter.js +93 -158
  56. package/dist/device/meter.js.map +1 -1
  57. package/dist/device/meterplus.d.ts +9 -4
  58. package/dist/device/meterplus.d.ts.map +1 -1
  59. package/dist/device/meterplus.js +94 -155
  60. package/dist/device/meterplus.js.map +1 -1
  61. package/dist/device/motion.d.ts +9 -4
  62. package/dist/device/motion.d.ts.map +1 -1
  63. package/dist/device/motion.js +84 -142
  64. package/dist/device/motion.js.map +1 -1
  65. package/dist/device/plug.d.ts +9 -4
  66. package/dist/device/plug.d.ts.map +1 -1
  67. package/dist/device/plug.js +99 -124
  68. package/dist/device/plug.js.map +1 -1
  69. package/dist/device/robotvacuumcleaner.d.ts +9 -6
  70. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  71. package/dist/device/robotvacuumcleaner.js +170 -253
  72. package/dist/device/robotvacuumcleaner.js.map +1 -1
  73. package/dist/device/waterdetector.d.ts +12 -4
  74. package/dist/device/waterdetector.d.ts.map +1 -1
  75. package/dist/device/waterdetector.js +102 -128
  76. package/dist/device/waterdetector.js.map +1 -1
  77. package/dist/irdevice/airconditioner.d.ts +2 -1
  78. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  79. package/dist/irdevice/airconditioner.js.map +1 -1
  80. package/dist/irdevice/airpurifier.d.ts +2 -1
  81. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  82. package/dist/irdevice/airpurifier.js.map +1 -1
  83. package/dist/irdevice/camera.d.ts +2 -1
  84. package/dist/irdevice/camera.d.ts.map +1 -1
  85. package/dist/irdevice/camera.js.map +1 -1
  86. package/dist/irdevice/fan.d.ts +2 -1
  87. package/dist/irdevice/fan.d.ts.map +1 -1
  88. package/dist/irdevice/fan.js.map +1 -1
  89. package/dist/irdevice/irdevice.d.ts +2 -1
  90. package/dist/irdevice/irdevice.d.ts.map +1 -1
  91. package/dist/irdevice/irdevice.js +1 -1
  92. package/dist/irdevice/irdevice.js.map +1 -1
  93. package/dist/irdevice/light.d.ts +2 -1
  94. package/dist/irdevice/light.d.ts.map +1 -1
  95. package/dist/irdevice/light.js.map +1 -1
  96. package/dist/irdevice/other.d.ts +2 -1
  97. package/dist/irdevice/other.d.ts.map +1 -1
  98. package/dist/irdevice/other.js.map +1 -1
  99. package/dist/irdevice/tv.d.ts +2 -1
  100. package/dist/irdevice/tv.d.ts.map +1 -1
  101. package/dist/irdevice/tv.js.map +1 -1
  102. package/dist/irdevice/vacuumcleaner.d.ts +2 -1
  103. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  104. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  105. package/dist/irdevice/waterheater.d.ts +2 -1
  106. package/dist/irdevice/waterheater.d.ts.map +1 -1
  107. package/dist/irdevice/waterheater.js.map +1 -1
  108. package/dist/platform.d.ts +5 -7
  109. package/dist/platform.d.ts.map +1 -1
  110. package/dist/platform.js +51 -34
  111. package/dist/platform.js.map +1 -1
  112. package/dist/settings.d.ts +49 -191
  113. package/dist/settings.d.ts.map +1 -1
  114. package/dist/settings.js +19 -0
  115. package/dist/settings.js.map +1 -1
  116. package/dist/types/bledevicestatus.d.ts +279 -0
  117. package/dist/types/bledevicestatus.d.ts.map +1 -0
  118. package/dist/types/bledevicestatus.js +2 -0
  119. package/dist/types/bledevicestatus.js.map +1 -0
  120. package/dist/types/devicelist.d.ts +89 -0
  121. package/dist/types/devicelist.d.ts.map +1 -0
  122. package/dist/types/devicelist.js +6 -0
  123. package/dist/types/devicelist.js.map +1 -0
  124. package/dist/types/deviceresponse.d.ts +13 -0
  125. package/dist/types/deviceresponse.d.ts.map +1 -0
  126. package/dist/types/deviceresponse.js +2 -0
  127. package/dist/types/deviceresponse.js.map +1 -0
  128. package/dist/types/devicestatus.d.ts +149 -0
  129. package/dist/types/devicestatus.d.ts.map +1 -0
  130. package/dist/types/devicestatus.js +3 -0
  131. package/dist/types/devicestatus.js.map +1 -0
  132. package/dist/types/devicewebhookstatus.d.ts +156 -0
  133. package/dist/types/devicewebhookstatus.d.ts.map +1 -0
  134. package/dist/types/devicewebhookstatus.js +2 -0
  135. package/dist/types/devicewebhookstatus.js.map +1 -0
  136. package/dist/types/irdevicelist.d.ts +10 -0
  137. package/dist/types/irdevicelist.d.ts.map +1 -0
  138. package/dist/types/irdevicelist.js +2 -0
  139. package/dist/types/irdevicelist.js.map +1 -0
  140. package/dist/types/pushbody.d.ts +6 -0
  141. package/dist/types/pushbody.d.ts.map +1 -0
  142. package/dist/types/pushbody.js +2 -0
  143. package/dist/types/pushbody.js.map +1 -0
  144. package/dist/utils.d.ts +25 -0
  145. package/dist/utils.d.ts.map +1 -1
  146. package/dist/utils.js +28 -0
  147. package/dist/utils.js.map +1 -1
  148. package/package.json +10 -10
  149. package/src/device/blindtilt.ts +223 -263
  150. package/src/device/bot.ts +208 -221
  151. package/src/device/ceilinglight.ts +210 -257
  152. package/src/device/colorbulb.ts +334 -397
  153. package/src/device/contact.ts +111 -146
  154. package/src/device/curtain.ts +220 -283
  155. package/src/device/device.ts +194 -245
  156. package/src/device/fan.ts +214 -230
  157. package/src/device/hub.ts +126 -246
  158. package/src/device/humidifier.ts +216 -243
  159. package/src/device/iosensor.ts +114 -166
  160. package/src/device/lightstrip.ts +302 -377
  161. package/src/device/lock.ts +187 -221
  162. package/src/device/meter.ts +116 -177
  163. package/src/device/meterplus.ts +117 -174
  164. package/src/device/motion.ts +99 -144
  165. package/src/device/plug.ts +110 -128
  166. package/src/device/robotvacuumcleaner.ts +189 -252
  167. package/src/device/waterdetector.ts +120 -138
  168. package/src/irdevice/airconditioner.ts +2 -1
  169. package/src/irdevice/airpurifier.ts +2 -1
  170. package/src/irdevice/camera.ts +2 -1
  171. package/src/irdevice/fan.ts +2 -1
  172. package/src/irdevice/irdevice.ts +3 -2
  173. package/src/irdevice/light.ts +2 -1
  174. package/src/irdevice/other.ts +2 -1
  175. package/src/irdevice/tv.ts +2 -1
  176. package/src/irdevice/vacuumcleaner.ts +2 -1
  177. package/src/irdevice/waterheater.ts +2 -1
  178. package/src/platform.ts +52 -34
  179. package/src/settings.ts +30 -239
  180. package/src/types/bledevicestatus.ts +305 -0
  181. package/src/types/devicelist.ts +124 -0
  182. package/src/types/deviceresponse.ts +15 -0
  183. package/src/types/devicestatus.ts +178 -0
  184. package/src/types/devicewebhookstatus.ts +196 -0
  185. package/src/types/irdevicelist.ts +15 -0
  186. package/src/types/pushbody.ts +9 -0
  187. package/src/utils.ts +33 -0
@@ -3,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,57 +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
303
  await this.apiError(e);
288
- await this.openAPIRefreshError(e);
304
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
289
305
  }
290
306
  }
291
- async registerWebhook(accessory, device) {
292
- if (device.webhook) {
293
- this.debugLog(`${device.deviceType}: ${accessory.displayName} is listening webhook.`);
294
- 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) => {
295
311
  try {
296
- this.debugLog(`${device.deviceType}: ${accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
297
- const { temperature, humidity } = context;
298
- const { CurrentRelativeHumidity } = this.HumidifierDehumidifier;
299
- const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
300
- this.debugLog(`${device.deviceType}: ${accessory.displayName} (temperature, humidity) = Webhook:(${convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo)}, ${humidity}), current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
301
- this.HumidifierDehumidifier.CurrentRelativeHumidity = humidity;
302
- if (!device.humidifier?.hide_temperature) {
303
- this.TemperatureSensor.CurrentTemperature = convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo);
304
- }
305
- this.updateHomeKitCharacteristics();
312
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
313
+ await this.parseStatusWebhook(context);
314
+ await this.updateHomeKitCharacteristics();
306
315
  }
307
316
  catch (e) {
308
- this.errorLog(`${device.deviceType}: ${accessory.displayName} `
309
- + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
317
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
310
318
  }
311
319
  };
312
320
  }
@@ -316,7 +324,7 @@ export class Humidifier extends deviceBase {
316
324
  */
317
325
  async pushChanges() {
318
326
  if (!this.device.enableCloudService && this.OpenAPI) {
319
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
327
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
320
328
  }
321
329
  else if (this.BLE) {
322
330
  await this.BLEpushChanges();
@@ -326,7 +334,7 @@ export class Humidifier extends deviceBase {
326
334
  }
327
335
  else {
328
336
  await this.offlineOff();
329
- await this.pushChangeDisabled();
337
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
330
338
  }
331
339
  // Refresh the status from the API
332
340
  interval(15000)
@@ -337,46 +345,58 @@ export class Humidifier extends deviceBase {
337
345
  });
338
346
  }
339
347
  async BLEpushChanges() {
340
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
341
- const switchbot = await this.platform.connectBLE();
342
- // Convert to BLE Address
343
- await this.convertBLEAddress();
344
- switchbot
345
- .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
346
- .then(async (device_list) => {
347
- this.infoLog(`${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
348
- return await device_list[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
349
- })
350
- .then(() => {
351
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
352
- this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
353
- + `Active: ${this.HumidifierDehumidifier.Active} sent over BLE, sent successfully`);
354
- })
355
- .catch(async (e) => {
356
- this.apiError(e);
357
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
358
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`);
359
- await this.BLEPushConnection();
360
- });
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
+ }
361
381
  }
362
382
  async openAPIpushChanges() {
363
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
364
- if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
365
- this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
366
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
367
- + ` 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}!`);
368
388
  const bodyChange = JSON.stringify({
369
389
  command: 'setMode',
370
390
  parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
371
391
  commandType: 'command',
372
392
  });
373
- 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)}`);
374
394
  try {
375
395
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
376
396
  const deviceStatus = await body.json();
377
- await this.pushStatusCodes(statusCode, deviceStatus);
378
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
379
- 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)}`);
380
400
  await this.updateHomeKitCharacteristics();
381
401
  }
382
402
  else {
@@ -385,14 +405,13 @@ export class Humidifier extends deviceBase {
385
405
  }
386
406
  }
387
407
  catch (e) {
388
- this.apiError(e);
389
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
390
- + ` 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)}`);
391
410
  }
392
411
  }
393
- else if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
394
- this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
395
- 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)) {
396
415
  await this.pushAutoChanges();
397
416
  }
398
417
  else {
@@ -403,23 +422,23 @@ export class Humidifier extends deviceBase {
403
422
  * Pushes the requested changes to the SwitchBot API
404
423
  */
405
424
  async pushAutoChanges() {
406
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
407
- if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState ===
408
- this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
409
- this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
410
- 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');
411
430
  const bodyChange = JSON.stringify({
412
431
  command: 'setMode',
413
432
  parameter: 'auto',
414
433
  commandType: 'command',
415
434
  });
416
- 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)}`);
417
436
  try {
418
437
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
419
438
  const deviceStatus = await body.json();
420
- await this.pushStatusCodes(statusCode, deviceStatus);
421
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
422
- 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)}`);
423
442
  await this.updateHomeKitCharacteristics();
424
443
  }
425
444
  else {
@@ -428,13 +447,12 @@ export class Humidifier extends deviceBase {
428
447
  }
429
448
  }
430
449
  catch (e) {
431
- this.apiError(e);
432
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}`
433
- + ` 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)}`);
434
452
  }
435
453
  }
436
454
  else {
437
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges. TargetHumidifierDehumidifierState:`
455
+ await this.debugLog('No changes (pushAutoChanges), TargetHumidifierDehumidifierState:'
438
456
  + ` ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`);
439
457
  }
440
458
  }
@@ -442,21 +460,21 @@ export class Humidifier extends deviceBase {
442
460
  * Pushes the requested changes to the SwitchBot API
443
461
  */
444
462
  async pushActiveChanges() {
445
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
463
+ await this.debugLog('pushActiveChanges');
446
464
  if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
447
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
465
+ await this.debugLog('Pushing Off');
448
466
  const bodyChange = JSON.stringify({
449
467
  command: 'turnOff',
450
468
  parameter: 'default',
451
469
  commandType: 'command',
452
470
  });
453
- 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)}`);
454
472
  try {
455
473
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
456
474
  const deviceStatus = await body.json();
457
- await this.pushStatusCodes(statusCode, deviceStatus);
458
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
459
- 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)}`);
460
478
  await this.updateHomeKitCharacteristics();
461
479
  }
462
480
  else {
@@ -465,24 +483,23 @@ export class Humidifier extends deviceBase {
465
483
  }
466
484
  }
467
485
  catch (e) {
468
- this.apiError(e);
469
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
470
- + ` 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)}`);
471
488
  }
472
489
  }
473
490
  else {
474
- 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}`);
475
492
  }
476
493
  }
477
494
  /**
478
495
  * Handle requests to set the "Active" characteristic
479
496
  */
480
497
  async ActiveSet(value) {
481
- if (this.HumidifierDehumidifier.Active === this.accessory.context.Active) {
482
- 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}`);
483
500
  }
484
501
  else {
485
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
502
+ await this.debugLog(`No Changes, Active: ${value}`);
486
503
  }
487
504
  this.HumidifierDehumidifier.Active = value;
488
505
  this.doHumidifierUpdate.next();
@@ -492,10 +509,10 @@ export class Humidifier extends deviceBase {
492
509
  */
493
510
  async TargetHumidifierDehumidifierStateSet(value) {
494
511
  if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
495
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
512
+ await this.infoLog(`Set TargetHumidifierDehumidifierState: ${value}`);
496
513
  }
497
514
  else {
498
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
515
+ await this.debugLog(`No Changes, TargetHumidifierDehumidifierState: ${value}`);
499
516
  }
500
517
  this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value;
501
518
  this.doHumidifierUpdate.next();
@@ -505,109 +522,54 @@ export class Humidifier extends deviceBase {
505
522
  */
506
523
  async RelativeHumidityHumidifierThresholdSet(value) {
507
524
  if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
508
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
525
+ await this.infoLog(`Set RelativeHumidityHumidifierThreshold: ${value}`);
509
526
  }
510
527
  else {
511
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
528
+ await this.debugLog(`No Changes, RelativeHumidityHumidifierThreshold: ${value}`);
512
529
  }
513
- this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
530
+ // If the Humidifier is off, turn it on
514
531
  if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
515
532
  this.HumidifierDehumidifier.Active = this.hap.Characteristic.Active.ACTIVE;
516
533
  this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
517
534
  }
535
+ this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold = value;
518
536
  this.doHumidifierUpdate.next();
519
537
  }
520
538
  /**
521
539
  * Updates the status for each of the HomeKit Characteristics
522
540
  */
523
541
  async updateHomeKitCharacteristics() {
524
- if (this.HumidifierDehumidifier.CurrentRelativeHumidity === undefined) {
525
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
526
- + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
527
- }
528
- else {
529
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.HumidifierDehumidifier.CurrentRelativeHumidity);
530
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
531
- + ` CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`);
532
- this.accessory.context.CurrentRelativeHumidity = this.HumidifierDehumidifier.CurrentRelativeHumidity;
533
- }
534
- if (this.OpenAPI) {
535
- if (this.HumidifierDehumidifier.WaterLevel === undefined) {
536
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
537
- }
538
- else {
539
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, this.HumidifierDehumidifier.WaterLevel);
540
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
541
- + ` WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`);
542
- this.accessory.context.WaterLevel = this.HumidifierDehumidifier.WaterLevel;
543
- }
544
- }
545
- if (this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState === undefined) {
546
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
547
- + ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
548
- }
549
- else {
550
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState);
551
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
552
- + ` CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`);
553
- this.accessory.context.CurrentHumidifierDehumidifierState = this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState;
554
- }
555
- if (this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === undefined) {
556
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
557
- + ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
558
- }
559
- else {
560
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.HumidifierDehumidifier.TargetHumidifierDehumidifierState);
561
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
562
- + ` TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}`);
563
- this.accessory.context.TargetHumidifierDehumidifierState = this.HumidifierDehumidifier.TargetHumidifierDehumidifierState;
564
- }
565
- if (this.HumidifierDehumidifier.Active === undefined) {
566
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.HumidifierDehumidifier.Active}`);
567
- }
568
- else {
569
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HumidifierDehumidifier.Active);
570
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.HumidifierDehumidifier.Active}`);
571
- this.accessory.context.Active = this.HumidifierDehumidifier.Active;
572
- }
573
- if (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold === undefined) {
574
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
575
- + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
576
- }
577
- else {
578
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold);
579
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
580
- + ` RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`);
581
- this.accessory.context.RelativeHumidityHumidifierThreshold = this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold;
582
- }
583
- if (!this.device.humidifier?.hide_temperature && !this.BLE) {
584
- if (this.TemperatureSensor.CurrentTemperature === undefined) {
585
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
586
- }
587
- else {
588
- this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
589
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
590
- + ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
591
- this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
592
- }
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');
593
557
  }
594
558
  }
595
559
  async BLEPushConnection() {
596
560
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
597
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
561
+ await this.warnLog('Using OpenAPI Connection to Push Changes');
598
562
  await this.openAPIpushChanges();
599
563
  }
600
564
  }
601
565
  async BLERefreshConnection(switchbot) {
602
- this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
603
- + ` ${JSON.stringify(switchbot)}`);
566
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
604
567
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
605
- this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
568
+ await this.warnLog('Using OpenAPI Connection to Refresh Status');
606
569
  await this.openAPIRefreshStatus();
607
570
  }
608
571
  }
609
572
  async offlineOff() {
610
- this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} offline: ${this.device.offline}`);
611
573
  if (this.device.offline) {
612
574
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, this.hap.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE);
613
575
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER);
@@ -616,14 +578,12 @@ export class Humidifier extends deviceBase {
616
578
  }
617
579
  async apiError(e) {
618
580
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
619
- if (!this.BLE) {
620
- this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
621
- }
581
+ this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.WaterLevel, e);
622
582
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHumidifierDehumidifierState, e);
623
583
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.TargetHumidifierDehumidifierState, e);
624
584
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
625
585
  this.HumidifierDehumidifier.Service.updateCharacteristic(this.hap.Characteristic.RelativeHumidityHumidifierThreshold, e);
626
- if (!this.device.humidifier?.hide_temperature && !this.BLE) {
586
+ if (!this.device.humidifier?.hide_temperature && this.TemperatureSensor?.Service) {
627
587
  this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
628
588
  }
629
589
  }