@switchbot/homebridge-switchbot 2.7.1 → 2.8.0-beta.1
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/npm-version-script.js +81 -0
- package/.prettierrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +10 -0
- package/config.schema.json +8 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +49 -59
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +44 -50
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +60 -63
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +68 -70
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -25
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -58
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +6 -0
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +168 -26
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +49 -56
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +18 -20
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +59 -61
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +40 -41
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +65 -68
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -20
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +20 -23
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +30 -33
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +48 -51
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +57 -61
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +29 -31
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +17 -20
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +27 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -26
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +19 -20
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +44 -47
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +17 -20
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +19 -20
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +44 -43
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +106 -72
- package/src/device/bot.ts +94 -58
- package/src/device/ceilinglight.ts +102 -68
- package/src/device/colorbulb.ts +134 -82
- package/src/device/contact.ts +54 -33
- package/src/device/curtain.ts +130 -101
- package/src/device/hub.ts +198 -35
- package/src/device/humidifier.ts +128 -80
- package/src/device/iosensor.ts +43 -27
- package/src/device/lightstrip.ts +108 -67
- package/src/device/lock.ts +73 -45
- package/src/device/meter.ts +94 -75
- package/src/device/meterplus.ts +43 -27
- package/src/device/motion.ts +50 -32
- package/src/device/plug.ts +62 -39
- package/src/device/robotvacuumcleaner.ts +78 -54
- package/src/irdevice/airconditioner.ts +111 -83
- package/src/irdevice/airpurifier.ts +55 -34
- package/src/irdevice/camera.ts +35 -23
- package/src/irdevice/fan.ts +47 -33
- package/src/irdevice/light.ts +43 -29
- package/src/irdevice/other.ts +39 -23
- package/src/irdevice/tv.ts +65 -51
- package/src/irdevice/vacuumcleaner.ts +35 -23
- package/src/irdevice/waterheater.ts +43 -27
- package/src/platform.ts +85 -55
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
package/src/device/humidifier.ts
CHANGED
|
@@ -54,10 +54,14 @@ export class Humidifier {
|
|
|
54
54
|
doHumidifierUpdate!: Subject<void>;
|
|
55
55
|
|
|
56
56
|
// Connection
|
|
57
|
-
private readonly BLE =
|
|
58
|
-
private readonly OpenAPI =
|
|
59
|
-
|
|
60
|
-
constructor(
|
|
57
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
58
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
59
|
+
|
|
60
|
+
constructor(
|
|
61
|
+
private readonly platform: SwitchBotPlatform,
|
|
62
|
+
private accessory: PlatformAccessory,
|
|
63
|
+
public device: device & devicesConfig,
|
|
64
|
+
) {
|
|
61
65
|
// default placeholders
|
|
62
66
|
this.logs(device);
|
|
63
67
|
this.scan(device);
|
|
@@ -184,8 +188,10 @@ export class Humidifier {
|
|
|
184
188
|
await this.pushChanges();
|
|
185
189
|
} catch (e: any) {
|
|
186
190
|
this.apiError(e);
|
|
187
|
-
this.errorLog(
|
|
188
|
-
|
|
191
|
+
this.errorLog(
|
|
192
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,` +
|
|
193
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
194
|
+
);
|
|
189
195
|
}
|
|
190
196
|
this.humidifierUpdateInProgress = false;
|
|
191
197
|
});
|
|
@@ -203,8 +209,9 @@ export class Humidifier {
|
|
|
203
209
|
await this.openAPIparseStatus();
|
|
204
210
|
} else {
|
|
205
211
|
await this.offlineOff();
|
|
206
|
-
this.debugWarnLog(
|
|
207
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
212
|
+
this.debugWarnLog(
|
|
213
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
214
|
+
);
|
|
208
215
|
}
|
|
209
216
|
}
|
|
210
217
|
|
|
@@ -254,14 +261,16 @@ export class Humidifier {
|
|
|
254
261
|
this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
|
|
255
262
|
}
|
|
256
263
|
}
|
|
257
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
258
|
-
+ ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
259
264
|
this.debugLog(
|
|
260
|
-
`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
261
|
-
|
|
265
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
266
|
+
);
|
|
267
|
+
this.debugLog(
|
|
268
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
269
|
+
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
270
|
+
);
|
|
271
|
+
this.debugLog(
|
|
272
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
262
273
|
);
|
|
263
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
264
|
-
+ ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
265
274
|
// Active
|
|
266
275
|
switch (this.power) {
|
|
267
276
|
case 'on':
|
|
@@ -278,7 +287,6 @@ export class Humidifier {
|
|
|
278
287
|
this.WaterLevel = 100;
|
|
279
288
|
}
|
|
280
289
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
|
|
281
|
-
|
|
282
290
|
}
|
|
283
291
|
|
|
284
292
|
/**
|
|
@@ -293,8 +301,10 @@ export class Humidifier {
|
|
|
293
301
|
await this.openAPIRefreshStatus();
|
|
294
302
|
} else {
|
|
295
303
|
await this.offlineOff();
|
|
296
|
-
this.debugWarnLog(
|
|
297
|
-
|
|
304
|
+
this.debugWarnLog(
|
|
305
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
306
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
307
|
+
);
|
|
298
308
|
}
|
|
299
309
|
}
|
|
300
310
|
|
|
@@ -319,8 +329,10 @@ export class Humidifier {
|
|
|
319
329
|
// Set an event hander
|
|
320
330
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
321
331
|
this.address = ad.address;
|
|
322
|
-
this.debugLog(
|
|
323
|
-
|
|
332
|
+
this.debugLog(
|
|
333
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
334
|
+
` BLE Address Found: ${this.address}`,
|
|
335
|
+
);
|
|
324
336
|
this.serviceData = ad.serviceData;
|
|
325
337
|
this.autoMode = ad.serviceData.autoMode;
|
|
326
338
|
this.onState = ad.serviceData.onState;
|
|
@@ -349,8 +361,10 @@ export class Humidifier {
|
|
|
349
361
|
})
|
|
350
362
|
.catch(async (e: any) => {
|
|
351
363
|
this.apiError(e);
|
|
352
|
-
this.errorLog(
|
|
353
|
-
|
|
364
|
+
this.errorLog(
|
|
365
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
366
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
367
|
+
);
|
|
354
368
|
await this.BLERefreshConnection(switchbot);
|
|
355
369
|
});
|
|
356
370
|
} else {
|
|
@@ -368,10 +382,7 @@ export class Humidifier {
|
|
|
368
382
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
369
383
|
this.statusCode(statusCode);
|
|
370
384
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
371
|
-
this.debugLog(
|
|
372
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
373
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
374
|
-
);
|
|
385
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
375
386
|
this.auto = deviceStatus.body.auto;
|
|
376
387
|
this.power = deviceStatus.body.power;
|
|
377
388
|
this.lackWater = deviceStatus.body.lackWater;
|
|
@@ -382,8 +393,10 @@ export class Humidifier {
|
|
|
382
393
|
this.updateHomeKitCharacteristics();
|
|
383
394
|
} catch (e: any) {
|
|
384
395
|
this.apiError(e);
|
|
385
|
-
this.errorLog(
|
|
386
|
-
|
|
396
|
+
this.errorLog(
|
|
397
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
398
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
399
|
+
);
|
|
387
400
|
}
|
|
388
401
|
}
|
|
389
402
|
|
|
@@ -393,14 +406,15 @@ export class Humidifier {
|
|
|
393
406
|
async pushChanges(): Promise<void> {
|
|
394
407
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
395
408
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
396
|
-
}
|
|
409
|
+
} /*if (this.BLE) {
|
|
397
410
|
await this.BLEpushChanges();
|
|
398
|
-
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
411
|
+
} else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
399
412
|
await this.openAPIpushChanges();
|
|
400
413
|
} else {
|
|
401
414
|
await this.offlineOff();
|
|
402
|
-
this.debugWarnLog(
|
|
403
|
-
|
|
415
|
+
this.debugWarnLog(
|
|
416
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`,
|
|
417
|
+
);
|
|
404
418
|
}
|
|
405
419
|
interval(5000)
|
|
406
420
|
.pipe(take(1))
|
|
@@ -433,21 +447,25 @@ export class Humidifier {
|
|
|
433
447
|
})
|
|
434
448
|
.catch(async (e: any) => {
|
|
435
449
|
this.apiError(e);
|
|
436
|
-
this.errorLog(
|
|
437
|
-
|
|
450
|
+
this.errorLog(
|
|
451
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}` +
|
|
452
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
453
|
+
);
|
|
438
454
|
await this.BLEPushConnection();
|
|
439
455
|
});
|
|
440
456
|
}
|
|
441
457
|
|
|
442
458
|
async openAPIpushChanges(): Promise<void> {
|
|
443
459
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
444
|
-
if (
|
|
445
|
-
this.
|
|
460
|
+
if (
|
|
461
|
+
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
462
|
+
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
463
|
+
) {
|
|
446
464
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
447
465
|
const bodyChange = JSON.stringify({
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
466
|
+
command: 'setMode',
|
|
467
|
+
parameter: `${this.RelativeHumidityHumidifierThreshold}`,
|
|
468
|
+
commandType: 'command',
|
|
451
469
|
});
|
|
452
470
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
453
471
|
try {
|
|
@@ -462,8 +480,9 @@ export class Humidifier {
|
|
|
462
480
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
463
481
|
} catch (e: any) {
|
|
464
482
|
this.apiError(e);
|
|
465
|
-
this.errorLog(
|
|
466
|
-
|
|
483
|
+
this.errorLog(
|
|
484
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}` +
|
|
485
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
467
486
|
);
|
|
468
487
|
}
|
|
469
488
|
} else if (
|
|
@@ -481,13 +500,15 @@ export class Humidifier {
|
|
|
481
500
|
*/
|
|
482
501
|
async pushAutoChanges(): Promise<void> {
|
|
483
502
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
484
|
-
if (
|
|
485
|
-
this.
|
|
503
|
+
if (
|
|
504
|
+
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
505
|
+
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
506
|
+
) {
|
|
486
507
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
487
508
|
const bodyChange = JSON.stringify({
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
509
|
+
command: 'setMode',
|
|
510
|
+
parameter: 'auto',
|
|
511
|
+
commandType: 'command',
|
|
491
512
|
});
|
|
492
513
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
493
514
|
try {
|
|
@@ -502,13 +523,16 @@ export class Humidifier {
|
|
|
502
523
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
503
524
|
} catch (e: any) {
|
|
504
525
|
this.apiError(e);
|
|
505
|
-
this.errorLog(
|
|
506
|
-
|
|
526
|
+
this.errorLog(
|
|
527
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}` +
|
|
528
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
507
529
|
);
|
|
508
530
|
}
|
|
509
531
|
} else {
|
|
510
|
-
this.debugLog(
|
|
511
|
-
|
|
532
|
+
this.debugLog(
|
|
533
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges.` +
|
|
534
|
+
`TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`,
|
|
535
|
+
);
|
|
512
536
|
}
|
|
513
537
|
}
|
|
514
538
|
|
|
@@ -520,9 +544,9 @@ export class Humidifier {
|
|
|
520
544
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
521
545
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
522
546
|
const bodyChange = JSON.stringify({
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
547
|
+
command: 'turnOff',
|
|
548
|
+
parameter: 'default',
|
|
549
|
+
commandType: 'command',
|
|
526
550
|
});
|
|
527
551
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
528
552
|
try {
|
|
@@ -537,8 +561,9 @@ export class Humidifier {
|
|
|
537
561
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
538
562
|
} catch (e: any) {
|
|
539
563
|
this.apiError(e);
|
|
540
|
-
this.errorLog(
|
|
541
|
-
|
|
564
|
+
this.errorLog(
|
|
565
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}` +
|
|
566
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
542
567
|
);
|
|
543
568
|
}
|
|
544
569
|
} else {
|
|
@@ -600,8 +625,9 @@ export class Humidifier {
|
|
|
600
625
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
601
626
|
} else {
|
|
602
627
|
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
603
|
-
this.debugLog(
|
|
604
|
-
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}
|
|
628
|
+
this.debugLog(
|
|
629
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
630
|
+
);
|
|
605
631
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
606
632
|
}
|
|
607
633
|
if (this.OpenAPI) {
|
|
@@ -614,23 +640,34 @@ export class Humidifier {
|
|
|
614
640
|
}
|
|
615
641
|
}
|
|
616
642
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
617
|
-
this.debugLog(
|
|
618
|
-
|
|
643
|
+
this.debugLog(
|
|
644
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
645
|
+
` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
646
|
+
);
|
|
619
647
|
} else {
|
|
620
|
-
this.humidifierService.updateCharacteristic(
|
|
621
|
-
this.CurrentHumidifierDehumidifierState
|
|
622
|
-
|
|
623
|
-
|
|
648
|
+
this.humidifierService.updateCharacteristic(
|
|
649
|
+
this.platform.Characteristic.CurrentHumidifierDehumidifierState,
|
|
650
|
+
this.CurrentHumidifierDehumidifierState,
|
|
651
|
+
);
|
|
652
|
+
this.debugLog(
|
|
653
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
654
|
+
` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
|
|
655
|
+
);
|
|
624
656
|
this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
|
|
625
657
|
}
|
|
626
658
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
627
|
-
this.debugLog(
|
|
628
|
-
+ ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}
|
|
659
|
+
this.debugLog(
|
|
660
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
661
|
+
);
|
|
629
662
|
} else {
|
|
630
|
-
this.humidifierService.updateCharacteristic(
|
|
631
|
-
this.TargetHumidifierDehumidifierState
|
|
632
|
-
|
|
633
|
-
|
|
663
|
+
this.humidifierService.updateCharacteristic(
|
|
664
|
+
this.platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
665
|
+
this.TargetHumidifierDehumidifierState,
|
|
666
|
+
);
|
|
667
|
+
this.debugLog(
|
|
668
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
669
|
+
` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
|
|
670
|
+
);
|
|
634
671
|
this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
|
|
635
672
|
}
|
|
636
673
|
if (this.Active === undefined) {
|
|
@@ -641,13 +678,19 @@ export class Humidifier {
|
|
|
641
678
|
this.accessory.context.Active = this.Active;
|
|
642
679
|
}
|
|
643
680
|
if (this.RelativeHumidityHumidifierThreshold === undefined) {
|
|
644
|
-
this.debugLog(
|
|
645
|
-
|
|
681
|
+
this.debugLog(
|
|
682
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
683
|
+
` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
684
|
+
);
|
|
646
685
|
} else {
|
|
647
|
-
this.humidifierService.updateCharacteristic(
|
|
648
|
-
this.RelativeHumidityHumidifierThreshold
|
|
649
|
-
|
|
650
|
-
|
|
686
|
+
this.humidifierService.updateCharacteristic(
|
|
687
|
+
this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
688
|
+
this.RelativeHumidityHumidifierThreshold,
|
|
689
|
+
);
|
|
690
|
+
this.debugLog(
|
|
691
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
692
|
+
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
693
|
+
);
|
|
651
694
|
this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
|
|
652
695
|
}
|
|
653
696
|
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
@@ -743,8 +786,10 @@ export class Humidifier {
|
|
|
743
786
|
this.offlineOff();
|
|
744
787
|
break;
|
|
745
788
|
case 171:
|
|
746
|
-
this.errorLog(
|
|
747
|
-
|
|
789
|
+
this.errorLog(
|
|
790
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
791
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
792
|
+
);
|
|
748
793
|
this.offlineOff();
|
|
749
794
|
break;
|
|
750
795
|
case 190:
|
|
@@ -760,8 +805,10 @@ export class Humidifier {
|
|
|
760
805
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
761
806
|
break;
|
|
762
807
|
default:
|
|
763
|
-
this.infoLog(
|
|
764
|
-
|
|
808
|
+
this.infoLog(
|
|
809
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
810
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
811
|
+
);
|
|
765
812
|
}
|
|
766
813
|
}
|
|
767
814
|
|
|
@@ -792,8 +839,9 @@ export class Humidifier {
|
|
|
792
839
|
|
|
793
840
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
794
841
|
let FirmwareRevision: string;
|
|
795
|
-
this.debugLog(
|
|
796
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
842
|
+
this.debugLog(
|
|
843
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
844
|
+
);
|
|
797
845
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
798
846
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
799
847
|
if (accessory.context.FirmwareRevision) {
|
package/src/device/iosensor.ts
CHANGED
|
@@ -61,10 +61,14 @@ export class IOSensor {
|
|
|
61
61
|
doIOSensorUpdate: Subject<void>;
|
|
62
62
|
|
|
63
63
|
// Connection
|
|
64
|
-
private readonly BLE =
|
|
65
|
-
private readonly OpenAPI =
|
|
66
|
-
|
|
67
|
-
constructor(
|
|
64
|
+
private readonly BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
65
|
+
private readonly OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
66
|
+
|
|
67
|
+
constructor(
|
|
68
|
+
private readonly platform: SwitchBotPlatform,
|
|
69
|
+
private accessory: PlatformAccessory,
|
|
70
|
+
public device: device & devicesConfig,
|
|
71
|
+
) {
|
|
68
72
|
// default placeholders
|
|
69
73
|
this.logs(device);
|
|
70
74
|
this.scan(device);
|
|
@@ -182,8 +186,9 @@ export class IOSensor {
|
|
|
182
186
|
await this.openAPIparseStatus();
|
|
183
187
|
} else {
|
|
184
188
|
await this.offlineOff();
|
|
185
|
-
this.debugWarnLog(
|
|
186
|
-
+ ` ${this.device.connectionType}, parseStatus will not happen
|
|
189
|
+
this.debugWarnLog(
|
|
190
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
191
|
+
);
|
|
187
192
|
}
|
|
188
193
|
}
|
|
189
194
|
|
|
@@ -213,7 +218,6 @@ export class IOSensor {
|
|
|
213
218
|
}
|
|
214
219
|
}
|
|
215
220
|
|
|
216
|
-
|
|
217
221
|
async openAPIparseStatus(): Promise<void> {
|
|
218
222
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
219
223
|
// Battery
|
|
@@ -250,8 +254,10 @@ export class IOSensor {
|
|
|
250
254
|
await this.openAPIRefreshStatus();
|
|
251
255
|
} else {
|
|
252
256
|
await this.offlineOff();
|
|
253
|
-
this.debugWarnLog(
|
|
254
|
-
|
|
257
|
+
this.debugWarnLog(
|
|
258
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` +
|
|
259
|
+
` ${this.device.connectionType}, refreshStatus will not happen.`,
|
|
260
|
+
);
|
|
255
261
|
}
|
|
256
262
|
}
|
|
257
263
|
|
|
@@ -276,8 +282,10 @@ export class IOSensor {
|
|
|
276
282
|
// Set an event hander
|
|
277
283
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
278
284
|
this.address = ad.address;
|
|
279
|
-
this.debugLog(
|
|
280
|
-
|
|
285
|
+
this.debugLog(
|
|
286
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
287
|
+
` BLE Address Found: ${this.address}`,
|
|
288
|
+
);
|
|
281
289
|
if (ad.serviceData.humidity! > 0) {
|
|
282
290
|
// reject unreliable data
|
|
283
291
|
this.humidity = ad.serviceData.humidity;
|
|
@@ -312,8 +320,10 @@ export class IOSensor {
|
|
|
312
320
|
})
|
|
313
321
|
.catch(async (e: any) => {
|
|
314
322
|
this.apiError(e);
|
|
315
|
-
this.errorLog(
|
|
316
|
-
|
|
323
|
+
this.errorLog(
|
|
324
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
325
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
326
|
+
);
|
|
317
327
|
await this.BLERefreshConnection(switchbot);
|
|
318
328
|
});
|
|
319
329
|
} else {
|
|
@@ -331,10 +341,7 @@ export class IOSensor {
|
|
|
331
341
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
332
342
|
this.statusCode(statusCode);
|
|
333
343
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
334
|
-
this.debugLog(
|
|
335
|
-
`${this.device.deviceType}: ${this.accessory.displayName
|
|
336
|
-
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
337
|
-
);
|
|
344
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
338
345
|
this.Humidity = deviceStatus.body.humidity!;
|
|
339
346
|
this.Temperature = deviceStatus.body.temperature!;
|
|
340
347
|
this.Battery = deviceStatus.body.battery!;
|
|
@@ -342,8 +349,10 @@ export class IOSensor {
|
|
|
342
349
|
this.updateHomeKitCharacteristics();
|
|
343
350
|
} catch (e: any) {
|
|
344
351
|
this.apiError(e);
|
|
345
|
-
this.errorLog(
|
|
346
|
-
|
|
352
|
+
this.errorLog(
|
|
353
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
|
|
354
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
355
|
+
);
|
|
347
356
|
}
|
|
348
357
|
}
|
|
349
358
|
|
|
@@ -359,8 +368,10 @@ export class IOSensor {
|
|
|
359
368
|
} else {
|
|
360
369
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
361
370
|
this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
362
|
-
this.debugLog(
|
|
363
|
-
|
|
371
|
+
this.debugLog(
|
|
372
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
373
|
+
` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
374
|
+
);
|
|
364
375
|
if (this.device.mqttURL) {
|
|
365
376
|
mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
|
|
366
377
|
}
|
|
@@ -530,8 +541,10 @@ export class IOSensor {
|
|
|
530
541
|
this.offlineOff();
|
|
531
542
|
break;
|
|
532
543
|
case 171:
|
|
533
|
-
this.errorLog(
|
|
534
|
-
|
|
544
|
+
this.errorLog(
|
|
545
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
546
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
547
|
+
);
|
|
535
548
|
this.offlineOff();
|
|
536
549
|
break;
|
|
537
550
|
case 190:
|
|
@@ -547,8 +560,10 @@ export class IOSensor {
|
|
|
547
560
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
548
561
|
break;
|
|
549
562
|
default:
|
|
550
|
-
this.infoLog(
|
|
551
|
-
|
|
563
|
+
this.infoLog(
|
|
564
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
565
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
566
|
+
);
|
|
552
567
|
}
|
|
553
568
|
}
|
|
554
569
|
|
|
@@ -572,8 +587,9 @@ export class IOSensor {
|
|
|
572
587
|
|
|
573
588
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
574
589
|
let FirmwareRevision: string;
|
|
575
|
-
this.debugLog(
|
|
576
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
590
|
+
this.debugLog(
|
|
591
|
+
`${this.device.deviceType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
592
|
+
);
|
|
577
593
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
578
594
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
579
595
|
if (accessory.context.FirmwareRevision) {
|