@switchbot/homebridge-switchbot 2.0.0-beta.4 → 2.0.0-beta.40

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 (119) hide show
  1. package/CHANGELOG.md +12 -2
  2. package/README.md +3 -2
  3. package/config.schema.json +108 -20
  4. package/dist/device/bot.d.ts +34 -28
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +657 -648
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.d.ts +137 -0
  9. package/dist/device/ceilinglight.d.ts.map +1 -0
  10. package/dist/device/ceilinglight.js +1127 -0
  11. package/dist/device/ceilinglight.js.map +1 -0
  12. package/dist/device/colorbulb.d.ts +36 -19
  13. package/dist/device/colorbulb.d.ts.map +1 -1
  14. package/dist/device/colorbulb.js +486 -309
  15. package/dist/device/colorbulb.js.map +1 -1
  16. package/dist/device/contact.d.ts +18 -8
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +306 -237
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts +23 -16
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +566 -502
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/humidifier.d.ts +24 -18
  25. package/dist/device/humidifier.d.ts.map +1 -1
  26. package/dist/device/humidifier.js +453 -369
  27. package/dist/device/humidifier.js.map +1 -1
  28. package/dist/device/lock.d.ts +27 -8
  29. package/dist/device/lock.d.ts.map +1 -1
  30. package/dist/device/lock.js +305 -148
  31. package/dist/device/lock.js.map +1 -1
  32. package/dist/device/meter.d.ts +22 -16
  33. package/dist/device/meter.d.ts.map +1 -1
  34. package/dist/device/meter.js +367 -267
  35. package/dist/device/meter.js.map +1 -1
  36. package/dist/device/meterplus.d.ts +24 -12
  37. package/dist/device/meterplus.d.ts.map +1 -1
  38. package/dist/device/meterplus.js +381 -213
  39. package/dist/device/meterplus.js.map +1 -1
  40. package/dist/device/motion.d.ts +18 -8
  41. package/dist/device/motion.d.ts.map +1 -1
  42. package/dist/device/motion.js +279 -216
  43. package/dist/device/motion.js.map +1 -1
  44. package/dist/device/plug.d.ts +27 -17
  45. package/dist/device/plug.d.ts.map +1 -1
  46. package/dist/device/plug.js +295 -251
  47. package/dist/device/plug.js.map +1 -1
  48. package/dist/device/striplight.d.ts +43 -19
  49. package/dist/device/striplight.d.ts.map +1 -1
  50. package/dist/device/striplight.js +506 -262
  51. package/dist/device/striplight.js.map +1 -1
  52. package/dist/irdevice/airconditioner.d.ts +9 -12
  53. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  54. package/dist/irdevice/airconditioner.js +278 -230
  55. package/dist/irdevice/airconditioner.js.map +1 -1
  56. package/dist/irdevice/airpurifier.d.ts +5 -3
  57. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  58. package/dist/irdevice/airpurifier.js +154 -104
  59. package/dist/irdevice/airpurifier.js.map +1 -1
  60. package/dist/irdevice/camera.d.ts +11 -8
  61. package/dist/irdevice/camera.d.ts.map +1 -1
  62. package/dist/irdevice/camera.js +133 -86
  63. package/dist/irdevice/camera.js.map +1 -1
  64. package/dist/irdevice/fan.d.ts +10 -7
  65. package/dist/irdevice/fan.d.ts.map +1 -1
  66. package/dist/irdevice/fan.js +160 -109
  67. package/dist/irdevice/fan.js.map +1 -1
  68. package/dist/irdevice/light.d.ts +11 -8
  69. package/dist/irdevice/light.d.ts.map +1 -1
  70. package/dist/irdevice/light.js +137 -103
  71. package/dist/irdevice/light.js.map +1 -1
  72. package/dist/irdevice/other.d.ts +11 -8
  73. package/dist/irdevice/other.d.ts.map +1 -1
  74. package/dist/irdevice/other.js +145 -98
  75. package/dist/irdevice/other.js.map +1 -1
  76. package/dist/irdevice/tv.d.ts +12 -9
  77. package/dist/irdevice/tv.d.ts.map +1 -1
  78. package/dist/irdevice/tv.js +143 -93
  79. package/dist/irdevice/tv.js.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.d.ts +9 -10
  81. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  82. package/dist/irdevice/vacuumcleaner.js +132 -89
  83. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  84. package/dist/irdevice/waterheater.d.ts +8 -9
  85. package/dist/irdevice/waterheater.d.ts.map +1 -1
  86. package/dist/irdevice/waterheater.js +132 -89
  87. package/dist/irdevice/waterheater.js.map +1 -1
  88. package/dist/platform.d.ts +15 -12
  89. package/dist/platform.d.ts.map +1 -1
  90. package/dist/platform.js +574 -454
  91. package/dist/platform.js.map +1 -1
  92. package/dist/settings.d.ts +21 -11
  93. package/dist/settings.d.ts.map +1 -1
  94. package/dist/settings.js.map +1 -1
  95. package/homebridge-ui/public/index.html +1 -0
  96. package/package.json +13 -11
  97. package/src/device/bot.ts +656 -659
  98. package/src/device/ceilinglight.ts +1208 -0
  99. package/src/device/colorbulb.ts +490 -344
  100. package/src/device/contact.ts +309 -241
  101. package/src/device/curtain.ts +571 -516
  102. package/src/device/humidifier.ts +456 -403
  103. package/src/device/lock.ts +314 -149
  104. package/src/device/meter.ts +378 -280
  105. package/src/device/meterplus.ts +391 -219
  106. package/src/device/motion.ts +285 -222
  107. package/src/device/plug.ts +299 -260
  108. package/src/device/striplight.ts +522 -289
  109. package/src/irdevice/airconditioner.ts +282 -241
  110. package/src/irdevice/airpurifier.ts +151 -103
  111. package/src/irdevice/camera.ts +131 -85
  112. package/src/irdevice/fan.ts +157 -106
  113. package/src/irdevice/light.ts +135 -103
  114. package/src/irdevice/other.ts +143 -97
  115. package/src/irdevice/tv.ts +142 -93
  116. package/src/irdevice/vacuumcleaner.ts +131 -89
  117. package/src/irdevice/waterheater.ts +130 -89
  118. package/src/platform.ts +567 -476
  119. package/src/settings.ts +22 -11
@@ -6,8 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MeterPlus = void 0;
7
7
  const https_1 = __importDefault(require("https"));
8
8
  const crypto_1 = __importDefault(require("crypto"));
9
+ const os_1 = require("os");
10
+ const async_mqtt_1 = require("async-mqtt");
9
11
  const rxjs_1 = require("rxjs");
10
12
  const operators_1 = require("rxjs/operators");
13
+ const super_stringify_1 = __importDefault(require("super-stringify"));
11
14
  const settings_1 = require("../settings");
12
15
  /**
13
16
  * Platform Accessory
@@ -19,23 +22,19 @@ class MeterPlus {
19
22
  this.platform = platform;
20
23
  this.accessory = accessory;
21
24
  this.device = device;
25
+ //MQTT stuff
26
+ this.mqttClient = null;
27
+ // Connection
28
+ this.BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
29
+ this.OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
22
30
  // default placeholders
23
31
  this.logs(device);
24
32
  this.scan(device);
25
33
  this.refreshRate(device);
26
34
  this.config(device);
27
- if (this.CurrentRelativeHumidity === undefined) {
28
- this.CurrentRelativeHumidity = 0;
29
- }
30
- else {
31
- this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
32
- }
33
- if (this.CurrentTemperature === undefined) {
34
- this.CurrentTemperature = 0;
35
- }
36
- else {
37
- this.CurrentTemperature = this.accessory.context.CurrentTemperature;
38
- }
35
+ this.context();
36
+ this.setupHistoryService(device);
37
+ this.setupMqtt(device);
39
38
  // this is subject we use to track when we need to POST changes to the SwitchBot API
40
39
  this.doMeterUpdate = new rxjs_1.Subject();
41
40
  this.meterUpdateInProgress = false;
@@ -52,12 +51,12 @@ class MeterPlus {
52
51
  .updateValue(this.FirmwareRevision(accessory, device));
53
52
  // Temperature Sensor Service
54
53
  if (device.meter?.hide_temperature) {
55
- this.debugLog(`Meter Plus: ${accessory.displayName} Removing Temperature Sensor Service`);
54
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
56
55
  this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
57
56
  accessory.removeService(this.temperatureservice);
58
57
  }
59
58
  else if (!this.temperatureservice) {
60
- this.debugLog(`Meter Plus: ${accessory.displayName} Add Temperature Sensor Service`);
59
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
61
60
  (this.temperatureservice =
62
61
  this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
63
62
  `${accessory.displayName} Temperature Sensor`;
@@ -76,16 +75,16 @@ class MeterPlus {
76
75
  });
77
76
  }
78
77
  else {
79
- this.debugLog(`Meter Plus: ${accessory.displayName} Temperature Sensor Service Not Added`);
78
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
80
79
  }
81
80
  // Humidity Sensor Service
82
81
  if (device.meter?.hide_humidity) {
83
- this.debugLog(`Meter Plus: ${accessory.displayName} Removing Humidity Sensor Service`);
82
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
84
83
  this.humidityservice = this.accessory.getService(this.platform.Service.HumiditySensor);
85
84
  accessory.removeService(this.humidityservice);
86
85
  }
87
86
  else if (!this.humidityservice) {
88
- this.debugLog(`Meter Plus: ${accessory.displayName} Add Humidity Sensor Service`);
87
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
89
88
  (this.humidityservice =
90
89
  this.accessory.getService(this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor)),
91
90
  `${accessory.displayName} Humidity Sensor`;
@@ -100,23 +99,23 @@ class MeterPlus {
100
99
  });
101
100
  }
102
101
  else {
103
- this.debugLog(`Meter Plus: ${accessory.displayName} Humidity Sensor Service Not Added`);
102
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
104
103
  }
105
104
  // Battery Service
106
- if (!device.ble) {
107
- this.debugLog(`Meter Plus: ${accessory.displayName} Removing Battery Service`);
105
+ if (!this.BLE) {
106
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
108
107
  this.batteryService = this.accessory.getService(this.platform.Service.Battery);
109
108
  accessory.removeService(this.batteryService);
110
109
  }
111
- else if (device.ble && !this.batteryService) {
112
- this.debugLog(`Meter Plus: ${accessory.displayName} Add Battery Service`);
110
+ else if (this.BLE && !this.batteryService) {
111
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
113
112
  (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
114
113
  `${accessory.displayName} Battery`;
115
114
  this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
116
115
  this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
117
116
  }
118
117
  else {
119
- this.debugLog(`Meter Plus: ${accessory.displayName} Battery Service Not Added`);
118
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
120
119
  }
121
120
  // Retrieve initial values and updateHomekit
122
121
  this.updateHomeKitCharacteristics();
@@ -131,15 +130,19 @@ class MeterPlus {
131
130
  * Parse the device status from the SwitchBot api
132
131
  */
133
132
  async parseStatus() {
134
- if (this.SwitchToOpenAPI || !this.device.ble) {
133
+ if (this.BLE) {
134
+ await this.BLEparseStatus();
135
+ }
136
+ else if (this.OpenAPI && this.platform.config.credentials?.token) {
135
137
  await this.openAPIparseStatus();
136
138
  }
137
139
  else {
138
- await this.BLEparseStatus();
140
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
141
+ + ` ${this.device.connectionType}, parseStatus will not happen.`);
139
142
  }
140
143
  }
141
144
  async BLEparseStatus() {
142
- this.debugLog(`Meter Plus: ${this.accessory.displayName} BLE parseStatus`);
145
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
143
146
  // Battery
144
147
  this.BatteryLevel = Number(this.battery);
145
148
  if (this.BatteryLevel < 15) {
@@ -152,53 +155,52 @@ class MeterPlus {
152
155
  // Humidity
153
156
  if (!this.device.meter?.hide_humidity) {
154
157
  this.CurrentRelativeHumidity = this.humidity;
155
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
158
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
156
159
  }
157
160
  // Current Temperature
158
161
  if (!this.device.meter?.hide_temperature) {
159
162
  this.temperature < 0 ? 0 : this.temperature > 100 ? 100 : this.temperature;
160
163
  this.CurrentTemperature = this.temperature;
161
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
164
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
162
165
  }
163
166
  }
164
167
  async openAPIparseStatus() {
165
- if (this.device.ble) {
166
- this.SwitchToOpenAPI = false;
168
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
169
+ // Current Relative Humidity
170
+ if (!this.device.meter?.hide_humidity) {
171
+ this.CurrentRelativeHumidity = this.Humidity;
172
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
167
173
  }
168
- if (this.platform.config.credentials?.token) {
169
- this.debugLog(`Meter Plus: ${this.accessory.displayName} OpenAPI parseStatus`);
170
- // Current Relative Humidity
171
- if (!this.device.meter?.hide_humidity) {
172
- this.CurrentRelativeHumidity = this.Humidity;
173
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
174
- }
175
- // Current Temperature
176
- if (!this.device.meter?.hide_temperature) {
177
- this.CurrentTemperature = this.Temperature;
178
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
179
- }
174
+ // Current Temperature
175
+ if (!this.device.meter?.hide_temperature) {
176
+ this.CurrentTemperature = this.Temperature;
177
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
180
178
  }
181
179
  }
182
180
  /**
183
181
  * Asks the SwitchBot API for the latest device information
184
182
  */
185
183
  async refreshStatus() {
186
- if (this.device.ble) {
187
- this.BLErefreshStatus();
184
+ if (this.BLE) {
185
+ await this.BLERefreshStatus();
186
+ }
187
+ else if (this.OpenAPI && this.platform.config.credentials?.token) {
188
+ await this.openAPIRefreshStatus();
188
189
  }
189
190
  else {
190
- this.openAPIRefreshStatus();
191
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
192
+ + ` ${this.device.connectionType}, refreshStatus will not happen.`);
191
193
  }
192
194
  }
193
- async BLErefreshStatus() {
194
- this.debugLog(`Meter Plus: ${this.accessory.displayName} BLE RefreshStatus`);
195
+ async BLERefreshStatus() {
196
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
195
197
  const switchbot = await this.platform.connectBLE();
196
198
  // Convert to BLE Address
197
199
  this.device.bleMac = this.device
198
200
  .deviceId.match(/.{1,2}/g)
199
201
  .join(':')
200
202
  .toLowerCase();
201
- this.debugLog(`Meter Plus: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
203
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
202
204
  this.getCustomBLEAddress(switchbot);
203
205
  // Start to monitor advertisement packets
204
206
  if (switchbot !== false) {
@@ -211,27 +213,26 @@ class MeterPlus {
211
213
  // Set an event hander
212
214
  switchbot.onadvertisement = (ad) => {
213
215
  this.address = ad.address;
214
- if (this.deviceLogging.includes('debug')) {
215
- this.infoLog(this.address);
216
- this.infoLog(this.device.bleMac);
217
- this.infoLog(`Meter Plus: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
218
- this.infoLog(`Meter Plus: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
216
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
217
+ + ` BLE Address Found: ${this.address}`);
218
+ if (ad.serviceData.humidity > 0) {
219
+ // reject unreliable data
220
+ this.humidity = ad.serviceData.humidity;
219
221
  }
220
222
  this.serviceData = ad.serviceData;
221
223
  this.temperature = ad.serviceData.temperature.c;
222
- this.humidity = ad.serviceData.humidity;
223
224
  this.battery = ad.serviceData.battery;
224
- this.debugLog(`Meter Plus: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
225
- this.debugLog(`Meter Plus: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
226
- `temperature: ${JSON.stringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
225
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
226
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
227
+ `temperature: ${(0, super_stringify_1.default)(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
227
228
  `battery: ${ad.serviceData.battery}`);
228
229
  if (this.serviceData) {
229
230
  this.connected = true;
230
- this.debugLog(`Meter Plus: ${this.accessory.displayName} connected: ${this.connected}`);
231
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
231
232
  }
232
233
  else {
233
234
  this.connected = false;
234
- this.debugLog(`Meter Plus: ${this.accessory.displayName} connected: ${this.connected}`);
235
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
235
236
  }
236
237
  };
237
238
  // Wait 10 seconds
@@ -245,147 +246,289 @@ class MeterPlus {
245
246
  this.updateHomeKitCharacteristics();
246
247
  }
247
248
  else {
248
- await this.BLEconnection(switchbot);
249
+ await this.BLERefreshConnection(switchbot);
249
250
  }
250
251
  })
251
252
  .catch(async (e) => {
252
- this.errorLog(`Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
253
- if (this.deviceLogging.includes('debug')) {
254
- this.errorLog(`Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
255
- }
256
- if (this.platform.config.credentials?.token) {
257
- this.warnLog(`Meter Plus: ${this.accessory.displayName} Using OpenAPI Connection`);
258
- this.SwitchToOpenAPI = true;
259
- this.openAPIRefreshStatus();
260
- }
261
253
  this.apiError(e);
254
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
255
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
256
+ await this.BLERefreshConnection(switchbot);
262
257
  });
263
258
  }
264
259
  else {
265
- await this.BLEconnection(switchbot);
266
- }
267
- }
268
- async getCustomBLEAddress(switchbot) {
269
- if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
270
- (async () => {
271
- // Start to monitor advertisement packets
272
- await switchbot.startScan({
273
- model: 'i',
274
- });
275
- // Set an event handler
276
- switchbot.onadvertisement = (ad) => {
277
- this.warnLog(`Meter Plus: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
278
- };
279
- await switchbot.wait(10000);
280
- // Stop to monitor
281
- switchbot.stopScan();
282
- })();
283
- }
284
- }
285
- async BLEconnection(switchbot) {
286
- this.errorLog(`Meter Plus: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
287
- if (this.platform.config.credentials?.token) {
288
- this.warnLog(`Meter Plus: ${this.accessory.displayName} Using OpenAPI Connection`);
289
- this.SwitchToOpenAPI = true;
290
- await this.openAPIRefreshStatus();
260
+ await this.BLERefreshConnection(switchbot);
291
261
  }
292
262
  }
293
263
  async openAPIRefreshStatus() {
294
- if (this.platform.config.credentials?.token) {
295
- this.debugLog(`Meter Plus: ${this.accessory.displayName} OpenAPI RefreshStatus`);
296
- try {
297
- const t = Date.now();
298
- const nonce = 'requestID';
299
- const data = this.platform.config.credentials?.token + t + nonce;
300
- const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
301
- const sign = signTerm.toString('base64');
302
- this.debugLog(`Meter Plus: ${this.accessory.displayName} sign: ${sign}`);
303
- const options = {
304
- hostname: settings_1.HostDomain,
305
- port: 443,
306
- path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
307
- method: 'GET',
308
- headers: {
309
- Authorization: this.platform.config.credentials?.token,
310
- sign: sign,
311
- nonce: nonce,
312
- t: t,
313
- 'Content-Type': 'application/json',
314
- },
315
- };
316
- const req = https_1.default.request(options, (res) => {
317
- this.debugLog(`Meter Plus: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
318
- let rawData = '';
319
- res.on('data', (d) => {
320
- rawData += d;
321
- this.debugLog(`Meter Plus: ${this.accessory.displayName} d: ${d}`);
322
- });
323
- res.on('end', () => {
324
- try {
325
- this.deviceStatus = JSON.parse(rawData);
326
- this.debugLog(`Meter Plus: ${this.accessory.displayName} openAPIRefreshStatus: ${JSON.stringify(this.deviceStatus)}`);
327
- this.Humidity = this.deviceStatus.body.humidity;
328
- this.Temperature = this.deviceStatus.body.temperature;
329
- this.parseStatus();
330
- this.updateHomeKitCharacteristics();
331
- }
332
- catch (e) {
333
- this.errorLog(`Meter Plus: ${this.accessory.displayName} error message: ${e.message}`);
334
- }
335
- });
264
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
265
+ try {
266
+ const t = Date.now();
267
+ const nonce = 'requestID';
268
+ const data = this.platform.config.credentials?.token + t + nonce;
269
+ const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
270
+ const sign = signTerm.toString('base64');
271
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
272
+ const options = {
273
+ hostname: settings_1.HostDomain,
274
+ port: 443,
275
+ path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
276
+ method: 'GET',
277
+ headers: {
278
+ Authorization: this.platform.config.credentials?.token,
279
+ sign: sign,
280
+ nonce: nonce,
281
+ t: t,
282
+ 'Content-Type': 'application/json',
283
+ },
284
+ };
285
+ const req = https_1.default.request(options, (res) => {
286
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
287
+ let rawData = '';
288
+ res.on('data', (d) => {
289
+ rawData += d;
290
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
336
291
  });
337
- req.on('error', (e) => {
338
- this.errorLog(`Meter Plus: ${this.accessory.displayName} error message: ${e.message}`);
292
+ res.on('end', () => {
293
+ try {
294
+ this.deviceStatus = JSON.parse(rawData);
295
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
296
+ this.Humidity = this.deviceStatus.body.humidity;
297
+ this.Temperature = this.deviceStatus.body.temperature;
298
+ this.parseStatus();
299
+ this.updateHomeKitCharacteristics();
300
+ }
301
+ catch (e) {
302
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
303
+ }
339
304
  });
340
- req.end();
341
- }
342
- catch (e) {
343
- this.errorLog(`Meter Plus: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
344
- if (this.deviceLogging.includes('debug')) {
345
- this.errorLog(`Meter Plus: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
346
- ` Error Message: ${JSON.stringify(e.message)}`);
347
- }
348
- this.apiError(e);
349
- }
305
+ });
306
+ req.on('error', (e) => {
307
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
308
+ });
309
+ req.end();
310
+ }
311
+ catch (e) {
312
+ this.apiError(e);
313
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
314
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
350
315
  }
351
316
  }
352
317
  /**
353
318
  * Updates the status for each of the HomeKit Characteristics
354
319
  */
355
320
  async updateHomeKitCharacteristics() {
321
+ const mqttmessage = [];
322
+ const entry = { time: Math.round(new Date().valueOf() / 1000) };
356
323
  if (!this.device.meter?.hide_humidity) {
357
324
  if (this.CurrentRelativeHumidity === undefined) {
358
- this.debugLog(`Meter Plus: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
325
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
359
326
  }
360
327
  else {
328
+ this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
361
329
  this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
362
- this.debugLog(`Meter Plus: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
330
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
331
+ + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
332
+ if (this.device.mqttURL) {
333
+ mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
334
+ }
335
+ if (this.device.history) {
336
+ entry['humidity'] = this.CurrentRelativeHumidity;
337
+ }
363
338
  }
364
339
  }
365
340
  if (!this.device.meter?.hide_temperature) {
366
341
  if (this.CurrentTemperature === undefined) {
367
- this.debugLog(`Meter Plus: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
342
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
368
343
  }
369
344
  else {
345
+ if (this.device.mqttURL) {
346
+ mqttmessage.push(`"temperature": ${this.CurrentTemperature}`);
347
+ }
348
+ if (this.device.history) {
349
+ entry['temp'] = this.CurrentTemperature;
350
+ }
351
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
370
352
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
371
- this.debugLog(`Meter Plus: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
353
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
372
354
  }
373
355
  }
374
- if (this.device.ble) {
356
+ if (this.BLE) {
375
357
  if (this.BatteryLevel === undefined) {
376
- this.debugLog(`Meter Plus: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
358
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
377
359
  }
378
360
  else {
361
+ if (this.device.mqttURL) {
362
+ mqttmessage.push(`"battery": ${this.BatteryLevel}`);
363
+ }
364
+ this.accessory.context.BatteryLevel = this.BatteryLevel;
379
365
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
380
- this.debugLog(`Meter Plus: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
366
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
381
367
  }
382
368
  if (this.StatusLowBattery === undefined) {
383
- this.debugLog(`Meter Plus: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
369
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
384
370
  }
385
371
  else {
372
+ if (this.device.mqttURL) {
373
+ mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
374
+ }
375
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
386
376
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
387
- this.debugLog(`Meter Plus: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
377
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
378
+ }
379
+ }
380
+ if (this.device.mqttURL) {
381
+ this.mqttPublish(`{${mqttmessage.join(',')}}`);
382
+ }
383
+ if (this.CurrentRelativeHumidity > 0) {
384
+ // reject unreliable data
385
+ if (this.device.history) {
386
+ this.historyService?.addEntry(entry);
387
+ }
388
+ }
389
+ }
390
+ /*
391
+ * Publish MQTT message for topics of
392
+ * 'homebridge-switchbot/meter/xx:xx:xx:xx:xx:xx'
393
+ */
394
+ mqttPublish(message) {
395
+ const mac = this.device.deviceId
396
+ ?.toLowerCase()
397
+ .match(/[\s\S]{1,2}/g)
398
+ ?.join(':');
399
+ const options = this.device.mqttPubOptions || {};
400
+ this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
401
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${message} options:${(0, super_stringify_1.default)(options)}`);
402
+ }
403
+ /*
404
+ * Setup MQTT hadler if URL is specifed.
405
+ */
406
+ async setupMqtt(device) {
407
+ if (device.mqttURL) {
408
+ try {
409
+ this.mqttClient = await (0, async_mqtt_1.connectAsync)(device.mqttURL, device.mqttOptions || {});
410
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
411
+ this.mqttClient.on('error', (e) => {
412
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
413
+ });
414
+ }
415
+ catch (e) {
416
+ this.mqttClient = null;
417
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
418
+ }
419
+ }
420
+ }
421
+ /*
422
+ * Setup EVE history graph feature if enabled.
423
+ */
424
+ async setupHistoryService(device) {
425
+ const mac = this.device
426
+ .deviceId.match(/.{1,2}/g)
427
+ .join(':')
428
+ .toLowerCase();
429
+ this.historyService = device.history
430
+ ? new this.platform.fakegatoAPI('room', this.accessory, {
431
+ log: this.platform.log,
432
+ storage: 'fs',
433
+ filename: `${(0, os_1.hostname)().split('.')[0]}_${mac}_persist.json`,
434
+ })
435
+ : null;
436
+ }
437
+ async getCustomBLEAddress(switchbot) {
438
+ if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
439
+ (async () => {
440
+ // Start to monitor advertisement packets
441
+ await switchbot.startScan({
442
+ model: 'i',
443
+ });
444
+ // Set an event handler
445
+ switchbot.onadvertisement = (ad) => {
446
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
447
+ };
448
+ await switchbot.wait(10000);
449
+ // Stop to monitor
450
+ switchbot.stopScan();
451
+ })();
452
+ }
453
+ }
454
+ async BLERefreshConnection(switchbot) {
455
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
456
+ if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
457
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
458
+ await this.openAPIRefreshStatus();
459
+ }
460
+ }
461
+ model(device) {
462
+ let model;
463
+ if (device.deviceType === 'Meter Plus (JP)') {
464
+ model = 'W2201500';
465
+ }
466
+ else {
467
+ model = 'W2301500';
468
+ }
469
+ return model;
470
+ }
471
+ async scan(device) {
472
+ if (device.scanDuration) {
473
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
474
+ if (this.BLE) {
475
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
476
+ }
477
+ }
478
+ else {
479
+ this.scanDuration = this.accessory.context.scanDuration = 1;
480
+ if (this.BLE) {
481
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
482
+ }
483
+ }
484
+ }
485
+ async statusCode({ res }) {
486
+ switch (res.statusCode) {
487
+ case 151:
488
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
489
+ break;
490
+ case 152:
491
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
492
+ break;
493
+ case 160:
494
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
495
+ break;
496
+ case 161:
497
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
498
+ this.offlineOff();
499
+ break;
500
+ case 171:
501
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
502
+ this.offlineOff();
503
+ break;
504
+ case 190:
505
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
506
+ ` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
507
+ break;
508
+ case 100:
509
+ if (this.platform.debugMode) {
510
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
511
+ }
512
+ break;
513
+ default:
514
+ if (this.platform.debugMode) {
515
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
516
+ }
517
+ }
518
+ }
519
+ async offlineOff() {
520
+ if (this.device.offline) {
521
+ if (!this.device.meter?.hide_humidity) {
522
+ this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.accessory.context.CurrentRelativeHumidity);
523
+ }
524
+ if (!this.device.meter?.hide_temperature) {
525
+ this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.accessory.context.CurrentTemperature);
526
+ }
527
+ if (this.BLE) {
528
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.accessory.context.BatteryLevel);
529
+ this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.accessory.context.StatusLowBattery);
388
530
  }
531
+ await this.updateHomeKitCharacteristics();
389
532
  }
390
533
  }
391
534
  async apiError(e) {
@@ -395,29 +538,80 @@ class MeterPlus {
395
538
  if (!this.device.meter?.hide_temperature) {
396
539
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
397
540
  }
398
- if (this.device.ble) {
541
+ if (this.BLE) {
399
542
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
400
543
  this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
401
544
  }
402
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
403
545
  }
404
- model(device) {
405
- let model;
406
- if (device.deviceType === 'Meter Plus (JP)') {
407
- model = 'W2201500';
546
+ FirmwareRevision(accessory, device) {
547
+ let FirmwareRevision;
548
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
549
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
550
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
551
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
552
+ if (accessory.context.FirmwareRevision) {
553
+ FirmwareRevision = accessory.context.FirmwareRevision;
554
+ }
555
+ else if (device.firmware) {
556
+ FirmwareRevision = device.firmware;
408
557
  }
409
558
  else {
410
- model = 'W2301500';
559
+ FirmwareRevision = this.platform.version;
560
+ }
561
+ return FirmwareRevision;
562
+ }
563
+ context() {
564
+ if (this.CurrentRelativeHumidity === undefined) {
565
+ this.CurrentRelativeHumidity = 0;
566
+ }
567
+ else {
568
+ this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
569
+ }
570
+ if (this.CurrentTemperature === undefined) {
571
+ this.CurrentTemperature = 0;
572
+ }
573
+ else {
574
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
575
+ }
576
+ if (this.BLE) {
577
+ if (this.BatteryLevel === undefined) {
578
+ this.BatteryLevel = 100;
579
+ }
580
+ else {
581
+ this.BatteryLevel = this.accessory.context.BatteryLevel;
582
+ }
583
+ if (this.StatusLowBattery === undefined) {
584
+ this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
585
+ this.accessory.context.StatusLowBattery = this.StatusLowBattery;
586
+ }
587
+ else {
588
+ this.StatusLowBattery = this.accessory.context.StatusLowBattery;
589
+ }
590
+ }
591
+ }
592
+ async refreshRate(device) {
593
+ if (device.refreshRate) {
594
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
595
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
596
+ }
597
+ else if (this.platform.config.options.refreshRate) {
598
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
599
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
411
600
  }
412
- return model;
413
601
  }
414
602
  async config(device) {
415
603
  let config = {};
416
604
  if (device.meter) {
417
605
  config = device.meter;
418
606
  }
419
- if (device.ble !== undefined) {
420
- config['ble'] = device.ble;
607
+ if (device.connectionType !== undefined) {
608
+ config['connectionType'] = device.connectionType;
609
+ }
610
+ if (device.external !== undefined) {
611
+ config['external'] = device.external;
612
+ }
613
+ if (device.mqttURL !== undefined) {
614
+ config['mqttURL'] = device.mqttURL;
421
615
  }
422
616
  if (device.logging !== undefined) {
423
617
  config['logging'] = device.logging;
@@ -429,67 +623,27 @@ class MeterPlus {
429
623
  config['scanDuration'] = device.scanDuration;
430
624
  }
431
625
  if (Object.entries(config).length !== 0) {
432
- this.infoLog(`Meter Plus: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
433
- }
434
- }
435
- async refreshRate(device) {
436
- if (device.refreshRate) {
437
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
438
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
439
- }
440
- else if (this.platform.config.options.refreshRate) {
441
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
442
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
443
- }
444
- }
445
- async scan(device) {
446
- if (device.scanDuration) {
447
- this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
448
- if (device.ble) {
449
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
450
- }
451
- }
452
- else {
453
- this.scanDuration = this.accessory.context.scanDuration = 1;
454
- if (this.device.ble) {
455
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
456
- }
626
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
457
627
  }
458
628
  }
459
629
  async logs(device) {
460
630
  if (this.platform.debugMode) {
461
631
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
462
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
632
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
463
633
  }
464
634
  else if (device.logging) {
465
635
  this.deviceLogging = this.accessory.context.logging = device.logging;
466
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
636
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
467
637
  }
468
638
  else if (this.platform.config.options?.logging) {
469
639
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
470
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
640
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
471
641
  }
472
642
  else {
473
643
  this.deviceLogging = this.accessory.context.logging = 'standard';
474
- this.debugLog(`Meter Plus: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
644
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
475
645
  }
476
646
  }
477
- FirmwareRevision(accessory, device) {
478
- let FirmwareRevision;
479
- this.debugLog(`Meter Plus: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
480
- this.debugLog(`Meter Plus: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
481
- this.debugLog(`Meter Plus: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
482
- if (accessory.context.FirmwareRevision) {
483
- FirmwareRevision = accessory.context.FirmwareRevision;
484
- }
485
- else if (device.firmware) {
486
- FirmwareRevision = device.firmware;
487
- }
488
- else {
489
- FirmwareRevision = this.platform.version;
490
- }
491
- return FirmwareRevision;
492
- }
493
647
  /**
494
648
  * Logging for Device
495
649
  */
@@ -503,11 +657,25 @@ class MeterPlus {
503
657
  this.platform.log.warn(String(...log));
504
658
  }
505
659
  }
660
+ debugWarnLog(...log) {
661
+ if (this.enablingDeviceLogging()) {
662
+ if (this.deviceLogging?.includes('debug')) {
663
+ this.platform.log.warn('[DEBUG]', String(...log));
664
+ }
665
+ }
666
+ }
506
667
  errorLog(...log) {
507
668
  if (this.enablingDeviceLogging()) {
508
669
  this.platform.log.error(String(...log));
509
670
  }
510
671
  }
672
+ debugErrorLog(...log) {
673
+ if (this.enablingDeviceLogging()) {
674
+ if (this.deviceLogging?.includes('debug')) {
675
+ this.platform.log.error('[DEBUG]', String(...log));
676
+ }
677
+ }
678
+ }
511
679
  debugLog(...log) {
512
680
  if (this.enablingDeviceLogging()) {
513
681
  if (this.deviceLogging === 'debug') {