@switchbot/homebridge-switchbot 2.0.0-beta.26 → 2.0.0-beta.28
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 +0 -2
- package/config.schema.json +2 -29
- package/dist/device/bot.d.ts +2 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +23 -19
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +43 -16
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +19 -9
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +27 -12
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +6 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +45 -20
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +25 -6
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +19 -9
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +2 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +19 -9
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +19 -9
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +27 -12
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +45 -18
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +14 -0
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -0
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +14 -0
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -0
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +14 -0
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -0
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +14 -0
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -0
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +14 -0
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -0
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +14 -0
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -0
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +14 -0
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -0
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +14 -0
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -0
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +14 -0
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +4 -5
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +148 -180
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +25 -19
- package/src/device/colorbulb.ts +40 -16
- package/src/device/contact.ts +21 -9
- package/src/device/curtain.ts +28 -12
- package/src/device/humidifier.ts +44 -20
- package/src/device/lock.ts +26 -6
- package/src/device/meter.ts +21 -9
- package/src/device/meterplus.ts +21 -9
- package/src/device/motion.ts +21 -9
- package/src/device/plug.ts +28 -12
- package/src/device/striplight.ts +42 -18
- package/src/irdevice/airconditioner.ts +16 -0
- package/src/irdevice/airpurifier.ts +16 -0
- package/src/irdevice/camera.ts +16 -0
- package/src/irdevice/fan.ts +16 -0
- package/src/irdevice/light.ts +16 -0
- package/src/irdevice/other.ts +16 -0
- package/src/irdevice/tv.ts +16 -0
- package/src/irdevice/vacuumcleaner.ts +16 -0
- package/src/irdevice/waterheater.ts +16 -0
- package/src/platform.ts +146 -181
- package/src/settings.ts +1 -0
package/dist/platform.js
CHANGED
|
@@ -31,7 +31,6 @@ const fakegato_history_1 = __importDefault(require("fakegato-history"));
|
|
|
31
31
|
const super_stringify_1 = __importDefault(require("super-stringify"));
|
|
32
32
|
const fs_1 = require("fs");
|
|
33
33
|
const settings_1 = require("./settings");
|
|
34
|
-
const rxjs_1 = require("rxjs");
|
|
35
34
|
/**
|
|
36
35
|
* HomebridgePlatform
|
|
37
36
|
* This class is the main constructor for your plugin, this is where you should
|
|
@@ -63,10 +62,8 @@ class SwitchBotPlatform {
|
|
|
63
62
|
this.debugLog('Config OK');
|
|
64
63
|
}
|
|
65
64
|
catch (e) {
|
|
66
|
-
this.errorLog(
|
|
67
|
-
|
|
68
|
-
this.errorLog(`Verify Config: ${e}`);
|
|
69
|
-
}
|
|
65
|
+
this.errorLog(`Verify Config, Error Message: ${e.message}`);
|
|
66
|
+
this.debugErrorLog(`Verify Config, Error: ${e}`);
|
|
70
67
|
return;
|
|
71
68
|
}
|
|
72
69
|
// import fakegato-history module
|
|
@@ -91,34 +88,11 @@ class SwitchBotPlatform {
|
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
90
|
catch (e) {
|
|
94
|
-
this.errorLog(
|
|
95
|
-
|
|
96
|
-
this.errorLog(`Platform: ${e}`);
|
|
97
|
-
}
|
|
91
|
+
this.errorLog(`Failed to Discover, Error Message: ${e.message}`);
|
|
92
|
+
this.debugErrorLog(`Failed to Discover, Error: ${e}`);
|
|
98
93
|
}
|
|
99
94
|
});
|
|
100
95
|
}
|
|
101
|
-
logs() {
|
|
102
|
-
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
103
|
-
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
104
|
-
this.platformLogging = this.config.options.logging;
|
|
105
|
-
if (this.platformLogging.includes('debug')) {
|
|
106
|
-
this.log.warn(`Using Config Logging: ${this.platformLogging}`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else if (this.debugMode) {
|
|
110
|
-
this.platformLogging = 'debugMode';
|
|
111
|
-
if (this.platformLogging?.includes('debug')) {
|
|
112
|
-
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
this.platformLogging = 'standard';
|
|
117
|
-
if (this.platformLogging?.includes('debug')) {
|
|
118
|
-
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
96
|
/**
|
|
123
97
|
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
|
124
98
|
* It should be used to setup event handlers for characteristics and update respective values.
|
|
@@ -180,45 +154,28 @@ class SwitchBotPlatform {
|
|
|
180
154
|
if (!this.config.options.refreshRate) {
|
|
181
155
|
// default 120 seconds (2 minutes)
|
|
182
156
|
this.config.options.refreshRate = 120;
|
|
183
|
-
|
|
184
|
-
this.debugLog('Using Default Refresh Rate (2 minutes).');
|
|
185
|
-
}
|
|
157
|
+
this.debugWarnLog('Using Default Refresh Rate (2 minutes).');
|
|
186
158
|
}
|
|
187
159
|
if (!this.config.options.pushRate) {
|
|
188
160
|
// default 100 milliseconds
|
|
189
161
|
this.config.options.pushRate = 0.1;
|
|
190
|
-
|
|
191
|
-
this.warnLog('Using Default Push Rate.');
|
|
192
|
-
}
|
|
162
|
+
this.debugWarnLog('Using Default Push Rate.');
|
|
193
163
|
}
|
|
194
|
-
if (!this.config.credentials) {
|
|
195
|
-
|
|
196
|
-
this.debugLog('Missing Credentials');
|
|
197
|
-
}
|
|
164
|
+
if (!this.config.credentials && !this.config.options) {
|
|
165
|
+
this.debugWarnLog('Missing Credentials');
|
|
198
166
|
}
|
|
199
|
-
if (!this.config.credentials
|
|
200
|
-
if (this.
|
|
201
|
-
this.
|
|
202
|
-
this.
|
|
167
|
+
else if (this.config.credentials && !this.config.credentials.notice) {
|
|
168
|
+
if (!this.config.credentials?.token) {
|
|
169
|
+
this.debugErrorLog('Missing token');
|
|
170
|
+
this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
203
171
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
this.errorLog('Missing secret');
|
|
209
|
-
this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
172
|
+
if (this.config.credentials?.token) {
|
|
173
|
+
if (!this.config.credentials?.secret) {
|
|
174
|
+
this.debugErrorLog('Missing secret');
|
|
175
|
+
this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
210
176
|
}
|
|
211
177
|
}
|
|
212
178
|
}
|
|
213
|
-
// Re-Discover Devices
|
|
214
|
-
if (!this.config.options.discoverDevices) {
|
|
215
|
-
this.config.options.discoverDevices = false;
|
|
216
|
-
this.debugLog(`Rediscover Devices disabled, discoverDevices: ${this.config.options.discoverDevices}`);
|
|
217
|
-
}
|
|
218
|
-
if (!this.config.options.discoverDevicesInterval) {
|
|
219
|
-
this.config.options.discoverDevicesInterval = 86400;
|
|
220
|
-
this.debugLog(`Default Rediscover Devices Interval, discoverDevicesInterval: ${this.config.options.discoverDevicesInterval}`);
|
|
221
|
-
}
|
|
222
179
|
}
|
|
223
180
|
/**
|
|
224
181
|
* The openToken was old config.
|
|
@@ -260,9 +217,7 @@ class SwitchBotPlatform {
|
|
|
260
217
|
// set the refresh token
|
|
261
218
|
pluginConfig.credentials.token = this.config.credentials?.openToken;
|
|
262
219
|
pluginConfig.credentials.openToken = 'Delete';
|
|
263
|
-
|
|
264
|
-
this.warnLog(`Token: ${pluginConfig.credentials.token}`);
|
|
265
|
-
}
|
|
220
|
+
this.debugWarnLog(`Token: ${pluginConfig.credentials.token}`);
|
|
266
221
|
// save the config, ensuring we maintain pretty json
|
|
267
222
|
(0, fs_1.writeFileSync)(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
|
|
268
223
|
this.verifyConfig();
|
|
@@ -430,62 +385,8 @@ class SwitchBotPlatform {
|
|
|
430
385
|
}
|
|
431
386
|
}
|
|
432
387
|
catch (e) {
|
|
433
|
-
this.
|
|
434
|
-
|
|
435
|
-
if (this.config.options?.discoverDevices) {
|
|
436
|
-
(0, rxjs_1.interval)(this.config.options.discoverDevicesInterval * 1000)
|
|
437
|
-
.pipe((0, rxjs_1.take)(1))
|
|
438
|
-
.subscribe(async () => {
|
|
439
|
-
await this.discoverDevices();
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
deviceError(e) {
|
|
444
|
-
if (e.message.includes('400')) {
|
|
445
|
-
this.errorLog('Failed to Discover Devices: Bad Request');
|
|
446
|
-
this.debugLog('The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.');
|
|
447
|
-
}
|
|
448
|
-
else if (e.message.includes('401')) {
|
|
449
|
-
this.errorLog('Failed to Discover Devices: Unauthorized Request');
|
|
450
|
-
this.debugLog('Authorization for the API is required, but the request has not been authenticated.');
|
|
451
|
-
}
|
|
452
|
-
else if (e.message.includes('403')) {
|
|
453
|
-
this.errorLog('Failed to Discover Devices: Forbidden Request');
|
|
454
|
-
this.debugLog('The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.');
|
|
455
|
-
}
|
|
456
|
-
else if (e.message.includes('404')) {
|
|
457
|
-
this.errorLog('Failed to Discover Devices: Requst Not Found');
|
|
458
|
-
this.debugLog('Specifies the requested path does not exist.');
|
|
459
|
-
}
|
|
460
|
-
else if (e.message.includes('406')) {
|
|
461
|
-
this.errorLog('Failed to Discover Devices: Request Not Acceptable');
|
|
462
|
-
this.debugLog('The client has requested a MIME type via the Accept header for a value not supported by the server.');
|
|
463
|
-
}
|
|
464
|
-
else if (e.message.includes('415')) {
|
|
465
|
-
this.errorLog('Failed to Discover Devices: Unsupported Requst Header');
|
|
466
|
-
this.debugLog('The client has defined a contentType header that is not supported by the server.');
|
|
467
|
-
}
|
|
468
|
-
else if (e.message.includes('422')) {
|
|
469
|
-
this.errorLog('Failed to Discover Devices: Unprocessable Entity');
|
|
470
|
-
this.debugLog('The client has made a valid request, but the server cannot process it.' +
|
|
471
|
-
' This is often used for APIs for which certain limits have been exceeded.');
|
|
472
|
-
}
|
|
473
|
-
else if (e.message.includes('429')) {
|
|
474
|
-
this.errorLog('Failed to Discover Devices: Too Many Requests');
|
|
475
|
-
this.debugLog('The client has exceeded the number of requests allowed for a given time window.');
|
|
476
|
-
}
|
|
477
|
-
else if (e.message.includes('500')) {
|
|
478
|
-
this.errorLog('Failed to Discover Devices: Internal Server Error');
|
|
479
|
-
this.debugLog('An unexpected error on the SmartThings servers has occurred. These errors should be rare.');
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
this.errorLog('Failed to Discover Devices');
|
|
483
|
-
}
|
|
484
|
-
if (this.platformLogging === 'debug') {
|
|
485
|
-
this.errorLog(`Failed to Discover Devices, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
486
|
-
}
|
|
487
|
-
if (this.platformLogging === 'debugMode') {
|
|
488
|
-
this.errorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
388
|
+
this.debugErrorLog(`Failed to Discover Devices, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
389
|
+
this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
489
390
|
}
|
|
490
391
|
}
|
|
491
392
|
createDevice(device) {
|
|
@@ -521,7 +422,7 @@ class SwitchBotPlatform {
|
|
|
521
422
|
this.createContact(device);
|
|
522
423
|
break;
|
|
523
424
|
case 'Curtain':
|
|
524
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
425
|
+
this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
525
426
|
this.createCurtain(device);
|
|
526
427
|
break;
|
|
527
428
|
case 'Plug':
|
|
@@ -664,7 +565,7 @@ class SwitchBotPlatform {
|
|
|
664
565
|
this.accessories.push(accessory);
|
|
665
566
|
}
|
|
666
567
|
else {
|
|
667
|
-
this.debugLog(`
|
|
568
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
668
569
|
}
|
|
669
570
|
}
|
|
670
571
|
async createBot(device) {
|
|
@@ -718,7 +619,7 @@ class SwitchBotPlatform {
|
|
|
718
619
|
this.accessories.push(accessory);
|
|
719
620
|
}
|
|
720
621
|
else {
|
|
721
|
-
this.debugLog(`
|
|
622
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
722
623
|
}
|
|
723
624
|
}
|
|
724
625
|
async createMeter(device) {
|
|
@@ -769,7 +670,7 @@ class SwitchBotPlatform {
|
|
|
769
670
|
this.accessories.push(accessory);
|
|
770
671
|
}
|
|
771
672
|
else {
|
|
772
|
-
this.debugLog(`
|
|
673
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
773
674
|
}
|
|
774
675
|
}
|
|
775
676
|
async createMeterPlus(device) {
|
|
@@ -820,7 +721,7 @@ class SwitchBotPlatform {
|
|
|
820
721
|
this.accessories.push(accessory);
|
|
821
722
|
}
|
|
822
723
|
else {
|
|
823
|
-
this.debugLog(`
|
|
724
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
824
725
|
}
|
|
825
726
|
}
|
|
826
727
|
async createMotion(device) {
|
|
@@ -871,7 +772,7 @@ class SwitchBotPlatform {
|
|
|
871
772
|
this.accessories.push(accessory);
|
|
872
773
|
}
|
|
873
774
|
else {
|
|
874
|
-
this.debugLog(`
|
|
775
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
875
776
|
}
|
|
876
777
|
}
|
|
877
778
|
async createContact(device) {
|
|
@@ -922,7 +823,7 @@ class SwitchBotPlatform {
|
|
|
922
823
|
this.accessories.push(accessory);
|
|
923
824
|
}
|
|
924
825
|
else {
|
|
925
|
-
this.debugLog(`
|
|
826
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
926
827
|
}
|
|
927
828
|
}
|
|
928
829
|
async createCurtain(device) {
|
|
@@ -932,7 +833,7 @@ class SwitchBotPlatform {
|
|
|
932
833
|
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
|
933
834
|
if (existingAccessory) {
|
|
934
835
|
// the accessory already exists
|
|
935
|
-
if (this.
|
|
836
|
+
if (await this.registerDevice(device)) {
|
|
936
837
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
937
838
|
existingAccessory.context.model = device.deviceType;
|
|
938
839
|
existingAccessory.context.deviceID = device.deviceId;
|
|
@@ -951,7 +852,7 @@ class SwitchBotPlatform {
|
|
|
951
852
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
952
853
|
}
|
|
953
854
|
}
|
|
954
|
-
else if (this.
|
|
855
|
+
else if (await this.registerDevice(device)) {
|
|
955
856
|
// the accessory does not yet exist, so we need to create it
|
|
956
857
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
957
858
|
if (device.group && !device.curtain?.disable_group) {
|
|
@@ -960,10 +861,10 @@ class SwitchBotPlatform {
|
|
|
960
861
|
}
|
|
961
862
|
else {
|
|
962
863
|
if (device.master) {
|
|
963
|
-
this.
|
|
864
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
964
865
|
}
|
|
965
866
|
else {
|
|
966
|
-
this.
|
|
867
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
967
868
|
}
|
|
968
869
|
}
|
|
969
870
|
// create a new accessory
|
|
@@ -985,19 +886,7 @@ class SwitchBotPlatform {
|
|
|
985
886
|
this.accessories.push(accessory);
|
|
986
887
|
}
|
|
987
888
|
else {
|
|
988
|
-
this.debugLog(`
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
isCurtainGrouped(device) {
|
|
992
|
-
this.debugLog(`deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},` +
|
|
993
|
-
` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`);
|
|
994
|
-
if (device.group && !device.curtain?.disable_group) {
|
|
995
|
-
this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}`);
|
|
996
|
-
return device.master && this.registerDevice(device);
|
|
997
|
-
}
|
|
998
|
-
else {
|
|
999
|
-
this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
|
|
1000
|
-
return this.registerDevice(device);
|
|
889
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1001
890
|
}
|
|
1002
891
|
}
|
|
1003
892
|
async createPlug(device) {
|
|
@@ -1048,7 +937,7 @@ class SwitchBotPlatform {
|
|
|
1048
937
|
this.accessories.push(accessory);
|
|
1049
938
|
}
|
|
1050
939
|
else {
|
|
1051
|
-
this.debugLog(`
|
|
940
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1052
941
|
}
|
|
1053
942
|
}
|
|
1054
943
|
async createLock(device) {
|
|
@@ -1099,7 +988,7 @@ class SwitchBotPlatform {
|
|
|
1099
988
|
this.accessories.push(accessory);
|
|
1100
989
|
}
|
|
1101
990
|
else {
|
|
1102
|
-
this.debugLog(`
|
|
991
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1103
992
|
}
|
|
1104
993
|
}
|
|
1105
994
|
async createColorBulb(device) {
|
|
@@ -1150,7 +1039,7 @@ class SwitchBotPlatform {
|
|
|
1150
1039
|
this.accessories.push(accessory);
|
|
1151
1040
|
}
|
|
1152
1041
|
else {
|
|
1153
|
-
this.debugLog(`
|
|
1042
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1154
1043
|
}
|
|
1155
1044
|
}
|
|
1156
1045
|
async createStripLight(device) {
|
|
@@ -1201,7 +1090,7 @@ class SwitchBotPlatform {
|
|
|
1201
1090
|
this.accessories.push(accessory);
|
|
1202
1091
|
}
|
|
1203
1092
|
else {
|
|
1204
|
-
this.debugLog(`
|
|
1093
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1205
1094
|
}
|
|
1206
1095
|
}
|
|
1207
1096
|
async createTV(device) {
|
|
@@ -1250,7 +1139,7 @@ class SwitchBotPlatform {
|
|
|
1250
1139
|
this.accessories.push(accessory);
|
|
1251
1140
|
}
|
|
1252
1141
|
else {
|
|
1253
|
-
this.debugLog(`
|
|
1142
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1254
1143
|
}
|
|
1255
1144
|
}
|
|
1256
1145
|
async createFan(device) {
|
|
@@ -1301,7 +1190,7 @@ class SwitchBotPlatform {
|
|
|
1301
1190
|
this.accessories.push(accessory);
|
|
1302
1191
|
}
|
|
1303
1192
|
else {
|
|
1304
|
-
this.debugLog(`
|
|
1193
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1305
1194
|
}
|
|
1306
1195
|
}
|
|
1307
1196
|
async createLight(device) {
|
|
@@ -1352,7 +1241,7 @@ class SwitchBotPlatform {
|
|
|
1352
1241
|
this.accessories.push(accessory);
|
|
1353
1242
|
}
|
|
1354
1243
|
else {
|
|
1355
|
-
this.debugLog(`
|
|
1244
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1356
1245
|
}
|
|
1357
1246
|
}
|
|
1358
1247
|
async createAirConditioner(device) {
|
|
@@ -1403,7 +1292,7 @@ class SwitchBotPlatform {
|
|
|
1403
1292
|
this.accessories.push(accessory);
|
|
1404
1293
|
}
|
|
1405
1294
|
else {
|
|
1406
|
-
this.debugLog(`
|
|
1295
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1407
1296
|
}
|
|
1408
1297
|
}
|
|
1409
1298
|
async createAirPurifier(device) {
|
|
@@ -1454,7 +1343,7 @@ class SwitchBotPlatform {
|
|
|
1454
1343
|
this.accessories.push(accessory);
|
|
1455
1344
|
}
|
|
1456
1345
|
else {
|
|
1457
|
-
this.debugLog(`
|
|
1346
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1458
1347
|
}
|
|
1459
1348
|
}
|
|
1460
1349
|
async createWaterHeater(device) {
|
|
@@ -1505,7 +1394,7 @@ class SwitchBotPlatform {
|
|
|
1505
1394
|
this.accessories.push(accessory);
|
|
1506
1395
|
}
|
|
1507
1396
|
else {
|
|
1508
|
-
this.debugLog(`
|
|
1397
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1509
1398
|
}
|
|
1510
1399
|
}
|
|
1511
1400
|
async createVacuumCleaner(device) {
|
|
@@ -1556,7 +1445,7 @@ class SwitchBotPlatform {
|
|
|
1556
1445
|
this.accessories.push(accessory);
|
|
1557
1446
|
}
|
|
1558
1447
|
else {
|
|
1559
|
-
this.debugLog(`
|
|
1448
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1560
1449
|
}
|
|
1561
1450
|
}
|
|
1562
1451
|
async createCamera(device) {
|
|
@@ -1607,7 +1496,7 @@ class SwitchBotPlatform {
|
|
|
1607
1496
|
this.accessories.push(accessory);
|
|
1608
1497
|
}
|
|
1609
1498
|
else {
|
|
1610
|
-
this.debugLog(`
|
|
1499
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1611
1500
|
}
|
|
1612
1501
|
}
|
|
1613
1502
|
async createOthers(device) {
|
|
@@ -1658,11 +1547,32 @@ class SwitchBotPlatform {
|
|
|
1658
1547
|
this.accessories.push(accessory);
|
|
1659
1548
|
}
|
|
1660
1549
|
else {
|
|
1661
|
-
this.debugLog(`
|
|
1550
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
async registerCurtains(device) {
|
|
1554
|
+
this.warnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: ` +
|
|
1555
|
+
`${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
|
|
1556
|
+
let registerCurtain;
|
|
1557
|
+
if (device.group && !device.curtain?.disable_group) {
|
|
1558
|
+
registerCurtain = true;
|
|
1559
|
+
this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}`);
|
|
1560
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1561
|
+
}
|
|
1562
|
+
else if (device.connectionType?.includes('BLE') || device.connectionType === 'Disabled') {
|
|
1563
|
+
registerCurtain = true;
|
|
1564
|
+
this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] connectionType: ${device.connectionType}`);
|
|
1565
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1566
|
+
}
|
|
1567
|
+
else {
|
|
1568
|
+
registerCurtain = false;
|
|
1569
|
+
this.errorLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
|
|
1570
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1662
1571
|
}
|
|
1572
|
+
return registerCurtain;
|
|
1663
1573
|
}
|
|
1664
1574
|
async connectionType(device) {
|
|
1665
|
-
let connectionType
|
|
1575
|
+
let connectionType;
|
|
1666
1576
|
if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
|
|
1667
1577
|
connectionType = 'OpenAPI';
|
|
1668
1578
|
}
|
|
@@ -1673,38 +1583,66 @@ class SwitchBotPlatform {
|
|
|
1673
1583
|
}
|
|
1674
1584
|
async registerDevice(device) {
|
|
1675
1585
|
device.connectionType = await this.connectionType(device);
|
|
1586
|
+
let registerDevice;
|
|
1676
1587
|
if (!device.hide_device && device.enableCloudService && device.connectionType === 'BLE/OpenAPI') {
|
|
1677
|
-
|
|
1678
|
-
|
|
1588
|
+
if (device.deviceType === 'Curtain') {
|
|
1589
|
+
registerDevice = await this.registerCurtains(device);
|
|
1590
|
+
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|
|
1591
|
+
}
|
|
1592
|
+
else {
|
|
1593
|
+
registerDevice = true;
|
|
1594
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
1595
|
+
}
|
|
1596
|
+
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
1679
1597
|
}
|
|
1680
1598
|
else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
|
|
1681
1599
|
&& device.connectionType === 'BLE') {
|
|
1682
|
-
|
|
1683
|
-
|
|
1600
|
+
if (device.deviceType === 'Curtain') {
|
|
1601
|
+
registerDevice = await this.registerCurtains(device);
|
|
1602
|
+
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|
|
1603
|
+
}
|
|
1604
|
+
else {
|
|
1605
|
+
registerDevice = true;
|
|
1606
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
1607
|
+
}
|
|
1608
|
+
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
1684
1609
|
}
|
|
1685
1610
|
else if (!device.hide_device && device.enableCloudService && device.connectionType === 'OpenAPI') {
|
|
1686
|
-
|
|
1687
|
-
|
|
1611
|
+
if (device.deviceType === 'Curtain') {
|
|
1612
|
+
registerDevice = await this.registerCurtains(device);
|
|
1613
|
+
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|
|
1614
|
+
}
|
|
1615
|
+
else {
|
|
1616
|
+
registerDevice = true;
|
|
1617
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
1618
|
+
}
|
|
1619
|
+
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
1688
1620
|
}
|
|
1689
|
-
else if (!device.hide_device && device.
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1621
|
+
else if (!device.hide_device && device.connectionType === 'Disabled') {
|
|
1622
|
+
if (device.deviceType === 'Curtain') {
|
|
1623
|
+
registerDevice = await this.registerCurtains(device);
|
|
1624
|
+
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|
|
1625
|
+
}
|
|
1626
|
+
else {
|
|
1627
|
+
registerDevice = true;
|
|
1628
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
1629
|
+
}
|
|
1630
|
+
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
|
|
1693
1631
|
}
|
|
1694
|
-
else if (!device.connectionType) {
|
|
1695
|
-
|
|
1696
|
-
this.
|
|
1632
|
+
else if (!device.connectionType && !device.hide_device) {
|
|
1633
|
+
registerDevice = false;
|
|
1634
|
+
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
1697
1635
|
}
|
|
1698
1636
|
else if (device.hide_device) {
|
|
1699
|
-
|
|
1700
|
-
this.
|
|
1637
|
+
registerDevice = false;
|
|
1638
|
+
this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
1701
1639
|
}
|
|
1702
1640
|
else {
|
|
1703
|
-
|
|
1704
|
-
this.
|
|
1705
|
-
+
|
|
1641
|
+
registerDevice = false;
|
|
1642
|
+
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
1643
|
+
+ `${device.hide_device}, will not display in HomeKit`);
|
|
1706
1644
|
}
|
|
1707
|
-
return
|
|
1645
|
+
return registerDevice;
|
|
1708
1646
|
}
|
|
1709
1647
|
async externalOrPlatform(device, accessory) {
|
|
1710
1648
|
this.debugLog(`${accessory.displayName} External Accessory Mode: ${device.external}`);
|
|
@@ -1724,11 +1662,6 @@ class SwitchBotPlatform {
|
|
|
1724
1662
|
this.api.unregisterPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [existingAccessory]);
|
|
1725
1663
|
this.warnLog(`Removing existing accessory from cache: ${existingAccessory.displayName}`);
|
|
1726
1664
|
}
|
|
1727
|
-
deviceListInfo(devices) {
|
|
1728
|
-
if (this.platformLogging?.includes('debug')) {
|
|
1729
|
-
this.warnLog(`deviceListInfoStatus: ${(0, super_stringify_1.default)(devices)}`);
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
1665
|
async statusCode({ res }) {
|
|
1733
1666
|
switch (res.statusCode) {
|
|
1734
1667
|
case 151:
|
|
@@ -1774,6 +1707,27 @@ class SwitchBotPlatform {
|
|
|
1774
1707
|
}
|
|
1775
1708
|
return switchbot;
|
|
1776
1709
|
}
|
|
1710
|
+
logs() {
|
|
1711
|
+
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
1712
|
+
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
1713
|
+
this.platformLogging = this.config.options.logging;
|
|
1714
|
+
if (this.platformLogging.includes('debug')) {
|
|
1715
|
+
this.log.warn(`Using Config Logging: ${this.platformLogging}`);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
else if (this.debugMode) {
|
|
1719
|
+
this.platformLogging = 'debugMode';
|
|
1720
|
+
if (this.platformLogging?.includes('debug')) {
|
|
1721
|
+
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
else {
|
|
1725
|
+
this.platformLogging = 'standard';
|
|
1726
|
+
if (this.platformLogging?.includes('debug')) {
|
|
1727
|
+
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1777
1731
|
/**
|
|
1778
1732
|
* If device level logging is turned on, log to log.warn
|
|
1779
1733
|
* Otherwise send debug logs to log.debug
|
|
@@ -1788,11 +1742,25 @@ class SwitchBotPlatform {
|
|
|
1788
1742
|
this.log.warn(String(...log));
|
|
1789
1743
|
}
|
|
1790
1744
|
}
|
|
1745
|
+
debugWarnLog(...log) {
|
|
1746
|
+
if (this.enablingPlatfromLogging()) {
|
|
1747
|
+
if (this.platformLogging?.includes('debug')) {
|
|
1748
|
+
this.log.warn('[DEBUG]', String(...log));
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1791
1752
|
errorLog(...log) {
|
|
1792
1753
|
if (this.enablingPlatfromLogging()) {
|
|
1793
1754
|
this.log.error(String(...log));
|
|
1794
1755
|
}
|
|
1795
1756
|
}
|
|
1757
|
+
debugErrorLog(...log) {
|
|
1758
|
+
if (this.enablingPlatfromLogging()) {
|
|
1759
|
+
if (this.platformLogging?.includes('debug')) {
|
|
1760
|
+
this.log.error('[DEBUG]', String(...log));
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1796
1764
|
debugLog(...log) {
|
|
1797
1765
|
if (this.enablingPlatfromLogging()) {
|
|
1798
1766
|
if (this.platformLogging === 'debugMode') {
|