@switchbot/homebridge-switchbot 3.5.0-beta.5 → 3.5.0-beta.51
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 +2 -0
- package/config.schema.json +120 -17
- package/dist/device/blindtilt.d.ts +21 -94
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +352 -757
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -71
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +588 -761
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -67
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +214 -588
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -74
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +256 -634
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -65
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +209 -532
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -86
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +340 -787
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +682 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +505 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +15 -59
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +247 -597
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -65
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +218 -579
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +179 -585
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -68
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +257 -569
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -62
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +215 -543
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -63
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +175 -578
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -64
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +164 -578
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +142 -520
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +87 -453
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -62
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +145 -452
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -70
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +126 -665
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +2 -2
- package/dist/index.js +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -48
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -38
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +6 -35
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +6 -39
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +67 -311
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +512 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +6 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -272
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -47
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -39
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -35
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -35
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +291 -147
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +41 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +87 -0
- package/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +378 -783
- package/src/device/bot.ts +621 -845
- package/src/device/ceilinglight.ts +227 -608
- package/src/device/colorbulb.ts +269 -657
- package/src/device/contact.ts +235 -555
- package/src/device/curtain.ts +360 -811
- package/src/device/device.ts +710 -0
- package/src/device/fan.ts +554 -0
- package/src/device/hub.ts +274 -625
- package/src/device/humidifier.ts +246 -624
- package/src/device/iosensor.ts +205 -611
- package/src/device/lightstrip.ts +278 -597
- package/src/device/lock.ts +252 -583
- package/src/device/meter.ts +200 -601
- package/src/device/meterplus.ts +189 -603
- package/src/device/motion.ts +161 -542
- package/src/device/plug.ts +97 -481
- package/src/device/robotvacuumcleaner.ts +166 -478
- package/src/device/waterdetector.ts +143 -689
- package/src/homebridge-ui/public/index.html +2 -2
- package/src/index.ts +1 -1
- package/src/irdevice/airconditioner.ts +330 -446
- package/src/irdevice/airpurifier.ts +89 -321
- package/src/irdevice/camera.ts +42 -293
- package/src/irdevice/fan.ts +78 -327
- package/src/irdevice/irdevice.ts +528 -0
- package/src/irdevice/light.ts +32 -287
- package/src/irdevice/other.ts +396 -615
- package/src/irdevice/tv.ts +100 -339
- package/src/irdevice/vacuumcleaner.ts +49 -305
- package/src/irdevice/waterheater.ts +50 -310
- package/src/platform.ts +301 -155
- package/src/settings.ts +57 -566
- package/src/utils.ts +642 -1
package/dist/platform.js
CHANGED
|
@@ -15,8 +15,9 @@ import { CeilingLight } from './device/ceilinglight.js';
|
|
|
15
15
|
import { StripLight } from './device/lightstrip.js';
|
|
16
16
|
import { Humidifier } from './device/humidifier.js';
|
|
17
17
|
import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
|
|
18
|
+
import { Fan } from './device/fan.js';
|
|
18
19
|
import { TV } from './irdevice/tv.js';
|
|
19
|
-
import {
|
|
20
|
+
import { IRFan } from './irdevice/fan.js';
|
|
20
21
|
import { Light } from './irdevice/light.js';
|
|
21
22
|
import { Others } from './irdevice/other.js';
|
|
22
23
|
import { Camera } from './irdevice/camera.js';
|
|
@@ -33,7 +34,8 @@ import fakegato from 'fakegato-history';
|
|
|
33
34
|
import asyncmqtt from 'async-mqtt';
|
|
34
35
|
import crypto, { randomUUID } from 'crypto';
|
|
35
36
|
import { readFileSync, writeFileSync } from 'fs';
|
|
36
|
-
import
|
|
37
|
+
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
38
|
+
import { sleep } from './utils.js';
|
|
37
39
|
/**
|
|
38
40
|
* HomebridgePlatform
|
|
39
41
|
* This class is the main constructor for your plugin, this is where you should
|
|
@@ -46,6 +48,8 @@ export class SwitchBotPlatform {
|
|
|
46
48
|
version;
|
|
47
49
|
Logging;
|
|
48
50
|
debugMode;
|
|
51
|
+
maxRetries;
|
|
52
|
+
delayBetweenRetries;
|
|
49
53
|
platformConfig;
|
|
50
54
|
platformLogging;
|
|
51
55
|
config;
|
|
@@ -85,7 +89,6 @@ export class SwitchBotPlatform {
|
|
|
85
89
|
return;
|
|
86
90
|
}
|
|
87
91
|
// import fakegato-history module and EVE characteristics
|
|
88
|
-
const { EveHomeKitTypes } = hbLib;
|
|
89
92
|
this.fakegatoAPI = fakegato(api);
|
|
90
93
|
this.eve = new EveHomeKitTypes(api);
|
|
91
94
|
// When this event is fired it means Homebridge has restored all cached accessories from disk.
|
|
@@ -355,6 +358,21 @@ export class SwitchBotPlatform {
|
|
|
355
358
|
this.config.options.pushRate = 0.1;
|
|
356
359
|
this.debugWarnLog('Using Default Push Rate.');
|
|
357
360
|
}
|
|
361
|
+
if (!this.config.options.maxRetries) {
|
|
362
|
+
this.config.options.maxRetries = 5;
|
|
363
|
+
this.debugWarnLog('Using Default Max Retries.');
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
this.maxRetries = this.config.options.maxRetries;
|
|
367
|
+
}
|
|
368
|
+
if (!this.config.options.delayBetweenRetries) {
|
|
369
|
+
// default 3 seconds
|
|
370
|
+
this.config.options.delayBetweenRetries = 3000;
|
|
371
|
+
this.debugWarnLog('Using Default Delay Between Retries.');
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
this.delayBetweenRetries = this.config.options.delayBetweenRetries * 1000;
|
|
375
|
+
}
|
|
358
376
|
if (!this.config.credentials && !this.config.options) {
|
|
359
377
|
this.debugWarnLog('Missing Credentials');
|
|
360
378
|
}
|
|
@@ -451,114 +469,129 @@ export class SwitchBotPlatform {
|
|
|
451
469
|
*/
|
|
452
470
|
async discoverDevices() {
|
|
453
471
|
if (this.config.credentials?.token) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
const
|
|
467
|
-
this.debugWarnLog(`
|
|
468
|
-
this.debugWarnLog(`
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
472
|
+
let retryCount = 0;
|
|
473
|
+
const maxRetries = this.maxRetries; // Maximum number of retries
|
|
474
|
+
const delayBetweenRetries = this.delayBetweenRetries; // Delay between retries in milliseconds
|
|
475
|
+
this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
476
|
+
this.debugWarnLog(`Max Retries: ${maxRetries}`);
|
|
477
|
+
this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
478
|
+
while (retryCount < maxRetries) {
|
|
479
|
+
try {
|
|
480
|
+
const { body, statusCode } = await request(Devices, {
|
|
481
|
+
headers: this.generateHeaders(),
|
|
482
|
+
});
|
|
483
|
+
this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
484
|
+
const devicesAPI = await body.json();
|
|
485
|
+
this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
486
|
+
this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
487
|
+
this.debugWarnLog(`devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
488
|
+
if ((statusCode === 200 || statusCode === 100) && (devicesAPI.statusCode === 200 || devicesAPI.statusCode === 100)) {
|
|
489
|
+
this.debugErrorLog(`statusCode: ${statusCode} & devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
490
|
+
// SwitchBot Devices
|
|
491
|
+
const deviceLists = devicesAPI.body.deviceList;
|
|
492
|
+
this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
493
|
+
this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
494
|
+
if (!this.config.options?.devices) {
|
|
495
|
+
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
496
|
+
if (deviceLists.length === 0) {
|
|
497
|
+
this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
const devices = deviceLists.map((v) => v);
|
|
501
|
+
for (const device of devices) {
|
|
502
|
+
if (device.deviceType) {
|
|
503
|
+
if (device.configDeviceName) {
|
|
504
|
+
device.deviceName = device.configDeviceName;
|
|
505
|
+
}
|
|
506
|
+
this.createDevice(device);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
473
510
|
}
|
|
474
|
-
else {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
511
|
+
else if (this.config.credentials?.token && this.config.options.devices) {
|
|
512
|
+
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
513
|
+
if (deviceLists.length === 0) {
|
|
514
|
+
this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
const deviceConfigs = this.config.options?.devices;
|
|
518
|
+
const mergeBydeviceId = (a1, a2) => a1.map((itm) => ({
|
|
519
|
+
...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
|
|
520
|
+
...itm,
|
|
521
|
+
}));
|
|
522
|
+
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
523
|
+
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
524
|
+
for (const device of devices) {
|
|
525
|
+
if (!device.deviceType) {
|
|
526
|
+
device.deviceType = device.configDeviceType;
|
|
527
|
+
this.errorLog(`API has displaying no deviceType: ${device.deviceType}, So using configDeviceType: ${device.configDeviceType}`);
|
|
528
|
+
}
|
|
529
|
+
if (device.deviceType) {
|
|
530
|
+
if (device.configDeviceName) {
|
|
531
|
+
device.deviceName = device.configDeviceName;
|
|
532
|
+
}
|
|
533
|
+
this.createDevice(device);
|
|
480
534
|
}
|
|
481
|
-
this.createDevice(device);
|
|
482
535
|
}
|
|
483
536
|
}
|
|
484
537
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (
|
|
489
|
-
this.
|
|
538
|
+
else {
|
|
539
|
+
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
540
|
+
}
|
|
541
|
+
if (devicesAPI.body.deviceList.length !== 0) {
|
|
542
|
+
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
490
543
|
}
|
|
491
544
|
else {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
545
|
+
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
546
|
+
}
|
|
547
|
+
// IR Devices
|
|
548
|
+
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
549
|
+
if (!this.config.options?.irdevices) {
|
|
550
|
+
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
551
|
+
const devices = irDeviceLists.map((v) => v);
|
|
499
552
|
for (const device of devices) {
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
this.errorLog(`API has displaying no deviceType: ${device.deviceType}, So using configDeviceType: ${device.configDeviceType}`);
|
|
503
|
-
}
|
|
504
|
-
if (device.deviceType) {
|
|
505
|
-
if (device.configDeviceName) {
|
|
506
|
-
device.deviceName = device.configDeviceName;
|
|
507
|
-
}
|
|
508
|
-
this.createDevice(device);
|
|
553
|
+
if (device.remoteType) {
|
|
554
|
+
this.createIRDevice(device);
|
|
509
555
|
}
|
|
510
556
|
}
|
|
511
557
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
// IR Devices
|
|
523
|
-
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
524
|
-
if (!this.config.options?.irdevices) {
|
|
525
|
-
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
526
|
-
const devices = irDeviceLists.map((v) => v);
|
|
527
|
-
for (const device of devices) {
|
|
528
|
-
if (device.remoteType) {
|
|
558
|
+
else {
|
|
559
|
+
this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
560
|
+
const irDeviceConfig = this.config.options?.irdevices;
|
|
561
|
+
const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
|
|
562
|
+
...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
|
|
563
|
+
...itm,
|
|
564
|
+
}));
|
|
565
|
+
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
566
|
+
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
567
|
+
for (const device of devices) {
|
|
529
568
|
this.createIRDevice(device);
|
|
530
569
|
}
|
|
531
570
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
535
|
-
const irDeviceConfig = this.config.options?.irdevices;
|
|
536
|
-
const mergeIRBydeviceId = (a1, a2) => a1.map((itm) => ({
|
|
537
|
-
...a2.find((item) => item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item),
|
|
538
|
-
...itm,
|
|
539
|
-
}));
|
|
540
|
-
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
541
|
-
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
542
|
-
for (const device of devices) {
|
|
543
|
-
this.createIRDevice(device);
|
|
571
|
+
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
572
|
+
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
544
573
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
574
|
+
else {
|
|
575
|
+
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
576
|
+
}
|
|
577
|
+
break;
|
|
548
578
|
}
|
|
549
579
|
else {
|
|
550
|
-
this.
|
|
580
|
+
this.statusCode(statusCode);
|
|
581
|
+
this.statusCode(devicesAPI.statusCode);
|
|
582
|
+
if (statusCode === 500) {
|
|
583
|
+
retryCount++;
|
|
584
|
+
this.infoLog(`statusCode: ${statusCode} Attempt ${retryCount} of ${maxRetries}`);
|
|
585
|
+
await sleep(delayBetweenRetries);
|
|
586
|
+
}
|
|
551
587
|
}
|
|
552
588
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
this.
|
|
589
|
+
catch (e) {
|
|
590
|
+
retryCount++;
|
|
591
|
+
this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
592
|
+
this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
556
593
|
}
|
|
557
594
|
}
|
|
558
|
-
catch (e) {
|
|
559
|
-
this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
560
|
-
this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
561
|
-
}
|
|
562
595
|
}
|
|
563
596
|
else if (!this.config.credentials?.token && this.config.options?.devices) {
|
|
564
597
|
this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
@@ -650,6 +683,7 @@ export class SwitchBotPlatform {
|
|
|
650
683
|
case 'WoSweeperMini':
|
|
651
684
|
case 'Robot Vacuum Cleaner S1':
|
|
652
685
|
case 'Robot Vacuum Cleaner S1 Plus':
|
|
686
|
+
case 'Robot Vacuum Cleaner S10':
|
|
653
687
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
654
688
|
this.createRobotVacuumCleaner(device);
|
|
655
689
|
break;
|
|
@@ -667,8 +701,13 @@ export class SwitchBotPlatform {
|
|
|
667
701
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
668
702
|
break;
|
|
669
703
|
case 'Remote':
|
|
704
|
+
case 'remote with screen+':
|
|
670
705
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
|
|
671
706
|
break;
|
|
707
|
+
case 'Battery Circulator Fan':
|
|
708
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
709
|
+
this.createFan(device);
|
|
710
|
+
break;
|
|
672
711
|
default:
|
|
673
712
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
674
713
|
// eslint-disable-next-line max-len
|
|
@@ -704,7 +743,7 @@ export class SwitchBotPlatform {
|
|
|
704
743
|
case 'Fan':
|
|
705
744
|
case 'DIY Fan':
|
|
706
745
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
707
|
-
this.
|
|
746
|
+
this.createIRFan(device);
|
|
708
747
|
break;
|
|
709
748
|
case 'Air Conditioner':
|
|
710
749
|
case 'DIY Air Conditioner':
|
|
@@ -759,7 +798,7 @@ export class SwitchBotPlatform {
|
|
|
759
798
|
existingAccessory.context.deviceID = device.deviceId;
|
|
760
799
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
761
800
|
if (device.firmware) {
|
|
762
|
-
existingAccessory.context.
|
|
801
|
+
existingAccessory.context.version = device.firmware;
|
|
763
802
|
}
|
|
764
803
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
765
804
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -787,7 +826,7 @@ export class SwitchBotPlatform {
|
|
|
787
826
|
accessory.context.model = device.deviceType;
|
|
788
827
|
accessory.context.deviceID = device.deviceId;
|
|
789
828
|
if (device.firmware) {
|
|
790
|
-
accessory.context.
|
|
829
|
+
accessory.context.version = device.firmware;
|
|
791
830
|
}
|
|
792
831
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
793
832
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -816,7 +855,7 @@ export class SwitchBotPlatform {
|
|
|
816
855
|
existingAccessory.context.deviceID = device.deviceId;
|
|
817
856
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
818
857
|
if (device.firmware) {
|
|
819
|
-
existingAccessory.context.
|
|
858
|
+
existingAccessory.context.version = device.firmware;
|
|
820
859
|
}
|
|
821
860
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
822
861
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -844,11 +883,11 @@ export class SwitchBotPlatform {
|
|
|
844
883
|
accessory.context.model = device.deviceType;
|
|
845
884
|
accessory.context.deviceID = device.deviceId;
|
|
846
885
|
if (device.firmware) {
|
|
847
|
-
accessory.context.
|
|
886
|
+
accessory.context.version = device.firmware;
|
|
848
887
|
}
|
|
849
888
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
850
889
|
accessory.context.connectionType = await this.connectionType(device);
|
|
851
|
-
// accessory.context.
|
|
890
|
+
// accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
|
|
852
891
|
// create the accessory handler for the newly create accessory
|
|
853
892
|
// this is imported from `platformAccessory.ts`
|
|
854
893
|
new Bot(this, accessory, device);
|
|
@@ -874,7 +913,7 @@ export class SwitchBotPlatform {
|
|
|
874
913
|
existingAccessory.context.deviceID = device.deviceId;
|
|
875
914
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
876
915
|
if (device.firmware) {
|
|
877
|
-
existingAccessory.context.
|
|
916
|
+
existingAccessory.context.version = device.firmware;
|
|
878
917
|
}
|
|
879
918
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
880
919
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -902,7 +941,7 @@ export class SwitchBotPlatform {
|
|
|
902
941
|
accessory.context.model = device.deviceType;
|
|
903
942
|
accessory.context.deviceID = device.deviceId;
|
|
904
943
|
if (device.firmware) {
|
|
905
|
-
accessory.context.
|
|
944
|
+
accessory.context.version = device.firmware;
|
|
906
945
|
}
|
|
907
946
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
908
947
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -932,7 +971,7 @@ export class SwitchBotPlatform {
|
|
|
932
971
|
existingAccessory.context.deviceID = device.deviceId;
|
|
933
972
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
934
973
|
if (device.firmware) {
|
|
935
|
-
existingAccessory.context.
|
|
974
|
+
existingAccessory.context.version = device.firmware;
|
|
936
975
|
}
|
|
937
976
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
938
977
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -960,7 +999,7 @@ export class SwitchBotPlatform {
|
|
|
960
999
|
accessory.context.model = device.deviceType;
|
|
961
1000
|
accessory.context.deviceID = device.deviceId;
|
|
962
1001
|
if (device.firmware) {
|
|
963
|
-
accessory.context.
|
|
1002
|
+
accessory.context.version = device.firmware;
|
|
964
1003
|
}
|
|
965
1004
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
966
1005
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -990,7 +1029,7 @@ export class SwitchBotPlatform {
|
|
|
990
1029
|
existingAccessory.context.deviceID = device.deviceId;
|
|
991
1030
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
992
1031
|
if (device.firmware) {
|
|
993
|
-
existingAccessory.context.
|
|
1032
|
+
existingAccessory.context.version = device.firmware;
|
|
994
1033
|
}
|
|
995
1034
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
996
1035
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1018,7 +1057,7 @@ export class SwitchBotPlatform {
|
|
|
1018
1057
|
accessory.context.model = device.deviceType;
|
|
1019
1058
|
accessory.context.deviceID = device.deviceId;
|
|
1020
1059
|
if (device.firmware) {
|
|
1021
|
-
accessory.context.
|
|
1060
|
+
accessory.context.version = device.firmware;
|
|
1022
1061
|
}
|
|
1023
1062
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1024
1063
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1047,7 +1086,7 @@ export class SwitchBotPlatform {
|
|
|
1047
1086
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1048
1087
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1049
1088
|
if (device.firmware) {
|
|
1050
|
-
existingAccessory.context.
|
|
1089
|
+
existingAccessory.context.version = device.firmware;
|
|
1051
1090
|
}
|
|
1052
1091
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1053
1092
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1075,7 +1114,7 @@ export class SwitchBotPlatform {
|
|
|
1075
1114
|
accessory.context.model = device.deviceType;
|
|
1076
1115
|
accessory.context.deviceID = device.deviceId;
|
|
1077
1116
|
if (device.firmware) {
|
|
1078
|
-
accessory.context.
|
|
1117
|
+
accessory.context.version = device.firmware;
|
|
1079
1118
|
}
|
|
1080
1119
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1081
1120
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1104,7 +1143,7 @@ export class SwitchBotPlatform {
|
|
|
1104
1143
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1105
1144
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1106
1145
|
if (device.firmware) {
|
|
1107
|
-
existingAccessory.context.
|
|
1146
|
+
existingAccessory.context.version = device.firmware;
|
|
1108
1147
|
}
|
|
1109
1148
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1110
1149
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1132,7 +1171,7 @@ export class SwitchBotPlatform {
|
|
|
1132
1171
|
accessory.context.model = device.deviceType;
|
|
1133
1172
|
accessory.context.deviceID = device.deviceId;
|
|
1134
1173
|
if (device.firmware) {
|
|
1135
|
-
accessory.context.
|
|
1174
|
+
accessory.context.version = device.firmware;
|
|
1136
1175
|
}
|
|
1137
1176
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1138
1177
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1161,7 +1200,7 @@ export class SwitchBotPlatform {
|
|
|
1161
1200
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1162
1201
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1163
1202
|
if (device.firmware) {
|
|
1164
|
-
existingAccessory.context.
|
|
1203
|
+
existingAccessory.context.version = device.firmware;
|
|
1165
1204
|
}
|
|
1166
1205
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1167
1206
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1189,7 +1228,7 @@ export class SwitchBotPlatform {
|
|
|
1189
1228
|
accessory.context.model = device.deviceType;
|
|
1190
1229
|
accessory.context.deviceID = device.deviceId;
|
|
1191
1230
|
if (device.firmware) {
|
|
1192
|
-
accessory.context.
|
|
1231
|
+
accessory.context.version = device.firmware;
|
|
1193
1232
|
}
|
|
1194
1233
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1195
1234
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1218,7 +1257,7 @@ export class SwitchBotPlatform {
|
|
|
1218
1257
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1219
1258
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1220
1259
|
if (device.firmware) {
|
|
1221
|
-
existingAccessory.context.
|
|
1260
|
+
existingAccessory.context.version = device.firmware;
|
|
1222
1261
|
}
|
|
1223
1262
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1224
1263
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1246,7 +1285,7 @@ export class SwitchBotPlatform {
|
|
|
1246
1285
|
accessory.context.model = device.deviceType;
|
|
1247
1286
|
accessory.context.deviceID = device.deviceId;
|
|
1248
1287
|
if (device.firmware) {
|
|
1249
|
-
accessory.context.
|
|
1288
|
+
accessory.context.version = device.firmware;
|
|
1250
1289
|
}
|
|
1251
1290
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1252
1291
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1275,7 +1314,7 @@ export class SwitchBotPlatform {
|
|
|
1275
1314
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1276
1315
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1277
1316
|
if (device.firmware) {
|
|
1278
|
-
existingAccessory.context.
|
|
1317
|
+
existingAccessory.context.version = device.firmware;
|
|
1279
1318
|
}
|
|
1280
1319
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1281
1320
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1315,7 +1354,7 @@ export class SwitchBotPlatform {
|
|
|
1315
1354
|
accessory.context.model = device.deviceType;
|
|
1316
1355
|
accessory.context.deviceID = device.deviceId;
|
|
1317
1356
|
if (device.firmware) {
|
|
1318
|
-
accessory.context.
|
|
1357
|
+
accessory.context.version = device.firmware;
|
|
1319
1358
|
}
|
|
1320
1359
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1321
1360
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1344,7 +1383,7 @@ export class SwitchBotPlatform {
|
|
|
1344
1383
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1345
1384
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1346
1385
|
if (device.firmware) {
|
|
1347
|
-
existingAccessory.context.
|
|
1386
|
+
existingAccessory.context.version = device.firmware;
|
|
1348
1387
|
}
|
|
1349
1388
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1350
1389
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1384,7 +1423,7 @@ export class SwitchBotPlatform {
|
|
|
1384
1423
|
accessory.context.model = device.deviceType;
|
|
1385
1424
|
accessory.context.deviceID = device.deviceId;
|
|
1386
1425
|
if (device.firmware) {
|
|
1387
|
-
accessory.context.
|
|
1426
|
+
accessory.context.version = device.firmware;
|
|
1388
1427
|
}
|
|
1389
1428
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1390
1429
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1413,7 +1452,7 @@ export class SwitchBotPlatform {
|
|
|
1413
1452
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1414
1453
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1415
1454
|
if (device.firmware) {
|
|
1416
|
-
existingAccessory.context.
|
|
1455
|
+
existingAccessory.context.version = device.firmware;
|
|
1417
1456
|
}
|
|
1418
1457
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1419
1458
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1441,7 +1480,7 @@ export class SwitchBotPlatform {
|
|
|
1441
1480
|
accessory.context.model = device.deviceType;
|
|
1442
1481
|
accessory.context.deviceID = device.deviceId;
|
|
1443
1482
|
if (device.firmware) {
|
|
1444
|
-
accessory.context.
|
|
1483
|
+
accessory.context.version = device.firmware;
|
|
1445
1484
|
}
|
|
1446
1485
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1447
1486
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1470,7 +1509,7 @@ export class SwitchBotPlatform {
|
|
|
1470
1509
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1471
1510
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1472
1511
|
if (device.firmware) {
|
|
1473
|
-
existingAccessory.context.
|
|
1512
|
+
existingAccessory.context.version = device.firmware;
|
|
1474
1513
|
}
|
|
1475
1514
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1476
1515
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1498,7 +1537,7 @@ export class SwitchBotPlatform {
|
|
|
1498
1537
|
accessory.context.model = device.deviceType;
|
|
1499
1538
|
accessory.context.deviceID = device.deviceId;
|
|
1500
1539
|
if (device.firmware) {
|
|
1501
|
-
accessory.context.
|
|
1540
|
+
accessory.context.version = device.firmware;
|
|
1502
1541
|
}
|
|
1503
1542
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1504
1543
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1527,7 +1566,7 @@ export class SwitchBotPlatform {
|
|
|
1527
1566
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1528
1567
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1529
1568
|
if (device.firmware) {
|
|
1530
|
-
existingAccessory.context.
|
|
1569
|
+
existingAccessory.context.version = device.firmware;
|
|
1531
1570
|
}
|
|
1532
1571
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1533
1572
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1555,7 +1594,7 @@ export class SwitchBotPlatform {
|
|
|
1555
1594
|
accessory.context.model = device.deviceType;
|
|
1556
1595
|
accessory.context.deviceID = device.deviceId;
|
|
1557
1596
|
if (device.firmware) {
|
|
1558
|
-
accessory.context.
|
|
1597
|
+
accessory.context.version = device.firmware;
|
|
1559
1598
|
}
|
|
1560
1599
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1561
1600
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1584,7 +1623,7 @@ export class SwitchBotPlatform {
|
|
|
1584
1623
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1585
1624
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1586
1625
|
if (device.firmware) {
|
|
1587
|
-
existingAccessory.context.
|
|
1626
|
+
existingAccessory.context.version = device.firmware;
|
|
1588
1627
|
}
|
|
1589
1628
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1590
1629
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1612,7 +1651,7 @@ export class SwitchBotPlatform {
|
|
|
1612
1651
|
accessory.context.model = device.deviceType;
|
|
1613
1652
|
accessory.context.deviceID = device.deviceId;
|
|
1614
1653
|
if (device.firmware) {
|
|
1615
|
-
accessory.context.
|
|
1654
|
+
accessory.context.version = device.firmware;
|
|
1616
1655
|
}
|
|
1617
1656
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1618
1657
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1641,7 +1680,7 @@ export class SwitchBotPlatform {
|
|
|
1641
1680
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1642
1681
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1643
1682
|
if (device.firmware) {
|
|
1644
|
-
existingAccessory.context.
|
|
1683
|
+
existingAccessory.context.version = device.firmware;
|
|
1645
1684
|
}
|
|
1646
1685
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1647
1686
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1669,7 +1708,7 @@ export class SwitchBotPlatform {
|
|
|
1669
1708
|
accessory.context.model = device.deviceType;
|
|
1670
1709
|
accessory.context.deviceID = device.deviceId;
|
|
1671
1710
|
if (device.firmware) {
|
|
1672
|
-
accessory.context.
|
|
1711
|
+
accessory.context.version = device.firmware;
|
|
1673
1712
|
}
|
|
1674
1713
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1675
1714
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1685,6 +1724,63 @@ export class SwitchBotPlatform {
|
|
|
1685
1724
|
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1686
1725
|
}
|
|
1687
1726
|
}
|
|
1727
|
+
async createFan(device) {
|
|
1728
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1729
|
+
// see if an accessory with the same uuid has already been registered and restored from
|
|
1730
|
+
// the cached devices we stored in the `configureAccessory` method above
|
|
1731
|
+
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
1732
|
+
if (existingAccessory) {
|
|
1733
|
+
// the accessory already exists
|
|
1734
|
+
if (await this.registerDevice(device)) {
|
|
1735
|
+
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1736
|
+
existingAccessory.context.model = device.deviceType;
|
|
1737
|
+
existingAccessory.context.deviceID = device.deviceId;
|
|
1738
|
+
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1739
|
+
if (device.firmware) {
|
|
1740
|
+
existingAccessory.context.version = device.firmware;
|
|
1741
|
+
}
|
|
1742
|
+
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1743
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1744
|
+
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1745
|
+
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1746
|
+
// create the accessory handler for the restored accessory
|
|
1747
|
+
// this is imported from `platformAccessory.ts`
|
|
1748
|
+
new Fan(this, existingAccessory, device);
|
|
1749
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1750
|
+
}
|
|
1751
|
+
else {
|
|
1752
|
+
this.unregisterPlatformAccessories(existingAccessory);
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
else if (await this.registerDevice(device)) {
|
|
1756
|
+
// the accessory does not yet exist, so we need to create it
|
|
1757
|
+
if (!device.external) {
|
|
1758
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1759
|
+
}
|
|
1760
|
+
// create a new accessory
|
|
1761
|
+
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1762
|
+
// store a copy of the device object in the `accessory.context`
|
|
1763
|
+
// the `context` property can be used to store any data about the accessory you may need
|
|
1764
|
+
accessory.context.device = device;
|
|
1765
|
+
accessory.context.model = device.deviceType;
|
|
1766
|
+
accessory.context.deviceID = device.deviceId;
|
|
1767
|
+
if (device.firmware) {
|
|
1768
|
+
accessory.context.version = device.firmware;
|
|
1769
|
+
}
|
|
1770
|
+
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1771
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1772
|
+
// create the accessory handler for the newly create accessory
|
|
1773
|
+
// this is imported from `platformAccessory.ts`
|
|
1774
|
+
new Fan(this, accessory, device);
|
|
1775
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1776
|
+
// publish device externally or link the accessory to your platform
|
|
1777
|
+
this.externalOrPlatform(device, accessory);
|
|
1778
|
+
this.accessories.push(accessory);
|
|
1779
|
+
}
|
|
1780
|
+
else {
|
|
1781
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1688
1784
|
async createRobotVacuumCleaner(device) {
|
|
1689
1785
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1690
1786
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
@@ -1698,7 +1794,7 @@ export class SwitchBotPlatform {
|
|
|
1698
1794
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1699
1795
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1700
1796
|
if (device.firmware) {
|
|
1701
|
-
existingAccessory.context.
|
|
1797
|
+
existingAccessory.context.version = device.firmware;
|
|
1702
1798
|
}
|
|
1703
1799
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1704
1800
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1726,7 +1822,7 @@ export class SwitchBotPlatform {
|
|
|
1726
1822
|
accessory.context.model = device.deviceType;
|
|
1727
1823
|
accessory.context.deviceID = device.deviceId;
|
|
1728
1824
|
if (device.firmware) {
|
|
1729
|
-
accessory.context.
|
|
1825
|
+
accessory.context.version = device.firmware;
|
|
1730
1826
|
}
|
|
1731
1827
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1732
1828
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1752,7 +1848,9 @@ export class SwitchBotPlatform {
|
|
|
1752
1848
|
existingAccessory.context.model = device.remoteType;
|
|
1753
1849
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1754
1850
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1755
|
-
|
|
1851
|
+
if (device.version && !device.firmware) {
|
|
1852
|
+
existingAccessory.context.version = device.version;
|
|
1853
|
+
}
|
|
1756
1854
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1757
1855
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1758
1856
|
existingAccessory.context.connectionType = device.connectionType;
|
|
@@ -1775,7 +1873,7 @@ export class SwitchBotPlatform {
|
|
|
1775
1873
|
accessory.context.model = device.remoteType;
|
|
1776
1874
|
accessory.context.deviceID = device.deviceId;
|
|
1777
1875
|
if (device.firmware) {
|
|
1778
|
-
accessory.context.
|
|
1876
|
+
accessory.context.version = device.firmware;
|
|
1779
1877
|
}
|
|
1780
1878
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1781
1879
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -1790,7 +1888,7 @@ export class SwitchBotPlatform {
|
|
|
1790
1888
|
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1791
1889
|
}
|
|
1792
1890
|
}
|
|
1793
|
-
async
|
|
1891
|
+
async createIRFan(device) {
|
|
1794
1892
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
1795
1893
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1796
1894
|
// the cached devices we stored in the `configureAccessory` method above
|
|
@@ -1803,7 +1901,7 @@ export class SwitchBotPlatform {
|
|
|
1803
1901
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1804
1902
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1805
1903
|
if (device.firmware) {
|
|
1806
|
-
existingAccessory.context.
|
|
1904
|
+
existingAccessory.context.version = device.firmware;
|
|
1807
1905
|
}
|
|
1808
1906
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1809
1907
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1811,7 +1909,7 @@ export class SwitchBotPlatform {
|
|
|
1811
1909
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1812
1910
|
// create the accessory handler for the restored accessory
|
|
1813
1911
|
// this is imported from `platformAccessory.ts`
|
|
1814
|
-
new
|
|
1912
|
+
new IRFan(this, existingAccessory, device);
|
|
1815
1913
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1816
1914
|
}
|
|
1817
1915
|
else {
|
|
@@ -1831,13 +1929,13 @@ export class SwitchBotPlatform {
|
|
|
1831
1929
|
accessory.context.model = device.remoteType;
|
|
1832
1930
|
accessory.context.deviceID = device.deviceId;
|
|
1833
1931
|
if (device.firmware) {
|
|
1834
|
-
accessory.context.
|
|
1932
|
+
accessory.context.version = device.firmware;
|
|
1835
1933
|
}
|
|
1836
1934
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1837
1935
|
accessory.context.connectionType = device.connectionType;
|
|
1838
1936
|
// create the accessory handler for the newly create accessory
|
|
1839
1937
|
// this is imported from `platformAccessory.ts`
|
|
1840
|
-
new
|
|
1938
|
+
new IRFan(this, accessory, device);
|
|
1841
1939
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1842
1940
|
// publish device externally or link the accessory to your platform
|
|
1843
1941
|
this.externalOrPlatformIR(device, accessory);
|
|
@@ -1860,7 +1958,7 @@ export class SwitchBotPlatform {
|
|
|
1860
1958
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1861
1959
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1862
1960
|
if (device.firmware) {
|
|
1863
|
-
existingAccessory.context.
|
|
1961
|
+
existingAccessory.context.version = device.firmware;
|
|
1864
1962
|
}
|
|
1865
1963
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1866
1964
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1888,7 +1986,7 @@ export class SwitchBotPlatform {
|
|
|
1888
1986
|
accessory.context.model = device.remoteType;
|
|
1889
1987
|
accessory.context.deviceID = device.deviceId;
|
|
1890
1988
|
if (device.firmware) {
|
|
1891
|
-
accessory.context.
|
|
1989
|
+
accessory.context.version = device.firmware;
|
|
1892
1990
|
}
|
|
1893
1991
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1894
1992
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -1917,7 +2015,7 @@ export class SwitchBotPlatform {
|
|
|
1917
2015
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1918
2016
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1919
2017
|
if (device.firmware) {
|
|
1920
|
-
existingAccessory.context.
|
|
2018
|
+
existingAccessory.context.version = device.firmware;
|
|
1921
2019
|
}
|
|
1922
2020
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1923
2021
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1945,7 +2043,7 @@ export class SwitchBotPlatform {
|
|
|
1945
2043
|
accessory.context.model = device.remoteType;
|
|
1946
2044
|
accessory.context.deviceID = device.deviceId;
|
|
1947
2045
|
if (device.firmware) {
|
|
1948
|
-
accessory.context.
|
|
2046
|
+
accessory.context.version = device.firmware;
|
|
1949
2047
|
}
|
|
1950
2048
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1951
2049
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -1974,7 +2072,7 @@ export class SwitchBotPlatform {
|
|
|
1974
2072
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1975
2073
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1976
2074
|
if (device.firmware) {
|
|
1977
|
-
existingAccessory.context.
|
|
2075
|
+
existingAccessory.context.version = device.firmware;
|
|
1978
2076
|
}
|
|
1979
2077
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1980
2078
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2002,7 +2100,7 @@ export class SwitchBotPlatform {
|
|
|
2002
2100
|
accessory.context.model = device.remoteType;
|
|
2003
2101
|
accessory.context.deviceID = device.deviceId;
|
|
2004
2102
|
if (device.firmware) {
|
|
2005
|
-
accessory.context.
|
|
2103
|
+
accessory.context.version = device.firmware;
|
|
2006
2104
|
}
|
|
2007
2105
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2008
2106
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2031,7 +2129,7 @@ export class SwitchBotPlatform {
|
|
|
2031
2129
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2032
2130
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2033
2131
|
if (device.firmware) {
|
|
2034
|
-
existingAccessory.context.
|
|
2132
|
+
existingAccessory.context.version = device.firmware;
|
|
2035
2133
|
}
|
|
2036
2134
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2037
2135
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2059,7 +2157,7 @@ export class SwitchBotPlatform {
|
|
|
2059
2157
|
accessory.context.model = device.remoteType;
|
|
2060
2158
|
accessory.context.deviceID = device.deviceId;
|
|
2061
2159
|
if (device.firmware) {
|
|
2062
|
-
accessory.context.
|
|
2160
|
+
accessory.context.version = device.firmware;
|
|
2063
2161
|
}
|
|
2064
2162
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2065
2163
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2088,7 +2186,7 @@ export class SwitchBotPlatform {
|
|
|
2088
2186
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2089
2187
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2090
2188
|
if (device.firmware) {
|
|
2091
|
-
existingAccessory.context.
|
|
2189
|
+
existingAccessory.context.version = device.firmware;
|
|
2092
2190
|
}
|
|
2093
2191
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2094
2192
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2116,7 +2214,7 @@ export class SwitchBotPlatform {
|
|
|
2116
2214
|
accessory.context.model = device.remoteType;
|
|
2117
2215
|
accessory.context.deviceID = device.deviceId;
|
|
2118
2216
|
if (device.firmware) {
|
|
2119
|
-
accessory.context.
|
|
2217
|
+
accessory.context.version = device.firmware;
|
|
2120
2218
|
}
|
|
2121
2219
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2122
2220
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2145,7 +2243,7 @@ export class SwitchBotPlatform {
|
|
|
2145
2243
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2146
2244
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2147
2245
|
if (device.firmware) {
|
|
2148
|
-
existingAccessory.context.
|
|
2246
|
+
existingAccessory.context.version = device.firmware;
|
|
2149
2247
|
}
|
|
2150
2248
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2151
2249
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2173,7 +2271,7 @@ export class SwitchBotPlatform {
|
|
|
2173
2271
|
accessory.context.model = device.remoteType;
|
|
2174
2272
|
accessory.context.deviceID = device.deviceId;
|
|
2175
2273
|
if (device.firmware) {
|
|
2176
|
-
accessory.context.
|
|
2274
|
+
accessory.context.version = device.firmware;
|
|
2177
2275
|
}
|
|
2178
2276
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2179
2277
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2202,7 +2300,7 @@ export class SwitchBotPlatform {
|
|
|
2202
2300
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2203
2301
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2204
2302
|
if (device.firmware) {
|
|
2205
|
-
existingAccessory.context.
|
|
2303
|
+
existingAccessory.context.version = device.firmware;
|
|
2206
2304
|
}
|
|
2207
2305
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2208
2306
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2230,7 +2328,7 @@ export class SwitchBotPlatform {
|
|
|
2230
2328
|
accessory.context.model = device.remoteType;
|
|
2231
2329
|
accessory.context.deviceID = device.deviceId;
|
|
2232
2330
|
if (device.firmware) {
|
|
2233
|
-
accessory.context.
|
|
2331
|
+
accessory.context.version = device.firmware;
|
|
2234
2332
|
}
|
|
2235
2333
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2236
2334
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2492,6 +2590,29 @@ export class SwitchBotPlatform {
|
|
|
2492
2590
|
this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2493
2591
|
}
|
|
2494
2592
|
}
|
|
2593
|
+
async retryRequest(deviceMaxRetries, deviceDelayBetweenRetries, url, options) {
|
|
2594
|
+
let retryCount = 0;
|
|
2595
|
+
const maxRetries = deviceMaxRetries;
|
|
2596
|
+
const delayBetweenRetries = deviceDelayBetweenRetries;
|
|
2597
|
+
while (retryCount < maxRetries) {
|
|
2598
|
+
try {
|
|
2599
|
+
const { body, statusCode } = await request(url, options);
|
|
2600
|
+
if (statusCode === 200 || statusCode === 100) {
|
|
2601
|
+
return { body, statusCode };
|
|
2602
|
+
}
|
|
2603
|
+
else {
|
|
2604
|
+
this.debugLog(`Received status code: ${statusCode}`);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
catch (error) {
|
|
2608
|
+
this.errorLog(`Error making request: ${error.message}`);
|
|
2609
|
+
}
|
|
2610
|
+
retryCount++;
|
|
2611
|
+
this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2612
|
+
await sleep(delayBetweenRetries);
|
|
2613
|
+
}
|
|
2614
|
+
return { body: null, statusCode: -1 };
|
|
2615
|
+
}
|
|
2495
2616
|
// BLE Connection
|
|
2496
2617
|
async connectBLE() {
|
|
2497
2618
|
let switchbot;
|
|
@@ -2522,6 +2643,24 @@ export class SwitchBotPlatform {
|
|
|
2522
2643
|
if (this.config.options.pushRate) {
|
|
2523
2644
|
platformConfig.pushRate = this.config.options.pushRate;
|
|
2524
2645
|
}
|
|
2646
|
+
if (this.config.options.maxRetries) {
|
|
2647
|
+
this.maxRetries = this.config.options.maxRetries;
|
|
2648
|
+
platformConfig.maxRetries = this.config.options.maxRetries;
|
|
2649
|
+
}
|
|
2650
|
+
else {
|
|
2651
|
+
this.maxRetries = 3;
|
|
2652
|
+
this.debugWarnLog('Using Default Max Retries');
|
|
2653
|
+
platformConfig.maxRetries = this.maxRetries;
|
|
2654
|
+
}
|
|
2655
|
+
if (this.config.options.delayBetweenRetries) {
|
|
2656
|
+
this.delayBetweenRetries = this.config.options.delayBetweenRetries * 1000;
|
|
2657
|
+
platformConfig.delayBetweenRetries = this.config.options.delayBetweenRetries;
|
|
2658
|
+
}
|
|
2659
|
+
else {
|
|
2660
|
+
this.delayBetweenRetries = 3000;
|
|
2661
|
+
this.debugWarnLog('Using Default Delay Between Retries');
|
|
2662
|
+
platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
|
|
2663
|
+
}
|
|
2525
2664
|
if (Object.entries(platformConfig).length !== 0) {
|
|
2526
2665
|
this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2527
2666
|
}
|
|
@@ -2547,6 +2686,11 @@ export class SwitchBotPlatform {
|
|
|
2547
2686
|
* If device level logging is turned on, log to log.warn
|
|
2548
2687
|
* Otherwise send debug logs to log.debug
|
|
2549
2688
|
*/
|
|
2689
|
+
successLog(...log) {
|
|
2690
|
+
if (this.enablingPlatformLogging()) {
|
|
2691
|
+
this.log.success(String(...log));
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2550
2694
|
infoLog(...log) {
|
|
2551
2695
|
if (this.enablingPlatformLogging()) {
|
|
2552
2696
|
this.log.info(String(...log));
|