@switchbot/homebridge-switchbot 2.0.0-beta.2 → 2.0.0-beta.21

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