@switchbot/homebridge-switchbot 3.5.0-beta.4 → 3.5.0-beta.41
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 +4 -1
- 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 +351 -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 +587 -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 +213 -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 +255 -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 +208 -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 +339 -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 +671 -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 +504 -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 +246 -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 +211 -572
- 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 +178 -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 +256 -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 +214 -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 +174 -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 +163 -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 +141 -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 +86 -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 +144 -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 +125 -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 +343 -198
- 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/package.json +16 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +377 -783
- package/src/device/bot.ts +620 -845
- package/src/device/ceilinglight.ts +226 -608
- package/src/device/colorbulb.ts +268 -657
- package/src/device/contact.ts +233 -554
- package/src/device/curtain.ts +359 -811
- package/src/device/device.ts +699 -0
- package/src/device/fan.ts +553 -0
- package/src/device/hub.ts +273 -625
- package/src/device/humidifier.ts +241 -619
- package/src/device/iosensor.ts +204 -611
- package/src/device/lightstrip.ts +277 -597
- package/src/device/lock.ts +251 -583
- package/src/device/meter.ts +199 -601
- package/src/device/meterplus.ts +188 -603
- package/src/device/motion.ts +160 -542
- package/src/device/plug.ts +96 -481
- package/src/device/robotvacuumcleaner.ts +165 -478
- package/src/device/waterdetector.ts +142 -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 +353 -206
- package/src/settings.ts +57 -566
- package/src/utils.ts +642 -1
package/src/platform.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Copyright(C) 2017-
|
|
1
|
+
/* Copyright(C) 2017-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
2
|
*
|
|
3
3
|
* platform.ts: @switchbot/homebridge-switchbot platform class.
|
|
4
4
|
*/
|
|
@@ -20,8 +20,9 @@ import { CeilingLight } from './device/ceilinglight.js';
|
|
|
20
20
|
import { StripLight } from './device/lightstrip.js';
|
|
21
21
|
import { Humidifier } from './device/humidifier.js';
|
|
22
22
|
import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
|
|
23
|
+
import { Fan } from './device/fan.js';
|
|
23
24
|
import { TV } from './irdevice/tv.js';
|
|
24
|
-
import {
|
|
25
|
+
import { IRFan } from './irdevice/fan.js';
|
|
25
26
|
import { Light } from './irdevice/light.js';
|
|
26
27
|
import { Others } from './irdevice/other.js';
|
|
27
28
|
import { Camera } from './irdevice/camera.js';
|
|
@@ -32,16 +33,16 @@ import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
|
|
|
32
33
|
import { AirConditioner } from './irdevice/airconditioner.js';
|
|
33
34
|
import * as http from 'http';
|
|
34
35
|
import { Buffer } from 'buffer';
|
|
35
|
-
import { request } from 'undici';
|
|
36
|
+
import { Dispatcher, request } from 'undici';
|
|
36
37
|
import { MqttClient } from 'mqtt';
|
|
37
38
|
import { queueScheduler } from 'rxjs';
|
|
38
39
|
import fakegato from 'fakegato-history';
|
|
39
40
|
import asyncmqtt from 'async-mqtt';
|
|
40
41
|
import crypto, { randomUUID } from 'crypto';
|
|
41
42
|
import { readFileSync, writeFileSync } from 'fs';
|
|
42
|
-
import
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
44
|
+
import { UrlObject } from 'url';
|
|
45
|
+
import { sleep } from './utils.js';
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* HomebridgePlatform
|
|
@@ -56,6 +57,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
56
57
|
version!: string;
|
|
57
58
|
Logging?: string;
|
|
58
59
|
debugMode!: boolean;
|
|
60
|
+
maxRetries!: number;
|
|
61
|
+
delayBetweenRetries!: number;
|
|
59
62
|
platformConfig!: SwitchBotPlatformConfig['options'];
|
|
60
63
|
platformLogging!: SwitchBotPlatformConfig['logging'];
|
|
61
64
|
config!: SwitchBotPlatformConfig;
|
|
@@ -104,7 +107,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
// import fakegato-history module and EVE characteristics
|
|
107
|
-
const { EveHomeKitTypes } = hbLib;
|
|
108
110
|
this.fakegatoAPI = fakegato(api);
|
|
109
111
|
this.eve = new EveHomeKitTypes(api);
|
|
110
112
|
|
|
@@ -383,6 +385,21 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
383
385
|
this.debugWarnLog('Using Default Push Rate.');
|
|
384
386
|
}
|
|
385
387
|
|
|
388
|
+
if (!this.config.options.maxRetries) {
|
|
389
|
+
this.config.options.maxRetries = 5;
|
|
390
|
+
this.debugWarnLog('Using Default Max Retries.');
|
|
391
|
+
} else {
|
|
392
|
+
this.maxRetries = this.config.options.maxRetries;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (!this.config.options.delayBetweenRetries) {
|
|
396
|
+
// default 3 seconds
|
|
397
|
+
this.config.options!.delayBetweenRetries! = 3000;
|
|
398
|
+
this.debugWarnLog('Using Default Delay Between Retries.');
|
|
399
|
+
} else {
|
|
400
|
+
this.delayBetweenRetries = this.config.options.delayBetweenRetries * 1000;
|
|
401
|
+
}
|
|
402
|
+
|
|
386
403
|
if (!this.config.credentials && !this.config.options) {
|
|
387
404
|
this.debugWarnLog('Missing Credentials');
|
|
388
405
|
} else if (this.config.credentials && !this.config.credentials.notice) {
|
|
@@ -492,44 +509,98 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
492
509
|
*/
|
|
493
510
|
async discoverDevices() {
|
|
494
511
|
if (this.config.credentials?.token) {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
const
|
|
508
|
-
this.debugWarnLog(`
|
|
509
|
-
this.debugWarnLog(`
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
512
|
+
let retryCount = 0;
|
|
513
|
+
const maxRetries = this.maxRetries; // Maximum number of retries
|
|
514
|
+
const delayBetweenRetries = this.delayBetweenRetries; // Delay between retries in milliseconds
|
|
515
|
+
this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
516
|
+
this.debugWarnLog(`Max Retries: ${maxRetries}`);
|
|
517
|
+
this.debugWarnLog(`Delay Between Retries: ${delayBetweenRetries}`);
|
|
518
|
+
while (retryCount < maxRetries) {
|
|
519
|
+
try {
|
|
520
|
+
const { body, statusCode } = await request(Devices, {
|
|
521
|
+
headers: this.generateHeaders(),
|
|
522
|
+
});
|
|
523
|
+
this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
524
|
+
const devicesAPI: any = await body.json();
|
|
525
|
+
this.debugWarnLog(`devicesAPI: ${JSON.stringify(devicesAPI)}`);
|
|
526
|
+
this.debugWarnLog(`devicesAPI Body: ${JSON.stringify(devicesAPI.body)}`);
|
|
527
|
+
this.debugWarnLog(`devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
528
|
+
if ((statusCode === 200 || statusCode === 100) && (devicesAPI.statusCode === 200 || devicesAPI.statusCode === 100)) {
|
|
529
|
+
this.debugErrorLog(`statusCode: ${statusCode} & devicesAPI StatusCode: ${devicesAPI.statusCode}`);
|
|
530
|
+
// SwitchBot Devices
|
|
531
|
+
const deviceLists = devicesAPI.body.deviceList;
|
|
532
|
+
this.debugWarnLog(`DeviceLists: ${JSON.stringify(deviceLists)}`);
|
|
533
|
+
this.debugWarnLog(`DeviceLists Length: ${deviceLists.length}`);
|
|
534
|
+
if (!this.config.options?.devices) {
|
|
535
|
+
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
536
|
+
if (deviceLists.length === 0) {
|
|
537
|
+
this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
538
|
+
} else {
|
|
539
|
+
const devices = deviceLists.map((v: any) => v);
|
|
540
|
+
for (const device of devices) {
|
|
541
|
+
if (device.deviceType) {
|
|
542
|
+
if (device.configDeviceName) {
|
|
543
|
+
device.deviceName = device.configDeviceName;
|
|
544
|
+
}
|
|
545
|
+
this.createDevice(device);
|
|
520
546
|
}
|
|
521
|
-
this.createDevice(device);
|
|
522
547
|
}
|
|
523
548
|
}
|
|
549
|
+
} else if (this.config.credentials?.token && this.config.options.devices) {
|
|
550
|
+
this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
551
|
+
if (deviceLists.length === 0) {
|
|
552
|
+
this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
553
|
+
} else {
|
|
554
|
+
const deviceConfigs = this.config.options?.devices;
|
|
555
|
+
|
|
556
|
+
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
557
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
558
|
+
...a2.find(
|
|
559
|
+
(item: { deviceId: string }) =>
|
|
560
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
561
|
+
),
|
|
562
|
+
...itm,
|
|
563
|
+
}));
|
|
564
|
+
|
|
565
|
+
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
566
|
+
this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`);
|
|
567
|
+
for (const device of devices) {
|
|
568
|
+
if (!device.deviceType) {
|
|
569
|
+
device.deviceType = device.configDeviceType;
|
|
570
|
+
this.errorLog(`API has displaying no deviceType: ${device.deviceType}, So using configDeviceType: ${device.configDeviceType}`);
|
|
571
|
+
}
|
|
572
|
+
if (device.deviceType) {
|
|
573
|
+
if (device.configDeviceName) {
|
|
574
|
+
device.deviceName = device.configDeviceName;
|
|
575
|
+
}
|
|
576
|
+
this.createDevice(device);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
} else {
|
|
581
|
+
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
524
582
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if (deviceLists.length === 0) {
|
|
528
|
-
this.debugLog(`SwitchBot API Currently Doesn't Have Any Devices With Cloud Services Enabled: ${JSON.stringify(devicesAPI.body)}`);
|
|
583
|
+
if (devicesAPI.body.deviceList.length !== 0) {
|
|
584
|
+
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
529
585
|
} else {
|
|
530
|
-
|
|
586
|
+
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
587
|
+
}
|
|
531
588
|
|
|
532
|
-
|
|
589
|
+
// IR Devices
|
|
590
|
+
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
591
|
+
if (!this.config.options?.irdevices) {
|
|
592
|
+
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
593
|
+
const devices = irDeviceLists.map((v: any) => v);
|
|
594
|
+
for (const device of devices) {
|
|
595
|
+
if (device.remoteType) {
|
|
596
|
+
this.createIRDevice(device);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
} else {
|
|
600
|
+
this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
601
|
+
const irDeviceConfig = this.config.options?.irdevices;
|
|
602
|
+
|
|
603
|
+
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
533
604
|
a1.map((itm: { deviceId: string }) => ({
|
|
534
605
|
...a2.find(
|
|
535
606
|
(item: { deviceId: string }) =>
|
|
@@ -538,73 +609,34 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
538
609
|
...itm,
|
|
539
610
|
}));
|
|
540
611
|
|
|
541
|
-
const devices =
|
|
542
|
-
this.debugLog(`
|
|
612
|
+
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
613
|
+
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
543
614
|
for (const device of devices) {
|
|
544
|
-
if (!device.deviceType) {
|
|
545
|
-
device.deviceType = device.configDeviceType;
|
|
546
|
-
this.errorLog(`API has displaying no deviceType: ${device.deviceType}, So using configDeviceType: ${device.configDeviceType}`);
|
|
547
|
-
}
|
|
548
|
-
if (device.deviceType) {
|
|
549
|
-
if (device.configDeviceName) {
|
|
550
|
-
device.deviceName = device.configDeviceName;
|
|
551
|
-
}
|
|
552
|
-
this.createDevice(device);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
} else {
|
|
557
|
-
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
558
|
-
}
|
|
559
|
-
if (devicesAPI.body.deviceList.length !== 0) {
|
|
560
|
-
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
561
|
-
} else {
|
|
562
|
-
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// IR Devices
|
|
566
|
-
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
567
|
-
if (!this.config.options?.irdevices) {
|
|
568
|
-
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
569
|
-
const devices = irDeviceLists.map((v: any) => v);
|
|
570
|
-
for (const device of devices) {
|
|
571
|
-
if (device.remoteType) {
|
|
572
615
|
this.createIRDevice(device);
|
|
573
616
|
}
|
|
574
617
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
580
|
-
a1.map((itm: { deviceId: string }) => ({
|
|
581
|
-
...a2.find(
|
|
582
|
-
(item: { deviceId: string }) =>
|
|
583
|
-
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
584
|
-
),
|
|
585
|
-
...itm,
|
|
586
|
-
}));
|
|
587
|
-
|
|
588
|
-
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
589
|
-
this.debugLog(`IR Devices: ${JSON.stringify(devices)}`);
|
|
590
|
-
for (const device of devices) {
|
|
591
|
-
this.createIRDevice(device);
|
|
618
|
+
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
619
|
+
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
620
|
+
} else {
|
|
621
|
+
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
592
622
|
}
|
|
593
|
-
|
|
594
|
-
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
595
|
-
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
623
|
+
break;
|
|
596
624
|
} else {
|
|
597
|
-
this.
|
|
625
|
+
this.statusCode(statusCode);
|
|
626
|
+
this.statusCode(devicesAPI.statusCode);
|
|
627
|
+
if (statusCode === 500) {
|
|
628
|
+
retryCount++;
|
|
629
|
+
this.infoLog(`statusCode: ${statusCode} Attempt ${retryCount} of ${maxRetries}`);
|
|
630
|
+
await sleep(delayBetweenRetries);
|
|
631
|
+
}
|
|
598
632
|
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
this.
|
|
633
|
+
} catch (e: any) {
|
|
634
|
+
retryCount++;
|
|
635
|
+
this.debugErrorLog(
|
|
636
|
+
`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug',
|
|
637
|
+
);
|
|
638
|
+
this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
602
639
|
}
|
|
603
|
-
} catch (e: any) {
|
|
604
|
-
this.debugErrorLog(
|
|
605
|
-
`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug',
|
|
606
|
-
);
|
|
607
|
-
this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
608
640
|
}
|
|
609
641
|
} else if (!this.config.credentials?.token && this.config.options?.devices) {
|
|
610
642
|
this.debugLog(`SwitchBot Device Manual Config Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
@@ -691,10 +723,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
691
723
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
692
724
|
this.createColorBulb(device);
|
|
693
725
|
break;
|
|
726
|
+
case 'K10+':
|
|
694
727
|
case 'WoSweeper':
|
|
695
728
|
case 'WoSweeperMini':
|
|
696
729
|
case 'Robot Vacuum Cleaner S1':
|
|
697
730
|
case 'Robot Vacuum Cleaner S1 Plus':
|
|
731
|
+
case 'Robot Vacuum Cleaner S10':
|
|
698
732
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
699
733
|
this.createRobotVacuumCleaner(device);
|
|
700
734
|
break;
|
|
@@ -712,8 +746,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
712
746
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
713
747
|
break;
|
|
714
748
|
case 'Remote':
|
|
749
|
+
case 'remote with screen+':
|
|
715
750
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
|
|
716
751
|
break;
|
|
752
|
+
case 'Battery Circulator Fan':
|
|
753
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
754
|
+
this.createFan(device);
|
|
755
|
+
break;
|
|
717
756
|
default:
|
|
718
757
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
719
758
|
// eslint-disable-next-line max-len
|
|
@@ -749,7 +788,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
749
788
|
case 'Fan':
|
|
750
789
|
case 'DIY Fan':
|
|
751
790
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
752
|
-
this.
|
|
791
|
+
this.createIRFan(device);
|
|
753
792
|
break;
|
|
754
793
|
case 'Air Conditioner':
|
|
755
794
|
case 'DIY Air Conditioner':
|
|
@@ -806,8 +845,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
806
845
|
existingAccessory.context.model = device.deviceType;
|
|
807
846
|
existingAccessory.context.deviceID = device.deviceId;
|
|
808
847
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
809
|
-
if (device.firmware) {
|
|
810
|
-
existingAccessory.context.
|
|
848
|
+
if (device.version && !device.firmware) {
|
|
849
|
+
existingAccessory.context.version = device.version;
|
|
811
850
|
}
|
|
812
851
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
813
852
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -834,8 +873,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
834
873
|
accessory.context.device = device;
|
|
835
874
|
accessory.context.model = device.deviceType;
|
|
836
875
|
accessory.context.deviceID = device.deviceId;
|
|
837
|
-
if (device.firmware) {
|
|
838
|
-
accessory.context.
|
|
876
|
+
if (device.version && !device.firmware) {
|
|
877
|
+
accessory.context.version = device.version;
|
|
839
878
|
}
|
|
840
879
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
841
880
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -866,8 +905,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
866
905
|
existingAccessory.context.model = device.deviceType;
|
|
867
906
|
existingAccessory.context.deviceID = device.deviceId;
|
|
868
907
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
869
|
-
if (device.firmware) {
|
|
870
|
-
existingAccessory.context.
|
|
908
|
+
if (device.version && !device.firmware) {
|
|
909
|
+
existingAccessory.context.version = device.version;
|
|
871
910
|
}
|
|
872
911
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
873
912
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -894,12 +933,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
894
933
|
accessory.context.device = device;
|
|
895
934
|
accessory.context.model = device.deviceType;
|
|
896
935
|
accessory.context.deviceID = device.deviceId;
|
|
897
|
-
if (device.firmware) {
|
|
898
|
-
accessory.context.
|
|
936
|
+
if (device.version && !device.firmware) {
|
|
937
|
+
accessory.context.version = device.version;
|
|
899
938
|
}
|
|
900
939
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
901
940
|
accessory.context.connectionType = await this.connectionType(device);
|
|
902
|
-
// accessory.context.
|
|
941
|
+
// accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
|
|
903
942
|
// create the accessory handler for the newly create accessory
|
|
904
943
|
// this is imported from `platformAccessory.ts`
|
|
905
944
|
new Bot(this, accessory, device);
|
|
@@ -927,8 +966,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
927
966
|
existingAccessory.context.model = device.deviceType;
|
|
928
967
|
existingAccessory.context.deviceID = device.deviceId;
|
|
929
968
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
930
|
-
if (device.firmware) {
|
|
931
|
-
existingAccessory.context.
|
|
969
|
+
if (device.version && !device.firmware) {
|
|
970
|
+
existingAccessory.context.version = device.version;
|
|
932
971
|
}
|
|
933
972
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
934
973
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -955,8 +994,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
955
994
|
accessory.context.device = device;
|
|
956
995
|
accessory.context.model = device.deviceType;
|
|
957
996
|
accessory.context.deviceID = device.deviceId;
|
|
958
|
-
if (device.firmware) {
|
|
959
|
-
accessory.context.
|
|
997
|
+
if (device.version && !device.firmware) {
|
|
998
|
+
accessory.context.version = device.version;
|
|
960
999
|
}
|
|
961
1000
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
962
1001
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -988,8 +1027,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
988
1027
|
existingAccessory.context.model = device.deviceType;
|
|
989
1028
|
existingAccessory.context.deviceID = device.deviceId;
|
|
990
1029
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
991
|
-
if (device.firmware) {
|
|
992
|
-
existingAccessory.context.
|
|
1030
|
+
if (device.version && !device.firmware) {
|
|
1031
|
+
existingAccessory.context.version = device.version;
|
|
993
1032
|
}
|
|
994
1033
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
995
1034
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1016,8 +1055,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1016
1055
|
accessory.context.device = device;
|
|
1017
1056
|
accessory.context.model = device.deviceType;
|
|
1018
1057
|
accessory.context.deviceID = device.deviceId;
|
|
1019
|
-
if (device.firmware) {
|
|
1020
|
-
accessory.context.
|
|
1058
|
+
if (device.version && !device.firmware) {
|
|
1059
|
+
accessory.context.version = device.version;
|
|
1021
1060
|
}
|
|
1022
1061
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1023
1062
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1049,8 +1088,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1049
1088
|
existingAccessory.context.model = device.deviceType;
|
|
1050
1089
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1051
1090
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1052
|
-
if (device.firmware) {
|
|
1053
|
-
existingAccessory.context.
|
|
1091
|
+
if (device.version && !device.firmware) {
|
|
1092
|
+
existingAccessory.context.version = device.version;
|
|
1054
1093
|
}
|
|
1055
1094
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1056
1095
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1077,8 +1116,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1077
1116
|
accessory.context.device = device;
|
|
1078
1117
|
accessory.context.model = device.deviceType;
|
|
1079
1118
|
accessory.context.deviceID = device.deviceId;
|
|
1080
|
-
if (device.firmware) {
|
|
1081
|
-
accessory.context.
|
|
1119
|
+
if (device.version && !device.firmware) {
|
|
1120
|
+
accessory.context.version = device.version;
|
|
1082
1121
|
}
|
|
1083
1122
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1084
1123
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1109,8 +1148,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1109
1148
|
existingAccessory.context.model = device.deviceType;
|
|
1110
1149
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1111
1150
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1112
|
-
if (device.firmware) {
|
|
1113
|
-
existingAccessory.context.
|
|
1151
|
+
if (device.version && !device.firmware) {
|
|
1152
|
+
existingAccessory.context.version = device.version;
|
|
1114
1153
|
}
|
|
1115
1154
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1116
1155
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1137,8 +1176,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1137
1176
|
accessory.context.device = device;
|
|
1138
1177
|
accessory.context.model = device.deviceType;
|
|
1139
1178
|
accessory.context.deviceID = device.deviceId;
|
|
1140
|
-
if (device.firmware) {
|
|
1141
|
-
accessory.context.
|
|
1179
|
+
if (device.version && !device.firmware) {
|
|
1180
|
+
accessory.context.version = device.version;
|
|
1142
1181
|
}
|
|
1143
1182
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1144
1183
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1169,8 +1208,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1169
1208
|
existingAccessory.context.model = device.deviceType;
|
|
1170
1209
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1171
1210
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1172
|
-
if (device.firmware) {
|
|
1173
|
-
existingAccessory.context.
|
|
1211
|
+
if (device.version && !device.firmware) {
|
|
1212
|
+
existingAccessory.context.version = device.version;
|
|
1174
1213
|
}
|
|
1175
1214
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1176
1215
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1197,8 +1236,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1197
1236
|
accessory.context.device = device;
|
|
1198
1237
|
accessory.context.model = device.deviceType;
|
|
1199
1238
|
accessory.context.deviceID = device.deviceId;
|
|
1200
|
-
if (device.firmware) {
|
|
1201
|
-
accessory.context.
|
|
1239
|
+
if (device.version && !device.firmware) {
|
|
1240
|
+
accessory.context.version = device.version;
|
|
1202
1241
|
}
|
|
1203
1242
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1204
1243
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1229,8 +1268,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1229
1268
|
existingAccessory.context.model = device.deviceType;
|
|
1230
1269
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1231
1270
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1232
|
-
if (device.firmware) {
|
|
1233
|
-
existingAccessory.context.
|
|
1271
|
+
if (device.version && !device.firmware) {
|
|
1272
|
+
existingAccessory.context.version = device.version;
|
|
1234
1273
|
}
|
|
1235
1274
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1236
1275
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1257,8 +1296,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1257
1296
|
accessory.context.device = device;
|
|
1258
1297
|
accessory.context.model = device.deviceType;
|
|
1259
1298
|
accessory.context.deviceID = device.deviceId;
|
|
1260
|
-
if (device.firmware) {
|
|
1261
|
-
accessory.context.
|
|
1299
|
+
if (device.version && !device.firmware) {
|
|
1300
|
+
accessory.context.version = device.version;
|
|
1262
1301
|
}
|
|
1263
1302
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1264
1303
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1289,8 +1328,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1289
1328
|
existingAccessory.context.model = device.deviceType;
|
|
1290
1329
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1291
1330
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1292
|
-
if (device.firmware) {
|
|
1293
|
-
existingAccessory.context.
|
|
1331
|
+
if (device.version && !device.firmware) {
|
|
1332
|
+
existingAccessory.context.version = device.version;
|
|
1294
1333
|
}
|
|
1295
1334
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1296
1335
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1317,8 +1356,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1317
1356
|
accessory.context.device = device;
|
|
1318
1357
|
accessory.context.model = device.deviceType;
|
|
1319
1358
|
accessory.context.deviceID = device.deviceId;
|
|
1320
|
-
if (device.firmware) {
|
|
1321
|
-
accessory.context.
|
|
1359
|
+
if (device.version && !device.firmware) {
|
|
1360
|
+
accessory.context.version = device.version;
|
|
1322
1361
|
}
|
|
1323
1362
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1324
1363
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1349,8 +1388,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1349
1388
|
existingAccessory.context.model = device.deviceType;
|
|
1350
1389
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1351
1390
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1352
|
-
if (device.firmware) {
|
|
1353
|
-
existingAccessory.context.
|
|
1391
|
+
if (device.version && !device.firmware) {
|
|
1392
|
+
existingAccessory.context.version = device.version;
|
|
1354
1393
|
}
|
|
1355
1394
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1356
1395
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1390,8 +1429,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1390
1429
|
accessory.context.device = device;
|
|
1391
1430
|
accessory.context.model = device.deviceType;
|
|
1392
1431
|
accessory.context.deviceID = device.deviceId;
|
|
1393
|
-
if (device.firmware) {
|
|
1394
|
-
accessory.context.
|
|
1432
|
+
if (device.version && !device.firmware) {
|
|
1433
|
+
accessory.context.version = device.version;
|
|
1395
1434
|
}
|
|
1396
1435
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1397
1436
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1422,8 +1461,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1422
1461
|
existingAccessory.context.model = device.deviceType;
|
|
1423
1462
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1424
1463
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1425
|
-
if (device.firmware) {
|
|
1426
|
-
existingAccessory.context.
|
|
1464
|
+
if (device.version && !device.firmware) {
|
|
1465
|
+
existingAccessory.context.version = device.version;
|
|
1427
1466
|
}
|
|
1428
1467
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1429
1468
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1463,8 +1502,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1463
1502
|
accessory.context.device = device;
|
|
1464
1503
|
accessory.context.model = device.deviceType;
|
|
1465
1504
|
accessory.context.deviceID = device.deviceId;
|
|
1466
|
-
if (device.firmware) {
|
|
1467
|
-
accessory.context.
|
|
1505
|
+
if (device.version && !device.firmware) {
|
|
1506
|
+
accessory.context.version = device.version;
|
|
1468
1507
|
}
|
|
1469
1508
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1470
1509
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1495,8 +1534,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1495
1534
|
existingAccessory.context.model = device.deviceType;
|
|
1496
1535
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1497
1536
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1498
|
-
if (device.firmware) {
|
|
1499
|
-
existingAccessory.context.
|
|
1537
|
+
if (device.version && !device.firmware) {
|
|
1538
|
+
existingAccessory.context.version = device.version;
|
|
1500
1539
|
}
|
|
1501
1540
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1502
1541
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1523,8 +1562,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1523
1562
|
accessory.context.device = device;
|
|
1524
1563
|
accessory.context.model = device.deviceType;
|
|
1525
1564
|
accessory.context.deviceID = device.deviceId;
|
|
1526
|
-
if (device.firmware) {
|
|
1527
|
-
accessory.context.
|
|
1565
|
+
if (device.version && !device.firmware) {
|
|
1566
|
+
accessory.context.version = device.version;
|
|
1528
1567
|
}
|
|
1529
1568
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1530
1569
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1555,8 +1594,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1555
1594
|
existingAccessory.context.model = device.deviceType;
|
|
1556
1595
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1557
1596
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1558
|
-
if (device.firmware) {
|
|
1559
|
-
existingAccessory.context.
|
|
1597
|
+
if (device.version && !device.firmware) {
|
|
1598
|
+
existingAccessory.context.version = device.version;
|
|
1560
1599
|
}
|
|
1561
1600
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1562
1601
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1583,8 +1622,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1583
1622
|
accessory.context.device = device;
|
|
1584
1623
|
accessory.context.model = device.deviceType;
|
|
1585
1624
|
accessory.context.deviceID = device.deviceId;
|
|
1586
|
-
if (device.firmware) {
|
|
1587
|
-
accessory.context.
|
|
1625
|
+
if (device.version && !device.firmware) {
|
|
1626
|
+
accessory.context.version = device.version;
|
|
1588
1627
|
}
|
|
1589
1628
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1590
1629
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1615,8 +1654,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1615
1654
|
existingAccessory.context.model = device.deviceType;
|
|
1616
1655
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1617
1656
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1618
|
-
if (device.firmware) {
|
|
1619
|
-
existingAccessory.context.
|
|
1657
|
+
if (device.version && !device.firmware) {
|
|
1658
|
+
existingAccessory.context.version = device.version;
|
|
1620
1659
|
}
|
|
1621
1660
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1622
1661
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1643,8 +1682,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1643
1682
|
accessory.context.device = device;
|
|
1644
1683
|
accessory.context.model = device.deviceType;
|
|
1645
1684
|
accessory.context.deviceID = device.deviceId;
|
|
1646
|
-
if (device.firmware) {
|
|
1647
|
-
accessory.context.
|
|
1685
|
+
if (device.version && !device.firmware) {
|
|
1686
|
+
accessory.context.version = device.version;
|
|
1648
1687
|
}
|
|
1649
1688
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1650
1689
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1675,8 +1714,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1675
1714
|
existingAccessory.context.model = device.deviceType;
|
|
1676
1715
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1677
1716
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1678
|
-
if (device.firmware) {
|
|
1679
|
-
existingAccessory.context.
|
|
1717
|
+
if (device.version && !device.firmware) {
|
|
1718
|
+
existingAccessory.context.version = device.version;
|
|
1680
1719
|
}
|
|
1681
1720
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1682
1721
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1703,8 +1742,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1703
1742
|
accessory.context.device = device;
|
|
1704
1743
|
accessory.context.model = device.deviceType;
|
|
1705
1744
|
accessory.context.deviceID = device.deviceId;
|
|
1706
|
-
if (device.firmware) {
|
|
1707
|
-
accessory.context.
|
|
1745
|
+
if (device.version && !device.firmware) {
|
|
1746
|
+
accessory.context.version = device.version;
|
|
1708
1747
|
}
|
|
1709
1748
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1710
1749
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1735,8 +1774,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1735
1774
|
existingAccessory.context.model = device.deviceType;
|
|
1736
1775
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1737
1776
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1738
|
-
if (device.firmware) {
|
|
1739
|
-
existingAccessory.context.
|
|
1777
|
+
if (device.version && !device.firmware) {
|
|
1778
|
+
existingAccessory.context.version = device.version;
|
|
1740
1779
|
}
|
|
1741
1780
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1742
1781
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1763,8 +1802,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1763
1802
|
accessory.context.device = device;
|
|
1764
1803
|
accessory.context.model = device.deviceType;
|
|
1765
1804
|
accessory.context.deviceID = device.deviceId;
|
|
1766
|
-
if (device.firmware) {
|
|
1767
|
-
accessory.context.
|
|
1805
|
+
if (device.version && !device.firmware) {
|
|
1806
|
+
accessory.context.version = device.version;
|
|
1768
1807
|
}
|
|
1769
1808
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1770
1809
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1781,6 +1820,66 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1781
1820
|
}
|
|
1782
1821
|
}
|
|
1783
1822
|
|
|
1823
|
+
private async createFan(device: device & devicesConfig) {
|
|
1824
|
+
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1825
|
+
|
|
1826
|
+
// see if an accessory with the same uuid has already been registered and restored from
|
|
1827
|
+
// the cached devices we stored in the `configureAccessory` method above
|
|
1828
|
+
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
1829
|
+
|
|
1830
|
+
if (existingAccessory) {
|
|
1831
|
+
// the accessory already exists
|
|
1832
|
+
if (await this.registerDevice(device)) {
|
|
1833
|
+
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
1834
|
+
existingAccessory.context.model = device.deviceType;
|
|
1835
|
+
existingAccessory.context.deviceID = device.deviceId;
|
|
1836
|
+
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1837
|
+
if (device.version && !device.firmware) {
|
|
1838
|
+
existingAccessory.context.version = device.version;
|
|
1839
|
+
}
|
|
1840
|
+
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1841
|
+
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1842
|
+
existingAccessory.context.connectionType = await this.connectionType(device);
|
|
1843
|
+
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1844
|
+
// create the accessory handler for the restored accessory
|
|
1845
|
+
// this is imported from `platformAccessory.ts`
|
|
1846
|
+
new Fan(this, existingAccessory, device);
|
|
1847
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`);
|
|
1848
|
+
} else {
|
|
1849
|
+
this.unregisterPlatformAccessories(existingAccessory);
|
|
1850
|
+
}
|
|
1851
|
+
} else if (await this.registerDevice(device)) {
|
|
1852
|
+
// the accessory does not yet exist, so we need to create it
|
|
1853
|
+
if (!device.external) {
|
|
1854
|
+
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
// create a new accessory
|
|
1858
|
+
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
1859
|
+
|
|
1860
|
+
// store a copy of the device object in the `accessory.context`
|
|
1861
|
+
// the `context` property can be used to store any data about the accessory you may need
|
|
1862
|
+
accessory.context.device = device;
|
|
1863
|
+
accessory.context.model = device.deviceType;
|
|
1864
|
+
accessory.context.deviceID = device.deviceId;
|
|
1865
|
+
if (device.version && !device.firmware) {
|
|
1866
|
+
accessory.context.version = device.version;
|
|
1867
|
+
}
|
|
1868
|
+
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1869
|
+
accessory.context.connectionType = await this.connectionType(device);
|
|
1870
|
+
// create the accessory handler for the newly create accessory
|
|
1871
|
+
// this is imported from `platformAccessory.ts`
|
|
1872
|
+
new Fan(this, accessory, device);
|
|
1873
|
+
this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`);
|
|
1874
|
+
|
|
1875
|
+
// publish device externally or link the accessory to your platform
|
|
1876
|
+
this.externalOrPlatform(device, accessory);
|
|
1877
|
+
this.accessories.push(accessory);
|
|
1878
|
+
} else {
|
|
1879
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1784
1883
|
private async createRobotVacuumCleaner(device: device & devicesConfig) {
|
|
1785
1884
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1786
1885
|
|
|
@@ -1795,8 +1894,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1795
1894
|
existingAccessory.context.model = device.deviceType;
|
|
1796
1895
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1797
1896
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1798
|
-
if (device.firmware) {
|
|
1799
|
-
existingAccessory.context.
|
|
1897
|
+
if (device.version && !device.firmware) {
|
|
1898
|
+
existingAccessory.context.version = device.version;
|
|
1800
1899
|
}
|
|
1801
1900
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1802
1901
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1823,8 +1922,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1823
1922
|
accessory.context.device = device;
|
|
1824
1923
|
accessory.context.model = device.deviceType;
|
|
1825
1924
|
accessory.context.deviceID = device.deviceId;
|
|
1826
|
-
if (device.firmware) {
|
|
1827
|
-
accessory.context.
|
|
1925
|
+
if (device.version && !device.firmware) {
|
|
1926
|
+
accessory.context.version = device.version;
|
|
1828
1927
|
}
|
|
1829
1928
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1830
1929
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1853,7 +1952,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1853
1952
|
existingAccessory.context.model = device.remoteType;
|
|
1854
1953
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1855
1954
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1856
|
-
|
|
1955
|
+
if (device.version && !device.firmware) {
|
|
1956
|
+
existingAccessory.context.version = device.version;
|
|
1957
|
+
}
|
|
1857
1958
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1858
1959
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1859
1960
|
existingAccessory.context.connectionType = device.connectionType;
|
|
@@ -1876,8 +1977,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1876
1977
|
accessory.context.device = device;
|
|
1877
1978
|
accessory.context.model = device.remoteType;
|
|
1878
1979
|
accessory.context.deviceID = device.deviceId;
|
|
1879
|
-
if (device.firmware) {
|
|
1880
|
-
accessory.context.
|
|
1980
|
+
if (device.version && !device.firmware) {
|
|
1981
|
+
accessory.context.version = device.version;
|
|
1881
1982
|
}
|
|
1882
1983
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1883
1984
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -1893,7 +1994,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1893
1994
|
}
|
|
1894
1995
|
}
|
|
1895
1996
|
|
|
1896
|
-
private async
|
|
1997
|
+
private async createIRFan(device: irdevice & devicesConfig) {
|
|
1897
1998
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
1898
1999
|
|
|
1899
2000
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
@@ -1907,8 +2008,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1907
2008
|
existingAccessory.context.model = device.remoteType;
|
|
1908
2009
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1909
2010
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1910
|
-
if (device.firmware) {
|
|
1911
|
-
existingAccessory.context.
|
|
2011
|
+
if (device.version && !device.firmware) {
|
|
2012
|
+
existingAccessory.context.version = device.version;
|
|
1912
2013
|
}
|
|
1913
2014
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1914
2015
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1916,7 +2017,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1916
2017
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1917
2018
|
// create the accessory handler for the restored accessory
|
|
1918
2019
|
// this is imported from `platformAccessory.ts`
|
|
1919
|
-
new
|
|
2020
|
+
new IRFan(this, existingAccessory, device);
|
|
1920
2021
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1921
2022
|
} else {
|
|
1922
2023
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
@@ -1935,14 +2036,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1935
2036
|
accessory.context.device = device;
|
|
1936
2037
|
accessory.context.model = device.remoteType;
|
|
1937
2038
|
accessory.context.deviceID = device.deviceId;
|
|
1938
|
-
if (device.firmware) {
|
|
1939
|
-
accessory.context.
|
|
2039
|
+
if (device.version && !device.firmware) {
|
|
2040
|
+
accessory.context.version = device.version;
|
|
1940
2041
|
}
|
|
1941
2042
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1942
2043
|
accessory.context.connectionType = device.connectionType;
|
|
1943
2044
|
// create the accessory handler for the newly create accessory
|
|
1944
2045
|
// this is imported from `platformAccessory.ts`
|
|
1945
|
-
new
|
|
2046
|
+
new IRFan(this, accessory, device);
|
|
1946
2047
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1947
2048
|
|
|
1948
2049
|
// publish device externally or link the accessory to your platform
|
|
@@ -1967,8 +2068,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1967
2068
|
existingAccessory.context.model = device.remoteType;
|
|
1968
2069
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1969
2070
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1970
|
-
if (device.firmware) {
|
|
1971
|
-
existingAccessory.context.
|
|
2071
|
+
if (device.version && !device.firmware) {
|
|
2072
|
+
existingAccessory.context.version = device.version;
|
|
1972
2073
|
}
|
|
1973
2074
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1974
2075
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1995,8 +2096,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1995
2096
|
accessory.context.device = device;
|
|
1996
2097
|
accessory.context.model = device.remoteType;
|
|
1997
2098
|
accessory.context.deviceID = device.deviceId;
|
|
1998
|
-
if (device.firmware) {
|
|
1999
|
-
accessory.context.
|
|
2099
|
+
if (device.version && !device.firmware) {
|
|
2100
|
+
accessory.context.version = device.version;
|
|
2000
2101
|
}
|
|
2001
2102
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2002
2103
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2027,8 +2128,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2027
2128
|
existingAccessory.context.model = device.remoteType;
|
|
2028
2129
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2029
2130
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2030
|
-
if (device.firmware) {
|
|
2031
|
-
existingAccessory.context.
|
|
2131
|
+
if (device.version && !device.firmware) {
|
|
2132
|
+
existingAccessory.context.version = device.version;
|
|
2032
2133
|
}
|
|
2033
2134
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2034
2135
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2055,8 +2156,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2055
2156
|
accessory.context.device = device;
|
|
2056
2157
|
accessory.context.model = device.remoteType;
|
|
2057
2158
|
accessory.context.deviceID = device.deviceId;
|
|
2058
|
-
if (device.firmware) {
|
|
2059
|
-
accessory.context.
|
|
2159
|
+
if (device.version && !device.firmware) {
|
|
2160
|
+
accessory.context.version = device.version;
|
|
2060
2161
|
}
|
|
2061
2162
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2062
2163
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2087,8 +2188,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2087
2188
|
existingAccessory.context.model = device.remoteType;
|
|
2088
2189
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2089
2190
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2090
|
-
if (device.firmware) {
|
|
2091
|
-
existingAccessory.context.
|
|
2191
|
+
if (device.version && !device.firmware) {
|
|
2192
|
+
existingAccessory.context.version = device.version;
|
|
2092
2193
|
}
|
|
2093
2194
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2094
2195
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2115,8 +2216,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2115
2216
|
accessory.context.device = device;
|
|
2116
2217
|
accessory.context.model = device.remoteType;
|
|
2117
2218
|
accessory.context.deviceID = device.deviceId;
|
|
2118
|
-
if (device.firmware) {
|
|
2119
|
-
accessory.context.
|
|
2219
|
+
if (device.version && !device.firmware) {
|
|
2220
|
+
accessory.context.version = device.version;
|
|
2120
2221
|
}
|
|
2121
2222
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2122
2223
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2147,8 +2248,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2147
2248
|
existingAccessory.context.model = device.remoteType;
|
|
2148
2249
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2149
2250
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2150
|
-
if (device.firmware) {
|
|
2151
|
-
existingAccessory.context.
|
|
2251
|
+
if (device.version && !device.firmware) {
|
|
2252
|
+
existingAccessory.context.version = device.version;
|
|
2152
2253
|
}
|
|
2153
2254
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2154
2255
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2175,8 +2276,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2175
2276
|
accessory.context.device = device;
|
|
2176
2277
|
accessory.context.model = device.remoteType;
|
|
2177
2278
|
accessory.context.deviceID = device.deviceId;
|
|
2178
|
-
if (device.firmware) {
|
|
2179
|
-
accessory.context.
|
|
2279
|
+
if (device.version && !device.firmware) {
|
|
2280
|
+
accessory.context.version = device.version;
|
|
2180
2281
|
}
|
|
2181
2282
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2182
2283
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2207,8 +2308,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2207
2308
|
existingAccessory.context.model = device.remoteType;
|
|
2208
2309
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2209
2310
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2210
|
-
if (device.firmware) {
|
|
2211
|
-
existingAccessory.context.
|
|
2311
|
+
if (device.version && !device.firmware) {
|
|
2312
|
+
existingAccessory.context.version = device.version;
|
|
2212
2313
|
}
|
|
2213
2314
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2214
2315
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2235,8 +2336,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2235
2336
|
accessory.context.device = device;
|
|
2236
2337
|
accessory.context.model = device.remoteType;
|
|
2237
2338
|
accessory.context.deviceID = device.deviceId;
|
|
2238
|
-
if (device.firmware) {
|
|
2239
|
-
accessory.context.
|
|
2339
|
+
if (device.version && !device.firmware) {
|
|
2340
|
+
accessory.context.version = device.version;
|
|
2240
2341
|
}
|
|
2241
2342
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2242
2343
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2267,8 +2368,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2267
2368
|
existingAccessory.context.model = device.remoteType;
|
|
2268
2369
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2269
2370
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2270
|
-
if (device.firmware) {
|
|
2271
|
-
existingAccessory.context.
|
|
2371
|
+
if (device.version && !device.firmware) {
|
|
2372
|
+
existingAccessory.context.version = device.version;
|
|
2272
2373
|
}
|
|
2273
2374
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2274
2375
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2295,8 +2396,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2295
2396
|
accessory.context.device = device;
|
|
2296
2397
|
accessory.context.model = device.remoteType;
|
|
2297
2398
|
accessory.context.deviceID = device.deviceId;
|
|
2298
|
-
if (device.firmware) {
|
|
2299
|
-
accessory.context.
|
|
2399
|
+
if (device.version && !device.firmware) {
|
|
2400
|
+
accessory.context.version = device.version;
|
|
2300
2401
|
}
|
|
2301
2402
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2302
2403
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2327,8 +2428,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2327
2428
|
existingAccessory.context.model = device.remoteType;
|
|
2328
2429
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2329
2430
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2330
|
-
if (device.firmware) {
|
|
2331
|
-
existingAccessory.context.
|
|
2431
|
+
if (device.version && !device.firmware) {
|
|
2432
|
+
existingAccessory.context.version = device.version;
|
|
2332
2433
|
}
|
|
2333
2434
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2334
2435
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2355,8 +2456,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2355
2456
|
accessory.context.device = device;
|
|
2356
2457
|
accessory.context.model = device.remoteType;
|
|
2357
2458
|
accessory.context.deviceID = device.deviceId;
|
|
2358
|
-
if (device.firmware) {
|
|
2359
|
-
accessory.context.
|
|
2459
|
+
if (device.version && !device.firmware) {
|
|
2460
|
+
accessory.context.version = device.version;
|
|
2360
2461
|
}
|
|
2361
2462
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2362
2463
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2626,6 +2727,30 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2626
2727
|
}
|
|
2627
2728
|
}
|
|
2628
2729
|
|
|
2730
|
+
async retryRequest(deviceMaxRetries: number, deviceDelayBetweenRetries: number, url: string | URL | UrlObject,
|
|
2731
|
+
options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions,
|
|
2732
|
+
'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>): Promise<{ body: any; statusCode: number }> {
|
|
2733
|
+
let retryCount = 0;
|
|
2734
|
+
const maxRetries = deviceMaxRetries;
|
|
2735
|
+
const delayBetweenRetries = deviceDelayBetweenRetries;
|
|
2736
|
+
while (retryCount < maxRetries) {
|
|
2737
|
+
try {
|
|
2738
|
+
const { body, statusCode } = await request(url, options);
|
|
2739
|
+
if (statusCode === 200 || statusCode === 100) {
|
|
2740
|
+
return { body, statusCode };
|
|
2741
|
+
} else {
|
|
2742
|
+
this.debugLog(`Received status code: ${statusCode}`);
|
|
2743
|
+
}
|
|
2744
|
+
} catch (error: any) {
|
|
2745
|
+
this.errorLog(`Error making request: ${error.message}`);
|
|
2746
|
+
}
|
|
2747
|
+
retryCount++;
|
|
2748
|
+
this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
|
|
2749
|
+
await sleep(delayBetweenRetries);
|
|
2750
|
+
}
|
|
2751
|
+
return { body: null, statusCode: -1 };
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2629
2754
|
// BLE Connection
|
|
2630
2755
|
async connectBLE() {
|
|
2631
2756
|
let switchbot: any;
|
|
@@ -2662,6 +2787,22 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2662
2787
|
if (this.config.options.pushRate) {
|
|
2663
2788
|
platformConfig.pushRate = this.config.options.pushRate;
|
|
2664
2789
|
}
|
|
2790
|
+
if (this.config.options.maxRetries) {
|
|
2791
|
+
this.maxRetries = this.config.options.maxRetries;
|
|
2792
|
+
platformConfig.maxRetries = this.config.options.maxRetries;
|
|
2793
|
+
} else {
|
|
2794
|
+
this.maxRetries = 3;
|
|
2795
|
+
this.debugWarnLog('Using Default Max Retries');
|
|
2796
|
+
platformConfig.maxRetries = this.maxRetries;
|
|
2797
|
+
}
|
|
2798
|
+
if (this.config.options.delayBetweenRetries) {
|
|
2799
|
+
this.delayBetweenRetries = this.config.options.delayBetweenRetries * 1000;
|
|
2800
|
+
platformConfig.delayBetweenRetries = this.config.options.delayBetweenRetries;
|
|
2801
|
+
} else {
|
|
2802
|
+
this.delayBetweenRetries = 3000;
|
|
2803
|
+
this.debugWarnLog('Using Default Delay Between Retries');
|
|
2804
|
+
platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
|
|
2805
|
+
}
|
|
2665
2806
|
if (Object.entries(platformConfig).length !== 0) {
|
|
2666
2807
|
this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2667
2808
|
}
|
|
@@ -2687,6 +2828,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2687
2828
|
* If device level logging is turned on, log to log.warn
|
|
2688
2829
|
* Otherwise send debug logs to log.debug
|
|
2689
2830
|
*/
|
|
2831
|
+
successLog(...log: any[]): void {
|
|
2832
|
+
if (this.enablingPlatformLogging()) {
|
|
2833
|
+
this.log.success(String(...log));
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2690
2837
|
infoLog(...log: any[]): void {
|
|
2691
2838
|
if (this.enablingPlatformLogging()) {
|
|
2692
2839
|
this.log.info(String(...log));
|