@switchbot/homebridge-switchbot 3.8.3-beta.30 → 3.8.3-beta.31
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/.github/workflows/release.yml +1 -1
- package/CHANGELOG.md +2 -1
- package/config.schema.json +24 -0
- package/dist/device/blindtilt.js +15 -15
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +15 -15
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +15 -15
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +27 -27
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +11 -11
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +15 -15
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.js +7 -7
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +15 -15
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +11 -11
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js +15 -15
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +11 -11
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +23 -23
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +16 -16
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +11 -11
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +11 -11
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.js +11 -11
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +15 -15
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +15 -15
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +11 -11
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +80 -76
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +3 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +3 -3
- package/src/device/blindtilt.ts +15 -15
- package/src/device/bot.ts +15 -15
- package/src/device/ceilinglight.ts +15 -15
- package/src/device/colorbulb.ts +27 -27
- package/src/device/contact.ts +11 -11
- package/src/device/curtain.ts +15 -15
- package/src/device/device.ts +7 -7
- package/src/device/fan.ts +15 -15
- package/src/device/hub.ts +11 -11
- package/src/device/humidifier.ts +15 -15
- package/src/device/iosensor.ts +11 -11
- package/src/device/lightstrip.ts +23 -23
- package/src/device/lock.ts +16 -16
- package/src/device/meter.ts +11 -11
- package/src/device/meterplus.ts +11 -11
- package/src/device/motion.ts +11 -11
- package/src/device/plug.ts +15 -15
- package/src/device/robotvacuumcleaner.ts +15 -15
- package/src/device/waterdetector.ts +11 -11
- package/src/platform.ts +81 -77
- package/src/settings.ts +3 -0
package/src/device/lock.ts
CHANGED
|
@@ -155,7 +155,7 @@ export class Lock extends deviceBase {
|
|
|
155
155
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
156
156
|
this.refreshStatus()
|
|
157
157
|
} catch (e: any) {
|
|
158
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
158
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
// regisiter webhook event handler if enabled
|
|
@@ -163,7 +163,7 @@ export class Lock extends deviceBase {
|
|
|
163
163
|
this.debugLog('Registering Webhook Event Handler')
|
|
164
164
|
this.registerWebhook()
|
|
165
165
|
} catch (e: any) {
|
|
166
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
166
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
// regisiter platform BLE event handler if enabled
|
|
@@ -171,7 +171,7 @@ export class Lock extends deviceBase {
|
|
|
171
171
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
172
172
|
this.registerPlatformBLE()
|
|
173
173
|
} catch (e: any) {
|
|
174
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
174
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
// Start an update interval
|
|
@@ -321,14 +321,14 @@ export class Lock extends deviceBase {
|
|
|
321
321
|
|
|
322
322
|
async BLERefreshStatus(): Promise<void> {
|
|
323
323
|
await this.debugLog('BLERefreshStatus')
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
326
|
-
await this.BLERefreshConnection(
|
|
324
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
325
|
+
if (switchBotBLE === undefined) {
|
|
326
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
327
327
|
} else {
|
|
328
328
|
// Start to monitor advertisement packets
|
|
329
329
|
(async () => {
|
|
330
330
|
// Start to monitor advertisement packets
|
|
331
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
331
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as lockServiceData | lockProServiceData
|
|
332
332
|
// Update HomeKit
|
|
333
333
|
if ((serviceData.model === SwitchBotBLEModel.Lock || SwitchBotBLEModel.LockPro)
|
|
334
334
|
&& (serviceData.modelName === SwitchBotBLEModelName.Lock || SwitchBotBLEModelName.LockPro)) {
|
|
@@ -336,8 +336,8 @@ export class Lock extends deviceBase {
|
|
|
336
336
|
await this.BLEparseStatus()
|
|
337
337
|
await this.updateHomeKitCharacteristics()
|
|
338
338
|
} else {
|
|
339
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
340
|
-
await this.BLERefreshConnection(
|
|
339
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
340
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
341
341
|
}
|
|
342
342
|
})()
|
|
343
343
|
}
|
|
@@ -358,7 +358,7 @@ export class Lock extends deviceBase {
|
|
|
358
358
|
await this.BLEparseStatus()
|
|
359
359
|
await this.updateHomeKitCharacteristics()
|
|
360
360
|
} catch (e: any) {
|
|
361
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
361
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
} catch (error) {
|
|
@@ -400,7 +400,7 @@ export class Lock extends deviceBase {
|
|
|
400
400
|
await this.parseStatusWebhook()
|
|
401
401
|
await this.updateHomeKitCharacteristics()
|
|
402
402
|
} catch (e: any) {
|
|
403
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
403
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
} else {
|
|
@@ -437,13 +437,13 @@ export class Lock extends deviceBase {
|
|
|
437
437
|
async BLEpushChanges(): Promise<void> {
|
|
438
438
|
await this.debugLog('BLEpushChanges')
|
|
439
439
|
if (this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) {
|
|
440
|
-
const
|
|
440
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
441
441
|
try {
|
|
442
442
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
443
443
|
this.device.bleMac = formattedDeviceId
|
|
444
444
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
445
|
-
if (
|
|
446
|
-
|
|
445
|
+
if (switchBotBLE !== false) {
|
|
446
|
+
switchBotBLE
|
|
447
447
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
448
448
|
.then(async (device_list: any) => {
|
|
449
449
|
return await this.retryBLE({
|
|
@@ -467,7 +467,7 @@ export class Lock extends deviceBase {
|
|
|
467
467
|
await this.BLEPushConnection()
|
|
468
468
|
})
|
|
469
469
|
} else {
|
|
470
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
470
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
471
471
|
await this.BLEPushConnection()
|
|
472
472
|
}
|
|
473
473
|
} catch (error) {
|
|
@@ -545,7 +545,7 @@ export class Lock extends deviceBase {
|
|
|
545
545
|
}
|
|
546
546
|
}).catch(async (e: any) => {
|
|
547
547
|
// Log the error if the operation failed
|
|
548
|
-
await this.debugLog(`Error opening latch: ${e}`)
|
|
548
|
+
await this.debugLog(`Error opening latch: ${e.message ?? e}`)
|
|
549
549
|
// Ensure we turn the switch back off even in case of an error
|
|
550
550
|
if (this.Switch?.Service) {
|
|
551
551
|
this.Switch.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(false)
|
package/src/device/meter.ts
CHANGED
|
@@ -141,7 +141,7 @@ export class Meter extends deviceBase {
|
|
|
141
141
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
142
142
|
this.refreshStatus()
|
|
143
143
|
} catch (e: any) {
|
|
144
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
144
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
// regisiter webhook event handler if enabled
|
|
@@ -149,7 +149,7 @@ export class Meter extends deviceBase {
|
|
|
149
149
|
this.debugLog('Registering Webhook Event Handler')
|
|
150
150
|
this.registerWebhook()
|
|
151
151
|
} catch (e: any) {
|
|
152
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
152
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// regisiter platform BLE event handler if enabled
|
|
@@ -157,7 +157,7 @@ export class Meter extends deviceBase {
|
|
|
157
157
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
158
158
|
this.registerPlatformBLE()
|
|
159
159
|
} catch (e: any) {
|
|
160
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
160
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
// Start an update interval
|
|
@@ -277,22 +277,22 @@ export class Meter extends deviceBase {
|
|
|
277
277
|
|
|
278
278
|
async BLERefreshStatus(): Promise<void> {
|
|
279
279
|
await this.debugLog('BLERefreshStatus')
|
|
280
|
-
const
|
|
281
|
-
if (
|
|
282
|
-
await this.BLERefreshConnection(
|
|
280
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
281
|
+
if (switchBotBLE === undefined) {
|
|
282
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
283
283
|
} else {
|
|
284
284
|
// Start to monitor advertisement packets
|
|
285
285
|
(async () => {
|
|
286
286
|
// Start to monitor advertisement packets
|
|
287
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
287
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as meterServiceData
|
|
288
288
|
// Update HomeKit
|
|
289
289
|
if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
|
|
290
290
|
this.serviceData = serviceData
|
|
291
291
|
await this.BLEparseStatus()
|
|
292
292
|
await this.updateHomeKitCharacteristics()
|
|
293
293
|
} else {
|
|
294
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
295
|
-
await this.BLERefreshConnection(
|
|
294
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
295
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
296
296
|
}
|
|
297
297
|
})()
|
|
298
298
|
}
|
|
@@ -313,7 +313,7 @@ export class Meter extends deviceBase {
|
|
|
313
313
|
await this.BLEparseStatus()
|
|
314
314
|
await this.updateHomeKitCharacteristics()
|
|
315
315
|
} catch (e: any) {
|
|
316
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
316
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
} catch (error) {
|
|
@@ -355,7 +355,7 @@ export class Meter extends deviceBase {
|
|
|
355
355
|
await this.parseStatusWebhook()
|
|
356
356
|
await this.updateHomeKitCharacteristics()
|
|
357
357
|
} catch (e: any) {
|
|
358
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
358
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
} else {
|
package/src/device/meterplus.ts
CHANGED
|
@@ -146,7 +146,7 @@ export class MeterPlus extends deviceBase {
|
|
|
146
146
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
147
147
|
this.refreshStatus()
|
|
148
148
|
} catch (e: any) {
|
|
149
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
149
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// regisiter webhook event handler if enabled
|
|
@@ -154,7 +154,7 @@ export class MeterPlus extends deviceBase {
|
|
|
154
154
|
this.debugLog('Registering Webhook Event Handler')
|
|
155
155
|
this.registerWebhook()
|
|
156
156
|
} catch (e: any) {
|
|
157
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
157
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
// regisiter platform BLE event handler if enabled
|
|
@@ -162,7 +162,7 @@ export class MeterPlus extends deviceBase {
|
|
|
162
162
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
163
163
|
this.registerPlatformBLE()
|
|
164
164
|
} catch (e: any) {
|
|
165
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
165
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// Start an update interval
|
|
@@ -279,22 +279,22 @@ export class MeterPlus extends deviceBase {
|
|
|
279
279
|
|
|
280
280
|
async BLERefreshStatus(): Promise<void> {
|
|
281
281
|
await this.debugLog('BLERefreshStatus')
|
|
282
|
-
const
|
|
283
|
-
if (
|
|
284
|
-
await this.BLERefreshConnection(
|
|
282
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
283
|
+
if (switchBotBLE === undefined) {
|
|
284
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
285
285
|
} else {
|
|
286
286
|
// Start to monitor advertisement packets
|
|
287
287
|
(async () => {
|
|
288
288
|
// Start to monitor advertisement packets
|
|
289
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
289
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as meterPlusServiceData
|
|
290
290
|
// Update HomeKit
|
|
291
291
|
if (serviceData.model === SwitchBotBLEModel.MeterPlus && serviceData.modelName === SwitchBotBLEModelName.MeterPlus) {
|
|
292
292
|
this.serviceData = serviceData
|
|
293
293
|
await this.BLEparseStatus()
|
|
294
294
|
await this.updateHomeKitCharacteristics()
|
|
295
295
|
} else {
|
|
296
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
297
|
-
await this.BLERefreshConnection(
|
|
296
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
297
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
298
298
|
}
|
|
299
299
|
})()
|
|
300
300
|
}
|
|
@@ -315,7 +315,7 @@ export class MeterPlus extends deviceBase {
|
|
|
315
315
|
await this.BLEparseStatus()
|
|
316
316
|
await this.updateHomeKitCharacteristics()
|
|
317
317
|
} catch (e: any) {
|
|
318
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
318
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
} catch (error) {
|
|
@@ -357,7 +357,7 @@ export class MeterPlus extends deviceBase {
|
|
|
357
357
|
await this.parseStatusWebhook()
|
|
358
358
|
await this.updateHomeKitCharacteristics()
|
|
359
359
|
} catch (e: any) {
|
|
360
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
360
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
} else {
|
package/src/device/motion.ts
CHANGED
|
@@ -130,7 +130,7 @@ export class Motion extends deviceBase {
|
|
|
130
130
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
131
131
|
this.refreshStatus()
|
|
132
132
|
} catch (e: any) {
|
|
133
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
133
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
// regisiter webhook event handler if enabled
|
|
@@ -138,7 +138,7 @@ export class Motion extends deviceBase {
|
|
|
138
138
|
this.debugLog('Registering Webhook Event Handler')
|
|
139
139
|
this.registerWebhook()
|
|
140
140
|
} catch (e: any) {
|
|
141
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
141
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
// regisiter platform BLE event handler if enabled
|
|
@@ -146,7 +146,7 @@ export class Motion extends deviceBase {
|
|
|
146
146
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
147
147
|
this.registerPlatformBLE()
|
|
148
148
|
} catch (e: any) {
|
|
149
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
149
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// Start an update interval
|
|
@@ -254,22 +254,22 @@ export class Motion extends deviceBase {
|
|
|
254
254
|
|
|
255
255
|
async BLERefreshStatus(): Promise<void> {
|
|
256
256
|
await this.debugLog('BLERefreshStatus')
|
|
257
|
-
const
|
|
258
|
-
if (
|
|
259
|
-
await this.BLERefreshConnection(
|
|
257
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
258
|
+
if (switchBotBLE === undefined) {
|
|
259
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
260
260
|
} else {
|
|
261
261
|
// Start to monitor advertisement packets
|
|
262
262
|
(async () => {
|
|
263
263
|
// Start to monitor advertisement packets
|
|
264
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
264
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as motionSensorServiceData
|
|
265
265
|
// Update HomeKit
|
|
266
266
|
if (serviceData.model === SwitchBotBLEModel.MotionSensor && serviceData.modelName === SwitchBotBLEModelName.MotionSensor) {
|
|
267
267
|
this.serviceData = serviceData
|
|
268
268
|
await this.BLEparseStatus()
|
|
269
269
|
await this.updateHomeKitCharacteristics()
|
|
270
270
|
} else {
|
|
271
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
272
|
-
await this.BLERefreshConnection(
|
|
271
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
272
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
273
273
|
}
|
|
274
274
|
})()
|
|
275
275
|
}
|
|
@@ -290,7 +290,7 @@ export class Motion extends deviceBase {
|
|
|
290
290
|
await this.BLEparseStatus()
|
|
291
291
|
await this.updateHomeKitCharacteristics()
|
|
292
292
|
} catch (e: any) {
|
|
293
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
293
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
} catch (error) {
|
|
@@ -332,7 +332,7 @@ export class Motion extends deviceBase {
|
|
|
332
332
|
await this.parseStatusWebhook()
|
|
333
333
|
await this.updateHomeKitCharacteristics()
|
|
334
334
|
} catch (e: any) {
|
|
335
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
335
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
} else {
|
package/src/device/plug.ts
CHANGED
|
@@ -71,7 +71,7 @@ export class Plug extends deviceBase {
|
|
|
71
71
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
72
72
|
this.refreshStatus()
|
|
73
73
|
} catch (e: any) {
|
|
74
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
74
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
// regisiter webhook event handler if enabled
|
|
@@ -79,7 +79,7 @@ export class Plug extends deviceBase {
|
|
|
79
79
|
this.debugLog('Registering Webhook Event Handler')
|
|
80
80
|
this.registerWebhook()
|
|
81
81
|
} catch (e: any) {
|
|
82
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
82
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// regisiter platform BLE event handler if enabled
|
|
@@ -87,7 +87,7 @@ export class Plug extends deviceBase {
|
|
|
87
87
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
88
88
|
this.registerPlatformBLE()
|
|
89
89
|
} catch (e: any) {
|
|
90
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
90
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// Start an update interval
|
|
@@ -177,14 +177,14 @@ export class Plug extends deviceBase {
|
|
|
177
177
|
|
|
178
178
|
async BLERefreshStatus(): Promise<void> {
|
|
179
179
|
await this.debugLog('BLERefreshStatus')
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
182
|
-
await this.BLERefreshConnection(
|
|
180
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
181
|
+
if (switchBotBLE === undefined) {
|
|
182
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
183
183
|
} else {
|
|
184
184
|
// Start to monitor advertisement packets
|
|
185
185
|
(async () => {
|
|
186
186
|
// Start to monitor advertisement packets
|
|
187
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
187
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as plugMiniUSServiceData | plugMiniJPServiceData
|
|
188
188
|
// Update HomeKit
|
|
189
189
|
if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
|
|
190
190
|
&& serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
|
|
@@ -192,8 +192,8 @@ export class Plug extends deviceBase {
|
|
|
192
192
|
await this.BLEparseStatus()
|
|
193
193
|
await this.updateHomeKitCharacteristics()
|
|
194
194
|
} else {
|
|
195
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
196
|
-
await this.BLERefreshConnection(
|
|
195
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
196
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
197
197
|
}
|
|
198
198
|
})()
|
|
199
199
|
}
|
|
@@ -214,7 +214,7 @@ export class Plug extends deviceBase {
|
|
|
214
214
|
await this.BLEparseStatus()
|
|
215
215
|
await this.updateHomeKitCharacteristics()
|
|
216
216
|
} catch (e: any) {
|
|
217
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
217
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
} catch (error) {
|
|
@@ -256,7 +256,7 @@ export class Plug extends deviceBase {
|
|
|
256
256
|
await this.parseStatusWebhook()
|
|
257
257
|
await this.updateHomeKitCharacteristics()
|
|
258
258
|
} catch (e: any) {
|
|
259
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
259
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
} else {
|
|
@@ -298,13 +298,13 @@ export class Plug extends deviceBase {
|
|
|
298
298
|
await this.debugLog('BLEpushChanges')
|
|
299
299
|
if (this.Outlet.On !== this.accessory.context.On) {
|
|
300
300
|
await this.debugLog(`BLEpushChanges On: ${this.Outlet.On}, OnCached: ${this.accessory.context.On}`)
|
|
301
|
-
const
|
|
301
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
302
302
|
try {
|
|
303
303
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
304
304
|
this.device.bleMac = formattedDeviceId
|
|
305
305
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
306
|
-
if (
|
|
307
|
-
|
|
306
|
+
if (switchBotBLE !== false) {
|
|
307
|
+
switchBotBLE
|
|
308
308
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
309
309
|
.then(async (device_list: any) => {
|
|
310
310
|
await this.infoLog(`On: ${this.Outlet.On}`)
|
|
@@ -329,7 +329,7 @@ export class Plug extends deviceBase {
|
|
|
329
329
|
await this.BLEPushConnection()
|
|
330
330
|
})
|
|
331
331
|
} else {
|
|
332
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
332
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
333
333
|
await this.BLEPushConnection()
|
|
334
334
|
}
|
|
335
335
|
} catch (error) {
|
|
@@ -116,7 +116,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
116
116
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
117
117
|
this.refreshStatus()
|
|
118
118
|
} catch (e: any) {
|
|
119
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
119
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
// regisiter webhook event handler if enabled
|
|
@@ -124,7 +124,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
124
124
|
this.debugLog('Registering Webhook Event Handler')
|
|
125
125
|
this.registerWebhook()
|
|
126
126
|
} catch (e: any) {
|
|
127
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
127
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// regisiter platform BLE event handler if enabled
|
|
@@ -132,7 +132,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
132
132
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
133
133
|
this.registerPlatformBLE()
|
|
134
134
|
} catch (e: any) {
|
|
135
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
135
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
// Start an update interval
|
|
@@ -264,22 +264,22 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
264
264
|
|
|
265
265
|
async BLERefreshStatus(): Promise<void> {
|
|
266
266
|
await this.debugLog('BLERefreshStatus')
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
await this.BLERefreshConnection(
|
|
267
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
268
|
+
if (switchBotBLE === undefined) {
|
|
269
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
270
270
|
} else {
|
|
271
271
|
// Start to monitor advertisement packets
|
|
272
272
|
(async () => {
|
|
273
273
|
// Start to monitor advertisement packets
|
|
274
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
274
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as unknown as robotVacuumCleanerServiceData
|
|
275
275
|
// Update HomeKit
|
|
276
276
|
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
277
277
|
this.serviceData = serviceData
|
|
278
278
|
await this.BLEparseStatus()
|
|
279
279
|
await this.updateHomeKitCharacteristics()
|
|
280
280
|
} else {
|
|
281
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
282
|
-
await this.BLERefreshConnection(
|
|
281
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
282
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
283
283
|
}
|
|
284
284
|
})()
|
|
285
285
|
}
|
|
@@ -300,7 +300,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
300
300
|
await this.BLEparseStatus()
|
|
301
301
|
await this.updateHomeKitCharacteristics()
|
|
302
302
|
} catch (e: any) {
|
|
303
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
303
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
} catch (error) {
|
|
@@ -342,7 +342,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
342
342
|
await this.parseStatusWebhook()
|
|
343
343
|
await this.updateHomeKitCharacteristics()
|
|
344
344
|
} catch (e: any) {
|
|
345
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
345
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
348
|
} else {
|
|
@@ -381,13 +381,13 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
381
381
|
async BLEpushChanges(): Promise<void> {
|
|
382
382
|
await this.debugLog('BLEpushChanges')
|
|
383
383
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
384
|
-
const
|
|
384
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
385
385
|
try {
|
|
386
386
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
387
387
|
this.device.bleMac = formattedDeviceId
|
|
388
388
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
389
|
-
if (
|
|
390
|
-
|
|
389
|
+
if (switchBotBLE !== false) {
|
|
390
|
+
switchBotBLE
|
|
391
391
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
392
392
|
.then(async (device_list: any) => {
|
|
393
393
|
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
@@ -412,7 +412,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
412
412
|
await this.BLEPushConnection()
|
|
413
413
|
})
|
|
414
414
|
} else {
|
|
415
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
415
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
416
416
|
await this.BLEPushConnection()
|
|
417
417
|
}
|
|
418
418
|
} catch (error) {
|
|
@@ -116,7 +116,7 @@ export class WaterDetector extends deviceBase {
|
|
|
116
116
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
117
117
|
this.refreshStatus()
|
|
118
118
|
} catch (e: any) {
|
|
119
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
119
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
// regisiter webhook event handler if enabled
|
|
@@ -124,7 +124,7 @@ export class WaterDetector extends deviceBase {
|
|
|
124
124
|
this.debugLog('Registering Webhook Event Handler')
|
|
125
125
|
this.registerWebhook()
|
|
126
126
|
} catch (e: any) {
|
|
127
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
127
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// regisiter platform BLE event handler if enabled
|
|
@@ -132,7 +132,7 @@ export class WaterDetector extends deviceBase {
|
|
|
132
132
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
133
133
|
this.registerPlatformBLE()
|
|
134
134
|
} catch (e: any) {
|
|
135
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
135
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
// Start an update interval
|
|
@@ -268,22 +268,22 @@ export class WaterDetector extends deviceBase {
|
|
|
268
268
|
|
|
269
269
|
async BLERefreshStatus(): Promise<void> {
|
|
270
270
|
await this.debugLog('BLERefreshStatus')
|
|
271
|
-
const
|
|
272
|
-
if (
|
|
273
|
-
await this.BLERefreshConnection(
|
|
271
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
272
|
+
if (switchBotBLE === undefined) {
|
|
273
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
274
274
|
} else {
|
|
275
275
|
// Start to monitor advertisement packets
|
|
276
276
|
(async () => {
|
|
277
277
|
// Start to monitor advertisement packets
|
|
278
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
278
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as waterLeakDetectorServiceData
|
|
279
279
|
// Update HomeKit
|
|
280
280
|
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
281
281
|
this.serviceData = serviceData
|
|
282
282
|
await this.BLEparseStatus()
|
|
283
283
|
await this.updateHomeKitCharacteristics()
|
|
284
284
|
} else {
|
|
285
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
286
|
-
await this.BLERefreshConnection(
|
|
285
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
286
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
287
287
|
}
|
|
288
288
|
})()
|
|
289
289
|
}
|
|
@@ -304,7 +304,7 @@ export class WaterDetector extends deviceBase {
|
|
|
304
304
|
await this.BLEparseStatus()
|
|
305
305
|
await this.updateHomeKitCharacteristics()
|
|
306
306
|
} catch (e: any) {
|
|
307
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
307
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
} catch (error) {
|
|
@@ -346,7 +346,7 @@ export class WaterDetector extends deviceBase {
|
|
|
346
346
|
await this.parseStatusWebhook()
|
|
347
347
|
await this.updateHomeKitCharacteristics()
|
|
348
348
|
} catch (e: any) {
|
|
349
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
349
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
} else {
|