@switchbot/homebridge-switchbot 1.4.1-beta.1 → 1.4.1-beta.2

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 (103) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/config.schema.json +82 -10
  3. package/dist/devices/bots.d.ts +12 -2
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +140 -89
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts +12 -2
  8. package/dist/devices/colorbulb.d.ts.map +1 -1
  9. package/dist/devices/colorbulb.js +138 -84
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.d.ts +12 -2
  12. package/dist/devices/contact.d.ts.map +1 -1
  13. package/dist/devices/contact.js +101 -52
  14. package/dist/devices/contact.js.map +1 -1
  15. package/dist/devices/curtains.d.ts +13 -4
  16. package/dist/devices/curtains.d.ts.map +1 -1
  17. package/dist/devices/curtains.js +173 -124
  18. package/dist/devices/curtains.js.map +1 -1
  19. package/dist/devices/humidifiers.d.ts +12 -2
  20. package/dist/devices/humidifiers.d.ts.map +1 -1
  21. package/dist/devices/humidifiers.js +156 -108
  22. package/dist/devices/humidifiers.js.map +1 -1
  23. package/dist/devices/meters.d.ts +12 -2
  24. package/dist/devices/meters.d.ts.map +1 -1
  25. package/dist/devices/meters.js +98 -49
  26. package/dist/devices/meters.js.map +1 -1
  27. package/dist/devices/motion.d.ts +12 -2
  28. package/dist/devices/motion.d.ts.map +1 -1
  29. package/dist/devices/motion.js +86 -37
  30. package/dist/devices/motion.js.map +1 -1
  31. package/dist/devices/plugs.d.ts +12 -2
  32. package/dist/devices/plugs.d.ts.map +1 -1
  33. package/dist/devices/plugs.js +80 -31
  34. package/dist/devices/plugs.js.map +1 -1
  35. package/dist/irdevices/airconditioners.d.ts +10 -2
  36. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  37. package/dist/irdevices/airconditioners.js +77 -37
  38. package/dist/irdevices/airconditioners.js.map +1 -1
  39. package/dist/irdevices/airpurifiers.d.ts +10 -2
  40. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  41. package/dist/irdevices/airpurifiers.js +65 -25
  42. package/dist/irdevices/airpurifiers.js.map +1 -1
  43. package/dist/irdevices/cameras.d.ts +10 -2
  44. package/dist/irdevices/cameras.d.ts.map +1 -1
  45. package/dist/irdevices/cameras.js +61 -21
  46. package/dist/irdevices/cameras.js.map +1 -1
  47. package/dist/irdevices/fans.d.ts +10 -2
  48. package/dist/irdevices/fans.d.ts.map +1 -1
  49. package/dist/irdevices/fans.js +71 -30
  50. package/dist/irdevices/fans.js.map +1 -1
  51. package/dist/irdevices/lights.d.ts +10 -2
  52. package/dist/irdevices/lights.d.ts.map +1 -1
  53. package/dist/irdevices/lights.js +62 -22
  54. package/dist/irdevices/lights.js.map +1 -1
  55. package/dist/irdevices/others.d.ts +10 -2
  56. package/dist/irdevices/others.d.ts.map +1 -1
  57. package/dist/irdevices/others.js +68 -28
  58. package/dist/irdevices/others.js.map +1 -1
  59. package/dist/irdevices/tvs.d.ts +10 -2
  60. package/dist/irdevices/tvs.d.ts.map +1 -1
  61. package/dist/irdevices/tvs.js +78 -38
  62. package/dist/irdevices/tvs.js.map +1 -1
  63. package/dist/irdevices/vacuumcleaners.d.ts +10 -2
  64. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  65. package/dist/irdevices/vacuumcleaners.js +61 -21
  66. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  67. package/dist/irdevices/waterheaters.d.ts +10 -2
  68. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  69. package/dist/irdevices/waterheaters.js +61 -21
  70. package/dist/irdevices/waterheaters.js.map +1 -1
  71. package/dist/platform.d.ts +9 -10
  72. package/dist/platform.d.ts.map +1 -1
  73. package/dist/platform.js +264 -285
  74. package/dist/platform.js.map +1 -1
  75. package/dist/settings.d.ts +4 -1
  76. package/dist/settings.d.ts.map +1 -1
  77. package/dist/settings.js.map +1 -1
  78. package/nodemon.json +1 -1
  79. package/package.json +1 -1
  80. package/src/devices/bots.ts +146 -89
  81. package/src/devices/colorbulb.ts +146 -86
  82. package/src/devices/contact.ts +107 -52
  83. package/src/devices/curtains.ts +182 -129
  84. package/src/devices/humidifiers.ts +162 -109
  85. package/src/devices/meters.ts +104 -49
  86. package/src/devices/motion.ts +91 -36
  87. package/src/devices/plugs.ts +84 -31
  88. package/src/irdevices/airconditioners.ts +81 -36
  89. package/src/irdevices/airpurifiers.ts +69 -24
  90. package/src/irdevices/cameras.ts +65 -20
  91. package/src/irdevices/fans.ts +75 -30
  92. package/src/irdevices/lights.ts +66 -21
  93. package/src/irdevices/others.ts +72 -27
  94. package/src/irdevices/tvs.ts +82 -37
  95. package/src/irdevices/vacuumcleaners.ts +65 -20
  96. package/src/irdevices/waterheaters.ts +65 -20
  97. package/src/platform.ts +267 -290
  98. package/src/settings.ts +4 -1
  99. package/dist/devices/indoorcam.d.ts +0 -64
  100. package/dist/devices/indoorcam.d.ts.map +0 -1
  101. package/dist/devices/indoorcam.js +0 -249
  102. package/dist/devices/indoorcam.js.map +0 -1
  103. package/src/devices/indoorcam.ts +0 -309
@@ -18,12 +18,9 @@ class Humidifier {
18
18
  this.platform = platform;
19
19
  this.accessory = accessory;
20
20
  this.device = device;
21
- this.deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
22
- this.debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
23
- // Humidifiers Config
24
- this.platform.device(`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: `
25
- + `${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`);
26
21
  // default placeholders
22
+ this.refreshRate();
23
+ this.logs();
27
24
  this.CurrentRelativeHumidity = 0;
28
25
  this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
29
26
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
@@ -31,6 +28,9 @@ class Humidifier {
31
28
  this.RelativeHumidityHumidifierThreshold = 0;
32
29
  this.CurrentTemperature = 0;
33
30
  this.WaterLevel = 0;
31
+ // Humidifiers Config
32
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: `
33
+ + `${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`);
34
34
  // this is subject we use to track when we need to POST changes to the SwitchBot API
35
35
  this.doHumidifierUpdate = new rxjs_1.Subject();
36
36
  this.humidifierUpdateInProgress = false;
@@ -79,12 +79,12 @@ class Humidifier {
79
79
  // create a new Temperature Sensor service
80
80
  // Temperature Sensor Service
81
81
  if (device.humidifier?.hide_temperature || device.ble) {
82
- this.platform.device(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
82
+ this.debugLog(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
83
83
  this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
84
84
  accessory.removeService(this.temperatureservice);
85
85
  }
86
86
  else if (!this.temperatureservice && !device.ble) {
87
- this.platform.device(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
87
+ this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
88
88
  (this.temperatureservice =
89
89
  this.accessory.getService(this.platform.Service.TemperatureSensor) ||
90
90
  this.accessory.addService(this.platform.Service.TemperatureSensor)), `${accessory.displayName} Temperature Sensor`;
@@ -102,14 +102,12 @@ class Humidifier {
102
102
  });
103
103
  }
104
104
  else {
105
- if (this.platform.config.options?.debug) {
106
- this.platform.device(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
107
- }
105
+ this.debugLog(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
108
106
  }
109
107
  // Retrieve initial values and updateHomekit
110
108
  this.updateHomeKitCharacteristics();
111
109
  // Start an update interval
112
- (0, rxjs_1.interval)(this.platform.config.options.refreshRate * 1000)
110
+ (0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
113
111
  .pipe((0, operators_1.skipWhile)(() => this.humidifierUpdateInProgress))
114
112
  .subscribe(() => {
115
113
  this.refreshStatus();
@@ -125,13 +123,13 @@ class Humidifier {
125
123
  await this.pushChanges();
126
124
  }
127
125
  catch (e) {
128
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
129
- if (this.deviceDebug) {
130
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
126
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
127
+ if (this.deviceLogging === 'debug') {
128
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
131
129
  + ` Error Message: ${JSON.stringify(e.message)}`);
132
130
  }
133
- if (this.debugDebug) {
134
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
131
+ if (this.platform.debugMode) {
132
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
135
133
  + ` Error: ${JSON.stringify(e)}`);
136
134
  }
137
135
  this.apiError();
@@ -139,6 +137,25 @@ class Humidifier {
139
137
  this.humidifierUpdateInProgress = false;
140
138
  });
141
139
  }
140
+ refreshRate() {
141
+ if (this.device.refreshRate) {
142
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
143
+ }
144
+ else if (this.platform.config.options.refreshRate) {
145
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
146
+ }
147
+ }
148
+ logs() {
149
+ if (this.device.logging) {
150
+ this.deviceLogging = this.accessory.context.logging = this.device.logging;
151
+ }
152
+ else if (this.platform.config.options?.logging) {
153
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
154
+ }
155
+ else {
156
+ this.deviceLogging = this.accessory.context.logging = 'standard';
157
+ }
158
+ }
142
159
  minStep() {
143
160
  if (this.device.humidifier?.set_minStep) {
144
161
  this.set_minStep = this.device.humidifier?.set_minStep;
@@ -160,10 +177,10 @@ class Humidifier {
160
177
  }
161
178
  }
162
179
  BLEparseStatus() {
163
- this.platform.debug(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
180
+ this.debugLog(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
164
181
  // Current Relative Humidity
165
182
  this.CurrentRelativeHumidity = this.percentage;
166
- this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
183
+ this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
167
184
  // Active
168
185
  if (this.onState) {
169
186
  this.Active = this.platform.Characteristic.Active.ACTIVE;
@@ -171,18 +188,18 @@ class Humidifier {
171
188
  else {
172
189
  this.Active = this.platform.Characteristic.Active.INACTIVE;
173
190
  }
174
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
191
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
175
192
  }
176
193
  openAPIparseStatus() {
177
194
  if (this.platform.config.credentials?.openToken) {
178
- this.platform.debug(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
195
+ this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
179
196
  // Current Relative Humidity
180
197
  this.CurrentRelativeHumidity = this.deviceStatus.body.humidity;
181
- this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
198
+ this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
182
199
  // Current Temperature
183
200
  if (!this.device.humidifier?.hide_temperature) {
184
201
  this.CurrentTemperature = Number(this.deviceStatus.body.temperature);
185
- this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
202
+ this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
186
203
  }
187
204
  // Target Humidifier Dehumidifier State
188
205
  switch (this.deviceStatus.body.auto) {
@@ -209,10 +226,10 @@ class Humidifier {
209
226
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
210
227
  }
211
228
  }
212
- this.platform.debug(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
213
- this.platform.debug(`Humidifier: ${this.accessory.displayName}`
229
+ this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
230
+ this.debugLog(`Humidifier: ${this.accessory.displayName}`
214
231
  + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
215
- this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
232
+ this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
216
233
  // Active
217
234
  switch (this.deviceStatus.body.power) {
218
235
  case 'on':
@@ -221,7 +238,7 @@ class Humidifier {
221
238
  default:
222
239
  this.Active = this.platform.Characteristic.Active.INACTIVE;
223
240
  }
224
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
241
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
225
242
  // Water Level
226
243
  if (this.deviceStatus.body.lackWater) {
227
244
  this.WaterLevel = 0;
@@ -229,7 +246,7 @@ class Humidifier {
229
246
  else {
230
247
  this.WaterLevel = 100;
231
248
  }
232
- this.platform.debug(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
249
+ this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
233
250
  }
234
251
  }
235
252
  /**
@@ -246,11 +263,11 @@ class Humidifier {
246
263
  connectBLE() {
247
264
  const switchbot = new node_switchbot_1.default();
248
265
  this.device.bleMac = ((this.device.deviceId.match(/.{1,2}/g)).join(':')).toLowerCase();
249
- this.platform.device(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
266
+ this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
250
267
  return switchbot;
251
268
  }
252
269
  async BLERefreshStatus() {
253
- this.platform.device(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
270
+ this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
254
271
  // eslint-disable-next-line @typescript-eslint/no-var-requires
255
272
  const switchbot = this.connectBLE();
256
273
  // Start to monitor advertisement packets
@@ -264,16 +281,16 @@ class Humidifier {
264
281
  this.autoMode = ad.serviceData.autoMode;
265
282
  this.onState = ad.serviceData.onState;
266
283
  this.percentage = ad.serviceData.percentage;
267
- this.platform.device(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
268
- this.platform.device(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
284
+ this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
285
+ this.debugLog(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
269
286
  + `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
270
287
  if (this.serviceData) {
271
288
  this.connected = true;
272
- this.platform.device(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
289
+ this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
273
290
  }
274
291
  else {
275
292
  this.connected = false;
276
- this.platform.device(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
293
+ this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
277
294
  }
278
295
  };
279
296
  // Wait 10 seconds
@@ -286,24 +303,24 @@ class Humidifier {
286
303
  this.updateHomeKitCharacteristics();
287
304
  }
288
305
  else {
289
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
306
+ this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
290
307
  if (this.platform.config.credentials?.openToken) {
291
- this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
308
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
292
309
  await this.openAPIRefreshStatus();
293
310
  }
294
311
  }
295
312
  }).catch(async (e) => {
296
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
297
- if (this.deviceDebug) {
298
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
313
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
314
+ if (this.deviceLogging === 'debug') {
315
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
299
316
  + ` Error Message: ${JSON.stringify(e.message)}`);
300
317
  }
301
- if (this.debugDebug) {
302
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
318
+ if (this.platform.debugMode) {
319
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
303
320
  + ` Error: ${JSON.stringify(e)}`);
304
321
  }
305
322
  if (this.platform.config.credentials?.openToken) {
306
- this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
323
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
307
324
  await this.openAPIRefreshStatus();
308
325
  }
309
326
  this.apiError();
@@ -311,26 +328,26 @@ class Humidifier {
311
328
  }
312
329
  async openAPIRefreshStatus() {
313
330
  if (this.platform.config.credentials?.openToken) {
314
- this.platform.device(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
331
+ this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
315
332
  try {
316
333
  this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
317
334
  if (this.deviceStatus.message === 'success') {
318
- this.platform.debug(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
335
+ this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
319
336
  this.parseStatus();
320
337
  this.updateHomeKitCharacteristics();
321
338
  }
322
339
  else {
323
- this.platform.debug(this.deviceStatus);
340
+ this.debugLog(this.deviceStatus);
324
341
  }
325
342
  }
326
343
  catch (e) {
327
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
328
- if (this.deviceDebug) {
329
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
344
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
345
+ if (this.deviceLogging === 'debug') {
346
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
330
347
  + ` Error Message: ${JSON.stringify(e.message)}`);
331
348
  }
332
- if (this.debugDebug) {
333
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
349
+ if (this.platform.debugMode) {
350
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
334
351
  + ` Error: ${JSON.stringify(e)}`);
335
352
  }
336
353
  this.apiError();
@@ -354,25 +371,25 @@ class Humidifier {
354
371
  });
355
372
  }
356
373
  async BLEpushChanges() {
357
- this.platform.debug(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
374
+ this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
358
375
  const switchbot = this.connectBLE();
359
376
  switchbot.discover({ model: 'e', quick: true, id: this.device.bleMac }).then((device_list) => {
360
- this.platform.log.info(`${this.accessory.displayName} Target Position: ${this.Active}`);
377
+ this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
361
378
  return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
362
379
  }).then(() => {
363
- this.platform.device(`Humidifier: ${this.accessory.displayName} Done.`);
380
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
364
381
  }).catch(async (e) => {
365
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
366
- if (this.deviceDebug) {
367
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
382
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
383
+ if (this.deviceLogging === 'debug') {
384
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
368
385
  + ` Error Message: ${JSON.stringify(e.message)}`);
369
386
  }
370
- if (this.debugDebug) {
371
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
387
+ if (this.platform.debugMode) {
388
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
372
389
  + ` Error: ${JSON.stringify(e)}`);
373
390
  }
374
391
  if (this.platform.config.credentials?.openToken) {
375
- this.platform.log.warn(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
392
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
376
393
  await this.OpenAPIpushChanges();
377
394
  }
378
395
  this.apiError();
@@ -380,32 +397,32 @@ class Humidifier {
380
397
  }
381
398
  async OpenAPIpushChanges() {
382
399
  if (this.platform.config.credentials?.openToken) {
383
- this.platform.device(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
400
+ this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
384
401
  if (this.TargetHumidifierDehumidifierState ===
385
402
  this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
386
403
  this.Active === this.platform.Characteristic.Active.ACTIVE) {
387
404
  try {
388
- this.platform.debug(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
405
+ this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
389
406
  const payload = {
390
407
  commandType: 'command',
391
408
  command: 'setMode',
392
409
  parameter: `${this.RelativeHumidityHumidifierThreshold}`,
393
410
  };
394
- this.platform.log.info(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
411
+ this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
395
412
  + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
396
413
  // Make the API request
397
414
  const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
398
- this.platform.debug(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
415
+ this.debugLog(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
399
416
  this.statusCode(push);
400
417
  }
401
418
  catch (e) {
402
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
403
- if (this.deviceDebug) {
404
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
419
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
420
+ if (this.deviceLogging === 'debug') {
421
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
405
422
  + ` Error Message: ${JSON.stringify(e.message)}`);
406
423
  }
407
- if (this.debugDebug) {
408
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
424
+ if (this.platform.debugMode) {
425
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
409
426
  + ` Error: ${JSON.stringify(e)}`);
410
427
  }
411
428
  this.apiError();
@@ -429,28 +446,28 @@ class Humidifier {
429
446
  if (this.TargetHumidifierDehumidifierState ===
430
447
  this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
431
448
  this.Active === this.platform.Characteristic.Active.ACTIVE) {
432
- this.platform.debug('Pushing Auto!');
449
+ this.debugLog('Pushing Auto!');
433
450
  const payload = {
434
451
  commandType: 'command',
435
452
  command: 'setMode',
436
453
  parameter: 'auto',
437
454
  };
438
- this.platform.log.info(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
455
+ this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
439
456
  + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
440
457
  // Make the API request
441
458
  const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
442
- this.platform.debug(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(push.data)}`);
459
+ this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(push.data)}`);
443
460
  this.statusCode(push);
444
461
  }
445
462
  }
446
463
  catch (e) {
447
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
448
- if (this.deviceDebug) {
449
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
464
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
465
+ if (this.deviceLogging === 'debug') {
466
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
450
467
  + ` Error Message: ${JSON.stringify(e.message)}`);
451
468
  }
452
- if (this.debugDebug) {
453
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
469
+ if (this.platform.debugMode) {
470
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
454
471
  + ` Error: ${JSON.stringify(e)}`);
455
472
  }
456
473
  this.apiError();
@@ -462,28 +479,28 @@ class Humidifier {
462
479
  async pushActiveChanges() {
463
480
  try {
464
481
  if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
465
- this.platform.debug('Pushing Off!');
482
+ this.debugLog('Pushing Off!');
466
483
  const payload = {
467
484
  commandType: 'command',
468
485
  command: 'turnOff',
469
486
  parameter: 'default',
470
487
  };
471
- this.platform.log.info(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
488
+ this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
472
489
  + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
473
490
  // Make the API request
474
491
  const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
475
- this.platform.debug(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(push.data)}`);
492
+ this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(push.data)}`);
476
493
  this.statusCode(push);
477
494
  }
478
495
  }
479
496
  catch (e) {
480
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
481
- if (this.deviceDebug) {
482
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
497
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
498
+ if (this.deviceLogging === 'debug') {
499
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
483
500
  + ` Error Message: ${JSON.stringify(e.message)}`);
484
501
  }
485
- if (this.debugDebug) {
486
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
502
+ if (this.platform.debugMode) {
503
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
487
504
  + ` Error: ${JSON.stringify(e)}`);
488
505
  }
489
506
  this.apiError();
@@ -494,61 +511,61 @@ class Humidifier {
494
511
  */
495
512
  updateHomeKitCharacteristics() {
496
513
  if (this.CurrentRelativeHumidity === undefined) {
497
- this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
514
+ this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
498
515
  }
499
516
  else {
500
517
  this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
501
- this.platform.device(`Humidifier: ${this.accessory.displayName}`
518
+ this.debugLog(`Humidifier: ${this.accessory.displayName}`
502
519
  + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
503
520
  }
504
521
  if (!this.device.ble) {
505
522
  if (this.WaterLevel === undefined) {
506
- this.platform.debug(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
523
+ this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
507
524
  }
508
525
  else {
509
526
  this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
510
- this.platform.device(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
527
+ this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
511
528
  }
512
529
  }
513
530
  if (this.CurrentHumidifierDehumidifierState === undefined) {
514
- this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
531
+ this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
515
532
  }
516
533
  else {
517
534
  this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
518
- this.platform.device(`Humidifier: ${this.accessory.displayName}`
535
+ this.debugLog(`Humidifier: ${this.accessory.displayName}`
519
536
  + ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
520
537
  }
521
538
  if (this.TargetHumidifierDehumidifierState === undefined) {
522
- this.platform.debug(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
539
+ this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
523
540
  }
524
541
  else {
525
542
  this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
526
- this.platform.device(`Humidifier: ${this.accessory.displayName}`
543
+ this.debugLog(`Humidifier: ${this.accessory.displayName}`
527
544
  + ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
528
545
  }
529
546
  if (this.Active === undefined) {
530
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
547
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
531
548
  }
532
549
  else {
533
550
  this.service.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
534
- this.platform.device(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
551
+ this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
535
552
  }
536
553
  if (this.RelativeHumidityHumidifierThreshold === undefined) {
537
- this.platform.debug(`Humidifier: ${this.accessory.displayName}`
554
+ this.debugLog(`Humidifier: ${this.accessory.displayName}`
538
555
  + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
539
556
  }
540
557
  else {
541
558
  this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
542
- this.platform.device(`Humidifier: ${this.accessory.displayName}`
559
+ this.debugLog(`Humidifier: ${this.accessory.displayName}`
543
560
  + ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
544
561
  }
545
562
  if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
546
563
  if (this.CurrentTemperature === undefined) {
547
- this.platform.debug(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
564
+ this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
548
565
  }
549
566
  else {
550
567
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
551
- this.platform.device(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
568
+ this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
552
569
  }
553
570
  }
554
571
  }
@@ -558,31 +575,31 @@ class Humidifier {
558
575
  statusCode(push) {
559
576
  switch (push.data.statusCode) {
560
577
  case 151:
561
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
578
+ this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
562
579
  break;
563
580
  case 152:
564
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} Device not found.`);
581
+ this.errorLog(`Humidifier: ${this.accessory.displayName} Device not found.`);
565
582
  break;
566
583
  case 160:
567
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} Command is not supported.`);
584
+ this.errorLog(`Humidifier: ${this.accessory.displayName} Command is not supported.`);
568
585
  break;
569
586
  case 161:
570
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} Device is offline.`);
587
+ this.errorLog(`Humidifier: ${this.accessory.displayName} Device is offline.`);
571
588
  this.offlineOff();
572
589
  break;
573
590
  case 171:
574
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
591
+ this.errorLog(`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
575
592
  this.offlineOff();
576
593
  break;
577
594
  case 190:
578
- this.platform.log.error(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
595
+ this.errorLog(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
579
596
  + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
580
597
  break;
581
598
  case 100:
582
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
599
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
583
600
  break;
584
601
  default:
585
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Unknown statusCode.`);
602
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Unknown statusCode.`);
586
603
  }
587
604
  }
588
605
  offlineOff() {
@@ -595,7 +612,7 @@ class Humidifier {
595
612
  * Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
596
613
  */
597
614
  handleTargetHumidifierDehumidifierStateSet(value) {
598
- this.platform.debug(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
615
+ this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
599
616
  this.TargetHumidifierDehumidifierState = value;
600
617
  this.doHumidifierUpdate.next();
601
618
  }
@@ -603,7 +620,7 @@ class Humidifier {
603
620
  * Handle requests to set the "Active" characteristic
604
621
  */
605
622
  handleActiveSet(value) {
606
- this.platform.debug(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
623
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
607
624
  this.Active = value;
608
625
  this.doHumidifierUpdate.next();
609
626
  }
@@ -611,7 +628,7 @@ class Humidifier {
611
628
  * Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
612
629
  */
613
630
  handleRelativeHumidityHumidifierThresholdSet(value) {
614
- this.platform.debug(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
631
+ this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
615
632
  this.RelativeHumidityHumidifierThreshold = value;
616
633
  if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
617
634
  this.Active = this.platform.Characteristic.Active.ACTIVE;
@@ -619,6 +636,37 @@ class Humidifier {
619
636
  }
620
637
  this.doHumidifierUpdate.next();
621
638
  }
639
+ /**
640
+ * Logging for Device
641
+ */
642
+ infoLog(...log) {
643
+ if (this.enablingDeviceLogging()) {
644
+ this.platform.log.info(String(...log));
645
+ }
646
+ }
647
+ warnLog(...log) {
648
+ if (this.enablingDeviceLogging()) {
649
+ this.platform.log.warn(String(...log));
650
+ }
651
+ }
652
+ errorLog(...log) {
653
+ if (this.enablingDeviceLogging()) {
654
+ this.platform.log.error(String(...log));
655
+ }
656
+ }
657
+ debugLog(...log) {
658
+ if (this.enablingDeviceLogging()) {
659
+ if (this.deviceLogging === 'debug') {
660
+ this.platform.log.info('[DEBUG]', String(...log));
661
+ }
662
+ else {
663
+ this.platform.log.debug(String(...log));
664
+ }
665
+ }
666
+ }
667
+ enablingDeviceLogging() {
668
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
669
+ }
622
670
  }
623
671
  exports.Humidifier = Humidifier;
624
672
  //# sourceMappingURL=humidifiers.js.map