@switchbot/homebridge-switchbot 4.1.1-beta.0 → 4.1.1-beta.10
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/config.schema.json +2 -2
- package/dist/device/blindtilt.js +104 -104
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +86 -86
- 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 +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 +95 -93
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +13 -13
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +46 -46
- 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 +46 -46
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +85 -87
- 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 +44 -44
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.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.d.ts.map +1 -1
- package/dist/device/waterdetector.js +54 -56
- 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 +93 -93
- 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/docs/functions/default.html +1 -1
- package/package.json +9 -9
- package/src/device/blindtilt.ts +104 -104
- package/src/device/bot.ts +86 -86
- package/src/device/ceilinglight.ts +98 -98
- package/src/device/colorbulb.ts +140 -140
- package/src/device/contact.ts +47 -47
- package/src/device/curtain.ts +95 -93
- package/src/device/device.ts +46 -46
- package/src/device/fan.ts +96 -96
- package/src/device/hub.ts +46 -46
- package/src/device/humidifier.ts +85 -87
- 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 +44 -44
- package/src/device/plug.ts +62 -62
- package/src/device/robotvacuumcleaner.ts +74 -74
- package/src/device/waterdetector.ts +54 -55
- 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 +93 -93
- 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
|
}
|