@switchbot/homebridge-switchbot 2.0.0-beta.17 → 2.0.0-beta.19

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 (106) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/config.schema.json +14 -4
  3. package/dist/device/bot.d.ts +2 -0
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +201 -163
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +2 -0
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +250 -218
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +2 -0
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +85 -66
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +2 -0
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +166 -136
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts.map +1 -1
  20. package/dist/device/humidifier.js +126 -115
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/lock.d.ts +2 -0
  23. package/dist/device/lock.d.ts.map +1 -1
  24. package/dist/device/lock.js +156 -130
  25. package/dist/device/lock.js.map +1 -1
  26. package/dist/device/meter.d.ts +2 -0
  27. package/dist/device/meter.d.ts.map +1 -1
  28. package/dist/device/meter.js +85 -64
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.d.ts +2 -0
  31. package/dist/device/meterplus.d.ts.map +1 -1
  32. package/dist/device/meterplus.js +78 -59
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.d.ts +2 -0
  35. package/dist/device/motion.d.ts.map +1 -1
  36. package/dist/device/motion.js +76 -57
  37. package/dist/device/motion.js.map +1 -1
  38. package/dist/device/plug.d.ts +2 -0
  39. package/dist/device/plug.d.ts.map +1 -1
  40. package/dist/device/plug.js +133 -107
  41. package/dist/device/plug.js.map +1 -1
  42. package/dist/device/striplight.d.ts +2 -0
  43. package/dist/device/striplight.d.ts.map +1 -1
  44. package/dist/device/striplight.js +224 -195
  45. package/dist/device/striplight.js.map +1 -1
  46. package/dist/irdevice/airconditioner.d.ts +2 -0
  47. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  48. package/dist/irdevice/airconditioner.js +127 -105
  49. package/dist/irdevice/airconditioner.js.map +1 -1
  50. package/dist/irdevice/airpurifier.d.ts +2 -0
  51. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  52. package/dist/irdevice/airpurifier.js +83 -66
  53. package/dist/irdevice/airpurifier.js.map +1 -1
  54. package/dist/irdevice/camera.d.ts +8 -6
  55. package/dist/irdevice/camera.d.ts.map +1 -1
  56. package/dist/irdevice/camera.js +83 -68
  57. package/dist/irdevice/camera.js.map +1 -1
  58. package/dist/irdevice/fan.d.ts +7 -5
  59. package/dist/irdevice/fan.d.ts.map +1 -1
  60. package/dist/irdevice/fan.js +90 -75
  61. package/dist/irdevice/fan.js.map +1 -1
  62. package/dist/irdevice/light.d.ts +8 -6
  63. package/dist/irdevice/light.d.ts.map +1 -1
  64. package/dist/irdevice/light.js +83 -68
  65. package/dist/irdevice/light.js.map +1 -1
  66. package/dist/irdevice/other.d.ts +8 -6
  67. package/dist/irdevice/other.d.ts.map +1 -1
  68. package/dist/irdevice/other.js +93 -78
  69. package/dist/irdevice/other.js.map +1 -1
  70. package/dist/irdevice/tv.d.ts +8 -6
  71. package/dist/irdevice/tv.d.ts.map +1 -1
  72. package/dist/irdevice/tv.js +68 -52
  73. package/dist/irdevice/tv.js.map +1 -1
  74. package/dist/irdevice/vacuumcleaner.d.ts +8 -6
  75. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.js +83 -69
  77. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  78. package/dist/irdevice/waterheater.d.ts +2 -0
  79. package/dist/irdevice/waterheater.d.ts.map +1 -1
  80. package/dist/irdevice/waterheater.js +75 -60
  81. package/dist/irdevice/waterheater.js.map +1 -1
  82. package/dist/settings.d.ts +12 -11
  83. package/dist/settings.d.ts.map +1 -1
  84. package/dist/settings.js.map +1 -1
  85. package/package.json +1 -1
  86. package/src/device/bot.ts +200 -163
  87. package/src/device/colorbulb.ts +252 -221
  88. package/src/device/contact.ts +85 -66
  89. package/src/device/curtain.ts +165 -136
  90. package/src/device/humidifier.ts +126 -115
  91. package/src/device/lock.ts +156 -131
  92. package/src/device/meter.ts +85 -64
  93. package/src/device/meterplus.ts +78 -59
  94. package/src/device/motion.ts +76 -57
  95. package/src/device/plug.ts +132 -107
  96. package/src/device/striplight.ts +226 -198
  97. package/src/irdevice/airconditioner.ts +126 -103
  98. package/src/irdevice/airpurifier.ts +84 -66
  99. package/src/irdevice/camera.ts +84 -68
  100. package/src/irdevice/fan.ts +91 -75
  101. package/src/irdevice/light.ts +84 -68
  102. package/src/irdevice/other.ts +94 -78
  103. package/src/irdevice/tv.ts +69 -53
  104. package/src/irdevice/vacuumcleaner.ts +83 -68
  105. package/src/irdevice/waterheater.ts +76 -60
  106. package/src/settings.ts +12 -11
@@ -35,6 +35,7 @@ export class Plug {
35
35
  currentPower: serviceData['currentPower'];
36
36
 
37
37
  // Config
38
+ OpenAPI?: boolean;
38
39
  scanDuration!: number;
39
40
  deviceLogging!: string;
40
41
  deviceRefreshRate!: number;
@@ -114,9 +115,10 @@ export class Plug {
114
115
  try {
115
116
  await this.pushChanges();
116
117
  } catch (e: any) {
117
- this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges`);
118
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
118
119
  if (this.deviceLogging.includes('debug')) {
119
- this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${superStringify(e.message)}`);
120
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,`
121
+ + ` Error Message: ${superStringify(e.message)}`);
120
122
  }
121
123
  this.apiError(e);
122
124
  }
@@ -133,7 +135,7 @@ export class Plug {
133
135
  }
134
136
 
135
137
  async BLEparseStatus(): Promise<void> {
136
- this.debugLog(`Plug: ${this.accessory.displayName} BLE parseStatus`);
138
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
137
139
  // State
138
140
  switch (this.state) {
139
141
  case 'on':
@@ -142,7 +144,7 @@ export class Plug {
142
144
  default:
143
145
  this.On = false;
144
146
  }
145
- this.debugLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
147
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
146
148
  }
147
149
 
148
150
  async openAPIparseStatus() {
@@ -153,7 +155,7 @@ export class Plug {
153
155
  default:
154
156
  this.On = false;
155
157
  }
156
- this.debugLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
158
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
157
159
  }
158
160
 
159
161
  async refreshStatus(): Promise<void> {
@@ -165,14 +167,14 @@ export class Plug {
165
167
  }
166
168
 
167
169
  async BLERefreshStatus(): Promise<void> {
168
- this.debugLog(`Plug: ${this.accessory.displayName} BLE refreshStatus`);
170
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE refreshStatus`);
169
171
  const switchbot = await this.platform.connectBLE();
170
172
  // Convert to BLE Address
171
173
  this.device.bleMac = this.device
172
174
  .deviceId!.match(/.{1,2}/g)!
173
175
  .join(':')
174
176
  .toLowerCase();
175
- this.debugLog(`Plug: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
177
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
176
178
  this.getCustomBLEAddress(switchbot);
177
179
  // Start to monitor advertisement packets
178
180
  if (switchbot !== false) {
@@ -188,8 +190,8 @@ export class Plug {
188
190
  if (this.deviceLogging.includes('debug')) {
189
191
  this.infoLog(this.address);
190
192
  this.infoLog(this.device.bleMac);
191
- this.infoLog(`Plug: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
192
- this.infoLog(`Plug: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
193
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
194
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
193
195
  }
194
196
  this.serviceData = ad.serviceData;
195
197
  this.state = ad.serviceData.state;
@@ -199,19 +201,19 @@ export class Plug {
199
201
  this.wifiRssi = ad.serviceData.wifiRssi;
200
202
  this.overload = ad.serviceData.overload;
201
203
  this.currentPower = ad.serviceData.currentPower;
202
- this.debugLog(`Plug: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
204
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
203
205
  this.debugLog(
204
- `Plug: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
206
+ `${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
205
207
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
206
208
  `wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
207
209
  );
208
210
 
209
211
  if (this.serviceData) {
210
212
  this.connected = true;
211
- this.debugLog(`Plug: ${this.accessory.displayName} connected: ${this.connected}`);
213
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
212
214
  } else {
213
215
  this.connected = false;
214
- this.debugLog(`Plug: ${this.accessory.displayName} connected: ${this.connected}`);
216
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
215
217
  }
216
218
  };
217
219
  // Wait 2 seconds
@@ -228,14 +230,15 @@ export class Plug {
228
230
  }
229
231
  })
230
232
  .catch(async (e: any) => {
231
- this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
233
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
232
234
  if (this.deviceLogging.includes('debug')) {
233
235
  this.errorLog(
234
- `Plug: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
236
+ `${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
237
+ + ` Error Message: ${superStringify(e.message)}`,
235
238
  );
236
239
  }
237
240
  if (this.platform.config.credentials?.token) {
238
- this.warnLog(`Plug: ${this.accessory.displayName} Using OpenAPI Connection`);
241
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
239
242
  this.SwitchToOpenAPI = true;
240
243
  await this.openAPIRefreshStatus();
241
244
  }
@@ -263,7 +266,7 @@ export class Plug {
263
266
  });
264
267
  // Set an event handler
265
268
  switchbot.onadvertisement = (ad: any) => {
266
- this.warnLog(`Plug: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
269
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
267
270
  };
268
271
  await switchbot.wait(10000);
269
272
  // Stop to monitor
@@ -273,66 +276,71 @@ export class Plug {
273
276
  }
274
277
 
275
278
  async BLEconnection(switchbot: any): Promise<void> {
276
- this.errorLog(`Plug: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
279
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
277
280
  if (this.platform.config.credentials?.token) {
278
- this.warnLog(`Plug: ${this.accessory.displayName} Using OpenAPI Connection`);
281
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
279
282
  this.SwitchToOpenAPI = true;
280
283
  await this.openAPIRefreshStatus();
281
284
  }
282
285
  }
283
286
 
284
287
  async openAPIRefreshStatus() {
285
- try {
286
- const t = Date.now();
287
- const nonce = 'requestID';
288
- const data = this.platform.config.credentials?.token + t + nonce;
289
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
290
- const sign = signTerm.toString('base64');
291
- this.debugLog(`Plug: ${this.accessory.displayName} sign: ${sign}`);
292
- const options = {
293
- hostname: HostDomain,
294
- port: 443,
295
- path: `${DevicePath}/${this.device.deviceId}/status`,
296
- method: 'GET',
297
- headers: {
298
- Authorization: this.platform.config.credentials?.token,
299
- sign: sign,
300
- nonce: nonce,
301
- t: t,
302
- 'Content-Type': 'application/json',
303
- },
304
- };
305
- const req = https.request(options, (res) => {
306
- this.debugLog(`Plug: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
307
- let rawData = '';
308
- res.on('data', (d) => {
309
- rawData += d;
310
- this.debugLog(`Plug: ${this.accessory.displayName} d: ${d}`);
288
+ if (this.OpenAPI) {
289
+ try {
290
+ const t = Date.now();
291
+ const nonce = 'requestID';
292
+ const data = this.platform.config.credentials?.token + t + nonce;
293
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
294
+ const sign = signTerm.toString('base64');
295
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
296
+ const options = {
297
+ hostname: HostDomain,
298
+ port: 443,
299
+ path: `${DevicePath}/${this.device.deviceId}/status`,
300
+ method: 'GET',
301
+ headers: {
302
+ Authorization: this.platform.config.credentials?.token,
303
+ sign: sign,
304
+ nonce: nonce,
305
+ t: t,
306
+ 'Content-Type': 'application/json',
307
+ },
308
+ };
309
+ const req = https.request(options, (res) => {
310
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
311
+ let rawData = '';
312
+ res.on('data', (d) => {
313
+ rawData += d;
314
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
315
+ });
316
+ res.on('end', () => {
317
+ try {
318
+ this.deviceStatus = JSON.parse(rawData);
319
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
320
+ this.power = this.deviceStatus.body.power;
321
+ this.parseStatus();
322
+ this.updateHomeKitCharacteristics();
323
+ } catch (e: any) {
324
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
325
+ }
326
+ });
311
327
  });
312
- res.on('end', () => {
313
- try {
314
- this.deviceStatus = JSON.parse(rawData);
315
- this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
316
- this.power = this.deviceStatus.body.power;
317
- this.parseStatus();
318
- this.updateHomeKitCharacteristics();
319
- } catch (e: any) {
320
- this.errorLog(`Plug: ${this.accessory.displayName} error message: ${e.message}`);
321
- }
328
+ req.on('error', (e: any) => {
329
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
322
330
  });
323
- });
324
- req.on('error', (e: any) => {
325
- this.errorLog(`Plug: ${this.accessory.displayName} error message: ${e.message}`);
326
- });
327
- req.end();
328
- } catch (e: any) {
329
- this.errorLog(`Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
330
- if (this.deviceLogging.includes('debug')) {
331
- this.errorLog(
332
- `Plug: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
333
- );
331
+ req.end();
332
+ } catch (e: any) {
333
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
334
+ if (this.deviceLogging.includes('debug')) {
335
+ this.errorLog(
336
+ `${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
337
+ + ` Error Message: ${superStringify(e.message)}`,
338
+ );
339
+ }
340
+ this.apiError(e);
334
341
  }
335
- this.apiError(e);
342
+ } else {
343
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
336
344
  }
337
345
  }
338
346
 
@@ -355,40 +363,42 @@ export class Plug {
355
363
  }
356
364
 
357
365
  async BLEpushChanges(): Promise<void> {
358
- this.debugLog(`Plug: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
359
- this.debugLog(`Plug: ${this.accessory.displayName} BLE pushChanges`);
366
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE pushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
367
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE pushChanges`);
360
368
  const switchbot = await this.platform.connectBLE();
361
369
  // Convert to BLE Address
362
370
  this.device.bleMac = this.device
363
371
  .deviceId!.match(/.{1,2}/g)!
364
372
  .join(':')
365
373
  .toLowerCase();
366
- this.debugLog(`Plug: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
374
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
367
375
  switchbot
368
376
  .discover({
369
377
  model: this.BLEmodel(),
370
378
  id: this.device.bleMac,
371
379
  })
372
380
  .then((device_list: any) => {
373
- this.infoLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
381
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
374
382
  return this.turnOnOff(device_list);
375
383
  })
376
384
  .then(() => {
377
- this.debugLog(`Plug: ${this.accessory.displayName} Done.`);
385
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
378
386
  this.On = false;
379
387
  })
380
388
  .catch(async (e: any) => {
381
- this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
389
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
382
390
  if (this.deviceLogging.includes('debug')) {
383
391
  this.errorLog(
384
- `Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
392
+ `${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
393
+ + ` Error Message: ${superStringify(e.message)}`,
385
394
  );
386
395
  }
387
396
  if (this.platform.debugMode) {
388
- this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${superStringify(e)}`);
397
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
398
+ + ` Error: ${superStringify(e)}`);
389
399
  }
390
400
  if (this.platform.config.credentials?.token) {
391
- this.warnLog(`Plug: ${this.accessory.displayName} Using OpenAPI Connection`);
401
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
392
402
  await this.openAPIpushChanges();
393
403
  }
394
404
  this.apiError(e);
@@ -409,10 +419,10 @@ export class Plug {
409
419
  }
410
420
 
411
421
  async openAPIpushChanges() {
412
- if (this.platform.config.credentials?.token) {
422
+ if (this.platform.config.credentials?.token && this.OpenAPI) {
413
423
  if (this.On !== this.accessory.context.On) {
414
424
  // Make Push On request to the API
415
- this.debugLog(`Plug: ${this.accessory.displayName} OpenAPI pushChanges`);
425
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`);
416
426
  const t = Date.now();
417
427
  const nonce = 'requestID';
418
428
  const data = this.platform.config.credentials?.token + t + nonce;
@@ -420,7 +430,7 @@ export class Plug {
420
430
  .update(Buffer.from(data, 'utf-8'))
421
431
  .digest();
422
432
  const sign = signTerm.toString('base64');
423
- this.debugLog(`Plug: ${this.accessory.displayName} sign: ${sign}`);
433
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
424
434
 
425
435
  let command = '';
426
436
  if (this.On) {
@@ -433,7 +443,7 @@ export class Plug {
433
443
  'parameter': 'default',
434
444
  'commandType': 'command',
435
445
  });
436
- this.infoLog(`Plug: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
446
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
437
447
  const options = {
438
448
  hostname: HostDomain,
439
449
  port: 443,
@@ -449,34 +459,36 @@ export class Plug {
449
459
  },
450
460
  };
451
461
  const req = https.request(options, res => {
452
- this.debugLog(`Plug: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
462
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
453
463
  this.statusCode({ res });
454
464
  res.on('data', d => {
455
- this.debugLog(`Plug: ${this.accessory.displayName} d: ${d}`);
465
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
456
466
  });
457
467
  });
458
468
  req.on('error', (e: any) => {
459
- this.errorLog(`Plug: ${this.accessory.displayName} error message: ${e.message}`);
469
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
460
470
  });
461
471
  req.write(body);
462
472
  req.end();
463
- this.debugLog(`Plug: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
473
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
464
474
  }
465
475
  interval(5000)
466
476
  .pipe(take(1))
467
477
  .subscribe(async () => {
468
478
  await this.refreshStatus();
469
479
  });
480
+ } else {
481
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
470
482
  }
471
483
  }
472
484
 
473
485
  async updateHomeKitCharacteristics(): Promise<void> {
474
486
  if (this.On === undefined) {
475
- this.debugLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
487
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
476
488
  } else {
477
489
  this.accessory.context.On = this.On;
478
490
  this.outletService.updateCharacteristic(this.platform.Characteristic.On, this.On);
479
- this.debugLog(`Plug: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
491
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
480
492
  }
481
493
  }
482
494
 
@@ -488,33 +500,33 @@ export class Plug {
488
500
  async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
489
501
  switch (res.statusCode) {
490
502
  case 151:
491
- this.errorLog(`Plug: ${this.accessory.displayName} Command not supported by this device type.`);
503
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
492
504
  break;
493
505
  case 152:
494
- this.errorLog(`Plug: ${this.accessory.displayName} Device not found.`);
506
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
495
507
  break;
496
508
  case 160:
497
- this.errorLog(`Plug: ${this.accessory.displayName} Command is not supported.`);
509
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
498
510
  break;
499
511
  case 161:
500
- this.errorLog(`Plug: ${this.accessory.displayName} Device is offline.`);
512
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
501
513
  this.offlineOff();
502
514
  break;
503
515
  case 171:
504
- this.errorLog(`Plug: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
516
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
505
517
  this.offlineOff();
506
518
  break;
507
519
  case 190:
508
520
  this.errorLog(
509
- `Plug: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
521
+ `${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
510
522
  ` Or command: ${superStringify(res)} format is invalid`,
511
523
  );
512
524
  break;
513
525
  case 100:
514
- this.debugLog(`Plug: ${this.accessory.displayName} Command successfully sent.`);
526
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
515
527
  break;
516
528
  default:
517
- this.debugLog(`Plug: ${this.accessory.displayName} Unknown statusCode.`);
529
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
518
530
  }
519
531
  }
520
532
 
@@ -529,7 +541,7 @@ export class Plug {
529
541
  * Handle requests to set the value of the "On" characteristic
530
542
  */
531
543
  async handleOnSet(value: CharacteristicValue): Promise<void> {
532
- this.debugLog(`Plug: ${this.accessory.displayName} - Set On: ${value}`);
544
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} - Set On: ${value}`);
533
545
 
534
546
  this.On = value;
535
547
  this.doPlugUpdate.next();
@@ -577,6 +589,9 @@ export class Plug {
577
589
  if (device.ble !== undefined) {
578
590
  config['ble'] = device.ble;
579
591
  }
592
+ if (device.openAPI !== undefined) {
593
+ config['openAPI'] = device.openAPI;
594
+ }
580
595
  if (device.logging !== undefined) {
581
596
  config['logging'] = device.logging;
582
597
  }
@@ -590,30 +605,39 @@ export class Plug {
590
605
  config['offline'] = device.offline;
591
606
  }
592
607
  if (Object.entries(config).length !== 0) {
593
- this.infoLog(`Plug: ${this.accessory.displayName} Config: ${superStringify(config)}`);
608
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
594
609
  }
595
610
  }
596
611
 
597
612
  async refreshRate(device: device & devicesConfig): Promise<void> {
598
613
  if (device.refreshRate) {
599
614
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
600
- this.debugLog(`Plug: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
615
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
601
616
  } else if (this.platform.config.options!.refreshRate) {
602
617
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
603
- this.debugLog(`Plug: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
618
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
619
+ }
620
+ }
621
+
622
+ async openAPI() {
623
+ if (!this.device.openAPI) {
624
+ this.OpenAPI = true;
625
+ } else {
626
+ this.OpenAPI = this.device.openAPI;
604
627
  }
628
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
605
629
  }
606
630
 
607
631
  async scan(device: device & devicesConfig): Promise<void> {
608
632
  if (device.scanDuration) {
609
633
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
610
634
  if (device.ble) {
611
- this.debugLog(`Plug: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
635
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
612
636
  }
613
637
  } else {
614
638
  this.scanDuration = this.accessory.context.scanDuration = 1;
615
639
  if (this.device.ble) {
616
- this.debugLog(`Plug: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
640
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
617
641
  }
618
642
  }
619
643
  }
@@ -621,24 +645,25 @@ export class Plug {
621
645
  async logs(device: device & devicesConfig): Promise<void> {
622
646
  if (this.platform.debugMode) {
623
647
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
624
- this.debugLog(`Plug: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
648
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
625
649
  } else if (device.logging) {
626
650
  this.deviceLogging = this.accessory.context.logging = device.logging;
627
- this.debugLog(`Plug: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
651
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
628
652
  } else if (this.platform.config.options?.logging) {
629
653
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
630
- this.debugLog(`Plug: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
654
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
631
655
  } else {
632
656
  this.deviceLogging = this.accessory.context.logging = 'standard';
633
- this.debugLog(`Plug: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
657
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
634
658
  }
635
659
  }
636
660
 
637
661
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
638
662
  let FirmwareRevision: string;
639
- this.debugLog(`Plug: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
640
- this.debugLog(`Plug: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
641
- this.debugLog(`Plug: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
663
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
664
+ +` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
665
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
666
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
642
667
  if (accessory.context.FirmwareRevision) {
643
668
  FirmwareRevision = accessory.context.FirmwareRevision;
644
669
  } else if (device.firmware) {