@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
|
@@ -263,12 +263,28 @@ export class VacuumCleaner {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
debugWarnLog(...log: any[]): void {
|
|
267
|
+
if (this.enablingDeviceLogging()) {
|
|
268
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
269
|
+
this.platform.log.warn('[DEBUG]', String(...log));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
266
274
|
errorLog(...log: any[]): void {
|
|
267
275
|
if (this.enablingDeviceLogging()) {
|
|
268
276
|
this.platform.log.error(String(...log));
|
|
269
277
|
}
|
|
270
278
|
}
|
|
271
279
|
|
|
280
|
+
debugErrorLog(...log: any[]): void {
|
|
281
|
+
if (this.enablingDeviceLogging()) {
|
|
282
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
283
|
+
this.platform.log.error('[DEBUG]', String(...log));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
272
288
|
debugLog(...log: any[]): void {
|
|
273
289
|
if (this.enablingDeviceLogging()) {
|
|
274
290
|
if (this.deviceLogging === 'debug') {
|
|
@@ -266,12 +266,28 @@ export class WaterHeater {
|
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
debugWarnLog(...log: any[]): void {
|
|
270
|
+
if (this.enablingDeviceLogging()) {
|
|
271
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
272
|
+
this.platform.log.warn('[DEBUG]', String(...log));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
269
277
|
errorLog(...log: any[]): void {
|
|
270
278
|
if (this.enablingDeviceLogging()) {
|
|
271
279
|
this.platform.log.error(String(...log));
|
|
272
280
|
}
|
|
273
281
|
}
|
|
274
282
|
|
|
283
|
+
debugErrorLog(...log: any[]): void {
|
|
284
|
+
if (this.enablingDeviceLogging()) {
|
|
285
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
286
|
+
this.platform.log.error('[DEBUG]', String(...log));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
275
291
|
debugLog(...log: any[]): void {
|
|
276
292
|
if (this.enablingDeviceLogging()) {
|
|
277
293
|
if (this.deviceLogging === 'debug') {
|
package/src/platform.ts
CHANGED
|
@@ -27,7 +27,6 @@ import { readFileSync, writeFileSync } from 'fs';
|
|
|
27
27
|
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
|
|
28
28
|
import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, DevicePath, HostDomain } from './settings';
|
|
29
29
|
import { IncomingMessage } from 'http';
|
|
30
|
-
import { interval, take } from 'rxjs';
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
32
|
* HomebridgePlatform
|
|
@@ -43,7 +42,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
43
42
|
|
|
44
43
|
version = require('../package.json').version || '1.12.8'; // eslint-disable-line @typescript-eslint/no-var-requires
|
|
45
44
|
deviceStatus!: any;
|
|
46
|
-
registeringDevice!: boolean;
|
|
47
45
|
debugMode!: boolean;
|
|
48
46
|
platformLogging?: string;
|
|
49
47
|
|
|
@@ -51,7 +49,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
51
49
|
|
|
52
50
|
constructor(public readonly log: Logger, public readonly config: SwitchBotPlatformConfig, public readonly api: API) {
|
|
53
51
|
this.logs();
|
|
54
|
-
|
|
55
52
|
this.debugLog('Finished initializing platform:', this.config.name);
|
|
56
53
|
// only load if configured
|
|
57
54
|
if (!this.config) {
|
|
@@ -68,10 +65,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
68
65
|
this.verifyConfig();
|
|
69
66
|
this.debugLog('Config OK');
|
|
70
67
|
} catch (e: any) {
|
|
71
|
-
this.errorLog(
|
|
72
|
-
|
|
73
|
-
this.errorLog(`Verify Config: ${e}`);
|
|
74
|
-
}
|
|
68
|
+
this.errorLog(`Verify Config, Error Message: ${e.message}`);
|
|
69
|
+
this.debugErrorLog(`Verify Config, Error: ${e}`);
|
|
75
70
|
return;
|
|
76
71
|
}
|
|
77
72
|
|
|
@@ -95,34 +90,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
95
90
|
this.discoverDevices();
|
|
96
91
|
}
|
|
97
92
|
} catch (e: any) {
|
|
98
|
-
this.errorLog(
|
|
99
|
-
|
|
100
|
-
this.errorLog(`Platform: ${e}`);
|
|
101
|
-
}
|
|
93
|
+
this.errorLog(`Failed to Discover, Error Message: ${e.message}`);
|
|
94
|
+
this.debugErrorLog(`Failed to Discover, Error: ${e}`);
|
|
102
95
|
}
|
|
103
96
|
});
|
|
104
97
|
}
|
|
105
98
|
|
|
106
|
-
logs() {
|
|
107
|
-
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
108
|
-
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
109
|
-
this.platformLogging = this.config.options!.logging;
|
|
110
|
-
if (this.platformLogging.includes('debug')) {
|
|
111
|
-
this.log.warn(`Using Config Logging: ${this.platformLogging}`);
|
|
112
|
-
}
|
|
113
|
-
} else if (this.debugMode) {
|
|
114
|
-
this.platformLogging = 'debugMode';
|
|
115
|
-
if (this.platformLogging?.includes('debug')) {
|
|
116
|
-
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
this.platformLogging = 'standard';
|
|
120
|
-
if (this.platformLogging?.includes('debug')) {
|
|
121
|
-
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
99
|
/**
|
|
127
100
|
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
|
128
101
|
* It should be used to setup event handlers for characteristics and update respective values.
|
|
@@ -191,48 +164,29 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
191
164
|
if (!this.config.options.refreshRate) {
|
|
192
165
|
// default 120 seconds (2 minutes)
|
|
193
166
|
this.config.options!.refreshRate! = 120;
|
|
194
|
-
|
|
195
|
-
this.debugLog('Using Default Refresh Rate (2 minutes).');
|
|
196
|
-
}
|
|
167
|
+
this.debugWarnLog('Using Default Refresh Rate (2 minutes).');
|
|
197
168
|
}
|
|
198
169
|
|
|
199
170
|
if (!this.config.options.pushRate) {
|
|
200
171
|
// default 100 milliseconds
|
|
201
172
|
this.config.options!.pushRate! = 0.1;
|
|
202
|
-
|
|
203
|
-
this.warnLog('Using Default Push Rate.');
|
|
204
|
-
}
|
|
173
|
+
this.debugWarnLog('Using Default Push Rate.');
|
|
205
174
|
}
|
|
206
175
|
|
|
207
|
-
if (!this.config.credentials) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (this.platformLogging?.includes('debug')) {
|
|
214
|
-
this.errorLog('Missing token');
|
|
215
|
-
this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
176
|
+
if (!this.config.credentials && !this.config.options) {
|
|
177
|
+
this.debugWarnLog('Missing Credentials');
|
|
178
|
+
} else if (this.config.credentials && !this.config.credentials.notice) {
|
|
179
|
+
if (!this.config.credentials?.token) {
|
|
180
|
+
this.debugErrorLog('Missing token');
|
|
181
|
+
this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
216
182
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this.errorLog('Missing secret');
|
|
222
|
-
this.warnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
183
|
+
if (this.config.credentials?.token) {
|
|
184
|
+
if (!this.config.credentials?.secret) {
|
|
185
|
+
this.debugErrorLog('Missing secret');
|
|
186
|
+
this.debugWarnLog('Cloud Enabled SwitchBot Devices & IR Devices will not work');
|
|
223
187
|
}
|
|
224
188
|
}
|
|
225
189
|
}
|
|
226
|
-
|
|
227
|
-
// Re-Discover Devices
|
|
228
|
-
if (!this.config.options.discoverDevices) {
|
|
229
|
-
this.config.options.discoverDevices = false;
|
|
230
|
-
this.debugLog(`Rediscover Devices disabled, discoverDevices: ${this.config.options.discoverDevices}`);
|
|
231
|
-
}
|
|
232
|
-
if (!this.config.options.discoverDevicesInterval) {
|
|
233
|
-
this.config.options.discoverDevicesInterval = 86400;
|
|
234
|
-
this.debugLog(`Default Rediscover Devices Interval, discoverDevicesInterval: ${this.config.options.discoverDevicesInterval}`);
|
|
235
|
-
}
|
|
236
190
|
}
|
|
237
191
|
|
|
238
192
|
/**
|
|
@@ -281,9 +235,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
281
235
|
pluginConfig.credentials.token = this.config.credentials?.openToken;
|
|
282
236
|
pluginConfig.credentials.openToken = 'Delete';
|
|
283
237
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
238
|
+
this.debugWarnLog(`Token: ${pluginConfig.credentials.token}`);
|
|
239
|
+
|
|
287
240
|
// save the config, ensuring we maintain pretty json
|
|
288
241
|
writeFileSync(this.api.user.configPath(), JSON.stringify(currentConfig, null, 4));
|
|
289
242
|
this.verifyConfig();
|
|
@@ -455,56 +408,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
455
408
|
this.errorLog('Neither SwitchBot Token or Device Config are not set.');
|
|
456
409
|
}
|
|
457
410
|
} catch (e: any) {
|
|
458
|
-
this.
|
|
459
|
-
|
|
460
|
-
if (this.config.options?.discoverDevices) {
|
|
461
|
-
interval(this.config.options!.discoverDevicesInterval * 1000)
|
|
462
|
-
.pipe(take(1))
|
|
463
|
-
.subscribe(async () => {
|
|
464
|
-
await this.discoverDevices();
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
deviceError(e: any) {
|
|
470
|
-
if (e.message.includes('400')) {
|
|
471
|
-
this.errorLog('Failed to Discover Devices: Bad Request');
|
|
472
|
-
this.debugLog('The client has issued an invalid request. This is commonly used to specify validation errors in a request payload.');
|
|
473
|
-
} else if (e.message.includes('401')) {
|
|
474
|
-
this.errorLog('Failed to Discover Devices: Unauthorized Request');
|
|
475
|
-
this.debugLog('Authorization for the API is required, but the request has not been authenticated.');
|
|
476
|
-
} else if (e.message.includes('403')) {
|
|
477
|
-
this.errorLog('Failed to Discover Devices: Forbidden Request');
|
|
478
|
-
this.debugLog('The request has been authenticated but does not have appropriate permissions, or a requested resource is not found.');
|
|
479
|
-
} else if (e.message.includes('404')) {
|
|
480
|
-
this.errorLog('Failed to Discover Devices: Requst Not Found');
|
|
481
|
-
this.debugLog('Specifies the requested path does not exist.');
|
|
482
|
-
} else if (e.message.includes('406')) {
|
|
483
|
-
this.errorLog('Failed to Discover Devices: Request Not Acceptable');
|
|
484
|
-
this.debugLog('The client has requested a MIME type via the Accept header for a value not supported by the server.');
|
|
485
|
-
} else if (e.message.includes('415')) {
|
|
486
|
-
this.errorLog('Failed to Discover Devices: Unsupported Requst Header');
|
|
487
|
-
this.debugLog('The client has defined a contentType header that is not supported by the server.');
|
|
488
|
-
} else if (e.message.includes('422')) {
|
|
489
|
-
this.errorLog('Failed to Discover Devices: Unprocessable Entity');
|
|
490
|
-
this.debugLog(
|
|
491
|
-
'The client has made a valid request, but the server cannot process it.' +
|
|
492
|
-
' This is often used for APIs for which certain limits have been exceeded.',
|
|
493
|
-
);
|
|
494
|
-
} else if (e.message.includes('429')) {
|
|
495
|
-
this.errorLog('Failed to Discover Devices: Too Many Requests');
|
|
496
|
-
this.debugLog('The client has exceeded the number of requests allowed for a given time window.');
|
|
497
|
-
} else if (e.message.includes('500')) {
|
|
498
|
-
this.errorLog('Failed to Discover Devices: Internal Server Error');
|
|
499
|
-
this.debugLog('An unexpected error on the SmartThings servers has occurred. These errors should be rare.');
|
|
500
|
-
} else {
|
|
501
|
-
this.errorLog('Failed to Discover Devices');
|
|
502
|
-
}
|
|
503
|
-
if (this.platformLogging === 'debug') {
|
|
504
|
-
this.errorLog(`Failed to Discover Devices, Error Message: ${superStringify(e.message)}`);
|
|
505
|
-
}
|
|
506
|
-
if (this.platformLogging === 'debugMode') {
|
|
507
|
-
this.errorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
411
|
+
this.debugErrorLog(`Failed to Discover Devices, Error Message: ${superStringify(e.message)}`);
|
|
412
|
+
this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
|
|
508
413
|
}
|
|
509
414
|
}
|
|
510
415
|
|
|
@@ -541,7 +446,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
541
446
|
this.createContact(device);
|
|
542
447
|
break;
|
|
543
448
|
case 'Curtain':
|
|
544
|
-
this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`);
|
|
449
|
+
this.debugLog(`Discovered ${device.deviceType} ${device.deviceName}: ${device.deviceId}`);
|
|
545
450
|
this.createCurtain(device);
|
|
546
451
|
break;
|
|
547
452
|
case 'Plug':
|
|
@@ -688,7 +593,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
688
593
|
this.externalOrPlatform(device, accessory);
|
|
689
594
|
this.accessories.push(accessory);
|
|
690
595
|
} else {
|
|
691
|
-
this.debugLog(`
|
|
596
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
692
597
|
}
|
|
693
598
|
}
|
|
694
599
|
|
|
@@ -747,7 +652,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
747
652
|
this.externalOrPlatform(device, accessory);
|
|
748
653
|
this.accessories.push(accessory);
|
|
749
654
|
} else {
|
|
750
|
-
this.debugLog(`
|
|
655
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
751
656
|
}
|
|
752
657
|
}
|
|
753
658
|
|
|
@@ -801,7 +706,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
801
706
|
this.externalOrPlatform(device, accessory);
|
|
802
707
|
this.accessories.push(accessory);
|
|
803
708
|
} else {
|
|
804
|
-
this.debugLog(`
|
|
709
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
805
710
|
}
|
|
806
711
|
}
|
|
807
712
|
|
|
@@ -855,7 +760,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
855
760
|
this.externalOrPlatform(device, accessory);
|
|
856
761
|
this.accessories.push(accessory);
|
|
857
762
|
} else {
|
|
858
|
-
this.debugLog(`
|
|
763
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
859
764
|
}
|
|
860
765
|
}
|
|
861
766
|
|
|
@@ -909,7 +814,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
909
814
|
this.externalOrPlatform(device, accessory);
|
|
910
815
|
this.accessories.push(accessory);
|
|
911
816
|
} else {
|
|
912
|
-
this.debugLog(`
|
|
817
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
913
818
|
}
|
|
914
819
|
}
|
|
915
820
|
|
|
@@ -963,7 +868,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
963
868
|
this.externalOrPlatform(device, accessory);
|
|
964
869
|
this.accessories.push(accessory);
|
|
965
870
|
} else {
|
|
966
|
-
this.debugLog(`
|
|
871
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
967
872
|
}
|
|
968
873
|
}
|
|
969
874
|
|
|
@@ -976,7 +881,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
976
881
|
|
|
977
882
|
if (existingAccessory) {
|
|
978
883
|
// the accessory already exists
|
|
979
|
-
if (this.
|
|
884
|
+
if (await this.registerDevice(device)) {
|
|
980
885
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
981
886
|
existingAccessory.context.model = device.deviceType;
|
|
982
887
|
existingAccessory.context.deviceID = device.deviceId;
|
|
@@ -993,7 +898,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
993
898
|
} else {
|
|
994
899
|
this.unregisterPlatformAccessories(existingAccessory);
|
|
995
900
|
}
|
|
996
|
-
} else if (this.
|
|
901
|
+
} else if (await this.registerDevice(device)) {
|
|
997
902
|
// the accessory does not yet exist, so we need to create it
|
|
998
903
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
999
904
|
|
|
@@ -1002,9 +907,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1002
907
|
, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1003
908
|
} else {
|
|
1004
909
|
if (device.master) {
|
|
1005
|
-
this.
|
|
910
|
+
this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1006
911
|
} else {
|
|
1007
|
-
this.
|
|
912
|
+
this.errorLog(`Secondary Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
|
|
1008
913
|
}
|
|
1009
914
|
}
|
|
1010
915
|
|
|
@@ -1028,22 +933,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1028
933
|
this.externalOrPlatform(device, accessory);
|
|
1029
934
|
this.accessories.push(accessory);
|
|
1030
935
|
} else {
|
|
1031
|
-
this.debugLog(`
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
private isCurtainGrouped(device: device & devicesConfig) {
|
|
1036
|
-
this.debugLog(
|
|
1037
|
-
`deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},` +
|
|
1038
|
-
` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`,
|
|
1039
|
-
);
|
|
1040
|
-
|
|
1041
|
-
if (device.group && !device.curtain?.disable_group) {
|
|
1042
|
-
this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}`);
|
|
1043
|
-
return device.master && this.registerDevice(device);
|
|
1044
|
-
} else {
|
|
1045
|
-
this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
|
|
1046
|
-
return this.registerDevice(device);
|
|
936
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1047
937
|
}
|
|
1048
938
|
}
|
|
1049
939
|
|
|
@@ -1097,7 +987,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1097
987
|
this.externalOrPlatform(device, accessory);
|
|
1098
988
|
this.accessories.push(accessory);
|
|
1099
989
|
} else {
|
|
1100
|
-
this.debugLog(`
|
|
990
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1101
991
|
}
|
|
1102
992
|
}
|
|
1103
993
|
|
|
@@ -1151,7 +1041,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1151
1041
|
this.externalOrPlatform(device, accessory);
|
|
1152
1042
|
this.accessories.push(accessory);
|
|
1153
1043
|
} else {
|
|
1154
|
-
this.debugLog(`
|
|
1044
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1155
1045
|
}
|
|
1156
1046
|
}
|
|
1157
1047
|
|
|
@@ -1205,7 +1095,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1205
1095
|
this.externalOrPlatform(device, accessory);
|
|
1206
1096
|
this.accessories.push(accessory);
|
|
1207
1097
|
} else {
|
|
1208
|
-
this.debugLog(`
|
|
1098
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1209
1099
|
}
|
|
1210
1100
|
}
|
|
1211
1101
|
|
|
@@ -1259,7 +1149,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1259
1149
|
this.externalOrPlatform(device, accessory);
|
|
1260
1150
|
this.accessories.push(accessory);
|
|
1261
1151
|
} else {
|
|
1262
|
-
this.debugLog(`
|
|
1152
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
1263
1153
|
}
|
|
1264
1154
|
}
|
|
1265
1155
|
|
|
@@ -1312,7 +1202,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1312
1202
|
this.externalAccessory(accessory);
|
|
1313
1203
|
this.accessories.push(accessory);
|
|
1314
1204
|
} else {
|
|
1315
|
-
this.debugLog(`
|
|
1205
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1316
1206
|
}
|
|
1317
1207
|
}
|
|
1318
1208
|
|
|
@@ -1366,7 +1256,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1366
1256
|
this.externalOrPlatform(device, accessory);
|
|
1367
1257
|
this.accessories.push(accessory);
|
|
1368
1258
|
} else {
|
|
1369
|
-
this.debugLog(`
|
|
1259
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1370
1260
|
}
|
|
1371
1261
|
}
|
|
1372
1262
|
|
|
@@ -1420,7 +1310,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1420
1310
|
this.externalOrPlatform(device, accessory);
|
|
1421
1311
|
this.accessories.push(accessory);
|
|
1422
1312
|
} else {
|
|
1423
|
-
this.debugLog(`
|
|
1313
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1424
1314
|
}
|
|
1425
1315
|
}
|
|
1426
1316
|
|
|
@@ -1474,7 +1364,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1474
1364
|
this.externalOrPlatform(device, accessory);
|
|
1475
1365
|
this.accessories.push(accessory);
|
|
1476
1366
|
} else {
|
|
1477
|
-
this.debugLog(`
|
|
1367
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1478
1368
|
}
|
|
1479
1369
|
}
|
|
1480
1370
|
|
|
@@ -1528,7 +1418,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1528
1418
|
this.externalOrPlatform(device, accessory);
|
|
1529
1419
|
this.accessories.push(accessory);
|
|
1530
1420
|
} else {
|
|
1531
|
-
this.debugLog(`
|
|
1421
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1532
1422
|
}
|
|
1533
1423
|
}
|
|
1534
1424
|
|
|
@@ -1582,7 +1472,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1582
1472
|
this.externalOrPlatform(device, accessory);
|
|
1583
1473
|
this.accessories.push(accessory);
|
|
1584
1474
|
} else {
|
|
1585
|
-
this.debugLog(`
|
|
1475
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1586
1476
|
}
|
|
1587
1477
|
}
|
|
1588
1478
|
|
|
@@ -1636,7 +1526,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1636
1526
|
this.externalOrPlatform(device, accessory);
|
|
1637
1527
|
this.accessories.push(accessory);
|
|
1638
1528
|
} else {
|
|
1639
|
-
this.debugLog(`
|
|
1529
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1640
1530
|
}
|
|
1641
1531
|
}
|
|
1642
1532
|
|
|
@@ -1690,7 +1580,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1690
1580
|
this.externalOrPlatform(device, accessory);
|
|
1691
1581
|
this.accessories.push(accessory);
|
|
1692
1582
|
} else {
|
|
1693
|
-
this.debugLog(`
|
|
1583
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1694
1584
|
}
|
|
1695
1585
|
}
|
|
1696
1586
|
|
|
@@ -1744,12 +1634,33 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1744
1634
|
this.externalOrPlatform(device, accessory);
|
|
1745
1635
|
this.accessories.push(accessory);
|
|
1746
1636
|
} else {
|
|
1747
|
-
this.debugLog(`
|
|
1637
|
+
this.debugLog(`Device not registered: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`);
|
|
1748
1638
|
}
|
|
1749
1639
|
}
|
|
1750
1640
|
|
|
1641
|
+
async registerCurtains(device: device & devicesConfig) {
|
|
1642
|
+
this.warnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: ` +
|
|
1643
|
+
`${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
|
|
1644
|
+
|
|
1645
|
+
let registerCurtain: boolean;
|
|
1646
|
+
if (device.group && !device.curtain?.disable_group) {
|
|
1647
|
+
registerCurtain = true;
|
|
1648
|
+
this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}`);
|
|
1649
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1650
|
+
} else if (device.connectionType?.includes('BLE') || device.connectionType === 'Disabled') {
|
|
1651
|
+
registerCurtain = true;
|
|
1652
|
+
this.debugLog(`deviceName: ${device.deviceName} [Curtain Config] connectionType: ${device.connectionType}`);
|
|
1653
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1654
|
+
} else {
|
|
1655
|
+
registerCurtain = false;
|
|
1656
|
+
this.errorLog(`deviceName: ${device.deviceName} [Curtain Config] disable_group: ${device.curtain?.disable_group}, UnGrouping ${device.master}`);
|
|
1657
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
|
|
1658
|
+
}
|
|
1659
|
+
return registerCurtain;
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1751
1662
|
async connectionType(device: device & devicesConfig): Promise<any> {
|
|
1752
|
-
let connectionType
|
|
1663
|
+
let connectionType: string;
|
|
1753
1664
|
if (!device.connectionType && this.config.credentials?.token && this.config.credentials.secret) {
|
|
1754
1665
|
connectionType = 'OpenAPI';
|
|
1755
1666
|
} else {
|
|
@@ -1760,32 +1671,56 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1760
1671
|
|
|
1761
1672
|
async registerDevice(device: device & devicesConfig) {
|
|
1762
1673
|
device.connectionType = await this.connectionType(device);
|
|
1674
|
+
let registerDevice: boolean;
|
|
1763
1675
|
if (!device.hide_device && device.enableCloudService && device.connectionType === 'BLE/OpenAPI') {
|
|
1764
|
-
|
|
1765
|
-
|
|
1676
|
+
if (device.deviceType === 'Curtain') {
|
|
1677
|
+
registerDevice = await this.registerCurtains(device);
|
|
1678
|
+
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|
|
1679
|
+
} else {
|
|
1680
|
+
registerDevice = true;
|
|
1681
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
1682
|
+
}
|
|
1683
|
+
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
1766
1684
|
} else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
|
|
1767
1685
|
&& device.connectionType === 'BLE') {
|
|
1768
|
-
|
|
1769
|
-
|
|
1686
|
+
if (device.deviceType === 'Curtain') {
|
|
1687
|
+
registerDevice = await this.registerCurtains(device);
|
|
1688
|
+
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|
|
1689
|
+
} else {
|
|
1690
|
+
registerDevice = true;
|
|
1691
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
1692
|
+
}
|
|
1693
|
+
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
1770
1694
|
} else if (!device.hide_device && device.enableCloudService && device.connectionType === 'OpenAPI') {
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
this.
|
|
1779
|
-
|
|
1695
|
+
if (device.deviceType === 'Curtain') {
|
|
1696
|
+
registerDevice = await this.registerCurtains(device);
|
|
1697
|
+
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|
|
1698
|
+
} else {
|
|
1699
|
+
registerDevice = true;
|
|
1700
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
1701
|
+
}
|
|
1702
|
+
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
|
|
1703
|
+
} else if (!device.hide_device && device.connectionType === 'Disabled') {
|
|
1704
|
+
if (device.deviceType === 'Curtain') {
|
|
1705
|
+
registerDevice = await this.registerCurtains(device);
|
|
1706
|
+
this.debugWarnLog(`Device: ${device.deviceName} Curtain registerDevice: ${registerDevice}`);
|
|
1707
|
+
} else {
|
|
1708
|
+
registerDevice = true;
|
|
1709
|
+
this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
|
|
1710
|
+
}
|
|
1711
|
+
this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will continue to display in HomeKit`);
|
|
1712
|
+
} else if (!device.connectionType && !device.hide_device) {
|
|
1713
|
+
registerDevice = false;
|
|
1714
|
+
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
|
|
1780
1715
|
} else if (device.hide_device){
|
|
1781
|
-
|
|
1782
|
-
this.
|
|
1716
|
+
registerDevice = false;
|
|
1717
|
+
this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
|
|
1783
1718
|
} else {
|
|
1784
|
-
|
|
1785
|
-
this.
|
|
1786
|
-
+
|
|
1719
|
+
registerDevice = false;
|
|
1720
|
+
this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
|
|
1721
|
+
+ `${device.hide_device}, will not display in HomeKit`);
|
|
1787
1722
|
}
|
|
1788
|
-
return
|
|
1723
|
+
return registerDevice;
|
|
1789
1724
|
}
|
|
1790
1725
|
|
|
1791
1726
|
public async externalOrPlatform(device: device & devicesConfig, accessory: PlatformAccessory) {
|
|
@@ -1808,12 +1743,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1808
1743
|
this.warnLog(`Removing existing accessory from cache: ${existingAccessory.displayName}`);
|
|
1809
1744
|
}
|
|
1810
1745
|
|
|
1811
|
-
public deviceListInfo(devices) {
|
|
1812
|
-
if (this.platformLogging?.includes('debug')) {
|
|
1813
|
-
this.warnLog(`deviceListInfoStatus: ${superStringify(devices)}`);
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1817
1746
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
1818
1747
|
switch (res.statusCode) {
|
|
1819
1748
|
case 151:
|
|
@@ -1860,6 +1789,26 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1860
1789
|
return switchbot;
|
|
1861
1790
|
}
|
|
1862
1791
|
|
|
1792
|
+
logs() {
|
|
1793
|
+
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
|
|
1794
|
+
if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
|
|
1795
|
+
this.platformLogging = this.config.options!.logging;
|
|
1796
|
+
if (this.platformLogging.includes('debug')) {
|
|
1797
|
+
this.log.warn(`Using Config Logging: ${this.platformLogging}`);
|
|
1798
|
+
}
|
|
1799
|
+
} else if (this.debugMode) {
|
|
1800
|
+
this.platformLogging = 'debugMode';
|
|
1801
|
+
if (this.platformLogging?.includes('debug')) {
|
|
1802
|
+
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
1803
|
+
}
|
|
1804
|
+
} else {
|
|
1805
|
+
this.platformLogging = 'standard';
|
|
1806
|
+
if (this.platformLogging?.includes('debug')) {
|
|
1807
|
+
this.log.warn(`Using ${this.platformLogging} Logging`);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1863
1812
|
/**
|
|
1864
1813
|
* If device level logging is turned on, log to log.warn
|
|
1865
1814
|
* Otherwise send debug logs to log.debug
|
|
@@ -1876,12 +1825,28 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1876
1825
|
}
|
|
1877
1826
|
}
|
|
1878
1827
|
|
|
1828
|
+
debugWarnLog(...log: any[]): void {
|
|
1829
|
+
if (this.enablingPlatfromLogging()) {
|
|
1830
|
+
if (this.platformLogging?.includes('debug')) {
|
|
1831
|
+
this.log.warn('[DEBUG]', String(...log));
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1879
1836
|
errorLog(...log: any[]): void {
|
|
1880
1837
|
if (this.enablingPlatfromLogging()) {
|
|
1881
1838
|
this.log.error(String(...log));
|
|
1882
1839
|
}
|
|
1883
1840
|
}
|
|
1884
1841
|
|
|
1842
|
+
debugErrorLog(...log: any[]): void {
|
|
1843
|
+
if (this.enablingPlatfromLogging()) {
|
|
1844
|
+
if (this.platformLogging?.includes('debug')) {
|
|
1845
|
+
this.log.error('[DEBUG]', String(...log));
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1885
1850
|
debugLog(...log: any[]): void {
|
|
1886
1851
|
if (this.enablingPlatfromLogging()) {
|
|
1887
1852
|
if (this.platformLogging === 'debugMode') {
|