@switchbot/homebridge-switchbot 3.5.0-beta.4 → 3.5.0-beta.40
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 +349 -756
- 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 +584 -759
- 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 +211 -587
- 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 +252 -632
- 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 +206 -531
- 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 +337 -786
- 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 +503 -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 +244 -596
- 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 +209 -571
- 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 +176 -584
- 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 +254 -568
- 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 +212 -542
- 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 +172 -577
- 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 +161 -577
- 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 +138 -518
- 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 +84 -452
- 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 +142 -451
- 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 +123 -664
- 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 +375 -782
- package/src/device/bot.ts +618 -844
- package/src/device/ceilinglight.ts +224 -607
- package/src/device/colorbulb.ts +266 -656
- package/src/device/contact.ts +231 -553
- package/src/device/curtain.ts +357 -810
- package/src/device/device.ts +699 -0
- package/src/device/fan.ts +552 -0
- package/src/device/hub.ts +271 -624
- package/src/device/humidifier.ts +239 -618
- package/src/device/iosensor.ts +202 -610
- package/src/device/lightstrip.ts +275 -596
- package/src/device/lock.ts +249 -582
- package/src/device/meter.ts +198 -601
- package/src/device/meterplus.ts +186 -602
- package/src/device/motion.ts +158 -541
- package/src/device/plug.ts +94 -480
- package/src/device/robotvacuumcleaner.ts +163 -477
- package/src/device/waterdetector.ts +141 -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/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)}`);
|
|
@@ -645,10 +678,12 @@ export class SwitchBotPlatform {
|
|
|
645
678
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
646
679
|
this.createColorBulb(device);
|
|
647
680
|
break;
|
|
681
|
+
case 'K10+':
|
|
648
682
|
case 'WoSweeper':
|
|
649
683
|
case 'WoSweeperMini':
|
|
650
684
|
case 'Robot Vacuum Cleaner S1':
|
|
651
685
|
case 'Robot Vacuum Cleaner S1 Plus':
|
|
686
|
+
case 'Robot Vacuum Cleaner S10':
|
|
652
687
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
653
688
|
this.createRobotVacuumCleaner(device);
|
|
654
689
|
break;
|
|
@@ -666,8 +701,13 @@ export class SwitchBotPlatform {
|
|
|
666
701
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
667
702
|
break;
|
|
668
703
|
case 'Remote':
|
|
704
|
+
case 'remote with screen+':
|
|
669
705
|
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId} is Not Supported.`);
|
|
670
706
|
break;
|
|
707
|
+
case 'Battery Circulator Fan':
|
|
708
|
+
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
709
|
+
this.createFan(device);
|
|
710
|
+
break;
|
|
671
711
|
default:
|
|
672
712
|
this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
|
|
673
713
|
// eslint-disable-next-line max-len
|
|
@@ -703,7 +743,7 @@ export class SwitchBotPlatform {
|
|
|
703
743
|
case 'Fan':
|
|
704
744
|
case 'DIY Fan':
|
|
705
745
|
this.debugLog(`Discovered ${device.remoteType}: ${device.deviceId}`);
|
|
706
|
-
this.
|
|
746
|
+
this.createIRFan(device);
|
|
707
747
|
break;
|
|
708
748
|
case 'Air Conditioner':
|
|
709
749
|
case 'DIY Air Conditioner':
|
|
@@ -757,8 +797,8 @@ export class SwitchBotPlatform {
|
|
|
757
797
|
existingAccessory.context.model = device.deviceType;
|
|
758
798
|
existingAccessory.context.deviceID = device.deviceId;
|
|
759
799
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
760
|
-
if (device.firmware) {
|
|
761
|
-
existingAccessory.context.
|
|
800
|
+
if (device.version && !device.firmware) {
|
|
801
|
+
existingAccessory.context.version = device.version;
|
|
762
802
|
}
|
|
763
803
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
764
804
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -785,8 +825,8 @@ export class SwitchBotPlatform {
|
|
|
785
825
|
accessory.context.device = device;
|
|
786
826
|
accessory.context.model = device.deviceType;
|
|
787
827
|
accessory.context.deviceID = device.deviceId;
|
|
788
|
-
if (device.firmware) {
|
|
789
|
-
accessory.context.
|
|
828
|
+
if (device.version && !device.firmware) {
|
|
829
|
+
accessory.context.version = device.version;
|
|
790
830
|
}
|
|
791
831
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
792
832
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -814,8 +854,8 @@ export class SwitchBotPlatform {
|
|
|
814
854
|
existingAccessory.context.model = device.deviceType;
|
|
815
855
|
existingAccessory.context.deviceID = device.deviceId;
|
|
816
856
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
817
|
-
if (device.firmware) {
|
|
818
|
-
existingAccessory.context.
|
|
857
|
+
if (device.version && !device.firmware) {
|
|
858
|
+
existingAccessory.context.version = device.version;
|
|
819
859
|
}
|
|
820
860
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
821
861
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -842,12 +882,12 @@ export class SwitchBotPlatform {
|
|
|
842
882
|
accessory.context.device = device;
|
|
843
883
|
accessory.context.model = device.deviceType;
|
|
844
884
|
accessory.context.deviceID = device.deviceId;
|
|
845
|
-
if (device.firmware) {
|
|
846
|
-
accessory.context.
|
|
885
|
+
if (device.version && !device.firmware) {
|
|
886
|
+
accessory.context.version = device.version;
|
|
847
887
|
}
|
|
848
888
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
849
889
|
accessory.context.connectionType = await this.connectionType(device);
|
|
850
|
-
// accessory.context.
|
|
890
|
+
// accessory.context.version = findaccessories.accessoryAttribute.softwareRevision;
|
|
851
891
|
// create the accessory handler for the newly create accessory
|
|
852
892
|
// this is imported from `platformAccessory.ts`
|
|
853
893
|
new Bot(this, accessory, device);
|
|
@@ -872,8 +912,8 @@ export class SwitchBotPlatform {
|
|
|
872
912
|
existingAccessory.context.model = device.deviceType;
|
|
873
913
|
existingAccessory.context.deviceID = device.deviceId;
|
|
874
914
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
875
|
-
if (device.firmware) {
|
|
876
|
-
existingAccessory.context.
|
|
915
|
+
if (device.version && !device.firmware) {
|
|
916
|
+
existingAccessory.context.version = device.version;
|
|
877
917
|
}
|
|
878
918
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
879
919
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -900,8 +940,8 @@ export class SwitchBotPlatform {
|
|
|
900
940
|
accessory.context.device = device;
|
|
901
941
|
accessory.context.model = device.deviceType;
|
|
902
942
|
accessory.context.deviceID = device.deviceId;
|
|
903
|
-
if (device.firmware) {
|
|
904
|
-
accessory.context.
|
|
943
|
+
if (device.version && !device.firmware) {
|
|
944
|
+
accessory.context.version = device.version;
|
|
905
945
|
}
|
|
906
946
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
907
947
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -930,8 +970,8 @@ export class SwitchBotPlatform {
|
|
|
930
970
|
existingAccessory.context.model = device.deviceType;
|
|
931
971
|
existingAccessory.context.deviceID = device.deviceId;
|
|
932
972
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
933
|
-
if (device.firmware) {
|
|
934
|
-
existingAccessory.context.
|
|
973
|
+
if (device.version && !device.firmware) {
|
|
974
|
+
existingAccessory.context.version = device.version;
|
|
935
975
|
}
|
|
936
976
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
937
977
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -958,8 +998,8 @@ export class SwitchBotPlatform {
|
|
|
958
998
|
accessory.context.device = device;
|
|
959
999
|
accessory.context.model = device.deviceType;
|
|
960
1000
|
accessory.context.deviceID = device.deviceId;
|
|
961
|
-
if (device.firmware) {
|
|
962
|
-
accessory.context.
|
|
1001
|
+
if (device.version && !device.firmware) {
|
|
1002
|
+
accessory.context.version = device.version;
|
|
963
1003
|
}
|
|
964
1004
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
965
1005
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -988,8 +1028,8 @@ export class SwitchBotPlatform {
|
|
|
988
1028
|
existingAccessory.context.model = device.deviceType;
|
|
989
1029
|
existingAccessory.context.deviceID = device.deviceId;
|
|
990
1030
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
991
|
-
if (device.firmware) {
|
|
992
|
-
existingAccessory.context.
|
|
1031
|
+
if (device.version && !device.firmware) {
|
|
1032
|
+
existingAccessory.context.version = device.version;
|
|
993
1033
|
}
|
|
994
1034
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
995
1035
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1016,8 +1056,8 @@ export class SwitchBotPlatform {
|
|
|
1016
1056
|
accessory.context.device = device;
|
|
1017
1057
|
accessory.context.model = device.deviceType;
|
|
1018
1058
|
accessory.context.deviceID = device.deviceId;
|
|
1019
|
-
if (device.firmware) {
|
|
1020
|
-
accessory.context.
|
|
1059
|
+
if (device.version && !device.firmware) {
|
|
1060
|
+
accessory.context.version = device.version;
|
|
1021
1061
|
}
|
|
1022
1062
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1023
1063
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1045,8 +1085,8 @@ export class SwitchBotPlatform {
|
|
|
1045
1085
|
existingAccessory.context.model = device.deviceType;
|
|
1046
1086
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1047
1087
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1048
|
-
if (device.firmware) {
|
|
1049
|
-
existingAccessory.context.
|
|
1088
|
+
if (device.version && !device.firmware) {
|
|
1089
|
+
existingAccessory.context.version = device.version;
|
|
1050
1090
|
}
|
|
1051
1091
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1052
1092
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1073,8 +1113,8 @@ export class SwitchBotPlatform {
|
|
|
1073
1113
|
accessory.context.device = device;
|
|
1074
1114
|
accessory.context.model = device.deviceType;
|
|
1075
1115
|
accessory.context.deviceID = device.deviceId;
|
|
1076
|
-
if (device.firmware) {
|
|
1077
|
-
accessory.context.
|
|
1116
|
+
if (device.version && !device.firmware) {
|
|
1117
|
+
accessory.context.version = device.version;
|
|
1078
1118
|
}
|
|
1079
1119
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1080
1120
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1102,8 +1142,8 @@ export class SwitchBotPlatform {
|
|
|
1102
1142
|
existingAccessory.context.model = device.deviceType;
|
|
1103
1143
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1104
1144
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1105
|
-
if (device.firmware) {
|
|
1106
|
-
existingAccessory.context.
|
|
1145
|
+
if (device.version && !device.firmware) {
|
|
1146
|
+
existingAccessory.context.version = device.version;
|
|
1107
1147
|
}
|
|
1108
1148
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1109
1149
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1130,8 +1170,8 @@ export class SwitchBotPlatform {
|
|
|
1130
1170
|
accessory.context.device = device;
|
|
1131
1171
|
accessory.context.model = device.deviceType;
|
|
1132
1172
|
accessory.context.deviceID = device.deviceId;
|
|
1133
|
-
if (device.firmware) {
|
|
1134
|
-
accessory.context.
|
|
1173
|
+
if (device.version && !device.firmware) {
|
|
1174
|
+
accessory.context.version = device.version;
|
|
1135
1175
|
}
|
|
1136
1176
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1137
1177
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1159,8 +1199,8 @@ export class SwitchBotPlatform {
|
|
|
1159
1199
|
existingAccessory.context.model = device.deviceType;
|
|
1160
1200
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1161
1201
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1162
|
-
if (device.firmware) {
|
|
1163
|
-
existingAccessory.context.
|
|
1202
|
+
if (device.version && !device.firmware) {
|
|
1203
|
+
existingAccessory.context.version = device.version;
|
|
1164
1204
|
}
|
|
1165
1205
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1166
1206
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1187,8 +1227,8 @@ export class SwitchBotPlatform {
|
|
|
1187
1227
|
accessory.context.device = device;
|
|
1188
1228
|
accessory.context.model = device.deviceType;
|
|
1189
1229
|
accessory.context.deviceID = device.deviceId;
|
|
1190
|
-
if (device.firmware) {
|
|
1191
|
-
accessory.context.
|
|
1230
|
+
if (device.version && !device.firmware) {
|
|
1231
|
+
accessory.context.version = device.version;
|
|
1192
1232
|
}
|
|
1193
1233
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1194
1234
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1216,8 +1256,8 @@ export class SwitchBotPlatform {
|
|
|
1216
1256
|
existingAccessory.context.model = device.deviceType;
|
|
1217
1257
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1218
1258
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1219
|
-
if (device.firmware) {
|
|
1220
|
-
existingAccessory.context.
|
|
1259
|
+
if (device.version && !device.firmware) {
|
|
1260
|
+
existingAccessory.context.version = device.version;
|
|
1221
1261
|
}
|
|
1222
1262
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1223
1263
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1244,8 +1284,8 @@ export class SwitchBotPlatform {
|
|
|
1244
1284
|
accessory.context.device = device;
|
|
1245
1285
|
accessory.context.model = device.deviceType;
|
|
1246
1286
|
accessory.context.deviceID = device.deviceId;
|
|
1247
|
-
if (device.firmware) {
|
|
1248
|
-
accessory.context.
|
|
1287
|
+
if (device.version && !device.firmware) {
|
|
1288
|
+
accessory.context.version = device.version;
|
|
1249
1289
|
}
|
|
1250
1290
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1251
1291
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1273,8 +1313,8 @@ export class SwitchBotPlatform {
|
|
|
1273
1313
|
existingAccessory.context.model = device.deviceType;
|
|
1274
1314
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1275
1315
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1276
|
-
if (device.firmware) {
|
|
1277
|
-
existingAccessory.context.
|
|
1316
|
+
if (device.version && !device.firmware) {
|
|
1317
|
+
existingAccessory.context.version = device.version;
|
|
1278
1318
|
}
|
|
1279
1319
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1280
1320
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1313,8 +1353,8 @@ export class SwitchBotPlatform {
|
|
|
1313
1353
|
accessory.context.device = device;
|
|
1314
1354
|
accessory.context.model = device.deviceType;
|
|
1315
1355
|
accessory.context.deviceID = device.deviceId;
|
|
1316
|
-
if (device.firmware) {
|
|
1317
|
-
accessory.context.
|
|
1356
|
+
if (device.version && !device.firmware) {
|
|
1357
|
+
accessory.context.version = device.version;
|
|
1318
1358
|
}
|
|
1319
1359
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1320
1360
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1342,8 +1382,8 @@ export class SwitchBotPlatform {
|
|
|
1342
1382
|
existingAccessory.context.model = device.deviceType;
|
|
1343
1383
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1344
1384
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1345
|
-
if (device.firmware) {
|
|
1346
|
-
existingAccessory.context.
|
|
1385
|
+
if (device.version && !device.firmware) {
|
|
1386
|
+
existingAccessory.context.version = device.version;
|
|
1347
1387
|
}
|
|
1348
1388
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1349
1389
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1382,8 +1422,8 @@ export class SwitchBotPlatform {
|
|
|
1382
1422
|
accessory.context.device = device;
|
|
1383
1423
|
accessory.context.model = device.deviceType;
|
|
1384
1424
|
accessory.context.deviceID = device.deviceId;
|
|
1385
|
-
if (device.firmware) {
|
|
1386
|
-
accessory.context.
|
|
1425
|
+
if (device.version && !device.firmware) {
|
|
1426
|
+
accessory.context.version = device.version;
|
|
1387
1427
|
}
|
|
1388
1428
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1389
1429
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1411,8 +1451,8 @@ export class SwitchBotPlatform {
|
|
|
1411
1451
|
existingAccessory.context.model = device.deviceType;
|
|
1412
1452
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1413
1453
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1414
|
-
if (device.firmware) {
|
|
1415
|
-
existingAccessory.context.
|
|
1454
|
+
if (device.version && !device.firmware) {
|
|
1455
|
+
existingAccessory.context.version = device.version;
|
|
1416
1456
|
}
|
|
1417
1457
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1418
1458
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1439,8 +1479,8 @@ export class SwitchBotPlatform {
|
|
|
1439
1479
|
accessory.context.device = device;
|
|
1440
1480
|
accessory.context.model = device.deviceType;
|
|
1441
1481
|
accessory.context.deviceID = device.deviceId;
|
|
1442
|
-
if (device.firmware) {
|
|
1443
|
-
accessory.context.
|
|
1482
|
+
if (device.version && !device.firmware) {
|
|
1483
|
+
accessory.context.version = device.version;
|
|
1444
1484
|
}
|
|
1445
1485
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1446
1486
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1468,8 +1508,8 @@ export class SwitchBotPlatform {
|
|
|
1468
1508
|
existingAccessory.context.model = device.deviceType;
|
|
1469
1509
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1470
1510
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1471
|
-
if (device.firmware) {
|
|
1472
|
-
existingAccessory.context.
|
|
1511
|
+
if (device.version && !device.firmware) {
|
|
1512
|
+
existingAccessory.context.version = device.version;
|
|
1473
1513
|
}
|
|
1474
1514
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1475
1515
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1496,8 +1536,8 @@ export class SwitchBotPlatform {
|
|
|
1496
1536
|
accessory.context.device = device;
|
|
1497
1537
|
accessory.context.model = device.deviceType;
|
|
1498
1538
|
accessory.context.deviceID = device.deviceId;
|
|
1499
|
-
if (device.firmware) {
|
|
1500
|
-
accessory.context.
|
|
1539
|
+
if (device.version && !device.firmware) {
|
|
1540
|
+
accessory.context.version = device.version;
|
|
1501
1541
|
}
|
|
1502
1542
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1503
1543
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1525,8 +1565,8 @@ export class SwitchBotPlatform {
|
|
|
1525
1565
|
existingAccessory.context.model = device.deviceType;
|
|
1526
1566
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1527
1567
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1528
|
-
if (device.firmware) {
|
|
1529
|
-
existingAccessory.context.
|
|
1568
|
+
if (device.version && !device.firmware) {
|
|
1569
|
+
existingAccessory.context.version = device.version;
|
|
1530
1570
|
}
|
|
1531
1571
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1532
1572
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1553,8 +1593,8 @@ export class SwitchBotPlatform {
|
|
|
1553
1593
|
accessory.context.device = device;
|
|
1554
1594
|
accessory.context.model = device.deviceType;
|
|
1555
1595
|
accessory.context.deviceID = device.deviceId;
|
|
1556
|
-
if (device.firmware) {
|
|
1557
|
-
accessory.context.
|
|
1596
|
+
if (device.version && !device.firmware) {
|
|
1597
|
+
accessory.context.version = device.version;
|
|
1558
1598
|
}
|
|
1559
1599
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1560
1600
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1582,8 +1622,8 @@ export class SwitchBotPlatform {
|
|
|
1582
1622
|
existingAccessory.context.model = device.deviceType;
|
|
1583
1623
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1584
1624
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1585
|
-
if (device.firmware) {
|
|
1586
|
-
existingAccessory.context.
|
|
1625
|
+
if (device.version && !device.firmware) {
|
|
1626
|
+
existingAccessory.context.version = device.version;
|
|
1587
1627
|
}
|
|
1588
1628
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1589
1629
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1610,8 +1650,8 @@ export class SwitchBotPlatform {
|
|
|
1610
1650
|
accessory.context.device = device;
|
|
1611
1651
|
accessory.context.model = device.deviceType;
|
|
1612
1652
|
accessory.context.deviceID = device.deviceId;
|
|
1613
|
-
if (device.firmware) {
|
|
1614
|
-
accessory.context.
|
|
1653
|
+
if (device.version && !device.firmware) {
|
|
1654
|
+
accessory.context.version = device.version;
|
|
1615
1655
|
}
|
|
1616
1656
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1617
1657
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1639,8 +1679,8 @@ export class SwitchBotPlatform {
|
|
|
1639
1679
|
existingAccessory.context.model = device.deviceType;
|
|
1640
1680
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1641
1681
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1642
|
-
if (device.firmware) {
|
|
1643
|
-
existingAccessory.context.
|
|
1682
|
+
if (device.version && !device.firmware) {
|
|
1683
|
+
existingAccessory.context.version = device.version;
|
|
1644
1684
|
}
|
|
1645
1685
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1646
1686
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1667,8 +1707,8 @@ export class SwitchBotPlatform {
|
|
|
1667
1707
|
accessory.context.device = device;
|
|
1668
1708
|
accessory.context.model = device.deviceType;
|
|
1669
1709
|
accessory.context.deviceID = device.deviceId;
|
|
1670
|
-
if (device.firmware) {
|
|
1671
|
-
accessory.context.
|
|
1710
|
+
if (device.version && !device.firmware) {
|
|
1711
|
+
accessory.context.version = device.version;
|
|
1672
1712
|
}
|
|
1673
1713
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1674
1714
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1684,6 +1724,63 @@ export class SwitchBotPlatform {
|
|
|
1684
1724
|
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1685
1725
|
}
|
|
1686
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.version && !device.firmware) {
|
|
1740
|
+
existingAccessory.context.version = device.version;
|
|
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.version && !device.firmware) {
|
|
1768
|
+
accessory.context.version = device.version;
|
|
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
|
+
}
|
|
1687
1784
|
async createRobotVacuumCleaner(device) {
|
|
1688
1785
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`);
|
|
1689
1786
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
@@ -1696,8 +1793,8 @@ export class SwitchBotPlatform {
|
|
|
1696
1793
|
existingAccessory.context.model = device.deviceType;
|
|
1697
1794
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1698
1795
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1699
|
-
if (device.firmware) {
|
|
1700
|
-
existingAccessory.context.
|
|
1796
|
+
if (device.version && !device.firmware) {
|
|
1797
|
+
existingAccessory.context.version = device.version;
|
|
1701
1798
|
}
|
|
1702
1799
|
existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1703
1800
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1724,8 +1821,8 @@ export class SwitchBotPlatform {
|
|
|
1724
1821
|
accessory.context.device = device;
|
|
1725
1822
|
accessory.context.model = device.deviceType;
|
|
1726
1823
|
accessory.context.deviceID = device.deviceId;
|
|
1727
|
-
if (device.firmware) {
|
|
1728
|
-
accessory.context.
|
|
1824
|
+
if (device.version && !device.firmware) {
|
|
1825
|
+
accessory.context.version = device.version;
|
|
1729
1826
|
}
|
|
1730
1827
|
accessory.context.deviceType = `SwitchBot: ${device.deviceType}`;
|
|
1731
1828
|
accessory.context.connectionType = await this.connectionType(device);
|
|
@@ -1751,7 +1848,9 @@ export class SwitchBotPlatform {
|
|
|
1751
1848
|
existingAccessory.context.model = device.remoteType;
|
|
1752
1849
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1753
1850
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1754
|
-
|
|
1851
|
+
if (device.version && !device.firmware) {
|
|
1852
|
+
existingAccessory.context.version = device.version;
|
|
1853
|
+
}
|
|
1755
1854
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1756
1855
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
1757
1856
|
existingAccessory.context.connectionType = device.connectionType;
|
|
@@ -1773,8 +1872,8 @@ export class SwitchBotPlatform {
|
|
|
1773
1872
|
accessory.context.device = device;
|
|
1774
1873
|
accessory.context.model = device.remoteType;
|
|
1775
1874
|
accessory.context.deviceID = device.deviceId;
|
|
1776
|
-
if (device.firmware) {
|
|
1777
|
-
accessory.context.
|
|
1875
|
+
if (device.version && !device.firmware) {
|
|
1876
|
+
accessory.context.version = device.version;
|
|
1778
1877
|
}
|
|
1779
1878
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1780
1879
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -1789,7 +1888,7 @@ export class SwitchBotPlatform {
|
|
|
1789
1888
|
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1790
1889
|
}
|
|
1791
1890
|
}
|
|
1792
|
-
async
|
|
1891
|
+
async createIRFan(device) {
|
|
1793
1892
|
const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.remoteType}`);
|
|
1794
1893
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
1795
1894
|
// the cached devices we stored in the `configureAccessory` method above
|
|
@@ -1801,8 +1900,8 @@ export class SwitchBotPlatform {
|
|
|
1801
1900
|
existingAccessory.context.model = device.remoteType;
|
|
1802
1901
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1803
1902
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1804
|
-
if (device.firmware) {
|
|
1805
|
-
existingAccessory.context.
|
|
1903
|
+
if (device.version && !device.firmware) {
|
|
1904
|
+
existingAccessory.context.version = device.version;
|
|
1806
1905
|
}
|
|
1807
1906
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1808
1907
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1810,7 +1909,7 @@ export class SwitchBotPlatform {
|
|
|
1810
1909
|
this.api.updatePlatformAccessories([existingAccessory]);
|
|
1811
1910
|
// create the accessory handler for the restored accessory
|
|
1812
1911
|
// this is imported from `platformAccessory.ts`
|
|
1813
|
-
new
|
|
1912
|
+
new IRFan(this, existingAccessory, device);
|
|
1814
1913
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`);
|
|
1815
1914
|
}
|
|
1816
1915
|
else {
|
|
@@ -1829,14 +1928,14 @@ export class SwitchBotPlatform {
|
|
|
1829
1928
|
accessory.context.device = device;
|
|
1830
1929
|
accessory.context.model = device.remoteType;
|
|
1831
1930
|
accessory.context.deviceID = device.deviceId;
|
|
1832
|
-
if (device.firmware) {
|
|
1833
|
-
accessory.context.
|
|
1931
|
+
if (device.version && !device.firmware) {
|
|
1932
|
+
accessory.context.version = device.version;
|
|
1834
1933
|
}
|
|
1835
1934
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1836
1935
|
accessory.context.connectionType = device.connectionType;
|
|
1837
1936
|
// create the accessory handler for the newly create accessory
|
|
1838
1937
|
// this is imported from `platformAccessory.ts`
|
|
1839
|
-
new
|
|
1938
|
+
new IRFan(this, accessory, device);
|
|
1840
1939
|
this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
|
|
1841
1940
|
// publish device externally or link the accessory to your platform
|
|
1842
1941
|
this.externalOrPlatformIR(device, accessory);
|
|
@@ -1858,8 +1957,8 @@ export class SwitchBotPlatform {
|
|
|
1858
1957
|
existingAccessory.context.model = device.remoteType;
|
|
1859
1958
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1860
1959
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1861
|
-
if (device.firmware) {
|
|
1862
|
-
existingAccessory.context.
|
|
1960
|
+
if (device.version && !device.firmware) {
|
|
1961
|
+
existingAccessory.context.version = device.version;
|
|
1863
1962
|
}
|
|
1864
1963
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1865
1964
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1886,8 +1985,8 @@ export class SwitchBotPlatform {
|
|
|
1886
1985
|
accessory.context.device = device;
|
|
1887
1986
|
accessory.context.model = device.remoteType;
|
|
1888
1987
|
accessory.context.deviceID = device.deviceId;
|
|
1889
|
-
if (device.firmware) {
|
|
1890
|
-
accessory.context.
|
|
1988
|
+
if (device.version && !device.firmware) {
|
|
1989
|
+
accessory.context.version = device.version;
|
|
1891
1990
|
}
|
|
1892
1991
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1893
1992
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -1915,8 +2014,8 @@ export class SwitchBotPlatform {
|
|
|
1915
2014
|
existingAccessory.context.model = device.remoteType;
|
|
1916
2015
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1917
2016
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1918
|
-
if (device.firmware) {
|
|
1919
|
-
existingAccessory.context.
|
|
2017
|
+
if (device.version && !device.firmware) {
|
|
2018
|
+
existingAccessory.context.version = device.version;
|
|
1920
2019
|
}
|
|
1921
2020
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1922
2021
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -1943,8 +2042,8 @@ export class SwitchBotPlatform {
|
|
|
1943
2042
|
accessory.context.device = device;
|
|
1944
2043
|
accessory.context.model = device.remoteType;
|
|
1945
2044
|
accessory.context.deviceID = device.deviceId;
|
|
1946
|
-
if (device.firmware) {
|
|
1947
|
-
accessory.context.
|
|
2045
|
+
if (device.version && !device.firmware) {
|
|
2046
|
+
accessory.context.version = device.version;
|
|
1948
2047
|
}
|
|
1949
2048
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1950
2049
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -1972,8 +2071,8 @@ export class SwitchBotPlatform {
|
|
|
1972
2071
|
existingAccessory.context.model = device.remoteType;
|
|
1973
2072
|
existingAccessory.context.deviceID = device.deviceId;
|
|
1974
2073
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
1975
|
-
if (device.firmware) {
|
|
1976
|
-
existingAccessory.context.
|
|
2074
|
+
if (device.version && !device.firmware) {
|
|
2075
|
+
existingAccessory.context.version = device.version;
|
|
1977
2076
|
}
|
|
1978
2077
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
1979
2078
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2000,8 +2099,8 @@ export class SwitchBotPlatform {
|
|
|
2000
2099
|
accessory.context.device = device;
|
|
2001
2100
|
accessory.context.model = device.remoteType;
|
|
2002
2101
|
accessory.context.deviceID = device.deviceId;
|
|
2003
|
-
if (device.firmware) {
|
|
2004
|
-
accessory.context.
|
|
2102
|
+
if (device.version && !device.firmware) {
|
|
2103
|
+
accessory.context.version = device.version;
|
|
2005
2104
|
}
|
|
2006
2105
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2007
2106
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2029,8 +2128,8 @@ export class SwitchBotPlatform {
|
|
|
2029
2128
|
existingAccessory.context.model = device.remoteType;
|
|
2030
2129
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2031
2130
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2032
|
-
if (device.firmware) {
|
|
2033
|
-
existingAccessory.context.
|
|
2131
|
+
if (device.version && !device.firmware) {
|
|
2132
|
+
existingAccessory.context.version = device.version;
|
|
2034
2133
|
}
|
|
2035
2134
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2036
2135
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2057,8 +2156,8 @@ export class SwitchBotPlatform {
|
|
|
2057
2156
|
accessory.context.device = device;
|
|
2058
2157
|
accessory.context.model = device.remoteType;
|
|
2059
2158
|
accessory.context.deviceID = device.deviceId;
|
|
2060
|
-
if (device.firmware) {
|
|
2061
|
-
accessory.context.
|
|
2159
|
+
if (device.version && !device.firmware) {
|
|
2160
|
+
accessory.context.version = device.version;
|
|
2062
2161
|
}
|
|
2063
2162
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2064
2163
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2086,8 +2185,8 @@ export class SwitchBotPlatform {
|
|
|
2086
2185
|
existingAccessory.context.model = device.remoteType;
|
|
2087
2186
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2088
2187
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2089
|
-
if (device.firmware) {
|
|
2090
|
-
existingAccessory.context.
|
|
2188
|
+
if (device.version && !device.firmware) {
|
|
2189
|
+
existingAccessory.context.version = device.version;
|
|
2091
2190
|
}
|
|
2092
2191
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2093
2192
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2114,8 +2213,8 @@ export class SwitchBotPlatform {
|
|
|
2114
2213
|
accessory.context.device = device;
|
|
2115
2214
|
accessory.context.model = device.remoteType;
|
|
2116
2215
|
accessory.context.deviceID = device.deviceId;
|
|
2117
|
-
if (device.firmware) {
|
|
2118
|
-
accessory.context.
|
|
2216
|
+
if (device.version && !device.firmware) {
|
|
2217
|
+
accessory.context.version = device.version;
|
|
2119
2218
|
}
|
|
2120
2219
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2121
2220
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2143,8 +2242,8 @@ export class SwitchBotPlatform {
|
|
|
2143
2242
|
existingAccessory.context.model = device.remoteType;
|
|
2144
2243
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2145
2244
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2146
|
-
if (device.firmware) {
|
|
2147
|
-
existingAccessory.context.
|
|
2245
|
+
if (device.version && !device.firmware) {
|
|
2246
|
+
existingAccessory.context.version = device.version;
|
|
2148
2247
|
}
|
|
2149
2248
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2150
2249
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2171,8 +2270,8 @@ export class SwitchBotPlatform {
|
|
|
2171
2270
|
accessory.context.device = device;
|
|
2172
2271
|
accessory.context.model = device.remoteType;
|
|
2173
2272
|
accessory.context.deviceID = device.deviceId;
|
|
2174
|
-
if (device.firmware) {
|
|
2175
|
-
accessory.context.
|
|
2273
|
+
if (device.version && !device.firmware) {
|
|
2274
|
+
accessory.context.version = device.version;
|
|
2176
2275
|
}
|
|
2177
2276
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2178
2277
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2200,8 +2299,8 @@ export class SwitchBotPlatform {
|
|
|
2200
2299
|
existingAccessory.context.model = device.remoteType;
|
|
2201
2300
|
existingAccessory.context.deviceID = device.deviceId;
|
|
2202
2301
|
existingAccessory.displayName = device.configDeviceName || device.deviceName;
|
|
2203
|
-
if (device.firmware) {
|
|
2204
|
-
existingAccessory.context.
|
|
2302
|
+
if (device.version && !device.firmware) {
|
|
2303
|
+
existingAccessory.context.version = device.version;
|
|
2205
2304
|
}
|
|
2206
2305
|
existingAccessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2207
2306
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
@@ -2228,8 +2327,8 @@ export class SwitchBotPlatform {
|
|
|
2228
2327
|
accessory.context.device = device;
|
|
2229
2328
|
accessory.context.model = device.remoteType;
|
|
2230
2329
|
accessory.context.deviceID = device.deviceId;
|
|
2231
|
-
if (device.firmware) {
|
|
2232
|
-
accessory.context.
|
|
2330
|
+
if (device.version && !device.firmware) {
|
|
2331
|
+
accessory.context.version = device.version;
|
|
2233
2332
|
}
|
|
2234
2333
|
accessory.context.deviceType = `IR: ${device.remoteType}`;
|
|
2235
2334
|
accessory.context.connectionType = device.connectionType;
|
|
@@ -2491,6 +2590,29 @@ export class SwitchBotPlatform {
|
|
|
2491
2590
|
this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
2492
2591
|
}
|
|
2493
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
|
+
}
|
|
2494
2616
|
// BLE Connection
|
|
2495
2617
|
async connectBLE() {
|
|
2496
2618
|
let switchbot;
|
|
@@ -2521,6 +2643,24 @@ export class SwitchBotPlatform {
|
|
|
2521
2643
|
if (this.config.options.pushRate) {
|
|
2522
2644
|
platformConfig.pushRate = this.config.options.pushRate;
|
|
2523
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
|
+
}
|
|
2524
2664
|
if (Object.entries(platformConfig).length !== 0) {
|
|
2525
2665
|
this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2526
2666
|
}
|
|
@@ -2546,6 +2686,11 @@ export class SwitchBotPlatform {
|
|
|
2546
2686
|
* If device level logging is turned on, log to log.warn
|
|
2547
2687
|
* Otherwise send debug logs to log.debug
|
|
2548
2688
|
*/
|
|
2689
|
+
successLog(...log) {
|
|
2690
|
+
if (this.enablingPlatformLogging()) {
|
|
2691
|
+
this.log.success(String(...log));
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2549
2694
|
infoLog(...log) {
|
|
2550
2695
|
if (this.enablingPlatformLogging()) {
|
|
2551
2696
|
this.log.info(String(...log));
|