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