@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
@@ -22,6 +22,7 @@ class ColorBulb {
22
22
  this.device = device;
23
23
  // default placeholders
24
24
  this.logs(device);
25
+ this.openAPI();
25
26
  this.scan(device);
26
27
  this.refreshRate(device);
27
28
  this.adaptiveLighting(device);
@@ -60,7 +61,7 @@ class ColorBulb {
60
61
  this.accessory.removeService(this.lightBulbService);
61
62
  this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
62
63
  this.accessory.context.adaptiveLighting = false;
63
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
64
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
64
65
  }
65
66
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
66
67
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -84,7 +85,7 @@ class ColorBulb {
84
85
  })
85
86
  .onSet(this.BrightnessSet.bind(this));
86
87
  // handle ColorTemperature events using the ColorTemperature characteristic
87
- this.debugLog(`Color Bulb: ${accessory.displayName} Add ColorTemperature Characteristic`);
88
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add ColorTemperature Characteristic`);
88
89
  this.lightBulbService
89
90
  .getCharacteristic(this.platform.Characteristic.ColorTemperature)
90
91
  .setProps({
@@ -120,14 +121,14 @@ class ColorBulb {
120
121
  return this.Saturation;
121
122
  })
122
123
  .onSet(this.SaturationSet.bind(this));
123
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
124
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
124
125
  if (this.adaptiveLightingShift !== -1) {
125
126
  this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
126
127
  customTemperatureAdjustment: this.adaptiveLightingShift,
127
128
  });
128
129
  this.accessory.configureController(this.AdaptiveLightingController);
129
130
  this.accessory.context.adaptiveLighting = true;
130
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
131
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
131
132
  ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
132
133
  }
133
134
  // Update Homekit
@@ -149,9 +150,10 @@ class ColorBulb {
149
150
  await this.pushChanges();
150
151
  }
151
152
  catch (e) {
152
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
153
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
153
154
  if (this.deviceLogging.includes('debug')) {
154
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
155
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,`
156
+ + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
155
157
  }
156
158
  this.apiError(e);
157
159
  }
@@ -174,7 +176,7 @@ class ColorBulb {
174
176
  }
175
177
  }
176
178
  async BLEparseStatus() {
177
- this.debugLog(`Color Bulb: ${this.accessory.displayName} BLE parseStatus`);
179
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
178
180
  // State
179
181
  switch (this.state) {
180
182
  case 'on':
@@ -183,7 +185,7 @@ class ColorBulb {
183
185
  default:
184
186
  this.On = false;
185
187
  }
186
- this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
188
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
187
189
  }
188
190
  async openAPIparseStatus() {
189
191
  switch (this.power) {
@@ -193,33 +195,34 @@ class ColorBulb {
193
195
  default:
194
196
  this.On = false;
195
197
  }
196
- this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
198
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
197
199
  // Brightness
198
200
  this.Brightness = Number(this.brightness);
199
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
201
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
200
202
  // Color, Hue & Brightness
201
203
  if (this.color) {
202
- this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${(0, super_stringify_1.default)(this.color)}`);
204
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${(0, super_stringify_1.default)(this.color)}`);
203
205
  const [red, green, blue] = this.color.split(':');
204
- this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${(0, super_stringify_1.default)(red)}`);
205
- this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${(0, super_stringify_1.default)(green)}`);
206
- this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${(0, super_stringify_1.default)(blue)}`);
206
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${(0, super_stringify_1.default)(red)}`);
207
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${(0, super_stringify_1.default)(green)}`);
208
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${(0, super_stringify_1.default)(blue)}`);
207
209
  const [hue, saturation] = (0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue));
208
- this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${(0, super_stringify_1.default)((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
210
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
211
+ + ` hs: ${(0, super_stringify_1.default)((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
209
212
  // Hue
210
213
  this.Hue = hue;
211
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
214
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
212
215
  // Saturation
213
216
  this.Saturation = saturation;
214
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
217
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
215
218
  }
216
219
  // ColorTemperature
217
220
  if (!Number.isNaN(this.colorTemperature)) {
218
- this.debugLog(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
221
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
219
222
  const mired = Math.round(1000000 / this.colorTemperature);
220
223
  this.ColorTemperature = Number(mired);
221
224
  this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
222
- this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
225
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
223
226
  }
224
227
  }
225
228
  async refreshStatus() {
@@ -231,14 +234,14 @@ class ColorBulb {
231
234
  }
232
235
  }
233
236
  async BLERefreshStatus() {
234
- this.debugLog(`Color Bulb: ${this.accessory.displayName} BLE refreshStatus`);
237
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE refreshStatus`);
235
238
  const switchbot = await this.platform.connectBLE();
236
239
  // Convert to BLE Address
237
240
  this.device.bleMac = this.device
238
241
  .deviceId.match(/.{1,2}/g)
239
242
  .join(':')
240
243
  .toLowerCase();
241
- this.debugLog(`Color Bulb: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
244
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
242
245
  this.getCustomBLEAddress(switchbot);
243
246
  // Start to monitor advertisement packets
244
247
  if (switchbot !== false) {
@@ -254,10 +257,10 @@ class ColorBulb {
254
257
  if (this.deviceLogging.includes('debug')) {
255
258
  this.infoLog(this.address);
256
259
  this.infoLog(this.device.bleMac);
257
- this.infoLog(`Color Bulb: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
258
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
260
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
261
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
259
262
  }
260
- this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
263
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
261
264
  this.serviceData = ad.serviceData;
262
265
  //this.state = ad.serviceData.state;
263
266
  //this.delay = ad.serviceData.delay;
@@ -266,19 +269,19 @@ class ColorBulb {
266
269
  //this.wifiRssi = ad.serviceData.wifiRssi;
267
270
  //this.overload = ad.serviceData.overload;
268
271
  //this.currentPower = ad.serviceData.currentPower;
269
- this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
272
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
270
273
  /*this.debugLog(
271
- `Color Bulb: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
274
+ `${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
272
275
  `delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
273
276
  `wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
274
277
  );*/
275
278
  if (this.serviceData) {
276
279
  this.connected = true;
277
- this.debugLog(`Color Bulb: ${this.accessory.displayName} connected: ${this.connected}`);
280
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
278
281
  }
279
282
  else {
280
283
  this.connected = false;
281
- this.debugLog(`Color Bulb: ${this.accessory.displayName} connected: ${this.connected}`);
284
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
282
285
  }
283
286
  };
284
287
  // Wait 2 seconds
@@ -292,21 +295,22 @@ class ColorBulb {
292
295
  this.updateHomeKitCharacteristics();
293
296
  }
294
297
  else {
295
- this.errorLog(`Color Bulb: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
298
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
296
299
  if (this.platform.config.credentials?.token) {
297
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Using OpenAPI Connection`);
300
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
298
301
  this.SwitchToOpenAPI = true;
299
302
  await this.openAPIRefreshStatus();
300
303
  }
301
304
  }
302
305
  })
303
306
  .catch(async (e) => {
304
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
307
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
305
308
  if (this.deviceLogging.includes('debug')) {
306
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
309
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
310
+ + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
307
311
  }
308
312
  if (this.platform.config.credentials?.token) {
309
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Using OpenAPI Connection`);
313
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
310
314
  this.SwitchToOpenAPI = true;
311
315
  await this.openAPIRefreshStatus();
312
316
  }
@@ -319,7 +323,7 @@ class ColorBulb {
319
323
  }
320
324
  async getCustomBLEAddress(switchbot) {
321
325
  if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
322
- this.debugLog(`Color Bulb: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
326
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
323
327
  (async () => {
324
328
  // Start to monitor advertisement packets
325
329
  await switchbot.startScan({
@@ -327,7 +331,7 @@ class ColorBulb {
327
331
  });
328
332
  // Set an event handler
329
333
  switchbot.onadvertisement = (ad) => {
330
- this.warnLog(`Color Bulb: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
334
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
331
335
  };
332
336
  await switchbot.wait(10000);
333
337
  // Stop to monitor
@@ -336,68 +340,74 @@ class ColorBulb {
336
340
  }
337
341
  }
338
342
  async BLEconnection(switchbot) {
339
- this.errorLog(`Color Bulb: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
343
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
340
344
  if (this.platform.config.credentials?.token) {
341
- this.warnLog(`Color Bulb: ${this.accessory.displayName} Using OpenAPI Connection`);
345
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
342
346
  this.SwitchToOpenAPI = true;
343
347
  await this.openAPIRefreshStatus();
344
348
  }
345
349
  }
346
350
  async openAPIRefreshStatus() {
347
- try {
348
- const t = Date.now();
349
- const nonce = 'requestID';
350
- const data = this.platform.config.credentials?.token + t + nonce;
351
- const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
352
- const sign = signTerm.toString('base64');
353
- this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
354
- const options = {
355
- hostname: settings_1.HostDomain,
356
- port: 443,
357
- path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
358
- method: 'GET',
359
- headers: {
360
- Authorization: this.platform.config.credentials?.token,
361
- sign: sign,
362
- nonce: nonce,
363
- t: t,
364
- 'Content-Type': 'application/json',
365
- },
366
- };
367
- const req = https_1.default.request(options, (res) => {
368
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Refresh statusCode: ${res.statusCode}`);
369
- let rawData = '';
370
- res.on('data', (d) => {
371
- rawData += d;
372
- this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
351
+ if (this.OpenAPI) {
352
+ try {
353
+ const t = Date.now();
354
+ const nonce = 'requestID';
355
+ const data = this.platform.config.credentials?.token + t + nonce;
356
+ const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
357
+ const sign = signTerm.toString('base64');
358
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
359
+ const options = {
360
+ hostname: settings_1.HostDomain,
361
+ port: 443,
362
+ path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
363
+ method: 'GET',
364
+ headers: {
365
+ Authorization: this.platform.config.credentials?.token,
366
+ sign: sign,
367
+ nonce: nonce,
368
+ t: t,
369
+ 'Content-Type': 'application/json',
370
+ },
371
+ };
372
+ const req = https_1.default.request(options, (res) => {
373
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Refresh statusCode: ${res.statusCode}`);
374
+ let rawData = '';
375
+ res.on('data', (d) => {
376
+ rawData += d;
377
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
378
+ });
379
+ res.on('end', () => {
380
+ try {
381
+ this.deviceStatus = JSON.parse(rawData);
382
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
383
+ this.power = this.deviceStatus.body.power;
384
+ this.color = this.deviceStatus.body.color;
385
+ this.brightness = this.deviceStatus.body.brightness;
386
+ this.colorTemperature = this.deviceStatus.body.colorTemperature;
387
+ this.parseStatus();
388
+ this.updateHomeKitCharacteristics();
389
+ }
390
+ catch (e) {
391
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
392
+ }
393
+ });
373
394
  });
374
- res.on('end', () => {
375
- try {
376
- this.deviceStatus = JSON.parse(rawData);
377
- this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
378
- this.power = this.deviceStatus.body.power;
379
- this.color = this.deviceStatus.body.color;
380
- this.brightness = this.deviceStatus.body.brightness;
381
- this.colorTemperature = this.deviceStatus.body.colorTemperature;
382
- this.parseStatus();
383
- this.updateHomeKitCharacteristics();
384
- }
385
- catch (e) {
386
- this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
387
- }
395
+ req.on('error', (e) => {
396
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
388
397
  });
389
- });
390
- req.on('error', (e) => {
391
- this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
392
- });
393
- req.end();
394
- }
395
- catch (e) {
396
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
397
- if (this.deviceLogging.includes('debug')) {
398
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
398
+ req.end();
399
+ }
400
+ catch (e) {
401
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
402
+ if (this.deviceLogging.includes('debug')) {
403
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
404
+ + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
405
+ }
406
+ this.apiError(e);
399
407
  }
400
- this.apiError(e);
408
+ }
409
+ else {
410
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
401
411
  }
402
412
  }
403
413
  /**
@@ -412,86 +422,92 @@ class ColorBulb {
412
422
  *
413
423
  */
414
424
  async pushChanges() {
415
- try {
416
- if (this.On !== this.accessory.context.On) {
417
- // Make Push On request to the API
418
- const t = Date.now();
419
- const nonce = 'requestID';
420
- const data = this.platform.config.credentials?.token + t + nonce;
421
- const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret)
422
- .update(Buffer.from(data, 'utf-8'))
423
- .digest();
424
- const sign = signTerm.toString('base64');
425
- this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
426
- let command = '';
425
+ if (this.OpenAPI) {
426
+ try {
427
+ if (this.On !== this.accessory.context.On) {
428
+ // Make Push On request to the API
429
+ const t = Date.now();
430
+ const nonce = 'requestID';
431
+ const data = this.platform.config.credentials?.token + t + nonce;
432
+ const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret)
433
+ .update(Buffer.from(data, 'utf-8'))
434
+ .digest();
435
+ const sign = signTerm.toString('base64');
436
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
437
+ let command = '';
438
+ if (this.On) {
439
+ command = 'turnOn';
440
+ }
441
+ else {
442
+ command = 'turnOff';
443
+ }
444
+ const body = (0, super_stringify_1.default)({
445
+ 'command': `${command}`,
446
+ 'parameter': 'default',
447
+ 'commandType': 'command',
448
+ });
449
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
450
+ const options = {
451
+ hostname: settings_1.HostDomain,
452
+ port: 443,
453
+ path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
454
+ method: 'POST',
455
+ headers: {
456
+ 'Authorization': this.platform.config.credentials?.token,
457
+ 'sign': sign,
458
+ 'nonce': nonce,
459
+ 't': t,
460
+ 'Content-Type': 'application/json',
461
+ 'Content-Length': body.length,
462
+ },
463
+ };
464
+ const req = https_1.default.request(options, res => {
465
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
466
+ this.statusCode({ res });
467
+ res.on('data', d => {
468
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
469
+ });
470
+ });
471
+ req.on('error', (e) => {
472
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
473
+ });
474
+ req.write(body);
475
+ req.end();
476
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${(0, super_stringify_1.default)(req)}`);
477
+ }
478
+ // Push Brightness Update
427
479
  if (this.On) {
428
- command = 'turnOn';
480
+ await this.pushBrightnessChanges();
429
481
  }
430
- else {
431
- command = 'turnOff';
482
+ // Push ColorTemperature Update
483
+ if (this.On) {
484
+ await this.pushColorTemperatureChanges();
485
+ }
486
+ // Push Hue & Saturation Update
487
+ if (this.On) {
488
+ await this.pushHueSaturationChanges();
432
489
  }
433
- const body = (0, super_stringify_1.default)({
434
- 'command': `${command}`,
435
- 'parameter': 'default',
436
- 'commandType': 'command',
437
- });
438
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
439
- const options = {
440
- hostname: settings_1.HostDomain,
441
- port: 443,
442
- path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
443
- method: 'POST',
444
- headers: {
445
- 'Authorization': this.platform.config.credentials?.token,
446
- 'sign': sign,
447
- 'nonce': nonce,
448
- 't': t,
449
- 'Content-Type': 'application/json',
450
- 'Content-Length': body.length,
451
- },
452
- };
453
- const req = https_1.default.request(options, res => {
454
- this.debugLog(`Color Bulb: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
455
- this.statusCode({ res });
456
- res.on('data', d => {
457
- this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
458
- });
459
- });
460
- req.on('error', (e) => {
461
- this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
462
- });
463
- req.write(body);
464
- req.end();
465
- this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${(0, super_stringify_1.default)(req)}`);
466
- }
467
- // Push Brightness Update
468
- if (this.On) {
469
- await this.pushBrightnessChanges();
470
- }
471
- // Push ColorTemperature Update
472
- if (this.On) {
473
- await this.pushColorTemperatureChanges();
474
490
  }
475
- // Push Hue & Saturation Update
476
- if (this.On) {
477
- await this.pushHueSaturationChanges();
491
+ catch (e) {
492
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
493
+ if (this.deviceLogging.includes('debug')) {
494
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
495
+ + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
496
+ }
497
+ this.apiError(e);
478
498
  }
479
499
  }
480
- catch (e) {
481
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
482
- if (this.deviceLogging.includes('debug')) {
483
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
484
- }
485
- this.apiError(e);
500
+ else {
501
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
486
502
  }
487
503
  }
488
504
  async pushHueSaturationChanges() {
489
505
  try {
490
506
  if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
491
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${(0, super_stringify_1.default)(this.Hue)}`);
492
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${(0, super_stringify_1.default)(this.Saturation)}`);
507
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${(0, super_stringify_1.default)(this.Hue)}`);
508
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${(0, super_stringify_1.default)(this.Saturation)}`);
493
509
  const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
494
- this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${(0, super_stringify_1.default)([red, green, blue])}`);
510
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${(0, super_stringify_1.default)([red, green, blue])}`);
495
511
  // Make Push Hue/Saturation request to the API
496
512
  const t = Date.now();
497
513
  const nonce = 'requestID';
@@ -500,13 +516,13 @@ class ColorBulb {
500
516
  .update(Buffer.from(data, 'utf-8'))
501
517
  .digest();
502
518
  const sign = signTerm.toString('base64');
503
- this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
519
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
504
520
  const body = (0, super_stringify_1.default)({
505
521
  'command': 'setColor',
506
522
  'parameter': `${red}:${green}:${blue}`,
507
523
  'commandType': 'command',
508
524
  });
509
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
525
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
510
526
  const options = {
511
527
  hostname: settings_1.HostDomain,
512
528
  port: 443,
@@ -522,28 +538,29 @@ class ColorBulb {
522
538
  },
523
539
  };
524
540
  const req = https_1.default.request(options, res => {
525
- this.debugLog(`Color Bulb: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
541
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
526
542
  res.on('data', d => {
527
- this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
543
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
528
544
  });
529
545
  });
530
546
  req.on('error', (e) => {
531
- this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
547
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
532
548
  });
533
549
  req.write(body);
534
550
  req.end();
535
- this.debugLog(`Color Bulb: ${this.accessory.displayName} pushHueSaturationChanges: ${(0, super_stringify_1.default)(req)}`);
551
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges: ${(0, super_stringify_1.default)(req)}`);
536
552
  }
537
553
  else {
538
- this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.` +
554
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
539
555
  `Hue: ${this.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation},`
540
556
  + ` SaturationCached: ${this.accessory.context.Saturation}`);
541
557
  }
542
558
  }
543
559
  catch (e) {
544
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
560
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
545
561
  if (this.deviceLogging.includes('debug')) {
546
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
562
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
563
+ + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
547
564
  }
548
565
  this.apiError(e);
549
566
  }
@@ -561,13 +578,13 @@ class ColorBulb {
561
578
  .update(Buffer.from(data, 'utf-8'))
562
579
  .digest();
563
580
  const sign = signTerm.toString('base64');
564
- this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
581
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
565
582
  const body = (0, super_stringify_1.default)({
566
583
  'command': 'setColorTemperature',
567
584
  'parameter': `${kelvin}`,
568
585
  'commandType': 'command',
569
586
  });
570
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
587
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
571
588
  const options = {
572
589
  hostname: settings_1.HostDomain,
573
590
  port: 443,
@@ -583,28 +600,29 @@ class ColorBulb {
583
600
  },
584
601
  };
585
602
  const req = https_1.default.request(options, res => {
586
- this.debugLog(`Color Bulb: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
603
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
587
604
  res.on('data', d => {
588
- this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
605
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
589
606
  });
590
607
  });
591
608
  req.on('error', (e) => {
592
- this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
609
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
593
610
  });
594
611
  req.write(body);
595
612
  req.end();
596
- this.debugLog(`Color Bulb: ${this.accessory.displayName} pushColorTemperatureChanges: ${(0, super_stringify_1.default)(req)}`);
613
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges: ${(0, super_stringify_1.default)(req)}`);
597
614
  this.accessory.context.ColorTemperature = this.ColorTemperature;
598
615
  }
599
616
  else {
600
- this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.` +
617
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
601
618
  `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
602
619
  }
603
620
  }
604
621
  catch (e) {
605
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
622
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
606
623
  if (this.deviceLogging.includes('debug')) {
607
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
624
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
625
+ + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
608
626
  }
609
627
  this.apiError(e);
610
628
  }
@@ -620,13 +638,13 @@ class ColorBulb {
620
638
  .update(Buffer.from(data, 'utf-8'))
621
639
  .digest();
622
640
  const sign = signTerm.toString('base64');
623
- this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
641
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
624
642
  const body = (0, super_stringify_1.default)({
625
643
  'command': 'setBrightness',
626
644
  'parameter': `${this.Brightness}`,
627
645
  'commandType': 'command',
628
646
  });
629
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
647
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
630
648
  const options = {
631
649
  hostname: settings_1.HostDomain,
632
650
  port: 443,
@@ -642,71 +660,72 @@ class ColorBulb {
642
660
  },
643
661
  };
644
662
  const req = https_1.default.request(options, res => {
645
- this.debugLog(`Color Bulb: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
663
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
646
664
  res.on('data', d => {
647
- this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
665
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
648
666
  });
649
667
  });
650
668
  req.on('error', (e) => {
651
- this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
669
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
652
670
  });
653
671
  req.write(body);
654
672
  req.end();
655
- this.debugLog(`Color Bulb: ${this.accessory.displayName} pushBrightnessChanges: ${(0, super_stringify_1.default)(req)}`);
673
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges: ${(0, super_stringify_1.default)(req)}`);
656
674
  }
657
675
  else {
658
- this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, `
676
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, `
659
677
  + `BrightnessCached: ${this.accessory.context.Brightness}`);
660
678
  }
661
679
  }
662
680
  catch (e) {
663
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
681
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
664
682
  if (this.deviceLogging.includes('debug')) {
665
- this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
683
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
684
+ + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
666
685
  }
667
686
  this.apiError(e);
668
687
  }
669
688
  }
670
689
  async updateHomeKitCharacteristics() {
671
690
  if (this.On === undefined) {
672
- this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
691
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
673
692
  }
674
693
  else {
675
694
  this.accessory.context.On = this.On;
676
695
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
677
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
696
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
678
697
  }
679
698
  if (this.Brightness === undefined) {
680
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
699
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
681
700
  }
682
701
  else {
683
702
  this.accessory.context.Brightness = this.Brightness;
684
703
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
685
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
704
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
686
705
  }
687
706
  if (this.ColorTemperature === undefined) {
688
- this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
707
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
689
708
  }
690
709
  else {
691
710
  this.accessory.context.ColorTemperature = this.ColorTemperature;
692
711
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
693
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
712
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
694
713
  }
695
714
  if (this.Hue === undefined) {
696
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
715
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
697
716
  }
698
717
  else {
699
718
  this.accessory.context.Hue = this.Hue;
700
719
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
701
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
720
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
702
721
  }
703
722
  if (this.Saturation === undefined) {
704
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
723
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
705
724
  }
706
725
  else {
707
726
  this.accessory.context.Saturation = this.Saturation;
708
727
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
709
- this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
728
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
710
729
  }
711
730
  }
712
731
  apiError(e) {
@@ -720,34 +739,34 @@ class ColorBulb {
720
739
  async statusCode({ res }) {
721
740
  switch (res.statusCode) {
722
741
  case 151:
723
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`);
742
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
724
743
  break;
725
744
  case 152:
726
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Device not found.`);
745
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
727
746
  break;
728
747
  case 160:
729
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Command is not supported.`);
748
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
730
749
  break;
731
750
  case 161:
732
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Device is offline.`);
751
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
733
752
  this.offlineOff();
734
753
  break;
735
754
  case 171:
736
- this.errorLog(`Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
755
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
737
756
  this.offlineOff();
738
757
  break;
739
758
  case 190:
740
- this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
759
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
741
760
  ` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
742
761
  break;
743
762
  case 100:
744
763
  if (this.platform.debugMode) {
745
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Command successfully sent.`);
764
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
746
765
  }
747
766
  break;
748
767
  default:
749
768
  if (this.platform.debugMode) {
750
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Unknown statusCode.`);
769
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
751
770
  }
752
771
  }
753
772
  }
@@ -761,7 +780,7 @@ class ColorBulb {
761
780
  * Handle requests to set the value of the "On" characteristic
762
781
  */
763
782
  async OnSet(value) {
764
- this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${value}`);
783
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${value}`);
765
784
  this.On = value;
766
785
  this.doColorBulbUpdate.next();
767
786
  }
@@ -769,7 +788,7 @@ class ColorBulb {
769
788
  * Handle requests to set the value of the "Brightness" characteristic
770
789
  */
771
790
  async BrightnessSet(value) {
772
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`);
791
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${value}`);
773
792
  this.Brightness = value;
774
793
  this.doColorBulbUpdate.next();
775
794
  }
@@ -777,7 +796,7 @@ class ColorBulb {
777
796
  * Handle requests to set the value of the "ColorTemperature" characteristic
778
797
  */
779
798
  async ColorTemperatureSet(value) {
780
- this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`);
799
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${value}`);
781
800
  // Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
782
801
  const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
783
802
  // Check and increase/decrease kelvin to range of device
@@ -796,7 +815,7 @@ class ColorBulb {
796
815
  * Handle requests to set the value of the "Hue" characteristic
797
816
  */
798
817
  async HueSet(value) {
799
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
818
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${value}`);
800
819
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
801
820
  this.Hue = value;
802
821
  this.doColorBulbUpdate.next();
@@ -805,7 +824,7 @@ class ColorBulb {
805
824
  * Handle requests to set the value of the "Saturation" characteristic
806
825
  */
807
826
  async SaturationSet(value) {
808
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
827
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${value}`);
809
828
  this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
810
829
  this.Saturation = value;
811
830
  this.doColorBulbUpdate.next();
@@ -818,6 +837,9 @@ class ColorBulb {
818
837
  if (device.ble) {
819
838
  config['ble'] = device.ble;
820
839
  }
840
+ if (device.openAPI !== undefined) {
841
+ config['openAPI'] = device.openAPI;
842
+ }
821
843
  if (device.logging !== undefined) {
822
844
  config['logging'] = device.logging;
823
845
  }
@@ -831,18 +853,27 @@ class ColorBulb {
831
853
  config['offline'] = device.offline;
832
854
  }
833
855
  if (Object.entries(config).length !== 0) {
834
- this.infoLog(`Color Bulb: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
856
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
835
857
  }
836
858
  }
837
859
  async refreshRate(device) {
838
860
  if (device.refreshRate) {
839
861
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
840
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
862
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
841
863
  }
842
864
  else if (this.platform.config.options.refreshRate) {
843
865
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
844
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
866
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
867
+ }
868
+ }
869
+ async openAPI() {
870
+ if (!this.device.openAPI) {
871
+ this.OpenAPI = true;
872
+ }
873
+ else {
874
+ this.OpenAPI = this.device.openAPI;
845
875
  }
876
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
846
877
  }
847
878
  async scan(device) {
848
879
  if (device.scanDuration) {
@@ -861,26 +892,27 @@ class ColorBulb {
861
892
  async logs(device) {
862
893
  if (this.platform.debugMode) {
863
894
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
864
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
895
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
865
896
  }
866
897
  else if (device.logging) {
867
898
  this.deviceLogging = this.accessory.context.logging = device.logging;
868
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
899
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
869
900
  }
870
901
  else if (this.platform.config.options?.logging) {
871
902
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
872
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
903
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
873
904
  }
874
905
  else {
875
906
  this.deviceLogging = this.accessory.context.logging = 'standard';
876
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
907
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
877
908
  }
878
909
  }
879
910
  FirmwareRevision(accessory, device) {
880
911
  let FirmwareRevision;
881
- this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
882
- this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
883
- this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
912
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
913
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
914
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
915
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
884
916
  if (accessory.context.FirmwareRevision) {
885
917
  FirmwareRevision = accessory.context.FirmwareRevision;
886
918
  }
@@ -895,11 +927,11 @@ class ColorBulb {
895
927
  async adaptiveLighting(device) {
896
928
  if (device.colorbulb?.adaptiveLightingShift) {
897
929
  this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
898
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
930
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
899
931
  }
900
932
  else {
901
933
  this.adaptiveLightingShift = 0;
902
- this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
934
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
903
935
  }
904
936
  }
905
937
  minStep(device) {