@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/device/blindtilt.js +103 -103
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +84 -84
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +97 -97
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +139 -139
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +47 -47
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +91 -89
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +12 -12
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +42 -42
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +95 -95
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +46 -46
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js +84 -84
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +44 -44
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +118 -118
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +74 -74
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +44 -44
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +42 -42
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/meterpro.js +42 -42
- package/dist/device/meterpro.js.map +1 -1
- package/dist/device/motion.js +44 -44
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +59 -59
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +73 -73
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +44 -44
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -31
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +10 -10
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js +9 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.js +11 -11
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.js +11 -11
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.js +9 -9
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +55 -55
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.js +33 -33
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.js +228 -228
- package/dist/platform.js.map +1 -1
- package/package.json +9 -9
- package/src/device/blindtilt.ts +103 -103
- package/src/device/bot.ts +84 -84
- package/src/device/ceilinglight.ts +97 -97
- package/src/device/colorbulb.ts +139 -139
- package/src/device/contact.ts +47 -47
- package/src/device/curtain.ts +91 -89
- package/src/device/device.ts +42 -42
- package/src/device/fan.ts +95 -95
- package/src/device/hub.ts +46 -46
- package/src/device/humidifier.ts +84 -84
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +118 -118
- package/src/device/lock.ts +74 -74
- package/src/device/meter.ts +44 -44
- package/src/device/meterplus.ts +42 -42
- package/src/device/meterpro.ts +42 -42
- package/src/device/motion.ts +44 -44
- package/src/device/plug.ts +61 -61
- package/src/device/robotvacuumcleaner.ts +73 -73
- package/src/device/waterdetector.ts +44 -44
- package/src/irdevice/airconditioner.ts +31 -31
- package/src/irdevice/airpurifier.ts +10 -10
- package/src/irdevice/camera.ts +9 -9
- package/src/irdevice/fan.ts +11 -11
- package/src/irdevice/irdevice.ts +11 -11
- package/src/irdevice/light.ts +9 -9
- package/src/irdevice/other.ts +55 -55
- package/src/irdevice/tv.ts +33 -33
- package/src/irdevice/vacuumcleaner.ts +9 -9
- package/src/irdevice/waterheater.ts +9 -9
- package/src/platform.ts +228 -228
package/dist/device/bot.js
CHANGED
|
@@ -186,7 +186,7 @@ export class Bot extends deviceBase {
|
|
|
186
186
|
}
|
|
187
187
|
catch (e) {
|
|
188
188
|
await this.apiError(e);
|
|
189
|
-
|
|
189
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
190
190
|
}
|
|
191
191
|
this.botUpdateInProgress = false;
|
|
192
192
|
});
|
|
@@ -195,40 +195,40 @@ export class Bot extends deviceBase {
|
|
|
195
195
|
* Parse the device status from the SwitchBotBLE API
|
|
196
196
|
*/
|
|
197
197
|
async BLEparseStatus() {
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
this.debugLog('BLEparseStatus');
|
|
199
|
+
this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
200
200
|
// BLEmode (true if Switch Mode) | (false if Press Mode)
|
|
201
201
|
this.On = this.serviceData.mode ? this.serviceData.state : false;
|
|
202
202
|
const mode = this.serviceData.mode ? 'Switch' : 'Press';
|
|
203
|
-
|
|
203
|
+
this.debugLog(`${mode} Mode, On: ${this.On}`);
|
|
204
204
|
this.accessory.context.On = this.On;
|
|
205
205
|
// BatteryLevel
|
|
206
206
|
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
207
|
-
|
|
207
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
208
208
|
// StatusLowBattery
|
|
209
209
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
210
210
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
211
211
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
212
|
-
|
|
212
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
213
213
|
}
|
|
214
214
|
/**
|
|
215
215
|
* Parse the device status from the SwitchBot OpenAPI
|
|
216
216
|
*/
|
|
217
217
|
async openAPIparseStatus() {
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
this.debugLog('openAPIparseStatus');
|
|
219
|
+
this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
220
220
|
// On
|
|
221
221
|
this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on';
|
|
222
|
-
|
|
222
|
+
this.debugLog(`On: ${this.On}`);
|
|
223
223
|
this.accessory.context.On = this.On;
|
|
224
224
|
// Battery Level
|
|
225
225
|
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
226
|
-
|
|
226
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
227
227
|
// StatusLowBattery
|
|
228
228
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
229
229
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
230
230
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
231
|
-
|
|
231
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
232
232
|
// Firmware Version
|
|
233
233
|
if (this.deviceStatus.version) {
|
|
234
234
|
const version = this.deviceStatus.version.toString();
|
|
@@ -241,33 +241,33 @@ export class Bot extends deviceBase {
|
|
|
241
241
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
242
242
|
.updateValue(deviceVersion);
|
|
243
243
|
this.accessory.context.version = deviceVersion;
|
|
244
|
-
|
|
244
|
+
this.debugLog(`version: ${deviceVersion}`);
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
async parseStatusWebhook() {
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
this.debugLog('parseStatusWebhook');
|
|
249
|
+
this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery}, ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
|
|
250
250
|
// On
|
|
251
251
|
this.On = this.webhookContext.power === 'on';
|
|
252
|
-
|
|
252
|
+
this.debugLog(`On: ${this.On}`);
|
|
253
253
|
// BatteryLevel
|
|
254
254
|
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
255
|
-
|
|
255
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
256
256
|
// StatusLowBattery
|
|
257
257
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
258
258
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
259
259
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
260
|
-
|
|
260
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
261
261
|
// Mode
|
|
262
262
|
this.botMode = this.webhookContext.deviceMode;
|
|
263
|
-
|
|
263
|
+
this.debugLog(`Mode: ${this.botMode}`);
|
|
264
264
|
}
|
|
265
265
|
/**
|
|
266
266
|
* Asks the SwitchBot API for the latest device information
|
|
267
267
|
*/
|
|
268
268
|
async refreshStatus() {
|
|
269
269
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
270
|
-
|
|
270
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
271
271
|
}
|
|
272
272
|
else if (this.BLE) {
|
|
273
273
|
await this.BLERefreshStatus();
|
|
@@ -277,11 +277,11 @@ export class Bot extends deviceBase {
|
|
|
277
277
|
}
|
|
278
278
|
else {
|
|
279
279
|
await this.offlineOff();
|
|
280
|
-
|
|
280
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
async BLERefreshStatus() {
|
|
284
|
-
|
|
284
|
+
this.debugLog('BLERefreshStatus');
|
|
285
285
|
const switchBotBLE = await this.switchbotBLE();
|
|
286
286
|
if (switchBotBLE === undefined) {
|
|
287
287
|
await this.BLERefreshConnection(switchBotBLE);
|
|
@@ -298,79 +298,79 @@ export class Bot extends deviceBase {
|
|
|
298
298
|
await this.updateHomeKitCharacteristics();
|
|
299
299
|
}
|
|
300
300
|
else {
|
|
301
|
-
|
|
301
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`);
|
|
302
302
|
await this.BLERefreshConnection(switchBotBLE);
|
|
303
303
|
}
|
|
304
304
|
})();
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
async registerPlatformBLE() {
|
|
308
|
-
|
|
308
|
+
this.debugLog('registerPlatformBLE');
|
|
309
309
|
if (this.config.options?.BLE) {
|
|
310
|
-
|
|
310
|
+
this.debugLog('is listening to Platform BLE.');
|
|
311
311
|
try {
|
|
312
312
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
313
313
|
this.device.bleMac = formattedDeviceId;
|
|
314
|
-
|
|
314
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
315
315
|
this.platform.bleEventHandler[this.device.bleMac] = async (context) => {
|
|
316
316
|
try {
|
|
317
|
-
|
|
317
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
318
318
|
this.serviceData = context;
|
|
319
319
|
await this.BLEparseStatus();
|
|
320
320
|
await this.updateHomeKitCharacteristics();
|
|
321
321
|
}
|
|
322
322
|
catch (e) {
|
|
323
|
-
|
|
323
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
324
324
|
}
|
|
325
325
|
};
|
|
326
326
|
}
|
|
327
327
|
catch (error) {
|
|
328
|
-
|
|
328
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
else {
|
|
332
|
-
|
|
332
|
+
this.debugLog('is not listening to Platform BLE');
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
async openAPIRefreshStatus() {
|
|
336
|
-
|
|
336
|
+
this.debugLog('openAPIRefreshStatus');
|
|
337
337
|
try {
|
|
338
|
-
const
|
|
339
|
-
const deviceStatus =
|
|
340
|
-
|
|
338
|
+
const response = await this.deviceRefreshStatus();
|
|
339
|
+
const deviceStatus = response.body;
|
|
340
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
341
341
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
342
|
-
|
|
342
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
343
343
|
this.deviceStatus = deviceStatus.body;
|
|
344
344
|
await this.openAPIparseStatus();
|
|
345
345
|
await this.updateHomeKitCharacteristics();
|
|
346
346
|
}
|
|
347
347
|
else {
|
|
348
|
-
|
|
349
|
-
|
|
348
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
349
|
+
this.debugWarnLog(deviceStatus);
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
catch (e) {
|
|
353
353
|
await this.apiError(e);
|
|
354
|
-
|
|
354
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
async registerWebhook() {
|
|
358
358
|
if (this.device.webhook) {
|
|
359
|
-
|
|
359
|
+
this.debugLog('is listening webhook.');
|
|
360
360
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
361
361
|
try {
|
|
362
|
-
|
|
362
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
363
363
|
this.webhookContext = context;
|
|
364
364
|
await this.parseStatusWebhook();
|
|
365
365
|
await this.updateHomeKitCharacteristics();
|
|
366
366
|
}
|
|
367
367
|
catch (e) {
|
|
368
|
-
|
|
368
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
369
369
|
}
|
|
370
370
|
};
|
|
371
371
|
}
|
|
372
372
|
else {
|
|
373
|
-
|
|
373
|
+
this.debugLog('is not listening webhook.');
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
/**
|
|
@@ -382,7 +382,7 @@ export class Bot extends deviceBase {
|
|
|
382
382
|
*/
|
|
383
383
|
async pushChanges() {
|
|
384
384
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
385
|
-
|
|
385
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
386
386
|
}
|
|
387
387
|
else if (this.BLE) {
|
|
388
388
|
await this.BLEpushChanges();
|
|
@@ -392,7 +392,7 @@ export class Bot extends deviceBase {
|
|
|
392
392
|
}
|
|
393
393
|
else {
|
|
394
394
|
await this.offlineOff();
|
|
395
|
-
|
|
395
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
396
396
|
}
|
|
397
397
|
// Refresh the status from the API
|
|
398
398
|
interval(15000)
|
|
@@ -403,26 +403,26 @@ export class Bot extends deviceBase {
|
|
|
403
403
|
});
|
|
404
404
|
}
|
|
405
405
|
async BLEpushChanges() {
|
|
406
|
-
|
|
406
|
+
this.debugLog('BLEpushChanges');
|
|
407
407
|
if ((this.On !== this.accessory.context.On) || this.allowPush) {
|
|
408
|
-
|
|
408
|
+
this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
409
409
|
const switchBotBLE = this.platform.switchBotBLE;
|
|
410
410
|
try {
|
|
411
411
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
412
412
|
this.device.bleMac = formattedDeviceId;
|
|
413
|
-
|
|
413
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
414
414
|
// if (switchBotBLE !== false) {
|
|
415
|
-
|
|
415
|
+
this.debugLog(`Bot Mode: ${this.botMode}`);
|
|
416
416
|
if (this.botMode === 'press') {
|
|
417
417
|
switchBotBLE
|
|
418
418
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
419
419
|
.then(async (device_list) => {
|
|
420
420
|
const deviceList = device_list;
|
|
421
|
-
|
|
421
|
+
this.infoLog(`On: ${this.On}`);
|
|
422
422
|
return await deviceList[0].press();
|
|
423
423
|
})
|
|
424
424
|
.then(async () => {
|
|
425
|
-
|
|
425
|
+
this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
|
|
426
426
|
await this.updateHomeKitCharacteristics();
|
|
427
427
|
setTimeout(async () => {
|
|
428
428
|
this.On = false;
|
|
@@ -432,7 +432,7 @@ export class Bot extends deviceBase {
|
|
|
432
432
|
})
|
|
433
433
|
.catch(async (e) => {
|
|
434
434
|
await this.apiError(e);
|
|
435
|
-
|
|
435
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
436
436
|
await this.BLEPushConnection();
|
|
437
437
|
});
|
|
438
438
|
}
|
|
@@ -461,41 +461,41 @@ export class Bot extends deviceBase {
|
|
|
461
461
|
});
|
|
462
462
|
})
|
|
463
463
|
.then(async () => {
|
|
464
|
-
|
|
464
|
+
this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
|
|
465
465
|
await this.updateHomeKitCharacteristics();
|
|
466
466
|
})
|
|
467
467
|
.catch(async (e) => {
|
|
468
468
|
await this.apiError(e);
|
|
469
|
-
|
|
469
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
470
470
|
await this.BLEPushConnection();
|
|
471
471
|
});
|
|
472
472
|
}
|
|
473
473
|
else {
|
|
474
|
-
|
|
474
|
+
this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`);
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
catch (error) {
|
|
478
|
-
|
|
478
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
481
|
else {
|
|
482
|
-
|
|
482
|
+
this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
async openAPIpushChanges() {
|
|
486
|
-
|
|
486
|
+
this.debugLog('openAPIpushChanges');
|
|
487
487
|
if (this.multiPressCount > 0) {
|
|
488
|
-
|
|
488
|
+
this.debugLog(`${this.multiPressCount} request(s) queued.`);
|
|
489
489
|
}
|
|
490
490
|
if ((this.On !== this.accessory.context.On) || this.allowPush || this.multiPressCount > 0) {
|
|
491
491
|
let command = '';
|
|
492
492
|
if (this.botMode === 'switch') {
|
|
493
493
|
command = this.On ? 'turnOn' : 'turnOff';
|
|
494
|
-
|
|
494
|
+
this.debugLog(`Switch Mode, Command: ${command}`);
|
|
495
495
|
}
|
|
496
496
|
else if (this.botMode === 'press' || this.botMode === 'multipress') {
|
|
497
497
|
command = 'press';
|
|
498
|
-
|
|
498
|
+
this.debugLog('Press Mode');
|
|
499
499
|
this.On = false;
|
|
500
500
|
}
|
|
501
501
|
else {
|
|
@@ -506,13 +506,13 @@ export class Bot extends deviceBase {
|
|
|
506
506
|
parameter: 'default',
|
|
507
507
|
commandType: 'command',
|
|
508
508
|
};
|
|
509
|
-
|
|
509
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
510
510
|
try {
|
|
511
|
-
const
|
|
512
|
-
const deviceStatus =
|
|
513
|
-
|
|
511
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
512
|
+
const deviceStatus = response.body;
|
|
513
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
514
514
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
515
|
-
|
|
515
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
516
516
|
await this.updateHomeKitCharacteristics();
|
|
517
517
|
}
|
|
518
518
|
else {
|
|
@@ -521,7 +521,7 @@ export class Bot extends deviceBase {
|
|
|
521
521
|
if (this.device.mode === 'multipress') {
|
|
522
522
|
this.multiPressCount--;
|
|
523
523
|
if (this.multiPressCount > 0) {
|
|
524
|
-
|
|
524
|
+
this.debugLog(`multiPressCount: ${this.multiPressCount}`);
|
|
525
525
|
this.On = true;
|
|
526
526
|
await this.openAPIpushChanges();
|
|
527
527
|
}
|
|
@@ -529,11 +529,11 @@ export class Bot extends deviceBase {
|
|
|
529
529
|
}
|
|
530
530
|
catch (e) {
|
|
531
531
|
await this.apiError(e);
|
|
532
|
-
|
|
532
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
535
|
else {
|
|
536
|
-
|
|
536
|
+
this.debugLog(`No Changes (openAPIpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
/**
|
|
@@ -567,29 +567,29 @@ export class Bot extends deviceBase {
|
|
|
567
567
|
* Updates the status for each of the HomeKit Characteristics
|
|
568
568
|
*/
|
|
569
569
|
async updateHomeKitCharacteristics() {
|
|
570
|
-
|
|
570
|
+
this.debugLog('updateHomeKitCharacteristics');
|
|
571
571
|
// BatteryLevel
|
|
572
572
|
if (this.Battery.BatteryLevel === undefined) {
|
|
573
|
-
|
|
573
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
574
574
|
}
|
|
575
575
|
else {
|
|
576
576
|
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
577
577
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
578
|
-
|
|
578
|
+
this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
579
579
|
}
|
|
580
580
|
// StatusLowBattery
|
|
581
581
|
if (this.Battery.StatusLowBattery === undefined) {
|
|
582
|
-
|
|
582
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
583
583
|
}
|
|
584
584
|
else {
|
|
585
585
|
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
586
586
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
587
|
-
|
|
587
|
+
this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
588
588
|
}
|
|
589
589
|
// State
|
|
590
590
|
const updateCharacteristic = async (service, characteristic, value, logMessage) => {
|
|
591
591
|
service.updateCharacteristic(characteristic, value);
|
|
592
|
-
|
|
592
|
+
this.debugLog(logMessage);
|
|
593
593
|
};
|
|
594
594
|
const stateActions = {
|
|
595
595
|
switch: async () => this.Switch && await updateCharacteristic(this.Switch.Service, this.hap.Characteristic.On, this.On, `updateCharacteristic On: ${this.On}`),
|
|
@@ -642,7 +642,7 @@ export class Bot extends deviceBase {
|
|
|
642
642
|
}
|
|
643
643
|
},
|
|
644
644
|
outlet: async () => this.Outlet && await updateCharacteristic(this.Outlet.Service, this.hap.Characteristic.On, this.On, `updateCharacteristic On: ${this.On}`),
|
|
645
|
-
default: async () =>
|
|
645
|
+
default: async () => this.errorLog(`botDeviceType: ${this.botDeviceType}, On: ${this.On}`),
|
|
646
646
|
};
|
|
647
647
|
const action = stateActions[this.botDeviceType] || stateActions.default;
|
|
648
648
|
await action();
|
|
@@ -655,7 +655,7 @@ export class Bot extends deviceBase {
|
|
|
655
655
|
Service: accessory.getService(this.hap.Service[serviceType]),
|
|
656
656
|
};
|
|
657
657
|
accessory.context[contextKey] = this[contextKey];
|
|
658
|
-
|
|
658
|
+
this.debugWarnLog(`Removing any leftover ${contextKey} Service`);
|
|
659
659
|
accessory.removeService(this[contextKey].Service);
|
|
660
660
|
}
|
|
661
661
|
async removeOutletService(accessory) {
|
|
@@ -692,7 +692,7 @@ export class Bot extends deviceBase {
|
|
|
692
692
|
// Bot Device Type
|
|
693
693
|
this.botDeviceType = device.type ?? 'Outlet';
|
|
694
694
|
const botDeviceType = device.type ? 'Device Config' : 'Default';
|
|
695
|
-
|
|
695
|
+
this.debugWarnLog(`Use ${botDeviceType} Device Type: ${this.botDeviceType}`);
|
|
696
696
|
// Bot Mode
|
|
697
697
|
this.botMode = device.mode ?? 'switch';
|
|
698
698
|
if (!device.mode) {
|
|
@@ -709,40 +709,40 @@ export class Bot extends deviceBase {
|
|
|
709
709
|
const botModeLog = device.mode
|
|
710
710
|
? `Using Bot Mode: ${this.botMode}`
|
|
711
711
|
: `No Bot Mode Set, Using default Bot Mode: ${this.botMode}`;
|
|
712
|
-
|
|
712
|
+
this.debugWarnLog(botModeLog);
|
|
713
713
|
this.accessory.context.botMode = this.botMode;
|
|
714
714
|
// Bot Double Press
|
|
715
715
|
this.doublePress = device.doublePress ?? 1;
|
|
716
716
|
const doublePress = device.doublePress
|
|
717
717
|
? `Using Double Press: ${this.doublePress}`
|
|
718
718
|
: `No Double Press Set, Using default Double Press: ${this.doublePress}`;
|
|
719
|
-
|
|
719
|
+
this.debugWarnLog(doublePress);
|
|
720
720
|
// Bot Press PushRate
|
|
721
721
|
this.pushRatePress = device.pushRatePress ?? 15;
|
|
722
722
|
const pushRatePress = device.pushRatePress
|
|
723
723
|
? `Using Bot Push Rate Press: ${this.pushRatePress}`
|
|
724
724
|
: `No Push Rate Press Set, Using default Push Rate Press: ${this.pushRatePress}`;
|
|
725
|
-
|
|
725
|
+
this.debugWarnLog(pushRatePress);
|
|
726
726
|
// Bot Allow Push
|
|
727
727
|
this.allowPush = device.allowPush ?? false;
|
|
728
728
|
const allowPush = device.allowPush
|
|
729
729
|
? `Using Allow Push: ${this.allowPush}`
|
|
730
730
|
: `No Allow Push Set, Using default Allow Push: ${this.allowPush}`;
|
|
731
|
-
|
|
731
|
+
this.debugWarnLog(allowPush);
|
|
732
732
|
// Bot Multi Press Count
|
|
733
733
|
this.multiPressCount = 0;
|
|
734
|
-
|
|
734
|
+
this.debugWarnLog(`Multi Press Count: ${this.multiPressCount}`);
|
|
735
735
|
}
|
|
736
736
|
async BLEPushConnection() {
|
|
737
737
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
738
|
-
|
|
738
|
+
this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
739
739
|
await this.openAPIpushChanges();
|
|
740
740
|
}
|
|
741
741
|
}
|
|
742
742
|
async BLERefreshConnection(switchbot) {
|
|
743
|
-
|
|
743
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
744
744
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
745
|
-
|
|
745
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
746
746
|
await this.openAPIRefreshStatus();
|
|
747
747
|
}
|
|
748
748
|
}
|