@switchbot/homebridge-switchbot 2.0.0-beta.2 → 2.0.0-beta.20

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 (113) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/README.md +1 -2
  3. package/config.schema.json +75 -20
  4. package/dist/device/bot.d.ts +32 -28
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +646 -648
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/colorbulb.d.ts +34 -19
  9. package/dist/device/colorbulb.d.ts.map +1 -1
  10. package/dist/device/colorbulb.js +429 -304
  11. package/dist/device/colorbulb.js.map +1 -1
  12. package/dist/device/contact.d.ts +16 -7
  13. package/dist/device/contact.d.ts.map +1 -1
  14. package/dist/device/contact.js +288 -230
  15. package/dist/device/contact.js.map +1 -1
  16. package/dist/device/curtain.d.ts +21 -16
  17. package/dist/device/curtain.d.ts.map +1 -1
  18. package/dist/device/curtain.js +519 -489
  19. package/dist/device/curtain.js.map +1 -1
  20. package/dist/device/humidifier.d.ts +22 -18
  21. package/dist/device/humidifier.d.ts.map +1 -1
  22. package/dist/device/humidifier.js +415 -360
  23. package/dist/device/humidifier.js.map +1 -1
  24. package/dist/device/lock.d.ts +22 -8
  25. package/dist/device/lock.d.ts.map +1 -1
  26. package/dist/device/lock.js +253 -147
  27. package/dist/device/lock.js.map +1 -1
  28. package/dist/device/meter.d.ts +21 -16
  29. package/dist/device/meter.d.ts.map +1 -1
  30. package/dist/device/meter.js +325 -255
  31. package/dist/device/meter.js.map +1 -1
  32. package/dist/device/meterplus.d.ts +23 -12
  33. package/dist/device/meterplus.d.ts.map +1 -1
  34. package/dist/device/meterplus.js +346 -208
  35. package/dist/device/meterplus.js.map +1 -1
  36. package/dist/device/motion.d.ts +17 -8
  37. package/dist/device/motion.d.ts.map +1 -1
  38. package/dist/device/motion.js +261 -209
  39. package/dist/device/motion.js.map +1 -1
  40. package/dist/device/plug.d.ts +24 -16
  41. package/dist/device/plug.d.ts.map +1 -1
  42. package/dist/device/plug.js +267 -242
  43. package/dist/device/plug.js.map +1 -1
  44. package/dist/device/striplight.d.ts +51 -16
  45. package/dist/device/striplight.d.ts.map +1 -1
  46. package/dist/device/striplight.js +527 -185
  47. package/dist/device/striplight.js.map +1 -1
  48. package/dist/irdevice/airconditioner.d.ts +7 -12
  49. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  50. package/dist/irdevice/airconditioner.js +261 -230
  51. package/dist/irdevice/airconditioner.js.map +1 -1
  52. package/dist/irdevice/airpurifier.d.ts +3 -3
  53. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  54. package/dist/irdevice/airpurifier.js +137 -104
  55. package/dist/irdevice/airpurifier.js.map +1 -1
  56. package/dist/irdevice/camera.d.ts +9 -8
  57. package/dist/irdevice/camera.d.ts.map +1 -1
  58. package/dist/irdevice/camera.js +116 -86
  59. package/dist/irdevice/camera.js.map +1 -1
  60. package/dist/irdevice/fan.d.ts +8 -7
  61. package/dist/irdevice/fan.d.ts.map +1 -1
  62. package/dist/irdevice/fan.js +143 -109
  63. package/dist/irdevice/fan.js.map +1 -1
  64. package/dist/irdevice/light.d.ts +9 -8
  65. package/dist/irdevice/light.d.ts.map +1 -1
  66. package/dist/irdevice/light.js +120 -103
  67. package/dist/irdevice/light.js.map +1 -1
  68. package/dist/irdevice/other.d.ts +9 -8
  69. package/dist/irdevice/other.d.ts.map +1 -1
  70. package/dist/irdevice/other.js +128 -98
  71. package/dist/irdevice/other.js.map +1 -1
  72. package/dist/irdevice/tv.d.ts +10 -9
  73. package/dist/irdevice/tv.d.ts.map +1 -1
  74. package/dist/irdevice/tv.js +126 -93
  75. package/dist/irdevice/tv.js.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.d.ts +7 -10
  77. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  78. package/dist/irdevice/vacuumcleaner.js +115 -89
  79. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  80. package/dist/irdevice/waterheater.d.ts +6 -9
  81. package/dist/irdevice/waterheater.d.ts.map +1 -1
  82. package/dist/irdevice/waterheater.js +115 -89
  83. package/dist/irdevice/waterheater.js.map +1 -1
  84. package/dist/platform.d.ts +3 -5
  85. package/dist/platform.d.ts.map +1 -1
  86. package/dist/platform.js +203 -200
  87. package/dist/platform.js.map +1 -1
  88. package/dist/settings.d.ts +15 -11
  89. package/dist/settings.d.ts.map +1 -1
  90. package/dist/settings.js.map +1 -1
  91. package/package.json +12 -10
  92. package/src/device/bot.ts +641 -657
  93. package/src/device/colorbulb.ts +440 -339
  94. package/src/device/contact.ts +289 -233
  95. package/src/device/curtain.ts +523 -503
  96. package/src/device/humidifier.ts +421 -396
  97. package/src/device/lock.ts +257 -147
  98. package/src/device/meter.ts +335 -268
  99. package/src/device/meterplus.ts +354 -213
  100. package/src/device/motion.ts +264 -213
  101. package/src/device/plug.ts +270 -251
  102. package/src/device/striplight.ts +552 -207
  103. package/src/irdevice/airconditioner.ts +263 -241
  104. package/src/irdevice/airpurifier.ts +132 -103
  105. package/src/irdevice/camera.ts +112 -85
  106. package/src/irdevice/fan.ts +138 -106
  107. package/src/irdevice/light.ts +116 -103
  108. package/src/irdevice/other.ts +124 -97
  109. package/src/irdevice/tv.ts +123 -93
  110. package/src/irdevice/vacuumcleaner.ts +112 -89
  111. package/src/irdevice/waterheater.ts +111 -89
  112. package/src/platform.ts +195 -216
  113. package/src/settings.ts +15 -11
@@ -3,6 +3,7 @@ import crypto from 'crypto';
3
3
  import { Context } from 'vm';
4
4
  import { IncomingMessage } from 'http';
5
5
  import { interval, Subject } from 'rxjs';
6
+ import superStringify from 'super-stringify';
6
7
  import { SwitchBotPlatform } from '../platform';
7
8
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
8
9
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
@@ -40,6 +41,7 @@ export class Humidifier {
40
41
  connected?: boolean;
41
42
  serviceData!: serviceData;
42
43
  address!: ad['address'];
44
+ SwitchToOpenAPI?: boolean;
43
45
  onState!: serviceData['onState'];
44
46
  autoMode!: serviceData['autoMode'];
45
47
  percentage!: serviceData['percentage'];
@@ -54,19 +56,17 @@ export class Humidifier {
54
56
  humidifierUpdateInProgress!: boolean;
55
57
  doHumidifierUpdate!: Subject<void>;
56
58
 
59
+ // Connection
60
+ private readonly BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'Both');
61
+ private readonly OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'Both');
62
+
57
63
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
58
64
  // default placeholders
59
65
  this.logs(device);
60
66
  this.scan(device);
61
67
  this.refreshRate(device);
62
68
  this.config(device);
63
- this.CurrentRelativeHumidity = 0;
64
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
65
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
66
- this.Active = this.platform.Characteristic.Active.ACTIVE;
67
- this.RelativeHumidityHumidifierThreshold = 0;
68
- this.CurrentTemperature = 0;
69
- this.WaterLevel = 0;
69
+ this.context();
70
70
 
71
71
  // this is subject we use to track when we need to POST changes to the SwitchBot API
72
72
  this.doHumidifierUpdate = new Subject();
@@ -116,9 +116,9 @@ export class Humidifier {
116
116
  maxValue: 1,
117
117
  validValues: [0, 1],
118
118
  })
119
- .onSet(this.handleTargetHumidifierDehumidifierStateSet.bind(this));
119
+ .onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
120
120
 
121
- this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleActiveSet.bind(this));
121
+ this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
122
122
 
123
123
  this.humidifierService
124
124
  .getCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold)
@@ -128,15 +128,15 @@ export class Humidifier {
128
128
  maxValue: 100,
129
129
  minStep: this.minStep(),
130
130
  })
131
- .onSet(this.handleRelativeHumidityHumidifierThresholdSet.bind(this));
131
+ .onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
132
132
 
133
133
  // Temperature Sensor Service
134
- if (device.humidifier?.hide_temperature || device.ble) {
135
- this.debugLog(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
134
+ if (device.humidifier?.hide_temperature || this.BLE) {
135
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
136
136
  this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
137
137
  accessory.removeService(this.temperatureservice!);
138
- } else if (!this.temperatureservice && !device.ble) {
139
- this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
138
+ } else if (!this.temperatureservice && !this.BLE) {
139
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
140
140
  (this.temperatureservice =
141
141
  this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
142
142
  `${accessory.displayName} Temperature Sensor`;
@@ -155,7 +155,7 @@ export class Humidifier {
155
155
  return this.CurrentTemperature;
156
156
  });
157
157
  } else {
158
- this.debugLog(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
158
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
159
159
  }
160
160
 
161
161
  // Retrieve initial values and updateHomekit
@@ -181,11 +181,9 @@ export class Humidifier {
181
181
  try {
182
182
  await this.pushChanges();
183
183
  } catch (e: any) {
184
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
185
- if (this.deviceLogging.includes('debug')) {
186
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
187
- }
188
184
  this.apiError(e);
185
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
186
+ + ` Error Message: ${superStringify(e.message)}`);
189
187
  }
190
188
  this.humidifierUpdateInProgress = false;
191
189
  });
@@ -195,104 +193,113 @@ export class Humidifier {
195
193
  * Parse the device status from the SwitchBot api
196
194
  */
197
195
  async parseStatus(): Promise<void> {
198
- if (this.device.ble) {
196
+ if (this.BLE && !this.SwitchToOpenAPI) {
199
197
  await this.BLEparseStatus();
200
- } else {
198
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
199
+ this.SwitchToOpenAPI = false;
201
200
  await this.openAPIparseStatus();
201
+ } else {
202
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
203
+ + ` ${this.device.connectionType}, parseStatus will not happen.`);
202
204
  }
203
205
  }
204
206
 
205
207
  async BLEparseStatus(): Promise<void> {
206
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
208
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
207
209
  // Current Relative Humidity
208
210
  this.CurrentRelativeHumidity = this.percentage!;
209
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
211
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
210
212
  // Active
211
213
  if (this.onState) {
212
214
  this.Active = this.platform.Characteristic.Active.ACTIVE;
213
215
  } else {
214
216
  this.Active = this.platform.Characteristic.Active.INACTIVE;
215
217
  }
216
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
218
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
217
219
  }
218
220
 
219
221
  async openAPIparseStatus(): Promise<void> {
220
- if (this.platform.config.credentials?.token) {
221
- this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
222
- // Current Relative Humidity
223
- this.CurrentRelativeHumidity = this.humidity!;
224
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
225
- // Current Temperature
226
- if (!this.device.humidifier?.hide_temperature) {
227
- this.CurrentTemperature = this.temperature!;
228
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
229
- }
230
- // Target Humidifier Dehumidifier State
231
- switch (this.auto) {
232
- case true:
233
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
222
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
223
+ // Current Relative Humidity
224
+ this.CurrentRelativeHumidity = this.humidity!;
225
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
226
+ // Current Temperature
227
+ if (!this.device.humidifier?.hide_temperature) {
228
+ this.CurrentTemperature = this.temperature!;
229
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
230
+ }
231
+ // Target Humidifier Dehumidifier State
232
+ switch (this.auto) {
233
+ case true:
234
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
235
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
236
+ this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
237
+ break;
238
+ default:
239
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
240
+ if (this.nebulizationEfficiency! > 100) {
241
+ this.RelativeHumidityHumidifierThreshold = 100;
242
+ } else {
243
+ this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency!;
244
+ }
245
+ if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
246
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
247
+ } else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
248
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
249
+ } else {
234
250
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
235
- this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
236
- break;
237
- default:
238
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
239
- if (this.nebulizationEfficiency! > 100) {
240
- this.RelativeHumidityHumidifierThreshold = 100;
241
- } else {
242
- this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency!;
243
- }
244
- if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
245
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
246
- } else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
247
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
248
- } else {
249
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
250
- }
251
- }
252
- this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
253
- this.debugLog(
254
- `Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
255
- );
256
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
257
- // Active
258
- switch (this.power) {
259
- case 'on':
260
- this.Active = this.platform.Characteristic.Active.ACTIVE;
261
- break;
262
- default:
263
- this.Active = this.platform.Characteristic.Active.INACTIVE;
264
- }
265
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
266
- // Water Level
267
- if (this.lackWater) {
268
- this.WaterLevel = 0;
269
- } else {
270
- this.WaterLevel = 100;
271
- }
272
- this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
251
+ }
273
252
  }
253
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
254
+ + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
255
+ this.debugLog(
256
+ `${this.device.deviceType}: ${this.accessory.displayName}`
257
+ + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
258
+ );
259
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
260
+ + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
261
+ // Active
262
+ switch (this.power) {
263
+ case 'on':
264
+ this.Active = this.platform.Characteristic.Active.ACTIVE;
265
+ break;
266
+ default:
267
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
268
+ }
269
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
270
+ // Water Level
271
+ if (this.lackWater) {
272
+ this.WaterLevel = 0;
273
+ } else {
274
+ this.WaterLevel = 100;
275
+ }
276
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
277
+
274
278
  }
275
279
 
276
280
  /**
277
281
  * Asks the SwitchBot API for the latest device information
278
282
  */
279
283
  async refreshStatus(): Promise<void> {
280
- if (this.device.ble) {
284
+ if (this.BLE) {
281
285
  await this.BLERefreshStatus();
282
- } else {
286
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
283
287
  await this.openAPIRefreshStatus();
288
+ } else {
289
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
290
+ + ` ${this.device.connectionType}, refreshStatus will not happen.`);
284
291
  }
285
292
  }
286
293
 
287
294
  async BLERefreshStatus(): Promise<void> {
288
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
295
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
289
296
  const switchbot = await this.platform.connectBLE();
290
297
  // Convert to BLE Address
291
298
  this.device.bleMac = this.device
292
299
  .deviceId!.match(/.{1,2}/g)!
293
300
  .join(':')
294
301
  .toLowerCase();
295
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
302
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
296
303
  this.getCustomBLEAddress(switchbot);
297
304
  // Start to monitor advertisement packets
298
305
  if (switchbot !== false) {
@@ -308,25 +315,25 @@ export class Humidifier {
308
315
  if (this.deviceLogging.includes('debug')) {
309
316
  this.infoLog(this.address);
310
317
  this.infoLog(this.device.bleMac);
311
- this.infoLog(`Humidifier: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
312
- this.infoLog(`Humidifier: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
318
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
319
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
313
320
  }
314
321
  this.serviceData = ad.serviceData;
315
322
  this.autoMode = ad.serviceData.autoMode;
316
323
  this.onState = ad.serviceData.onState;
317
324
  this.percentage = ad.serviceData.percentage;
318
- this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
325
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
319
326
  this.debugLog(
320
- `Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
327
+ `${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
321
328
  `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
322
329
  );
323
330
 
324
331
  if (this.serviceData) {
325
332
  this.connected = true;
326
- this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
333
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
327
334
  } else {
328
335
  this.connected = false;
329
- this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
336
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
330
337
  }
331
338
  };
332
339
  // Wait 2 seconds
@@ -343,110 +350,70 @@ export class Humidifier {
343
350
  }
344
351
  })
345
352
  .catch(async (e: any) => {
346
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
347
- if (this.deviceLogging.includes('debug')) {
348
- this.errorLog(
349
- `Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
350
- );
351
- }
352
- if (this.platform.config.credentials?.token) {
353
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
354
- await this.openAPIRefreshStatus();
355
- }
356
353
  this.apiError(e);
354
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
355
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
356
+ await this.BLEconnection(switchbot);
357
357
  });
358
358
  } else {
359
359
  await this.BLEconnection(switchbot);
360
360
  }
361
361
  }
362
362
 
363
- async getCustomBLEAddress(switchbot: any) {
364
- if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
365
- (async () => {
366
- // Start to monitor advertisement packets
367
- await switchbot.startScan({
368
- model: 'e',
369
- });
370
- // Set an event handler
371
- switchbot.onadvertisement = (ad: any) => {
372
- this.warnLog(`Humidifier: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
373
- };
374
- await switchbot.wait(10000);
375
- // Stop to monitor
376
- switchbot.stopScan();
377
- })();
378
- }
379
- }
380
-
381
- async BLEconnection(switchbot: any): Promise<void> {
382
- this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
383
- if (this.platform.config.credentials?.token) {
384
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
385
- await this.openAPIRefreshStatus();
386
- }
387
- }
388
-
389
363
  async openAPIRefreshStatus(): Promise<void> {
390
- if (this.platform.config.credentials?.token) {
391
- this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
392
- try {
393
- const t = Date.now();
394
- const nonce = 'requestID';
395
- const data = this.platform.config.credentials?.token + t + nonce;
396
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
397
- const sign = signTerm.toString('base64');
398
- this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
399
- const options = {
400
- hostname: HostDomain,
401
- port: 443,
402
- path: `${DevicePath}/${this.device.deviceId}/status`,
403
- method: 'GET',
404
- headers: {
405
- Authorization: this.platform.config.credentials?.token,
406
- sign: sign,
407
- nonce: nonce,
408
- t: t,
409
- 'Content-Type': 'application/json',
410
- },
411
- };
412
- const req = https.request(options, (res) => {
413
- this.debugLog(`Humidifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
414
- let rawData = '';
415
- res.on('data', (d) => {
416
- rawData += d;
417
- this.debugLog(`Humidifier: ${this.accessory.displayName} d: ${d}`);
418
- });
419
- res.on('end', () => {
420
- try {
421
- this.deviceStatus = JSON.parse(rawData);
422
- this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
423
- this.auto = this.deviceStatus.body.auto;
424
- this.power = this.deviceStatus.body.power;
425
- this.lackWater = this.deviceStatus.body.lackWater;
426
- this.humidity = this.deviceStatus.body.humidity;
427
- this.temperature = this.deviceStatus.body.temperature;
428
- this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
429
- this.parseStatus();
430
- this.updateHomeKitCharacteristics();
431
- } catch (e: any) {
432
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
433
- }
434
- });
364
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
365
+ try {
366
+ const t = Date.now();
367
+ const nonce = 'requestID';
368
+ const data = this.platform.config.credentials?.token + t + nonce;
369
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
370
+ const sign = signTerm.toString('base64');
371
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
372
+ const options = {
373
+ hostname: HostDomain,
374
+ port: 443,
375
+ path: `${DevicePath}/${this.device.deviceId}/status`,
376
+ method: 'GET',
377
+ headers: {
378
+ Authorization: this.platform.config.credentials?.token,
379
+ sign: sign,
380
+ nonce: nonce,
381
+ t: t,
382
+ 'Content-Type': 'application/json',
383
+ },
384
+ };
385
+ const req = https.request(options, (res) => {
386
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
387
+ let rawData = '';
388
+ res.on('data', (d) => {
389
+ rawData += d;
390
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
435
391
  });
436
- req.on('error', (e: any) => {
437
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
392
+ res.on('end', () => {
393
+ try {
394
+ this.deviceStatus = JSON.parse(rawData);
395
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
396
+ this.auto = this.deviceStatus.body.auto;
397
+ this.power = this.deviceStatus.body.power;
398
+ this.lackWater = this.deviceStatus.body.lackWater;
399
+ this.humidity = this.deviceStatus.body.humidity;
400
+ this.temperature = this.deviceStatus.body.temperature;
401
+ this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
402
+ this.parseStatus();
403
+ this.updateHomeKitCharacteristics();
404
+ } catch (e: any) {
405
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
406
+ }
438
407
  });
439
- req.end();
440
- } catch (e: any) {
441
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
442
- if (this.deviceLogging.includes('debug')) {
443
- this.errorLog(
444
- `Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
445
- ` Error Message: ${JSON.stringify(e.message)}`,
446
- );
447
- }
448
- this.apiError(e);
449
- }
408
+ });
409
+ req.on('error', (e: any) => {
410
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
411
+ });
412
+ req.end();
413
+ } catch (e: any) {
414
+ this.apiError(e);
415
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
416
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
450
417
  }
451
418
  }
452
419
 
@@ -454,11 +421,14 @@ export class Humidifier {
454
421
  * Pushes the requested changes to the SwitchBot API
455
422
  */
456
423
  async pushChanges(): Promise<void> {
457
- //if (this.device.ble) {
458
- // await this.BLEpushChanges();
459
- //} else {
460
- await this.openAPIpushChanges();
461
- //}
424
+ /*if (this.BLE) {
425
+ await this.BLERefreshStatus();
426
+ } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
427
+ await this.openAPIpushChanges();
428
+ } else {
429
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
430
+ + ` ${this.device.connectionType}, pushChanges will not happen.`);
431
+ }
462
432
  interval(5000)
463
433
  .pipe(take(1))
464
434
  .subscribe(async () => {
@@ -467,54 +437,44 @@ export class Humidifier {
467
437
  }
468
438
 
469
439
  async BLEpushChanges(): Promise<void> {
470
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
440
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
471
441
  const switchbot = await this.platform.connectBLE();
472
442
  // Convert to BLE Address
473
443
  this.device.bleMac = this.device
474
444
  .deviceId!.match(/.{1,2}/g)!
475
445
  .join(':')
476
446
  .toLowerCase();
477
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
478
- if (switchbot !== false) {
479
- switchbot
480
- .discover({ model: 'e', quick: true, id: this.device.bleMac })
481
- .then((device_list) => {
482
- this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
483
- return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
484
- })
485
- .then(() => {
486
- this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
487
- })
488
- .catch(async (e: any) => {
489
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
490
- if (this.deviceLogging.includes('debug')) {
491
- this.errorLog(
492
- `Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
493
- );
494
- }
495
- if (this.platform.config.credentials?.token) {
496
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
497
- await this.openAPIpushChanges();
498
- }
499
- this.apiError(e);
500
- });
501
- } else {
502
- this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
503
- if (this.platform.config.credentials?.token) {
504
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
505
- await this.openAPIpushChanges();
506
- }
507
- }
447
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
448
+ switchbot
449
+ .discover({
450
+ model: 'e',
451
+ quick: true,
452
+ id: this.device.bleMac,
453
+ })
454
+ .then((device_list: any) => {
455
+ this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
456
+ return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
457
+ })
458
+ .then(() => {
459
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
460
+ })
461
+ .catch(async (e: any) => {
462
+ this.apiError(e);
463
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
464
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
465
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
466
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
467
+ await this.openAPIpushChanges();
468
+ }
469
+ });
508
470
  }
509
471
 
510
472
  async openAPIpushChanges(): Promise<void> {
511
- if (this.platform.config.credentials?.token) {
512
- this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
513
- if (
514
- this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
515
- this.Active === this.platform.Characteristic.Active.ACTIVE
516
- ) {
517
- // Make Push On request to the API
473
+ try {
474
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
475
+ if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
476
+ this.Active === this.platform.Characteristic.Active.ACTIVE) {
477
+ // Make Push On request to the API
518
478
  const t = Date.now();
519
479
  const nonce = 'requestID';
520
480
  const data = this.platform.config.credentials?.token + t + nonce;
@@ -522,14 +482,14 @@ export class Humidifier {
522
482
  .update(Buffer.from(data, 'utf-8'))
523
483
  .digest();
524
484
  const sign = signTerm.toString('base64');
525
- this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
485
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
526
486
  this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
527
- const body = JSON.stringify({
487
+ const body = superStringify({
528
488
  'command': 'setMode',
529
489
  'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
530
490
  'commandType': 'command',
531
491
  });
532
- this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
492
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
533
493
  const options = {
534
494
  hostname: HostDomain,
535
495
  port: 443,
@@ -545,18 +505,18 @@ export class Humidifier {
545
505
  },
546
506
  };
547
507
  const req = https.request(options, res => {
548
- this.debugLog(`Humidifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
508
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
549
509
  res.on('data', d => {
550
- this.debugLog(`Humidifier: ${this.accessory.displayName} d: ${d}`);
510
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
551
511
  });
552
512
  });
553
513
  req.on('error', (e: any) => {
554
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
514
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
555
515
  this.apiError(e);
556
516
  });
557
517
  req.write(body);
558
518
  req.end();
559
- this.debugLog(`Humidifier: ${this.accessory.displayName} openAPIpushChanges: ${JSON.stringify(req)}`);
519
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
560
520
  } else if (
561
521
  this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
562
522
  this.Active === this.platform.Characteristic.Active.ACTIVE
@@ -565,6 +525,10 @@ export class Humidifier {
565
525
  } else {
566
526
  await this.pushActiveChanges();
567
527
  }
528
+ } catch (e: any) {
529
+ this.apiError(e);
530
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
531
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
568
532
  }
569
533
  }
570
534
 
@@ -573,6 +537,7 @@ export class Humidifier {
573
537
  */
574
538
  async pushAutoChanges(): Promise<void> {
575
539
  try {
540
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
576
541
  if (
577
542
  this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
578
543
  this.Active === this.platform.Characteristic.Active.ACTIVE
@@ -585,14 +550,14 @@ export class Humidifier {
585
550
  .update(Buffer.from(data, 'utf-8'))
586
551
  .digest();
587
552
  const sign = signTerm.toString('base64');
588
- this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
553
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
589
554
  this.debugLog('Pushing Auto!');
590
- const body = JSON.stringify({
555
+ const body = superStringify({
591
556
  'command': 'setMode',
592
557
  'parameter': 'auto',
593
558
  'commandType': 'command',
594
559
  });
595
- this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
560
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
596
561
  const options = {
597
562
  hostname: HostDomain,
598
563
  port: 443,
@@ -608,28 +573,26 @@ export class Humidifier {
608
573
  },
609
574
  };
610
575
  const req = https.request(options, res => {
611
- this.debugLog(`Humidifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
576
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
612
577
  this.statusCode({ res });
613
578
  res.on('data', d => {
614
- this.debugLog(`Humidifier: ${this.accessory.displayName} d: ${d}`);
579
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
615
580
  });
616
581
  });
617
582
  req.on('error', (e: any) => {
618
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
583
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
619
584
  });
620
585
  req.write(body);
621
586
  req.end();
622
- this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(req)}`);
587
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges: ${superStringify(req)}`);
588
+ } else {
589
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges.` +
590
+ `TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`);
623
591
  }
624
592
  } catch (e: any) {
625
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
626
- if (this.deviceLogging.includes('debug')) {
627
- this.errorLog(
628
- `Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` +
629
- ` Error Message: ${JSON.stringify(e.message)}`,
630
- );
631
- }
632
593
  this.apiError(e);
594
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}`
595
+ + ` Connection, Error Message: ${superStringify(e.message)}`);
633
596
  }
634
597
  }
635
598
 
@@ -638,6 +601,7 @@ export class Humidifier {
638
601
  */
639
602
  async pushActiveChanges(): Promise<void> {
640
603
  try {
604
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
641
605
  if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
642
606
  // Make Push On request to the API
643
607
  const t = Date.now();
@@ -647,14 +611,14 @@ export class Humidifier {
647
611
  .update(Buffer.from(data, 'utf-8'))
648
612
  .digest();
649
613
  const sign = signTerm.toString('base64');
650
- this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
614
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
651
615
  this.debugLog('Pushing Off!');
652
- const body = JSON.stringify({
616
+ const body = superStringify({
653
617
  'command': 'turnOff',
654
618
  'parameter': 'default',
655
619
  'commandType': 'command',
656
620
  });
657
- this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
621
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
658
622
  const options = {
659
623
  hostname: HostDomain,
660
624
  port: 443,
@@ -670,148 +634,211 @@ export class Humidifier {
670
634
  },
671
635
  };
672
636
  const req = https.request(options, res => {
673
- this.debugLog(`Humidifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
637
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges statusCode: ${res.statusCode}`);
674
638
  this.statusCode({ res });
675
639
  res.on('data', d => {
676
- this.debugLog(`Humidifier: ${this.accessory.displayName} d: ${d}`);
640
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
677
641
  });
678
642
  });
679
643
  req.on('error', (e: any) => {
680
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
644
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
681
645
  });
682
646
  req.write(body);
683
647
  req.end();
684
- this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(req)}`);
648
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges: ${superStringify(req)}`);
685
649
  }
686
650
  } catch (e: any) {
687
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
688
- if (this.deviceLogging.includes('debug')) {
689
- this.errorLog(
690
- `Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` +
691
- ` Error Message: ${JSON.stringify(e.message)}`,
692
- );
693
- }
694
651
  this.apiError(e);
652
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
653
+ + ` Connection, Error Message: ${superStringify(e.message)}`,
654
+ );
695
655
  }
696
656
  }
697
657
 
658
+ /**
659
+ * Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
660
+ */
661
+ async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
662
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
663
+
664
+ this.TargetHumidifierDehumidifierState = value;
665
+ this.doHumidifierUpdate.next();
666
+ }
667
+
668
+ /**
669
+ * Handle requests to set the "Active" characteristic
670
+ */
671
+ async ActiveSet(value: CharacteristicValue): Promise<void> {
672
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
673
+
674
+ this.Active = value;
675
+ this.doHumidifierUpdate.next();
676
+ }
677
+
678
+ /**
679
+ * Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
680
+ */
681
+ async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
682
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
683
+
684
+ this.RelativeHumidityHumidifierThreshold = value;
685
+ if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
686
+ this.Active = this.platform.Characteristic.Active.ACTIVE;
687
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
688
+ }
689
+ this.doHumidifierUpdate.next();
690
+ }
691
+
698
692
  /**
699
693
  * Updates the status for each of the HomeKit Characteristics
700
694
  */
701
695
  async updateHomeKitCharacteristics(): Promise<void> {
702
696
  if (this.CurrentRelativeHumidity === undefined) {
703
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
697
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
704
698
  } else {
699
+ this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
705
700
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
706
- this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
701
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
702
+ + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
707
703
  }
708
- if (!this.device.ble) {
704
+ if (this.OpenAPI) {
709
705
  if (this.WaterLevel === undefined) {
710
- this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
706
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
711
707
  } else {
708
+ this.accessory.context.WaterLevel = this.WaterLevel;
712
709
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
713
- this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
710
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
714
711
  }
715
712
  }
716
713
  if (this.CurrentHumidifierDehumidifierState === undefined) {
717
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
714
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
715
+ + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
718
716
  } else {
719
- this.humidifierService.updateCharacteristic(
720
- this.platform.Characteristic.CurrentHumidifierDehumidifierState,
721
- this.CurrentHumidifierDehumidifierState,
722
- );
723
- this.debugLog(
724
- `Humidifier: ${this.accessory.displayName}` +
725
- ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
726
- );
717
+ this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
718
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState,
719
+ this.CurrentHumidifierDehumidifierState);
720
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
721
+ ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
727
722
  }
728
723
  if (this.TargetHumidifierDehumidifierState === undefined) {
729
- this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
724
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
725
+ +` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
730
726
  } else {
731
- this.humidifierService.updateCharacteristic(
732
- this.platform.Characteristic.TargetHumidifierDehumidifierState,
733
- this.TargetHumidifierDehumidifierState,
734
- );
735
- this.debugLog(
736
- `Humidifier: ${this.accessory.displayName}` +
727
+ this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
728
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState,
729
+ this.TargetHumidifierDehumidifierState);
730
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
737
731
  ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
738
732
  );
739
733
  }
740
734
  if (this.Active === undefined) {
741
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
735
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
742
736
  } else {
737
+ this.accessory.context.Active = this.Active;
743
738
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
744
- this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
739
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
745
740
  }
746
741
  if (this.RelativeHumidityHumidifierThreshold === undefined) {
747
- this.debugLog(
748
- `Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
749
- );
742
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
743
+ + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
750
744
  } else {
751
- this.humidifierService.updateCharacteristic(
752
- this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
753
- this.RelativeHumidityHumidifierThreshold,
754
- );
755
- this.debugLog(
756
- `Humidifier: ${this.accessory.displayName}` +
757
- ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
758
- );
745
+ this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
746
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
747
+ this.RelativeHumidityHumidifierThreshold);
748
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
749
+ ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
759
750
  }
760
- if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
751
+ if (!this.device.humidifier?.hide_temperature && !this.BLE) {
761
752
  if (this.CurrentTemperature === undefined) {
762
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
753
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
763
754
  } else {
755
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
764
756
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
765
- this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
757
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
766
758
  }
767
759
  }
768
760
  }
769
761
 
770
- async apiError(e: any): Promise<void> {
771
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
772
- if (!this.device.ble) {
773
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
762
+ async getCustomBLEAddress(switchbot: any) {
763
+ if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
764
+ (async () => {
765
+ // Start to monitor advertisement packets
766
+ await switchbot.startScan({
767
+ model: 'e',
768
+ });
769
+ // Set an event handler
770
+ switchbot.onadvertisement = (ad: any) => {
771
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
772
+ };
773
+ await switchbot.wait(10000);
774
+ // Stop to monitor
775
+ switchbot.stopScan();
776
+ })();
774
777
  }
775
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
776
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
777
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
778
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
779
- if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
780
- this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
778
+ }
779
+
780
+ async BLEconnection(switchbot: any): Promise<void> {
781
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
782
+ if (this.platform.config.credentials?.token && this.device.connectionType !== 'Both') {
783
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
784
+ this.SwitchToOpenAPI = true;
785
+ await this.openAPIRefreshStatus();
786
+ }
787
+ }
788
+
789
+ minStep(): number {
790
+ if (this.device.humidifier?.set_minStep) {
791
+ this.set_minStep = this.device.humidifier?.set_minStep;
792
+ } else {
793
+ this.set_minStep = 1;
794
+ }
795
+ return this.set_minStep;
796
+ }
797
+
798
+ async scan(device: device & devicesConfig): Promise<void> {
799
+ if (device.scanDuration) {
800
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
801
+ if (this.BLE) {
802
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
803
+ }
804
+ } else {
805
+ this.scanDuration = this.accessory.context.scanDuration = 1;
806
+ if (this.BLE) {
807
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
808
+ }
781
809
  }
782
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
783
810
  }
784
811
 
785
812
  async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
786
813
  switch (res.statusCode) {
787
814
  case 151:
788
- this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
815
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
789
816
  break;
790
817
  case 152:
791
- this.errorLog(`Humidifier: ${this.accessory.displayName} Device not found.`);
818
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
792
819
  break;
793
820
  case 160:
794
- this.errorLog(`Humidifier: ${this.accessory.displayName} Command is not supported.`);
821
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
795
822
  break;
796
823
  case 161:
797
- this.errorLog(`Humidifier: ${this.accessory.displayName} Device is offline.`);
824
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
798
825
  this.offlineOff();
799
826
  break;
800
827
  case 171:
801
- this.errorLog(`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
828
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
802
829
  this.offlineOff();
803
830
  break;
804
831
  case 190:
805
832
  this.errorLog(
806
- `Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
807
- ` Or command: ${JSON.stringify(res)} format is invalid`,
833
+ `${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
834
+ ` Or command: ${superStringify(res)} format is invalid`,
808
835
  );
809
836
  break;
810
837
  case 100:
811
- this.debugLog(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
838
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
812
839
  break;
813
840
  default:
814
- this.debugLog(`Humidifier: ${this.accessory.displayName} Unknown statusCode.`);
841
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
815
842
  }
816
843
  }
817
844
 
@@ -819,40 +846,86 @@ export class Humidifier {
819
846
  if (this.device.offline) {
820
847
  this.Active = this.platform.Characteristic.Active.INACTIVE;
821
848
  this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
849
+ await this.updateHomeKitCharacteristics();
822
850
  }
823
851
  }
824
852
 
825
- /**
826
- * Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
827
- */
828
- async handleTargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
829
- this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
830
-
831
- this.TargetHumidifierDehumidifierState = value;
832
- this.doHumidifierUpdate.next();
853
+ async apiError(e: any): Promise<void> {
854
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
855
+ if (!this.BLE) {
856
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
857
+ }
858
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
859
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
860
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
861
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
862
+ if (!this.device.humidifier?.hide_temperature && !this.BLE) {
863
+ this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
864
+ }
833
865
  }
834
866
 
835
- /**
836
- * Handle requests to set the "Active" characteristic
837
- */
838
- async handleActiveSet(value: CharacteristicValue): Promise<void> {
839
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
840
- this.Active = value;
841
- this.doHumidifierUpdate.next();
867
+ FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
868
+ let FirmwareRevision: string;
869
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
870
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
871
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
872
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
873
+ if (accessory.context.FirmwareRevision) {
874
+ FirmwareRevision = accessory.context.FirmwareRevision;
875
+ } else if (device.firmware) {
876
+ FirmwareRevision = device.firmware;
877
+ } else {
878
+ FirmwareRevision = this.platform.version;
879
+ }
880
+ return FirmwareRevision;
842
881
  }
843
882
 
844
- /**
845
- * Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
846
- */
847
- async handleRelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
848
- this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
849
-
850
- this.RelativeHumidityHumidifierThreshold = value;
851
- if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
883
+ async context() {
884
+ if (this.Active === undefined) {
852
885
  this.Active = this.platform.Characteristic.Active.ACTIVE;
853
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
886
+ } else {
887
+ this.Active = this.accessory.context.Active;
888
+ }
889
+ if (this.CurrentTemperature === undefined) {
890
+ this.CurrentTemperature = 0;
891
+ } else {
892
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
893
+ }
894
+ if (this.CurrentRelativeHumidity === undefined) {
895
+ this.CurrentRelativeHumidity = 0;
896
+ } else {
897
+ this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
898
+ }
899
+ if (this.TargetHumidifierDehumidifierState === undefined) {
900
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
901
+ } else {
902
+ this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
903
+ }
904
+ if (this.CurrentHumidifierDehumidifierState === undefined) {
905
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
906
+ } else {
907
+ this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
908
+ }
909
+ if (this.RelativeHumidityHumidifierThreshold === undefined) {
910
+ this.RelativeHumidityHumidifierThreshold = 0;
911
+ } else {
912
+ this.RelativeHumidityHumidifierThreshold = this.accessory.context.RelativeHumidityHumidifierThreshold;
913
+ }
914
+ if (this.WaterLevel === undefined) {
915
+ this.WaterLevel = 0;
916
+ } else {
917
+ this.WaterLevel = this.accessory.context.WaterLevel;
918
+ }
919
+ }
920
+
921
+ async refreshRate(device: device & devicesConfig): Promise<void> {
922
+ if (device.refreshRate) {
923
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
924
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
925
+ } else if (this.platform.config.options!.refreshRate) {
926
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
927
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
854
928
  }
855
- this.doHumidifierUpdate.next();
856
929
  }
857
930
 
858
931
  async config(device: device & devicesConfig): Promise<void> {
@@ -860,8 +933,8 @@ export class Humidifier {
860
933
  if (device.humidifier) {
861
934
  config = device.humidifier;
862
935
  }
863
- if (device.ble !== undefined) {
864
- config['ble'] = device.ble;
936
+ if (device.connectionType !== undefined) {
937
+ config['connectionType'] = device.connectionType;
865
938
  }
866
939
  if (device.logging !== undefined) {
867
940
  config['logging'] = device.logging;
@@ -876,74 +949,26 @@ export class Humidifier {
876
949
  config['offline'] = device.offline;
877
950
  }
878
951
  if (Object.entries(config).length !== 0) {
879
- this.infoLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
880
- }
881
- }
882
-
883
- async refreshRate(device: device & devicesConfig): Promise<void> {
884
- if (device.refreshRate) {
885
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
886
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
887
- } else if (this.platform.config.options!.refreshRate) {
888
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
889
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
890
- }
891
- }
892
-
893
- async scan(device: device & devicesConfig): Promise<void> {
894
- if (device.scanDuration) {
895
- this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
896
- if (device.ble) {
897
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
898
- }
899
- } else {
900
- this.scanDuration = this.accessory.context.scanDuration = 1;
901
- if (this.device.ble) {
902
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
903
- }
952
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
904
953
  }
905
954
  }
906
955
 
907
956
  async logs(device: device & devicesConfig): Promise<void> {
908
957
  if (this.platform.debugMode) {
909
958
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
910
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
959
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
911
960
  } else if (device.logging) {
912
961
  this.deviceLogging = this.accessory.context.logging = device.logging;
913
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
962
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
914
963
  } else if (this.platform.config.options?.logging) {
915
964
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
916
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
965
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
917
966
  } else {
918
967
  this.deviceLogging = this.accessory.context.logging = 'standard';
919
- this.debugLog(`Humidifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
968
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
920
969
  }
921
970
  }
922
971
 
923
- FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
924
- let FirmwareRevision: string;
925
- this.debugLog(`Humidifier: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
926
- this.debugLog(`Humidifier: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
927
- this.debugLog(`Humidifier: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
928
- if (accessory.context.FirmwareRevision) {
929
- FirmwareRevision = accessory.context.FirmwareRevision;
930
- } else if (device.firmware) {
931
- FirmwareRevision = device.firmware;
932
- } else {
933
- FirmwareRevision = this.platform.version;
934
- }
935
- return FirmwareRevision;
936
- }
937
-
938
- minStep(): number {
939
- if (this.device.humidifier?.set_minStep) {
940
- this.set_minStep = this.device.humidifier?.set_minStep;
941
- } else {
942
- this.set_minStep = 1;
943
- }
944
- return this.set_minStep;
945
- }
946
-
947
972
  /**
948
973
  * Logging for Device
949
974
  */