@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
@@ -45,6 +45,7 @@ export class Contact {
45
45
  lightLevel!: serviceData['lightLevel'];
46
46
 
47
47
  // Config
48
+ OpenAPI?: boolean;
48
49
  set_minLux!: number;
49
50
  set_maxLux!: number;
50
51
  scanDuration!: number;
@@ -58,6 +59,7 @@ export class Contact {
58
59
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
59
60
  // default placeholders
60
61
  this.logs(device);
62
+ this.openAPI();
61
63
  this.scan(device);
62
64
  this.refreshRate(device);
63
65
  this.config(device);
@@ -99,49 +101,49 @@ export class Contact {
99
101
 
100
102
  // Motion Sensor Service
101
103
  if (device.contact?.hide_motionsensor) {
102
- this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Motion Sensor Service`);
104
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Motion Sensor Service`);
103
105
  this.motionService = this.accessory.getService(this.platform.Service.MotionSensor);
104
106
  accessory.removeService(this.motionService!);
105
107
  } else if (!this.motionService) {
106
- this.debugLog(`Contact Sensor: ${accessory.displayName} Add Motion Sensor Service`);
108
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Motion Sensor Service`);
107
109
  (this.motionService =
108
110
  this.accessory.getService(this.platform.Service.MotionSensor) || this.accessory.addService(this.platform.Service.MotionSensor)),
109
111
  `${accessory.displayName} Motion Sensor`;
110
112
 
111
113
  this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`);
112
114
  } else {
113
- this.debugLog(`Contact Sensor: ${accessory.displayName} Motion Sensor Service Not Added`);
115
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Motion Sensor Service Not Added`);
114
116
  }
115
117
 
116
118
  // Light Sensor Service
117
119
  if (device.contact?.hide_lightsensor) {
118
- this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Light Sensor Service`);
120
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
119
121
  this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
120
122
  accessory.removeService(this.lightSensorService!);
121
123
  } else if (!this.lightSensorService) {
122
- this.debugLog(`Contact Sensor: ${accessory.displayName} Add Light Sensor Service`);
124
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
123
125
  (this.lightSensorService =
124
126
  this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
125
127
  `${accessory.displayName} Light Sensor`;
126
128
 
127
129
  this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
128
130
  } else {
129
- this.debugLog(`Contact Sensor: ${accessory.displayName} Light Sensor Service Not Added`);
131
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
130
132
  }
131
133
 
132
134
  // Battery Service
133
135
  if (!device.ble) {
134
- this.debugLog(`Contact Sensor: ${accessory.displayName} Removing Battery Service`);
136
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
135
137
  this.batteryService = this.accessory.getService(this.platform.Service.Battery);
136
138
  accessory.removeService(this.batteryService!);
137
139
  } else if (device.ble && !this.batteryService) {
138
- this.debugLog(`Contact Sensor: ${accessory.displayName} Add Battery Service`);
140
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
139
141
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
140
142
  `${accessory.displayName} Battery`;
141
143
 
142
144
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
143
145
  } else {
144
- this.debugLog(`Contact Sensor: ${accessory.displayName} Battery Service Not Added`);
146
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
145
147
  }
146
148
 
147
149
  // Retrieve initial values and updateHomekit
@@ -167,7 +169,7 @@ export class Contact {
167
169
  }
168
170
 
169
171
  async BLEparseStatus(): Promise<void> {
170
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE parseStatus`);
172
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
171
173
  // Door State
172
174
  switch (this.doorState) {
173
175
  case 'open':
@@ -179,12 +181,12 @@ export class Contact {
179
181
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
180
182
  break;
181
183
  default:
182
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
184
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} timeout no closed, doorstate: ${this.doorState}`);
183
185
  }
184
186
  // Movement
185
187
  if (!this.device.contact?.hide_motionsensor) {
186
188
  this.MotionDetected = Boolean(this.movement);
187
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
189
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
188
190
  }
189
191
  // Light Level
190
192
  if (!this.device.contact?.hide_lightsensor) {
@@ -199,7 +201,7 @@ export class Contact {
199
201
  this.CurrentAmbientLightLevel = this.set_maxLux;
200
202
  }
201
203
  this.debugLog(
202
- `Contact Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
204
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
203
205
  ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
204
206
  );
205
207
  }
@@ -213,7 +215,8 @@ export class Contact {
213
215
  } else {
214
216
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
215
217
  }
216
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
218
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, `
219
+ + `StatusLowBattery: ${this.StatusLowBattery}`);
217
220
  }
218
221
 
219
222
  async openAPIparseStatus(): Promise<void> {
@@ -221,21 +224,21 @@ export class Contact {
221
224
  this.SwitchToOpenAPI = false;
222
225
  }
223
226
  if (this.platform.config.credentials?.token) {
224
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
227
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI parseStatus`);
225
228
  // Contact State
226
229
  if (this.openState === 'open') {
227
230
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
228
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
231
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
229
232
  } else if (this.openState === 'close') {
230
233
  this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;
231
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
234
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
232
235
  } else {
233
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} openState: ${this.openState}`);
236
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openState: ${this.openState}`);
234
237
  }
235
238
  // Motion State
236
239
  if (!this.device.contact?.hide_motionsensor) {
237
240
  this.MotionDetected = this.moveDetected!;
238
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
241
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
239
242
  }
240
243
  // Light Level
241
244
  if (!this.device.contact?.hide_lightsensor) {
@@ -249,7 +252,7 @@ export class Contact {
249
252
  default:
250
253
  this.CurrentAmbientLightLevel = this.set_maxLux;
251
254
  }
252
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
255
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
253
256
  }
254
257
  }
255
258
  }
@@ -266,7 +269,7 @@ export class Contact {
266
269
  }
267
270
 
268
271
  async BLERefreshStatus(): Promise<void> {
269
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE refreshStatus`);
272
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE refreshStatus`);
270
273
  const switchbot = await this.platform.connectBLE();
271
274
  // Convert to BLE Address
272
275
  this.device.bleMac =
@@ -275,7 +278,7 @@ export class Contact {
275
278
  .deviceId!.match(/.{1,2}/g)!
276
279
  .join(':')
277
280
  .toLowerCase();
278
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
281
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
279
282
  this.getCustomBLEAddress(switchbot);
280
283
  // Start to monitor advertisement packets
281
284
  if (switchbot !== false) {
@@ -291,26 +294,26 @@ export class Contact {
291
294
  if (this.deviceLogging.includes('debug')) {
292
295
  this.infoLog(this.address);
293
296
  this.infoLog(this.device.bleMac);
294
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
295
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
297
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
298
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
296
299
  }
297
300
  this.serviceData = ad.serviceData;
298
301
  this.movement = ad.serviceData.movement;
299
302
  this.doorState = ad.serviceData.doorState;
300
303
  this.lightLevel = ad.serviceData.lightLevel;
301
304
  this.battery = ad.serviceData.battery;
302
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
305
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
303
306
  this.debugLog(
304
- `Contact Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
307
+ `${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, doorState: ` +
305
308
  `${ad.serviceData.doorState}, lightLevel: ${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
306
309
  );
307
310
 
308
311
  if (this.serviceData) {
309
312
  this.connected = true;
310
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
313
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
311
314
  } else {
312
315
  this.connected = false;
313
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
316
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
314
317
  }
315
318
  };
316
319
  // Wait 2 seconds
@@ -327,15 +330,15 @@ export class Contact {
327
330
  }
328
331
  })
329
332
  .catch(async (e: any) => {
330
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
333
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
331
334
  if (this.deviceLogging.includes('debug')) {
332
335
  this.errorLog(
333
- `Contact Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
336
+ `${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
334
337
  ` Error Message: ${superStringify(e.message)}`,
335
338
  );
336
339
  }
337
340
  if (this.platform.config.credentials?.token) {
338
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
341
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
339
342
  this.SwitchToOpenAPI = true;
340
343
  await this.openAPIRefreshStatus();
341
344
  }
@@ -355,7 +358,7 @@ export class Contact {
355
358
  });
356
359
  // Set an event handler
357
360
  switchbot.onadvertisement = (ad: any) => {
358
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
361
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
359
362
  };
360
363
  await switchbot.wait(10000);
361
364
  // Stop to monitor
@@ -365,24 +368,24 @@ export class Contact {
365
368
  }
366
369
 
367
370
  async BLEconnection(switchbot: any): Promise<void> {
368
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
371
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
369
372
  if (this.platform.config.credentials?.token) {
370
- this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
373
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
371
374
  this.SwitchToOpenAPI = true;
372
375
  await this.openAPIRefreshStatus();
373
376
  }
374
377
  }
375
378
 
376
379
  async openAPIRefreshStatus(): Promise<void> {
377
- if (this.platform.config.credentials?.token) {
378
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} OpenAPI refreshStatus`);
380
+ if (this.platform.config.credentials?.token && this.OpenAPI) {
381
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI refreshStatus`);
379
382
  try {
380
383
  const t = Date.now();
381
384
  const nonce = 'requestID';
382
385
  const data = this.platform.config.credentials?.token + t + nonce;
383
386
  const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
384
387
  const sign = signTerm.toString('base64');
385
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} sign: ${sign}`);
388
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
386
389
  const options = {
387
390
  hostname: HostDomain,
388
391
  port: 443,
@@ -397,40 +400,42 @@ export class Contact {
397
400
  },
398
401
  };
399
402
  const req = https.request(options, (res) => {
400
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
403
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
401
404
  let rawData = '';
402
405
  res.on('data', (d) => {
403
406
  rawData += d;
404
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} d: ${d}`);
407
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
405
408
  });
406
409
  res.on('end', () => {
407
410
  try {
408
411
  this.deviceStatus = JSON.parse(rawData);
409
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
412
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
410
413
  this.openState = this.deviceStatus.body.openState;
411
414
  this.moveDetected = this.deviceStatus.body.moveDetected;
412
415
  this.brightness = this.deviceStatus.body.brightness;
413
416
  this.parseStatus();
414
417
  this.updateHomeKitCharacteristics();
415
418
  } catch (e: any) {
416
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} error message: ${e.message}`);
419
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
417
420
  }
418
421
  });
419
422
  });
420
423
  req.on('error', (e: any) => {
421
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} error message: ${e.message}`);
424
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
422
425
  });
423
426
  req.end();
424
427
  } catch (e: any) {
425
- this.errorLog(`Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
428
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
426
429
  if (this.deviceLogging.includes('debug')) {
427
430
  this.errorLog(
428
- `Contact Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
431
+ `${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
429
432
  ` Error Message: ${superStringify(e.message)}`,
430
433
  );
431
434
  }
432
435
  this.apiError(e);
433
436
  }
437
+ } else {
438
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
434
439
  }
435
440
  }
436
441
 
@@ -439,41 +444,42 @@ export class Contact {
439
444
  */
440
445
  async updateHomeKitCharacteristics(): Promise<void> {
441
446
  if (this.ContactSensorState === undefined) {
442
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
447
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
443
448
  } else {
444
449
  this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState);
445
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
450
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
446
451
  }
447
452
  if (!this.device.contact?.hide_motionsensor) {
448
453
  if (this.MotionDetected === undefined) {
449
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
454
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
450
455
  } else {
451
456
  this.motionService?.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
452
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
457
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
453
458
  }
454
459
  }
455
460
  if (!this.device.contact?.hide_lightsensor) {
456
461
  if (this.CurrentAmbientLightLevel === undefined) {
457
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
462
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
458
463
  } else {
459
464
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
460
465
  this.debugLog(
461
- `Contact Sensor: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
466
+ `${this.device.deviceType}: ${this.accessory.displayName}`
467
+ + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
462
468
  );
463
469
  }
464
470
  }
465
471
  if (this.device.ble) {
466
472
  if (this.BatteryLevel === undefined) {
467
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
473
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
468
474
  } else {
469
475
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
470
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
476
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
471
477
  }
472
478
  if (this.StatusLowBattery === undefined) {
473
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
479
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
474
480
  } else {
475
481
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
476
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
482
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
477
483
  }
478
484
  }
479
485
  }
@@ -501,6 +507,9 @@ export class Contact {
501
507
  if (device.ble) {
502
508
  config['ble'] = device.ble;
503
509
  }
510
+ if (device.openAPI !== undefined) {
511
+ config['openAPI'] = device.openAPI;
512
+ }
504
513
  if (device.logging !== undefined) {
505
514
  config['logging'] = device.logging;
506
515
  }
@@ -511,30 +520,39 @@ export class Contact {
511
520
  config['scanDuration'] = device.scanDuration;
512
521
  }
513
522
  if (Object.entries(config).length !== 0) {
514
- this.infoLog(`Contact Sensor: ${this.accessory.displayName} Config: ${superStringify(config)}`);
523
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
515
524
  }
516
525
  }
517
526
 
518
527
  async refreshRate(device: device & devicesConfig): Promise<void> {
519
528
  if (device.refreshRate) {
520
529
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
521
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
530
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
522
531
  } else if (this.platform.config.options!.refreshRate) {
523
532
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
524
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
533
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
534
+ }
535
+ }
536
+
537
+ async openAPI() {
538
+ if (!this.device.openAPI) {
539
+ this.OpenAPI = true;
540
+ } else {
541
+ this.OpenAPI = this.device.openAPI;
525
542
  }
543
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
526
544
  }
527
545
 
528
546
  async scan(device: device & devicesConfig): Promise<void> {
529
547
  if (device.scanDuration) {
530
548
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
531
549
  if (device.ble) {
532
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
550
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
533
551
  }
534
552
  } else {
535
553
  this.scanDuration = this.accessory.context.scanDuration = 1;
536
554
  if (this.device.ble) {
537
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
555
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
538
556
  }
539
557
  }
540
558
  }
@@ -542,24 +560,25 @@ export class Contact {
542
560
  async logs(device: device & devicesConfig): Promise<void> {
543
561
  if (this.platform.debugMode) {
544
562
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
545
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
563
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
546
564
  } else if (device.logging) {
547
565
  this.deviceLogging = this.accessory.context.logging = device.logging;
548
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
566
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
549
567
  } else if (this.platform.config.options?.logging) {
550
568
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
551
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
569
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
552
570
  } else {
553
571
  this.deviceLogging = this.accessory.context.logging = 'standard';
554
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
572
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
555
573
  }
556
574
  }
557
575
 
558
576
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
559
577
  let FirmwareRevision: string;
560
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
561
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
562
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
578
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
579
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
580
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
581
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
563
582
  if (accessory.context.FirmwareRevision) {
564
583
  FirmwareRevision = accessory.context.FirmwareRevision;
565
584
  } else if (device.firmware) {