@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.3
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/dist/device/blindtilt.js +102 -102
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +85 -85
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +98 -98
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +140 -140
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +44 -44
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +82 -82
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +11 -11
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +41 -41
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +96 -96
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +43 -43
- 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 +119 -119
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +75 -75
- 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 +42 -42
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +60 -60
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -74
- 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 +1 -1
- package/src/device/blindtilt.ts +102 -102
- package/src/device/bot.ts +85 -85
- package/src/device/ceilinglight.ts +98 -98
- package/src/device/colorbulb.ts +140 -140
- package/src/device/contact.ts +44 -44
- package/src/device/curtain.ts +82 -82
- package/src/device/device.ts +41 -41
- package/src/device/fan.ts +96 -96
- package/src/device/hub.ts +43 -43
- package/src/device/humidifier.ts +84 -84
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +119 -119
- package/src/device/lock.ts +75 -75
- 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 +42 -42
- package/src/device/plug.ts +60 -60
- package/src/device/robotvacuumcleaner.ts +74 -74
- 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
|
@@ -156,59 +156,59 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
156
156
|
await this.pushChanges()
|
|
157
157
|
} catch (e: any) {
|
|
158
158
|
await this.apiError(e)
|
|
159
|
-
|
|
159
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
160
160
|
}
|
|
161
161
|
this.robotVacuumCleanerUpdateInProgress = false
|
|
162
162
|
})
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
async BLEparseStatus(): Promise<void> {
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
this.debugLog('BLEparseStatus')
|
|
167
|
+
this.debugLog(`(state, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.battery}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel})`)
|
|
168
168
|
|
|
169
169
|
// On
|
|
170
170
|
this.LightBulb.On = !!['InDustCollecting', 'Clearing'].includes(this.deviceStatus.workingStatus)
|
|
171
|
-
|
|
171
|
+
this.debugLog(`On: ${this.LightBulb.On}`)
|
|
172
172
|
|
|
173
173
|
// BatteryLevel
|
|
174
174
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
175
|
-
|
|
175
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
176
176
|
|
|
177
177
|
// StatusLowBattery
|
|
178
178
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
179
179
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
180
180
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
181
|
-
|
|
181
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
async openAPIparseStatus() {
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
this.debugLog('openAPIparseStatus')
|
|
186
|
+
this.debugLog(`(onlineStatus, battery, workingStatus) = API: (${this.deviceStatus.onlineStatus}, ${this.deviceStatus.battery}, ${this.deviceStatus.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`)
|
|
187
187
|
|
|
188
188
|
// On
|
|
189
189
|
this.LightBulb.On = this.deviceStatus.onlineStatus === 'online'
|
|
190
|
-
|
|
190
|
+
this.debugLog(`On: ${this.LightBulb.On}`)
|
|
191
191
|
|
|
192
192
|
// BatteryLevel
|
|
193
193
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
194
|
-
|
|
194
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
195
195
|
|
|
196
196
|
// StatusLowBattery
|
|
197
197
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
198
198
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
199
199
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
200
|
-
|
|
200
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
201
201
|
|
|
202
202
|
// ChargingState
|
|
203
203
|
this.Battery.ChargingState = this.deviceStatus.workingStatus === 'Charging'
|
|
204
204
|
? this.hap.Characteristic.ChargingState.CHARGING
|
|
205
205
|
: this.hap.Characteristic.ChargingState.NOT_CHARGING
|
|
206
|
-
|
|
206
|
+
this.debugLog(`ChargingState: ${this.Battery.ChargingState}`)
|
|
207
207
|
|
|
208
208
|
// Firmware Version
|
|
209
209
|
if (this.deviceStatus.version) {
|
|
210
210
|
const version = this.deviceStatus.version.toString()
|
|
211
|
-
|
|
211
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
212
212
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
213
213
|
this.accessory
|
|
214
214
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -217,33 +217,33 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
217
217
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
218
218
|
.updateValue(deviceVersion)
|
|
219
219
|
this.accessory.context.version = deviceVersion
|
|
220
|
-
|
|
220
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
async parseStatusWebhook(): Promise<void> {
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
this.debugLog('parseStatusWebhook')
|
|
226
|
+
this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${this.webhookContext.onlineStatus}, ${this.webhookContext.battery}, ${this.webhookContext.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`)
|
|
227
227
|
|
|
228
228
|
// On
|
|
229
229
|
this.LightBulb.On = this.webhookContext.onlineStatus === 'online'
|
|
230
|
-
|
|
230
|
+
this.debugLog(`On: ${this.LightBulb.On}`)
|
|
231
231
|
|
|
232
232
|
// BatteryLevel
|
|
233
233
|
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
234
|
-
|
|
234
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
235
235
|
|
|
236
236
|
// StatusLowBattery
|
|
237
237
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
238
238
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
239
239
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
240
|
-
|
|
240
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
241
241
|
|
|
242
242
|
// ChargingState
|
|
243
243
|
this.Battery.ChargingState = this.webhookContext.workingStatus === 'Charging'
|
|
244
244
|
? this.hap.Characteristic.ChargingState.CHARGING
|
|
245
245
|
: this.hap.Characteristic.ChargingState.NOT_CHARGING
|
|
246
|
-
|
|
246
|
+
this.debugLog(`ChargingState: ${this.Battery.ChargingState}`)
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
/**
|
|
@@ -251,19 +251,19 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
251
251
|
*/
|
|
252
252
|
async refreshStatus(): Promise<void> {
|
|
253
253
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
254
|
-
|
|
254
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
255
255
|
} else if (this.BLE) {
|
|
256
256
|
await this.BLERefreshStatus()
|
|
257
257
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
258
258
|
await this.openAPIRefreshStatus()
|
|
259
259
|
} else {
|
|
260
260
|
await this.offlineOff()
|
|
261
|
-
|
|
261
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
async BLERefreshStatus(): Promise<void> {
|
|
266
|
-
|
|
266
|
+
this.debugLog('BLERefreshStatus')
|
|
267
267
|
const switchBotBLE = await this.switchbotBLE()
|
|
268
268
|
if (switchBotBLE === undefined) {
|
|
269
269
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -278,7 +278,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
278
278
|
await this.BLEparseStatus()
|
|
279
279
|
await this.updateHomeKitCharacteristics()
|
|
280
280
|
} else {
|
|
281
|
-
|
|
281
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
282
282
|
await this.BLERefreshConnection(switchBotBLE)
|
|
283
283
|
}
|
|
284
284
|
})()
|
|
@@ -286,67 +286,67 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
async registerPlatformBLE(): Promise<void> {
|
|
289
|
-
|
|
289
|
+
this.debugLog('registerPlatformBLE')
|
|
290
290
|
if (this.config.options?.BLE) {
|
|
291
|
-
|
|
291
|
+
this.debugLog('is listening to Platform BLE.')
|
|
292
292
|
try {
|
|
293
293
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
294
294
|
this.device.bleMac = formattedDeviceId
|
|
295
|
-
|
|
295
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
296
296
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: robotVacuumCleanerServiceData) => {
|
|
297
297
|
try {
|
|
298
|
-
|
|
298
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
299
299
|
this.serviceData = context
|
|
300
300
|
await this.BLEparseStatus()
|
|
301
301
|
await this.updateHomeKitCharacteristics()
|
|
302
302
|
} catch (e: any) {
|
|
303
|
-
|
|
303
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
} catch (error) {
|
|
307
|
-
|
|
307
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
308
308
|
}
|
|
309
309
|
} else {
|
|
310
|
-
|
|
310
|
+
this.debugLog('is not listening to Platform BLE')
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
async openAPIRefreshStatus(): Promise<void> {
|
|
315
|
-
|
|
315
|
+
this.debugLog('openAPIRefreshStatus')
|
|
316
316
|
try {
|
|
317
|
-
const
|
|
318
|
-
const deviceStatus: any =
|
|
319
|
-
|
|
317
|
+
const response = await this.deviceRefreshStatus()
|
|
318
|
+
const deviceStatus: any = response.body
|
|
319
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
320
320
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
321
|
-
|
|
321
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
322
322
|
this.deviceStatus = deviceStatus.body
|
|
323
323
|
await this.openAPIparseStatus()
|
|
324
324
|
await this.updateHomeKitCharacteristics()
|
|
325
325
|
} else {
|
|
326
|
-
|
|
327
|
-
|
|
326
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
327
|
+
this.debugWarnLog(deviceStatus)
|
|
328
328
|
}
|
|
329
329
|
} catch (e: any) {
|
|
330
330
|
await this.apiError(e)
|
|
331
|
-
|
|
331
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
async registerWebhook() {
|
|
336
336
|
if (this.device.webhook) {
|
|
337
|
-
|
|
337
|
+
this.debugLog('is listening webhook.')
|
|
338
338
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: robotVacuumCleanerS1WebhookContext | robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext) => {
|
|
339
339
|
try {
|
|
340
|
-
|
|
340
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
341
341
|
this.webhookContext = context
|
|
342
342
|
await this.parseStatusWebhook()
|
|
343
343
|
await this.updateHomeKitCharacteristics()
|
|
344
344
|
} catch (e: any) {
|
|
345
|
-
|
|
345
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
348
|
} else {
|
|
349
|
-
|
|
349
|
+
this.debugLog('is not listening webhook.')
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
|
|
@@ -360,14 +360,14 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
360
360
|
*/
|
|
361
361
|
async pushChanges(): Promise<void> {
|
|
362
362
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
363
|
-
|
|
363
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
364
364
|
} else if (this.BLE) {
|
|
365
365
|
await this.BLEpushChanges()
|
|
366
366
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
367
367
|
await this.openAPIpushChanges()
|
|
368
368
|
} else {
|
|
369
369
|
await this.offlineOff()
|
|
370
|
-
|
|
370
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
371
371
|
}
|
|
372
372
|
// Refresh the status from the API
|
|
373
373
|
interval(15000)
|
|
@@ -379,21 +379,21 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
async BLEpushChanges(): Promise<void> {
|
|
382
|
-
|
|
382
|
+
this.debugLog('BLEpushChanges')
|
|
383
383
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
384
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
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
389
389
|
if (switchBotBLE !== false) {
|
|
390
390
|
switchBotBLE
|
|
391
391
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
392
392
|
.then(async (device_list: SwitchbotDevice[]) => {
|
|
393
393
|
const deviceList = device_list as unknown as SwitchbotDevice[]
|
|
394
|
-
|
|
394
|
+
this.infoLog(`On: ${this.LightBulb.On}`)
|
|
395
395
|
return await this.retryBLE({
|
|
396
|
-
max:
|
|
396
|
+
max: this.maxRetryBLE(),
|
|
397
397
|
fn: async () => {
|
|
398
398
|
if (this.LightBulb.On) {
|
|
399
399
|
return await deviceList[0].turnOn()
|
|
@@ -404,28 +404,28 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
404
404
|
})
|
|
405
405
|
})
|
|
406
406
|
.then(async () => {
|
|
407
|
-
|
|
407
|
+
this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
408
408
|
await this.updateHomeKitCharacteristics()
|
|
409
409
|
})
|
|
410
410
|
.catch(async (e: any) => {
|
|
411
411
|
await this.apiError(e)
|
|
412
|
-
|
|
412
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
413
413
|
await this.BLEPushConnection()
|
|
414
414
|
})
|
|
415
415
|
} else {
|
|
416
|
-
|
|
416
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
417
417
|
await this.BLEPushConnection()
|
|
418
418
|
}
|
|
419
419
|
} catch (error) {
|
|
420
|
-
|
|
420
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
421
421
|
}
|
|
422
422
|
} else {
|
|
423
|
-
|
|
423
|
+
this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
async openAPIpushChanges() {
|
|
428
|
-
|
|
428
|
+
this.debugLog('openAPIpushChanges')
|
|
429
429
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
430
430
|
const command = this.LightBulb.On ? 'start' : 'dock'
|
|
431
431
|
const bodyChange: bodyChange = {
|
|
@@ -433,28 +433,28 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
433
433
|
parameter: 'default',
|
|
434
434
|
commandType: 'command',
|
|
435
435
|
}
|
|
436
|
-
|
|
436
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
437
437
|
try {
|
|
438
|
-
const
|
|
439
|
-
const deviceStatus: any =
|
|
440
|
-
|
|
438
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
439
|
+
const deviceStatus: any = response.body
|
|
440
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
441
441
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
442
|
-
|
|
442
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
443
443
|
await this.updateHomeKitCharacteristics()
|
|
444
444
|
} else {
|
|
445
445
|
await this.statusCode(deviceStatus.statusCode)
|
|
446
446
|
}
|
|
447
447
|
} catch (e: any) {
|
|
448
448
|
await this.apiError(e)
|
|
449
|
-
|
|
449
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
450
450
|
}
|
|
451
451
|
} else {
|
|
452
|
-
|
|
452
|
+
this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
455
|
|
|
456
456
|
async openAPIpushBrightnessChanges() {
|
|
457
|
-
|
|
457
|
+
this.debugLog('openAPIpushBrightnessChanges')
|
|
458
458
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
459
459
|
const command = this.LightBulb.Brightness === 0 ? 'dock' : 'PowLevel'
|
|
460
460
|
const parameter = this.LightBulb.Brightness === 25
|
|
@@ -469,23 +469,23 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
469
469
|
parameter: `${parameter}`,
|
|
470
470
|
commandType: 'command',
|
|
471
471
|
}
|
|
472
|
-
|
|
472
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
473
473
|
try {
|
|
474
|
-
const
|
|
475
|
-
const deviceStatus: any =
|
|
476
|
-
|
|
474
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
475
|
+
const deviceStatus: any = response.body
|
|
476
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
477
477
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
478
|
-
|
|
478
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
479
479
|
await this.updateHomeKitCharacteristics()
|
|
480
480
|
} else {
|
|
481
481
|
await this.statusCode(deviceStatus.statusCode)
|
|
482
482
|
}
|
|
483
483
|
} catch (e: any) {
|
|
484
484
|
await this.apiError(e)
|
|
485
|
-
|
|
485
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
486
486
|
}
|
|
487
487
|
} else {
|
|
488
|
-
|
|
488
|
+
this.debugLog(`No changes (openAPIpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
491
|
|
|
@@ -508,7 +508,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
508
508
|
*/
|
|
509
509
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
510
510
|
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
511
|
-
|
|
511
|
+
this.infoLog(`Set Brightness: ${value}`)
|
|
512
512
|
} else {
|
|
513
513
|
if (this.LightBulb.On) {
|
|
514
514
|
this.debugLog(`No Changes, Brightness: ${value}`)
|
|
@@ -536,15 +536,15 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
536
536
|
|
|
537
537
|
async BLEPushConnection() {
|
|
538
538
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
539
|
-
|
|
539
|
+
this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
540
540
|
await this.openAPIpushChanges()
|
|
541
541
|
}
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
545
|
-
|
|
545
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
546
546
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
547
|
-
|
|
547
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
548
548
|
await this.openAPIRefreshStatus()
|
|
549
549
|
}
|
|
550
550
|
}
|
|
@@ -139,20 +139,20 @@ export class WaterDetector extends deviceBase {
|
|
|
139
139
|
interval(this.deviceRefreshRate * 1000)
|
|
140
140
|
.pipe(skipWhile(() => this.WaterDetectorUpdateInProgress))
|
|
141
141
|
.subscribe(async () => {
|
|
142
|
-
|
|
142
|
+
this.debugLog(`update interval: ${this.deviceRefreshRate * 1000} seconds`)
|
|
143
143
|
await this.refreshStatus()
|
|
144
144
|
})
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
async BLEparseStatus(): Promise<void> {
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
this.debugLog('BLEparseStatus')
|
|
149
|
+
this.debugLog(`(state, status, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.status}, ${this.serviceData.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
|
|
150
150
|
|
|
151
151
|
// LeakSensor
|
|
152
152
|
if (!(this.device as waterDetectorConfig).hide_leak && this.LeakSensor?.Service) {
|
|
153
153
|
// StatusActive
|
|
154
154
|
this.LeakSensor.StatusActive = this.serviceData.state
|
|
155
|
-
|
|
155
|
+
this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
|
|
156
156
|
|
|
157
157
|
// LeakDetected
|
|
158
158
|
if ((this.device as waterDetectorConfig).dry) {
|
|
@@ -165,23 +165,23 @@ export class WaterDetector extends deviceBase {
|
|
|
165
165
|
}
|
|
166
166
|
// BatteryLevel
|
|
167
167
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
168
|
-
|
|
168
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
169
169
|
// StatusLowBattery
|
|
170
170
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
171
171
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
172
172
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
173
|
-
|
|
173
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
async openAPIparseStatus(): Promise<void> {
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
this.debugLog('openAPIparseStatus')
|
|
178
|
+
this.debugLog(`(status, battery) = OpenAPI: (${this.deviceStatus.status}, ${this.deviceStatus.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
|
|
179
179
|
|
|
180
180
|
// LeakSensor
|
|
181
181
|
if (!(this.device as waterDetectorConfig).hide_leak && this.LeakSensor?.Service) {
|
|
182
182
|
// StatusActive
|
|
183
183
|
this.LeakSensor.StatusActive = this.deviceStatus.battery !== 0
|
|
184
|
-
|
|
184
|
+
this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
|
|
185
185
|
|
|
186
186
|
// LeakDetected
|
|
187
187
|
if ((this.device as waterDetectorConfig).dry) {
|
|
@@ -195,18 +195,18 @@ export class WaterDetector extends deviceBase {
|
|
|
195
195
|
|
|
196
196
|
// BatteryLevel
|
|
197
197
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
198
|
-
|
|
198
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
199
199
|
|
|
200
200
|
// StatusLowBattery
|
|
201
201
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
202
202
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
203
203
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
204
|
-
|
|
204
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
205
205
|
|
|
206
206
|
// FirmwareVersion
|
|
207
207
|
if (this.deviceStatus.version) {
|
|
208
208
|
const version = this.deviceStatus.version.toString()
|
|
209
|
-
|
|
209
|
+
this.debugLog(`FirmwareVersion: ${version.replace(/^V|-.*$/g, '')}`)
|
|
210
210
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
211
211
|
this.accessory
|
|
212
212
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -215,19 +215,19 @@ export class WaterDetector extends deviceBase {
|
|
|
215
215
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
216
216
|
.updateValue(deviceVersion)
|
|
217
217
|
this.accessory.context.version = deviceVersion
|
|
218
|
-
|
|
218
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
async parseStatusWebhook(): Promise<void> {
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
this.debugLog('parseStatusWebhook')
|
|
224
|
+
this.debugLog(`(detectionState, battery) = Webhook: (${this.webhookContext.detectionState}, ${this.webhookContext.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
|
|
225
225
|
|
|
226
226
|
// LeakSensor
|
|
227
227
|
if (!(this.device as waterDetectorConfig).hide_leak && this.LeakSensor?.Service) {
|
|
228
228
|
// StatusActive
|
|
229
229
|
this.LeakSensor.StatusActive = !!this.webhookContext.detectionState
|
|
230
|
-
|
|
230
|
+
this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
|
|
231
231
|
|
|
232
232
|
// LeakDetected
|
|
233
233
|
if ((this.device as waterDetectorConfig).dry) {
|
|
@@ -235,19 +235,19 @@ export class WaterDetector extends deviceBase {
|
|
|
235
235
|
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
|
|
236
236
|
} else {
|
|
237
237
|
this.LeakSensor.LeakDetected = this.webhookContext.detectionState
|
|
238
|
-
|
|
238
|
+
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
// BatteryLevel
|
|
243
243
|
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
244
|
-
|
|
244
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
245
245
|
|
|
246
246
|
// StatusLowBattery
|
|
247
247
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
248
248
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
249
249
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
250
|
-
|
|
250
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
/**
|
|
@@ -255,19 +255,19 @@ export class WaterDetector extends deviceBase {
|
|
|
255
255
|
*/
|
|
256
256
|
async refreshStatus(): Promise<void> {
|
|
257
257
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
258
|
-
|
|
258
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
259
259
|
} else if (this.BLE) {
|
|
260
260
|
await this.BLERefreshStatus()
|
|
261
261
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
262
262
|
await this.openAPIRefreshStatus()
|
|
263
263
|
} else {
|
|
264
264
|
await this.offlineOff()
|
|
265
|
-
|
|
265
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
async BLERefreshStatus(): Promise<void> {
|
|
270
|
-
|
|
270
|
+
this.debugLog('BLERefreshStatus')
|
|
271
271
|
const switchBotBLE = await this.switchbotBLE()
|
|
272
272
|
if (switchBotBLE === undefined) {
|
|
273
273
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -282,7 +282,7 @@ export class WaterDetector extends deviceBase {
|
|
|
282
282
|
await this.BLEparseStatus()
|
|
283
283
|
await this.updateHomeKitCharacteristics()
|
|
284
284
|
} else {
|
|
285
|
-
|
|
285
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
286
286
|
await this.BLERefreshConnection(switchBotBLE)
|
|
287
287
|
}
|
|
288
288
|
})()
|
|
@@ -290,67 +290,67 @@ export class WaterDetector extends deviceBase {
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
async registerPlatformBLE(): Promise<void> {
|
|
293
|
-
|
|
293
|
+
this.debugLog('registerPlatformBLE')
|
|
294
294
|
if (this.config.options?.BLE) {
|
|
295
|
-
|
|
295
|
+
this.debugLog('is listening to Platform BLE.')
|
|
296
296
|
try {
|
|
297
297
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
298
298
|
this.device.bleMac = formattedDeviceId
|
|
299
|
-
|
|
299
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
300
300
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: waterLeakDetectorServiceData) => {
|
|
301
301
|
try {
|
|
302
|
-
|
|
302
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
303
303
|
this.serviceData = context
|
|
304
304
|
await this.BLEparseStatus()
|
|
305
305
|
await this.updateHomeKitCharacteristics()
|
|
306
306
|
} catch (e: any) {
|
|
307
|
-
|
|
307
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
} catch (error) {
|
|
311
|
-
|
|
311
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
312
312
|
}
|
|
313
313
|
} else {
|
|
314
|
-
|
|
314
|
+
this.debugLog('is not listening to Platform BLE')
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
async openAPIRefreshStatus(): Promise<void> {
|
|
319
|
-
|
|
319
|
+
this.debugLog('openAPIRefreshStatus')
|
|
320
320
|
try {
|
|
321
|
-
const
|
|
322
|
-
const deviceStatus: any =
|
|
323
|
-
|
|
321
|
+
const response = await this.deviceRefreshStatus()
|
|
322
|
+
const deviceStatus: any = response.body
|
|
323
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
324
324
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
325
|
-
|
|
325
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
326
326
|
this.deviceStatus = deviceStatus.body
|
|
327
327
|
await this.openAPIparseStatus()
|
|
328
328
|
await this.updateHomeKitCharacteristics()
|
|
329
329
|
} else {
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
331
|
+
this.debugWarnLog(deviceStatus)
|
|
332
332
|
}
|
|
333
333
|
} catch (e: any) {
|
|
334
334
|
await this.apiError(e)
|
|
335
|
-
|
|
335
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
async registerWebhook() {
|
|
340
340
|
if (this.device.webhook) {
|
|
341
|
-
|
|
341
|
+
this.debugLog('is listening webhook.')
|
|
342
342
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: waterLeakDetectorWebhookContext) => {
|
|
343
343
|
try {
|
|
344
|
-
|
|
344
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
345
345
|
this.webhookContext = context
|
|
346
346
|
await this.parseStatusWebhook()
|
|
347
347
|
await this.updateHomeKitCharacteristics()
|
|
348
348
|
} catch (e: any) {
|
|
349
|
-
|
|
349
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
} else {
|
|
353
|
-
|
|
353
|
+
this.debugLog('is not listening webhook.')
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
|
|
@@ -371,9 +371,9 @@ export class WaterDetector extends deviceBase {
|
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
374
|
-
|
|
374
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
375
375
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
376
|
-
|
|
376
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
377
377
|
await this.openAPIRefreshStatus()
|
|
378
378
|
}
|
|
379
379
|
}
|