@switchbot/homebridge-switchbot 2.0.0-beta.18 → 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 +11 -2
  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
@@ -41,6 +41,7 @@ export class Motion {
41
41
  lightLevel!: serviceData['lightLevel'];
42
42
 
43
43
  // Config
44
+ OpenAPI?: boolean;
44
45
  set_minLux!: number;
45
46
  set_maxLux!: number;
46
47
  scanDuration!: number;
@@ -54,6 +55,7 @@ export class Motion {
54
55
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
55
56
  // default placeholders
56
57
  this.logs(device);
58
+ this.openAPI();
57
59
  this.scan(device);
58
60
  this.refreshRate(device);
59
61
  this.config(device);
@@ -94,33 +96,33 @@ export class Motion {
94
96
 
95
97
  // Light Sensor Service
96
98
  if (device.motion?.hide_lightsensor) {
97
- this.debugLog(`Motion Sensor: ${accessory.displayName} Removing Light Sensor Service`);
99
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
98
100
  this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
99
101
  accessory.removeService(this.lightSensorService!);
100
102
  } else if (!this.lightSensorService) {
101
- this.debugLog(`Motion Sensor: ${accessory.displayName} Add Light Sensor Service`);
103
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
102
104
  (this.lightSensorService =
103
105
  this.accessory.getService(this.platform.Service.LightSensor) || this.accessory.addService(this.platform.Service.LightSensor)),
104
106
  `${accessory.displayName} Light Sensor`;
105
107
 
106
108
  this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
107
109
  } else {
108
- this.debugLog(`Motion Sensor: ${accessory.displayName} Light Sensor Service Not Added`);
110
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Light Sensor Service Not Added`);
109
111
  }
110
112
 
111
113
  // Battery Service
112
114
  if (!device.ble) {
113
- this.debugLog(`Motion Sensor: ${accessory.displayName} Removing Battery Service`);
115
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
114
116
  this.batteryService = this.accessory.getService(this.platform.Service.Battery);
115
117
  accessory.removeService(this.batteryService!);
116
118
  } else if (device.ble && !this.batteryService) {
117
- this.debugLog(`Motion Sensor: ${accessory.displayName} Add Battery Service`);
119
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
118
120
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
119
121
  `${accessory.displayName} Battery`;
120
122
 
121
123
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
122
124
  } else {
123
- this.debugLog(`Motion Sensor: ${accessory.displayName} Battery Service Not Added`);
125
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
124
126
  }
125
127
 
126
128
  // Retrieve initial values and updateHomekit
@@ -146,10 +148,10 @@ export class Motion {
146
148
  }
147
149
 
148
150
  async BLEparseStatus(): Promise<void> {
149
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE parseStatus`);
151
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
150
152
  // Movement
151
153
  this.MotionDetected = this.movement!;
152
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
154
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
153
155
  // Light Level
154
156
  if (!this.device.motion?.hide_lightsensor) {
155
157
  this.set_minLux = this.minLux();
@@ -163,7 +165,7 @@ export class Motion {
163
165
  this.CurrentAmbientLightLevel = this.set_maxLux;
164
166
  }
165
167
  this.debugLog(
166
- `Motion Sensor: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
168
+ `${this.device.deviceType}: ${this.accessory.displayName} LightLevel: ${this.lightLevel},` +
167
169
  ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
168
170
  );
169
171
  }
@@ -177,7 +179,8 @@ export class Motion {
177
179
  } else {
178
180
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
179
181
  }
180
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
182
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
183
+ +` StatusLowBattery: ${this.StatusLowBattery}`);
181
184
  }
182
185
 
183
186
  async openAPIparseStatus(): Promise<void> {
@@ -185,10 +188,10 @@ export class Motion {
185
188
  this.SwitchToOpenAPI = false;
186
189
  }
187
190
  if (this.platform.config.credentials?.token) {
188
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
191
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI parseStatus`);
189
192
  // Motion State
190
193
  this.MotionDetected = this.moveDetected!;
191
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
194
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
192
195
  // Light Level
193
196
  if (!this.device.motion?.hide_lightsensor) {
194
197
  this.set_minLux = this.minLux();
@@ -201,7 +204,7 @@ export class Motion {
201
204
  default:
202
205
  this.CurrentAmbientLightLevel = this.set_maxLux;
203
206
  }
204
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
207
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
205
208
  }
206
209
  }
207
210
  }
@@ -218,7 +221,7 @@ export class Motion {
218
221
  }
219
222
 
220
223
  async BLERefreshStatus(): Promise<void> {
221
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE RefreshStatus`);
224
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE RefreshStatus`);
222
225
  const switchbot = await this.platform.connectBLE();
223
226
  // Convert to BLE Address
224
227
  this.device.bleMac =
@@ -227,7 +230,7 @@ export class Motion {
227
230
  .deviceId!.match(/.{1,2}/g)!
228
231
  .join(':')
229
232
  .toLowerCase();
230
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
233
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
231
234
 
232
235
  this.getCustomBLEAddress(switchbot);
233
236
  // Start to monitor advertisement packets
@@ -244,25 +247,25 @@ export class Motion {
244
247
  if (this.deviceLogging.includes('debug')) {
245
248
  this.infoLog(this.address);
246
249
  this.infoLog(this.device.bleMac);
247
- this.infoLog(`Motion Sensor: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
248
- this.infoLog(`Motion Sensor: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
250
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
251
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
249
252
  }
250
253
  this.serviceData = ad.serviceData;
251
254
  this.movement = ad.serviceData.movement;
252
255
  this.battery = ad.serviceData.battery;
253
256
  this.lightLevel = ad.serviceData.lightLevel;
254
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
257
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
255
258
  this.debugLog(
256
- `Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: ` +
259
+ `${this.device.deviceType}: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: ` +
257
260
  `${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
258
261
  );
259
262
 
260
263
  if (this.serviceData) {
261
264
  this.connected = true;
262
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
265
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
263
266
  } else {
264
267
  this.connected = false;
265
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
268
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
266
269
  }
267
270
  };
268
271
  // Wait 10 seconds
@@ -279,15 +282,15 @@ export class Motion {
279
282
  }
280
283
  })
281
284
  .catch(async (e: any) => {
282
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
285
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
283
286
  if (this.deviceLogging.includes('debug')) {
284
287
  this.errorLog(
285
- `Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
288
+ `${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
286
289
  ` Error Message: ${superStringify(e.message)}`,
287
290
  );
288
291
  }
289
292
  if (this.platform.config.credentials?.token) {
290
- this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
293
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
291
294
  this.SwitchToOpenAPI = true;
292
295
  await this.openAPIRefreshStatus();
293
296
  }
@@ -307,7 +310,7 @@ export class Motion {
307
310
  });
308
311
  // Set an event handler
309
312
  switchbot.onadvertisement = (ad: any) => {
310
- this.warnLog(`Motion Sensor: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
313
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
311
314
  };
312
315
  await switchbot.wait(10000);
313
316
  // Stop to monitor
@@ -317,24 +320,24 @@ export class Motion {
317
320
  }
318
321
 
319
322
  async BLEconnection(switchbot: any): Promise<void> {
320
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
323
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
321
324
  if (this.platform.config.credentials?.token) {
322
- this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
325
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
323
326
  this.SwitchToOpenAPI = true;
324
327
  await this.openAPIRefreshStatus();
325
328
  }
326
329
  }
327
330
 
328
331
  async openAPIRefreshStatus(): Promise<void> {
329
- if (this.platform.config.credentials?.token) {
330
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI RefreshStatus`);
332
+ if (this.platform.config.credentials?.token && this.OpenAPI) {
333
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI RefreshStatus`);
331
334
  try {
332
335
  const t = Date.now();
333
336
  const nonce = 'requestID';
334
337
  const data = this.platform.config.credentials?.token + t + nonce;
335
338
  const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
336
339
  const sign = signTerm.toString('base64');
337
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} sign: ${sign}`);
340
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
338
341
  const options = {
339
342
  hostname: HostDomain,
340
343
  port: 443,
@@ -349,39 +352,41 @@ export class Motion {
349
352
  },
350
353
  };
351
354
  const req = https.request(options, (res) => {
352
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
355
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
353
356
  let rawData = '';
354
357
  res.on('data', (d) => {
355
358
  rawData += d;
356
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} d: ${d}`);
359
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
357
360
  });
358
361
  res.on('end', () => {
359
362
  try {
360
363
  this.deviceStatus = JSON.parse(rawData);
361
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
364
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
362
365
  this.moveDetected = this.deviceStatus.body.moveDetected;
363
366
  this.brightness = this.deviceStatus.body.brightness;
364
367
  this.parseStatus();
365
368
  this.updateHomeKitCharacteristics();
366
369
  } catch (e: any) {
367
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} error message: ${e.message}`);
370
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
368
371
  }
369
372
  });
370
373
  });
371
374
  req.on('error', (e: any) => {
372
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} error message: ${e.message}`);
375
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
373
376
  });
374
377
  req.end();
375
378
  } catch (e: any) {
376
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
379
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
377
380
  if (this.deviceLogging.includes('debug')) {
378
381
  this.errorLog(
379
- `Motion Sensor: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
382
+ `${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
380
383
  ` Error Message: ${superStringify(e.message)}`,
381
384
  );
382
385
  }
383
386
  this.apiError(e);
384
387
  }
388
+ } else {
389
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
385
390
  }
386
391
  }
387
392
 
@@ -390,30 +395,31 @@ export class Motion {
390
395
  */
391
396
  async updateHomeKitCharacteristics(): Promise<void> {
392
397
  if (this.MotionDetected === undefined) {
393
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
398
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
394
399
  } else {
395
400
  this.motionSensorService.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected);
396
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
401
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`);
397
402
  }
398
403
  if (this.device.ble) {
399
404
  if (this.BatteryLevel === undefined) {
400
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
405
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
401
406
  } else {
402
407
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
403
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
408
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
404
409
  }
405
410
  if (this.StatusLowBattery === undefined) {
406
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
411
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
407
412
  } else {
408
413
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
409
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
414
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
410
415
  }
411
416
  if (this.CurrentAmbientLightLevel === undefined) {
412
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
417
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
413
418
  } else {
414
419
  this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
415
420
  this.debugLog(
416
- `Motion Sensor: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
421
+ `${this.device.deviceType}: ${this.accessory.displayName}`
422
+ + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`,
417
423
  );
418
424
  }
419
425
  }
@@ -437,6 +443,9 @@ export class Motion {
437
443
  if (device.ble !== undefined) {
438
444
  config['ble'] = device.ble;
439
445
  }
446
+ if (device.openAPI !== undefined) {
447
+ config['openAPI'] = device.openAPI;
448
+ }
440
449
  if (device.logging !== undefined) {
441
450
  config['logging'] = device.logging;
442
451
  }
@@ -450,30 +459,39 @@ export class Motion {
450
459
  config['offline'] = device.offline;
451
460
  }
452
461
  if (Object.entries(config).length !== 0) {
453
- this.infoLog(`Motion Sensor: ${this.accessory.displayName} Config: ${superStringify(config)}`);
462
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
454
463
  }
455
464
  }
456
465
 
457
466
  async refreshRate(device: device & devicesConfig): Promise<void> {
458
467
  if (device.refreshRate) {
459
468
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
460
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
469
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
461
470
  } else if (this.platform.config.options!.refreshRate) {
462
471
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
463
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
472
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
473
+ }
474
+ }
475
+
476
+ async openAPI() {
477
+ if (!this.device.openAPI) {
478
+ this.OpenAPI = true;
479
+ } else {
480
+ this.OpenAPI = this.device.openAPI;
464
481
  }
482
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
465
483
  }
466
484
 
467
485
  async scan(device: device & devicesConfig): Promise<void> {
468
486
  if (device.scanDuration) {
469
487
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
470
488
  if (device.ble) {
471
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
489
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
472
490
  }
473
491
  } else {
474
492
  this.scanDuration = this.accessory.context.scanDuration = 1;
475
493
  if (this.device.ble) {
476
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
494
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
477
495
  }
478
496
  }
479
497
  }
@@ -481,24 +499,25 @@ export class Motion {
481
499
  async logs(device: device & devicesConfig): Promise<void> {
482
500
  if (this.platform.debugMode) {
483
501
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
484
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
502
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
485
503
  } else if (device.logging) {
486
504
  this.deviceLogging = this.accessory.context.logging = device.logging;
487
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
505
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
488
506
  } else if (this.platform.config.options?.logging) {
489
507
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
490
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
508
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
491
509
  } else {
492
510
  this.deviceLogging = this.accessory.context.logging = 'standard';
493
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
511
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
494
512
  }
495
513
  }
496
514
 
497
515
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
498
516
  let FirmwareRevision: string;
499
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
500
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
501
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
517
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
518
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
519
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
520
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
502
521
  if (accessory.context.FirmwareRevision) {
503
522
  FirmwareRevision = accessory.context.FirmwareRevision;
504
523
  } else if (device.firmware) {