@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 Meter {
45
45
  humidity!: serviceData['humidity'];
46
46
 
47
47
  // Config
48
+ OpenAPI?: boolean;
48
49
  scanDuration!: number;
49
50
  deviceLogging!: string;
50
51
  deviceRefreshRate!: number;
@@ -62,6 +63,7 @@ export class Meter {
62
63
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
63
64
  // default placeholders
64
65
  this.logs(device);
66
+ this.openAPI();
65
67
  this.scan(device);
66
68
  this.setupHistoryService(device);
67
69
  this.refreshRate(device);
@@ -97,11 +99,11 @@ export class Meter {
97
99
 
98
100
  // Temperature Sensor Service
99
101
  if (device.meter?.hide_temperature) {
100
- this.debugLog(`Meter: ${accessory.displayName} Removing Temperature Sensor Service`);
102
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
101
103
  this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
102
104
  accessory.removeService(this.temperatureservice!);
103
105
  } else if (!this.temperatureservice) {
104
- this.debugLog(`Meter: ${accessory.displayName} Add Temperature Sensor Service`);
106
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
105
107
  (this.temperatureservice =
106
108
  this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
107
109
  `${accessory.displayName} Temperature Sensor`;
@@ -121,16 +123,16 @@ export class Meter {
121
123
  return this.CurrentTemperature!;
122
124
  });
123
125
  } else {
124
- this.debugLog(`Meter: ${accessory.displayName} Temperature Sensor Service Not Added`);
126
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
125
127
  }
126
128
 
127
129
  // Humidity Sensor Service
128
130
  if (device.meter?.hide_humidity) {
129
- this.debugLog(`Meter: ${accessory.displayName} Removing Humidity Sensor Service`);
131
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
130
132
  this.humidityservice = this.accessory.getService(this.platform.Service.HumiditySensor);
131
133
  accessory.removeService(this.humidityservice!);
132
134
  } else if (!this.humidityservice) {
133
- this.debugLog(`Meter: ${accessory.displayName} Add Humidity Sensor Service`);
135
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
134
136
  (this.humidityservice =
135
137
  this.accessory.getService(this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor)),
136
138
  `${accessory.displayName} Humidity Sensor`;
@@ -146,16 +148,16 @@ export class Meter {
146
148
  return this.CurrentRelativeHumidity;
147
149
  });
148
150
  } else {
149
- this.debugLog(`Meter: ${accessory.displayName} Humidity Sensor Service Not Added`);
151
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
150
152
  }
151
153
 
152
154
  // Battery Service
153
155
  if (!device.ble) {
154
- this.debugLog(`Meter: ${accessory.displayName} Removing Battery Service`);
156
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
155
157
  this.batteryService = this.accessory.getService(this.platform.Service.Battery);
156
158
  accessory.removeService(this.batteryService!);
157
159
  } else if (device.ble && !this.batteryService) {
158
- this.debugLog(`Meter: ${accessory.displayName} Add Battery Service`);
160
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
159
161
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
160
162
  `${accessory.displayName} Battery`;
161
163
 
@@ -163,7 +165,7 @@ export class Meter {
163
165
 
164
166
  this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
165
167
  } else {
166
- this.debugLog(`Meter: ${accessory.displayName} Battery Service Not Added`);
168
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
167
169
  }
168
170
 
169
171
  // Retrieve initial values and updateHomekit
@@ -188,7 +190,7 @@ export class Meter {
188
190
  ?.join(':');
189
191
  const options = this.device.mqttPubOptions || {};
190
192
  this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
191
- this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${message} options:${superStringify(options)}`);
193
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${message} options:${superStringify(options)}`);
192
194
  }
193
195
 
194
196
  /*
@@ -198,13 +200,13 @@ export class Meter {
198
200
  if (device.mqttURL) {
199
201
  try {
200
202
  this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
201
- this.debugLog(`Meter: ${this.accessory.displayName} MQTT connection has been established successfully.`);
203
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
202
204
  this.mqttClient.on('error', (e: Error) => {
203
- this.errorLog(`Meter: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
205
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
204
206
  });
205
207
  } catch (e) {
206
208
  this.mqttClient = null;
207
- this.errorLog(`Meter: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
209
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
208
210
  }
209
211
  }
210
212
  }
@@ -238,7 +240,7 @@ export class Meter {
238
240
  }
239
241
 
240
242
  async BLEparseStatus(): Promise<void> {
241
- this.debugLog(`Meter: ${this.accessory.displayName} BLE parseStatus`);
243
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
242
244
 
243
245
  // Battery
244
246
  this.BatteryLevel = Number(this.battery);
@@ -247,19 +249,20 @@ export class Meter {
247
249
  } else {
248
250
  this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
249
251
  }
250
- this.debugLog(`Meter: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
252
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
253
+ + ` StatusLowBattery: ${this.StatusLowBattery}`);
251
254
 
252
255
  // Humidity
253
256
  if (!this.device.meter?.hide_humidity) {
254
257
  this.CurrentRelativeHumidity = this.humidity!;
255
- this.debugLog(`Meter: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
258
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
256
259
  }
257
260
 
258
261
  // Current Temperature
259
262
  if (!this.device.meter?.hide_temperature) {
260
263
  this.temperature < 0 ? 0 : this.temperature > 100 ? 100 : this.temperature;
261
264
  this.CurrentTemperature = this.temperature;
262
- this.debugLog(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
265
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
263
266
  }
264
267
  }
265
268
 
@@ -268,17 +271,17 @@ export class Meter {
268
271
  this.SwitchToOpenAPI = false;
269
272
  }
270
273
  if (this.platform.config.credentials?.token) {
271
- this.debugLog(`Meter: ${this.accessory.displayName} OpenAPI parseStatus`);
274
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI parseStatus`);
272
275
  // Current Relative Humidity
273
276
  if (!this.device.meter?.hide_humidity) {
274
277
  this.CurrentRelativeHumidity = this.Humidity!;
275
- this.debugLog(`Meter: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
278
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
276
279
  }
277
280
 
278
281
  // Current Temperature
279
282
  if (!this.device.meter?.hide_temperature) {
280
283
  this.CurrentTemperature = this.Temperature!;
281
- this.debugLog(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
284
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
282
285
  }
283
286
  }
284
287
  }
@@ -295,14 +298,14 @@ export class Meter {
295
298
  }
296
299
 
297
300
  async BLErefreshStatus(): Promise<void> {
298
- this.debugLog(`Meter: ${this.accessory.displayName} BLE RefreshStatus`);
301
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE RefreshStatus`);
299
302
  const switchbot = await this.platform.connectBLE();
300
303
  // Convert to BLE Address
301
304
  this.device.bleMac = this.device
302
305
  .deviceId!.match(/.{1,2}/g)!
303
306
  .join(':')
304
307
  .toLowerCase();
305
- this.debugLog(`Meter: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
308
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
306
309
  this.getCustomBLEAddress(switchbot);
307
310
  // Start to monitor advertisement packets
308
311
  if (switchbot !== false) {
@@ -318,8 +321,8 @@ export class Meter {
318
321
  if (this.deviceLogging.includes('debug')) {
319
322
  this.infoLog(this.address);
320
323
  this.infoLog(this.device.bleMac);
321
- this.infoLog(`Meter: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
322
- this.infoLog(`Meter: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
324
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
325
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
323
326
  }
324
327
  if (ad.serviceData.humidity! > 0) {
325
328
  // reject unreliable data
@@ -328,19 +331,19 @@ export class Meter {
328
331
  this.humidity = ad.serviceData.humidity;
329
332
  this.battery = ad.serviceData.battery;
330
333
  }
331
- this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
334
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
332
335
  this.debugLog(
333
- `Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
336
+ `${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
334
337
  `temperature: ${superStringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
335
338
  `battery: ${ad.serviceData.battery}`,
336
339
  );
337
340
 
338
341
  if (this.serviceData) {
339
342
  this.connected = true;
340
- this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
343
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
341
344
  } else {
342
345
  this.connected = false;
343
- this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
346
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
344
347
  }
345
348
  };
346
349
  // Wait 10 seconds
@@ -357,14 +360,15 @@ export class Meter {
357
360
  }
358
361
  })
359
362
  .catch(async (e: any) => {
360
- this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
363
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
361
364
  if (this.deviceLogging.includes('debug')) {
362
365
  this.errorLog(
363
- `Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${superStringify(e.message)}`,
366
+ `${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
367
+ + ` Error Message: ${superStringify(e.message)}`,
364
368
  );
365
369
  }
366
370
  if (this.platform.config.credentials?.token) {
367
- this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
371
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
368
372
  this.SwitchToOpenAPI = true;
369
373
  this.openAPIRefreshStatus();
370
374
  }
@@ -384,7 +388,7 @@ export class Meter {
384
388
  });
385
389
  // Set an event handler
386
390
  switchbot.onadvertisement = (ad: any) => {
387
- this.warnLog(`Meter: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
391
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
388
392
  };
389
393
  await switchbot.wait(10000);
390
394
  // Stop to monitor
@@ -394,24 +398,24 @@ export class Meter {
394
398
  }
395
399
 
396
400
  async BLEconnection(switchbot: any): Promise<void> {
397
- this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
401
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
398
402
  if (this.platform.config.credentials?.token) {
399
- this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
403
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
400
404
  this.SwitchToOpenAPI = true;
401
405
  await this.openAPIRefreshStatus();
402
406
  }
403
407
  }
404
408
 
405
409
  async openAPIRefreshStatus(): Promise<void> {
406
- if (this.platform.config.credentials?.token) {
407
- this.debugLog(`Meter: ${this.accessory.displayName} OpenAPI RefreshStatus`);
410
+ if (this.platform.config.credentials?.token && this.OpenAPI) {
411
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI RefreshStatus`);
408
412
  try {
409
413
  const t = Date.now();
410
414
  const nonce = 'requestID';
411
415
  const data = this.platform.config.credentials?.token + t + nonce;
412
416
  const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
413
417
  const sign = signTerm.toString('base64');
414
- this.debugLog(`Meter: ${this.accessory.displayName} sign: ${sign}`);
418
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
415
419
  const options = {
416
420
  hostname: HostDomain,
417
421
  port: 443,
@@ -426,38 +430,41 @@ export class Meter {
426
430
  },
427
431
  };
428
432
  const req = https.request(options, (res) => {
429
- this.debugLog(`Meter: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
433
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
430
434
  let rawData = '';
431
435
  res.on('data', (d) => {
432
436
  rawData += d;
433
- this.debugLog(`Meter: ${this.accessory.displayName} d: ${d}`);
437
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
434
438
  });
435
439
  res.on('end', () => {
436
440
  try {
437
441
  this.deviceStatus = JSON.parse(rawData);
438
- this.debugLog(`Meter: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
442
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
439
443
  this.Humidity = this.deviceStatus.body.humidity!;
440
444
  this.Temperature = this.deviceStatus.body.temperature!;
441
445
  this.parseStatus();
442
446
  this.updateHomeKitCharacteristics();
443
447
  } catch (e: any) {
444
- this.errorLog(`Meter: ${this.accessory.displayName} error message: ${e.message}`);
448
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
445
449
  }
446
450
  });
447
451
  });
448
452
  req.on('error', (e: any) => {
449
- this.errorLog(`Meter: ${this.accessory.displayName} error message: ${e.message}`);
453
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
450
454
  });
451
455
  req.end();
452
456
  } catch (e: any) {
453
- this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
457
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
454
458
  if (this.deviceLogging.includes('debug')) {
455
459
  this.errorLog(
456
- `Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
460
+ `${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
461
+ + ` Error Message: ${superStringify(e.message)}`,
457
462
  );
458
463
  }
459
464
  this.apiError(e);
460
465
  }
466
+ } else {
467
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
461
468
  }
462
469
  }
463
470
 
@@ -469,37 +476,38 @@ export class Meter {
469
476
  const entry = { time: Math.round(new Date().valueOf() / 1000) };
470
477
  if (!this.device.meter?.hide_humidity) {
471
478
  if (this.CurrentRelativeHumidity === undefined) {
472
- this.debugLog(`Meter: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
479
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
473
480
  } else {
474
481
  this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
475
- this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
482
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
483
+ + ` CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
476
484
  mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
477
485
  entry['humidity'] = this.CurrentRelativeHumidity;
478
486
  }
479
487
  }
480
488
  if (!this.device.meter?.hide_temperature) {
481
489
  if (this.CurrentTemperature === undefined) {
482
- this.debugLog(`Meter: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
490
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
483
491
  } else {
484
492
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
485
- this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
493
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
486
494
  mqttmessage.push(`"temperature": ${this.CurrentTemperature}`);
487
495
  entry['temp'] = this.CurrentTemperature;
488
496
  }
489
497
  }
490
498
  if (this.device.ble) {
491
499
  if (this.BatteryLevel === undefined) {
492
- this.debugLog(`Meter: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
500
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
493
501
  } else {
494
502
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
495
- this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
503
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
496
504
  mqttmessage.push(`"battery": ${this.BatteryLevel}`);
497
505
  }
498
506
  if (this.StatusLowBattery === undefined) {
499
- this.debugLog(`Meter: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
507
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
500
508
  } else {
501
509
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
502
- this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
510
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
503
511
  mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
504
512
  }
505
513
  }
@@ -532,6 +540,9 @@ export class Meter {
532
540
  if (device.ble !== undefined) {
533
541
  config['ble'] = device.ble;
534
542
  }
543
+ if (device.openAPI !== undefined) {
544
+ config['openAPI'] = device.openAPI;
545
+ }
535
546
  if (device.logging !== undefined) {
536
547
  config['logging'] = device.logging;
537
548
  }
@@ -542,30 +553,39 @@ export class Meter {
542
553
  config['scanDuration'] = device.scanDuration;
543
554
  }
544
555
  if (Object.entries(config).length !== 0) {
545
- this.infoLog(`Meter: ${this.accessory.displayName} Config: ${superStringify(config)}`);
556
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
546
557
  }
547
558
  }
548
559
 
549
560
  async refreshRate(device: device & devicesConfig): Promise<void> {
550
561
  if (device.refreshRate) {
551
562
  this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
552
- this.debugLog(`Meter: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
563
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
553
564
  } else if (this.platform.config.options!.refreshRate) {
554
565
  this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
555
- this.debugLog(`Meter: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
566
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
567
+ }
568
+ }
569
+
570
+ async openAPI() {
571
+ if (!this.device.openAPI) {
572
+ this.OpenAPI = true;
573
+ } else {
574
+ this.OpenAPI = this.device.openAPI;
556
575
  }
576
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
557
577
  }
558
578
 
559
579
  async scan(device: device & devicesConfig): Promise<void> {
560
580
  if (device.scanDuration) {
561
581
  this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
562
582
  if (device.ble) {
563
- this.debugLog(`Meter: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
583
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
564
584
  }
565
585
  } else {
566
586
  this.scanDuration = this.accessory.context.scanDuration = 1;
567
587
  if (this.device.ble) {
568
- this.debugLog(`Meter: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
588
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
569
589
  }
570
590
  }
571
591
  }
@@ -573,24 +593,25 @@ export class Meter {
573
593
  async logs(device: device & devicesConfig): Promise<void> {
574
594
  if (this.platform.debugMode) {
575
595
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
576
- this.debugLog(`Meter: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
596
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
577
597
  } else if (device.logging) {
578
598
  this.deviceLogging = this.accessory.context.logging = device.logging;
579
- this.debugLog(`Meter: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
599
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
580
600
  } else if (this.platform.config.options?.logging) {
581
601
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
582
- this.debugLog(`Meter: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
602
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
583
603
  } else {
584
604
  this.deviceLogging = this.accessory.context.logging = 'standard';
585
- this.debugLog(`Meter: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
605
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
586
606
  }
587
607
  }
588
608
 
589
609
  FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
590
610
  let FirmwareRevision: string;
591
- this.debugLog(`Meter: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
592
- this.debugLog(`Meter: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
593
- this.debugLog(`Meter: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
611
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
612
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
613
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
614
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
594
615
  if (accessory.context.FirmwareRevision) {
595
616
  FirmwareRevision = accessory.context.FirmwareRevision;
596
617
  } else if (device.firmware) {