@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.4
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.
- package/CHANGELOG.md +14 -0
- package/dist/device/blindtilt.js +103 -103
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +84 -84
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +97 -97
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +139 -139
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +47 -47
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +91 -89
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +12 -12
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +42 -42
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +95 -95
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +46 -46
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js +84 -84
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +44 -44
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +118 -118
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +74 -74
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +44 -44
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +42 -42
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/meterpro.js +42 -42
- package/dist/device/meterpro.js.map +1 -1
- package/dist/device/motion.js +44 -44
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +59 -59
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +73 -73
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +44 -44
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -31
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +10 -10
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js +9 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.js +11 -11
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.js +11 -11
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.js +9 -9
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +55 -55
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.js +33 -33
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.js +228 -228
- package/dist/platform.js.map +1 -1
- package/package.json +9 -9
- package/src/device/blindtilt.ts +103 -103
- package/src/device/bot.ts +84 -84
- package/src/device/ceilinglight.ts +97 -97
- package/src/device/colorbulb.ts +139 -139
- package/src/device/contact.ts +47 -47
- package/src/device/curtain.ts +91 -89
- package/src/device/device.ts +42 -42
- package/src/device/fan.ts +95 -95
- package/src/device/hub.ts +46 -46
- package/src/device/humidifier.ts +84 -84
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +118 -118
- package/src/device/lock.ts +74 -74
- package/src/device/meter.ts +44 -44
- package/src/device/meterplus.ts +42 -42
- package/src/device/meterpro.ts +42 -42
- package/src/device/motion.ts +44 -44
- package/src/device/plug.ts +61 -61
- package/src/device/robotvacuumcleaner.ts +73 -73
- package/src/device/waterdetector.ts +44 -44
- package/src/irdevice/airconditioner.ts +31 -31
- package/src/irdevice/airpurifier.ts +10 -10
- package/src/irdevice/camera.ts +9 -9
- package/src/irdevice/fan.ts +11 -11
- package/src/irdevice/irdevice.ts +11 -11
- package/src/irdevice/light.ts +9 -9
- package/src/irdevice/other.ts +55 -55
- package/src/irdevice/tv.ts +33 -33
- package/src/irdevice/vacuumcleaner.ts +9 -9
- package/src/irdevice/waterheater.ts +9 -9
- package/src/platform.ts +228 -228
package/src/device/meter.ts
CHANGED
|
@@ -169,63 +169,63 @@ export class Meter extends deviceBase {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
async BLEparseStatus(): Promise<void> {
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
this.debugLog('BLEparseStatus')
|
|
173
|
+
this.debugLog(`(scale, temperature, humidity) = BLE:(${this.serviceData.fahrenheit}, ${this.serviceData.celsius}, ${this.serviceData.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
|
|
174
174
|
|
|
175
175
|
// CurrentRelativeHumidity
|
|
176
176
|
if (!(this.device as meterConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
177
177
|
this.HumiditySensor.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100)
|
|
178
|
-
|
|
178
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
// Current Temperature
|
|
182
182
|
if (!(this.device as meterConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
183
183
|
const CELSIUS = this.serviceData.celsius < 0 ? 0 : this.serviceData.celsius > 100 ? 100 : this.serviceData.celsius
|
|
184
184
|
this.TemperatureSensor.CurrentTemperature = CELSIUS
|
|
185
|
-
|
|
185
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
// BatteryLevel
|
|
189
189
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
190
|
-
|
|
190
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
191
191
|
|
|
192
192
|
// StatusLowBattery
|
|
193
193
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
194
194
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
195
195
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
196
|
-
|
|
196
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
async openAPIparseStatus(): Promise<void> {
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
this.debugLog('openAPIparseStatus')
|
|
201
|
+
this.debugLog(`(battery, temperature, humidity) = OpenAPI:(${this.deviceStatus.battery}, ${this.deviceStatus.temperature}, ${this.deviceStatus.humidity}), current:(${this.Battery?.BatteryLevel}, ${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
|
|
202
202
|
|
|
203
203
|
// CurrentRelativeHumidity
|
|
204
204
|
if (!(this.device as meterConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
205
205
|
this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity
|
|
206
|
-
|
|
206
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
// CurrentTemperature
|
|
210
210
|
if (!(this.device as meterConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
211
211
|
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
212
|
-
|
|
212
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
// BatteryLevel
|
|
216
216
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
217
|
-
|
|
217
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
218
218
|
|
|
219
219
|
// StatusLowBattery
|
|
220
220
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
221
221
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
222
222
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
223
|
-
|
|
223
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
224
224
|
|
|
225
225
|
// FirmwareVersion
|
|
226
226
|
if (this.deviceStatus.version) {
|
|
227
227
|
const version = this.deviceStatus.version.toString()
|
|
228
|
-
|
|
228
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
229
229
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
230
230
|
this.accessory
|
|
231
231
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -234,28 +234,28 @@ export class Meter extends deviceBase {
|
|
|
234
234
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
235
235
|
.updateValue(deviceVersion)
|
|
236
236
|
this.accessory.context.version = deviceVersion
|
|
237
|
-
|
|
237
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
async parseStatusWebhook(): Promise<void> {
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
this.debugLog('parseStatusWebhook')
|
|
243
|
+
this.debugLog(`(scale, temperature, humidity) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as meterConfig).convertUnitTo)}, ${this.webhookContext.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
|
|
244
244
|
// Check if the scale is not CELSIUS
|
|
245
245
|
if (this.webhookContext.scale !== 'CELSIUS' && (this.device as meterConfig).convertUnitTo === undefined) {
|
|
246
|
-
|
|
246
|
+
this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings, if displaying incorrectly in HomeKit.`)
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
// CurrentRelativeHumidity
|
|
250
250
|
if (!(this.device as meterConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
251
251
|
this.HumiditySensor.CurrentRelativeHumidity = this.webhookContext.humidity
|
|
252
|
-
|
|
252
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`)
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
// CurrentTemperature
|
|
256
256
|
if (!(this.device as meterConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
257
257
|
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as meterConfig).convertUnitTo)
|
|
258
|
-
|
|
258
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
|
|
@@ -264,19 +264,19 @@ export class Meter extends deviceBase {
|
|
|
264
264
|
*/
|
|
265
265
|
async refreshStatus(): Promise<void> {
|
|
266
266
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
267
|
-
|
|
267
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
268
268
|
} else if (this.BLE) {
|
|
269
269
|
await this.BLERefreshStatus()
|
|
270
270
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
271
271
|
await this.openAPIRefreshStatus()
|
|
272
272
|
} else {
|
|
273
273
|
await this.offlineOff()
|
|
274
|
-
|
|
274
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
async BLERefreshStatus(): Promise<void> {
|
|
279
|
-
|
|
279
|
+
this.debugLog('BLERefreshStatus')
|
|
280
280
|
const switchBotBLE = await this.switchbotBLE()
|
|
281
281
|
if (switchBotBLE === undefined) {
|
|
282
282
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -291,7 +291,7 @@ export class Meter extends deviceBase {
|
|
|
291
291
|
await this.BLEparseStatus()
|
|
292
292
|
await this.updateHomeKitCharacteristics()
|
|
293
293
|
} else {
|
|
294
|
-
|
|
294
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
295
295
|
await this.BLERefreshConnection(switchBotBLE)
|
|
296
296
|
}
|
|
297
297
|
})()
|
|
@@ -299,67 +299,67 @@ export class Meter extends deviceBase {
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
async registerPlatformBLE(): Promise<void> {
|
|
302
|
-
|
|
302
|
+
this.debugLog('registerPlatformBLE')
|
|
303
303
|
if (this.config.options?.BLE) {
|
|
304
|
-
|
|
304
|
+
this.debugLog('is listening to Platform BLE.')
|
|
305
305
|
try {
|
|
306
306
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
307
307
|
this.device.bleMac = formattedDeviceId
|
|
308
|
-
|
|
308
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
309
309
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: meterServiceData) => {
|
|
310
310
|
try {
|
|
311
|
-
|
|
311
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
312
312
|
this.serviceData = context
|
|
313
313
|
await this.BLEparseStatus()
|
|
314
314
|
await this.updateHomeKitCharacteristics()
|
|
315
315
|
} catch (e: any) {
|
|
316
|
-
|
|
316
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
} catch (error) {
|
|
320
|
-
|
|
320
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
321
321
|
}
|
|
322
322
|
} else {
|
|
323
|
-
|
|
323
|
+
this.debugLog('is not listening to Platform BLE')
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
|
|
327
327
|
async openAPIRefreshStatus(): Promise<void> {
|
|
328
|
-
|
|
328
|
+
this.debugLog('openAPIRefreshStatus')
|
|
329
329
|
try {
|
|
330
|
-
const
|
|
331
|
-
const deviceStatus: any =
|
|
332
|
-
|
|
330
|
+
const response = await this.deviceRefreshStatus()
|
|
331
|
+
const deviceStatus: any = response.body
|
|
332
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
333
333
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
334
|
-
|
|
334
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
335
335
|
this.deviceStatus = deviceStatus.body
|
|
336
336
|
await this.openAPIparseStatus()
|
|
337
337
|
await this.updateHomeKitCharacteristics()
|
|
338
338
|
} else {
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
340
|
+
this.debugWarnLog(deviceStatus)
|
|
341
341
|
}
|
|
342
342
|
} catch (e: any) {
|
|
343
343
|
await this.apiError(e)
|
|
344
|
-
|
|
344
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
async registerWebhook() {
|
|
349
349
|
if (this.device.webhook) {
|
|
350
|
-
|
|
350
|
+
this.debugLog('is listening webhook.')
|
|
351
351
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: meterWebhookContext) => {
|
|
352
352
|
try {
|
|
353
|
-
|
|
353
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
354
354
|
this.webhookContext = context
|
|
355
355
|
await this.parseStatusWebhook()
|
|
356
356
|
await this.updateHomeKitCharacteristics()
|
|
357
357
|
} catch (e: any) {
|
|
358
|
-
|
|
358
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
} else {
|
|
362
|
-
|
|
362
|
+
this.debugLog('is not listening webhook.')
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
|
|
@@ -382,9 +382,9 @@ export class Meter extends deviceBase {
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
385
|
-
|
|
385
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
386
386
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
387
|
-
|
|
387
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
388
388
|
await this.openAPIRefreshStatus()
|
|
389
389
|
}
|
|
390
390
|
}
|
package/src/device/meterplus.ts
CHANGED
|
@@ -174,55 +174,55 @@ export class MeterPlus extends deviceBase {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
async BLEparseStatus(): Promise<void> {
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
this.debugLog('BLEparseStatus')
|
|
178
|
+
this.debugLog(`(temperature, humidity) = BLE:(${this.serviceData.celsius}, ${this.serviceData.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
|
|
179
179
|
|
|
180
180
|
// CurrentRelativeHumidity
|
|
181
181
|
if (!(this.device as meterConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
182
182
|
this.HumiditySensor.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100)
|
|
183
|
-
|
|
183
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
184
184
|
}
|
|
185
185
|
// Current Temperature
|
|
186
186
|
if (!(this.device as meterConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
187
187
|
const CELSIUS = this.serviceData.celsius < 0 ? 0 : this.serviceData.celsius > 100 ? 100 : this.serviceData.celsius
|
|
188
188
|
this.TemperatureSensor.CurrentTemperature = CELSIUS
|
|
189
|
-
|
|
189
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
190
190
|
}
|
|
191
191
|
// BatteryLevel
|
|
192
192
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
193
|
-
|
|
193
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
194
194
|
// StatusLowBattery
|
|
195
195
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
196
196
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
197
197
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
198
|
-
|
|
198
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
async openAPIparseStatus(): Promise<void> {
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
this.debugLog('openAPIparseStatus')
|
|
203
|
+
this.debugLog(`(temperature, humidity) = OpenAPI:(${this.deviceStatus.temperature}, ${this.deviceStatus.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
|
|
204
204
|
|
|
205
205
|
// CurrentRelativeHumidity
|
|
206
206
|
if (!(this.device as meterConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
207
207
|
this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity
|
|
208
|
-
|
|
208
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
// CurrentTemperature
|
|
212
212
|
if (!(this.device as meterConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
213
213
|
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
214
|
-
|
|
214
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
// BatteryLevel
|
|
218
218
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
219
|
-
|
|
219
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
220
220
|
|
|
221
221
|
// StatusLowBattery
|
|
222
222
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
223
223
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
224
224
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
225
|
-
|
|
225
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
226
226
|
|
|
227
227
|
// FirmwareVersion
|
|
228
228
|
if (this.deviceStatus.version) {
|
|
@@ -241,23 +241,23 @@ export class MeterPlus extends deviceBase {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
async parseStatusWebhook(): Promise<void> {
|
|
244
|
-
|
|
245
|
-
|
|
244
|
+
this.debugLog('parseStatusWebhook')
|
|
245
|
+
this.debugLog(`(scale, temperature, humidity) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as meterConfig).convertUnitTo)}, ${this.webhookContext.humidity}) current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
|
|
246
246
|
// Check if the scale is not CELSIUS
|
|
247
247
|
if (this.webhookContext.scale !== 'CELSIUS' && (this.device as meterConfig).convertUnitTo === undefined) {
|
|
248
|
-
|
|
248
|
+
this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings, if displaying incorrectly in HomeKit.`)
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
// CurrentRelativeHumidity
|
|
252
252
|
if (!(this.device as meterConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
253
253
|
this.HumiditySensor.CurrentRelativeHumidity = this.webhookContext.humidity
|
|
254
|
-
|
|
254
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`)
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
// CurrentTemperature
|
|
258
258
|
if (!(this.device as meterConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
259
259
|
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as meterConfig).convertUnitTo)
|
|
260
|
-
|
|
260
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
|
|
@@ -266,19 +266,19 @@ export class MeterPlus extends deviceBase {
|
|
|
266
266
|
*/
|
|
267
267
|
async refreshStatus(): Promise<void> {
|
|
268
268
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
269
|
-
|
|
269
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
270
270
|
} else if (this.BLE) {
|
|
271
271
|
await this.BLERefreshStatus()
|
|
272
272
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
273
273
|
await this.openAPIRefreshStatus()
|
|
274
274
|
} else {
|
|
275
275
|
await this.offlineOff()
|
|
276
|
-
|
|
276
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
async BLERefreshStatus(): Promise<void> {
|
|
281
|
-
|
|
281
|
+
this.debugLog('BLERefreshStatus')
|
|
282
282
|
const switchBotBLE = await this.switchbotBLE()
|
|
283
283
|
if (switchBotBLE === undefined) {
|
|
284
284
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -293,7 +293,7 @@ export class MeterPlus extends deviceBase {
|
|
|
293
293
|
await this.BLEparseStatus()
|
|
294
294
|
await this.updateHomeKitCharacteristics()
|
|
295
295
|
} else {
|
|
296
|
-
|
|
296
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
297
297
|
await this.BLERefreshConnection(switchBotBLE)
|
|
298
298
|
}
|
|
299
299
|
})()
|
|
@@ -301,67 +301,67 @@ export class MeterPlus extends deviceBase {
|
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
async registerPlatformBLE(): Promise<void> {
|
|
304
|
-
|
|
304
|
+
this.debugLog('registerPlatformBLE')
|
|
305
305
|
if (this.config.options?.BLE) {
|
|
306
|
-
|
|
306
|
+
this.debugLog('is listening to Platform BLE.')
|
|
307
307
|
try {
|
|
308
308
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
309
309
|
this.device.bleMac = formattedDeviceId
|
|
310
|
-
|
|
310
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
311
311
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: meterPlusServiceData) => {
|
|
312
312
|
try {
|
|
313
|
-
|
|
313
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
314
314
|
this.serviceData = context
|
|
315
315
|
await this.BLEparseStatus()
|
|
316
316
|
await this.updateHomeKitCharacteristics()
|
|
317
317
|
} catch (e: any) {
|
|
318
|
-
|
|
318
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
} catch (error) {
|
|
322
|
-
|
|
322
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
323
323
|
}
|
|
324
324
|
} else {
|
|
325
|
-
|
|
325
|
+
this.debugLog('is not listening to Platform BLE')
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
async openAPIRefreshStatus(): Promise<void> {
|
|
330
|
-
|
|
330
|
+
this.debugLog('openAPIRefreshStatus')
|
|
331
331
|
try {
|
|
332
|
-
const
|
|
333
|
-
const deviceStatus: any =
|
|
334
|
-
|
|
332
|
+
const response = await this.deviceRefreshStatus()
|
|
333
|
+
const deviceStatus: any = response.body
|
|
334
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
335
335
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
336
|
-
|
|
336
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
337
337
|
this.deviceStatus = deviceStatus.body
|
|
338
338
|
await this.openAPIparseStatus()
|
|
339
339
|
await this.updateHomeKitCharacteristics()
|
|
340
340
|
} else {
|
|
341
|
-
|
|
342
|
-
|
|
341
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
342
|
+
this.debugWarnLog(deviceStatus)
|
|
343
343
|
}
|
|
344
344
|
} catch (e: any) {
|
|
345
345
|
await this.apiError(e)
|
|
346
|
-
|
|
346
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
|
|
350
350
|
async registerWebhook() {
|
|
351
351
|
if (this.device.webhook) {
|
|
352
|
-
|
|
352
|
+
this.debugLog('is listening webhook.')
|
|
353
353
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: meterPlusWebhookContext) => {
|
|
354
354
|
try {
|
|
355
|
-
|
|
355
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
356
356
|
this.webhookContext = context
|
|
357
357
|
await this.parseStatusWebhook()
|
|
358
358
|
await this.updateHomeKitCharacteristics()
|
|
359
359
|
} catch (e: any) {
|
|
360
|
-
|
|
360
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
} else {
|
|
364
|
-
|
|
364
|
+
this.debugLog('is not listening webhook.')
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
|
|
@@ -384,9 +384,9 @@ export class MeterPlus extends deviceBase {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
387
|
-
|
|
387
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
388
388
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
389
|
-
|
|
389
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
390
390
|
await this.openAPIRefreshStatus()
|
|
391
391
|
}
|
|
392
392
|
}
|