@switchbot/homebridge-switchbot 1.4.0 → 1.4.1-beta.3

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