@switchbot/homebridge-switchbot 2.0.0-beta.12 → 2.0.0-beta.14
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/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +19 -18
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +32 -25
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +7 -6
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +14 -13
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +18 -17
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +8 -7
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +9 -8
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +8 -7
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +7 -6
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +13 -12
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -2
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +44 -36
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +10 -9
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +8 -7
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +7 -6
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +10 -9
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +9 -8
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +7 -6
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +16 -15
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +7 -6
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +7 -6
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +24 -23
- package/dist/platform.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +19 -18
- package/src/device/colorbulb.ts +33 -26
- package/src/device/contact.ts +7 -6
- package/src/device/curtain.ts +14 -13
- package/src/device/humidifier.ts +18 -17
- package/src/device/lock.ts +8 -7
- package/src/device/meter.ts +9 -8
- package/src/device/meterplus.ts +8 -7
- package/src/device/motion.ts +7 -6
- package/src/device/plug.ts +13 -12
- package/src/device/striplight.ts +47 -39
- package/src/irdevice/airconditioner.ts +10 -9
- package/src/irdevice/airpurifier.ts +8 -7
- package/src/irdevice/camera.ts +7 -6
- package/src/irdevice/fan.ts +10 -9
- package/src/irdevice/light.ts +9 -8
- package/src/irdevice/other.ts +7 -6
- package/src/irdevice/tv.ts +16 -15
- package/src/irdevice/vacuumcleaner.ts +7 -6
- package/src/irdevice/waterheater.ts +7 -6
- package/src/platform.ts +24 -23
package/src/irdevice/other.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import https from 'https';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
|
+
import superStringify from 'super-stringify';
|
|
4
5
|
import { SwitchBotPlatform } from '../platform';
|
|
5
6
|
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
6
7
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
@@ -99,7 +100,7 @@ export class Others {
|
|
|
99
100
|
if (this.device.other) {
|
|
100
101
|
if (this.device.other.commandOn) {
|
|
101
102
|
if (!this.Active) {
|
|
102
|
-
const body =
|
|
103
|
+
const body = superStringify({
|
|
103
104
|
'command': `${this.device.other.commandOn}`,
|
|
104
105
|
'parameter': 'default',
|
|
105
106
|
'commandType': 'customize',
|
|
@@ -122,7 +123,7 @@ export class Others {
|
|
|
122
123
|
if (this.device.other) {
|
|
123
124
|
if (this.device.other.commandOff) {
|
|
124
125
|
if (this.Active) {
|
|
125
|
-
const body =
|
|
126
|
+
const body = superStringify({
|
|
126
127
|
'command': `${this.device.other.commandOff}`,
|
|
127
128
|
'parameter': 'default',
|
|
128
129
|
'commandType': 'customize',
|
|
@@ -178,13 +179,13 @@ export class Others {
|
|
|
178
179
|
});
|
|
179
180
|
req.write(body);
|
|
180
181
|
req.end();
|
|
181
|
-
this.debugLog(`Other: ${this.accessory.displayName} pushchanges: ${
|
|
182
|
+
this.debugLog(`Other: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
182
183
|
this.updateHomeKitCharacteristics();
|
|
183
184
|
} catch (e: any) {
|
|
184
185
|
this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
185
186
|
if (this.deviceLogging.includes('debug')) {
|
|
186
187
|
this.errorLog(
|
|
187
|
-
`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${
|
|
188
|
+
`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
188
189
|
);
|
|
189
190
|
}
|
|
190
191
|
this.apiError(e);
|
|
@@ -211,7 +212,7 @@ export class Others {
|
|
|
211
212
|
case 190:
|
|
212
213
|
this.errorLog(
|
|
213
214
|
`Other: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
214
|
-
` with server, Or command: ${
|
|
215
|
+
` with server, Or command: ${superStringify(res)} format is invalid`,
|
|
215
216
|
);
|
|
216
217
|
break;
|
|
217
218
|
case 100:
|
|
@@ -247,7 +248,7 @@ export class Others {
|
|
|
247
248
|
config['logging'] = device.logging;
|
|
248
249
|
}
|
|
249
250
|
if (Object.entries(config).length !== 0) {
|
|
250
|
-
this.infoLog(`Other: ${this.accessory.displayName} Config: ${
|
|
251
|
+
this.infoLog(`Other: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
254
|
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import https from 'https';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
|
+
import superStringify from 'super-stringify';
|
|
4
5
|
import { SwitchBotPlatform } from '../platform';
|
|
5
6
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
6
7
|
import { irdevice, irDevicesConfig, HostDomain, DevicePath } from '../settings';
|
|
@@ -237,7 +238,7 @@ export class TV {
|
|
|
237
238
|
*/
|
|
238
239
|
async pushTvOnChanges(): Promise<void> {
|
|
239
240
|
if (this.Active !== 1) {
|
|
240
|
-
const body =
|
|
241
|
+
const body = superStringify({
|
|
241
242
|
'command': 'turnOn',
|
|
242
243
|
'parameter': 'default',
|
|
243
244
|
'commandType': 'command',
|
|
@@ -247,7 +248,7 @@ export class TV {
|
|
|
247
248
|
}
|
|
248
249
|
|
|
249
250
|
async pushTvOffChanges(): Promise<void> {
|
|
250
|
-
const body =
|
|
251
|
+
const body = superStringify({
|
|
251
252
|
'command': 'turnOff',
|
|
252
253
|
'parameter': 'default',
|
|
253
254
|
'commandType': 'command',
|
|
@@ -256,7 +257,7 @@ export class TV {
|
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
async pushOkChanges(): Promise<void> {
|
|
259
|
-
const body =
|
|
260
|
+
const body = superStringify({
|
|
260
261
|
'command': 'Ok',
|
|
261
262
|
'parameter': 'default',
|
|
262
263
|
'commandType': 'command',
|
|
@@ -265,7 +266,7 @@ export class TV {
|
|
|
265
266
|
}
|
|
266
267
|
|
|
267
268
|
async pushBackChanges(): Promise<void> {
|
|
268
|
-
const body =
|
|
269
|
+
const body = superStringify({
|
|
269
270
|
'command': 'Back',
|
|
270
271
|
'parameter': 'default',
|
|
271
272
|
'commandType': 'command',
|
|
@@ -274,7 +275,7 @@ export class TV {
|
|
|
274
275
|
}
|
|
275
276
|
|
|
276
277
|
async pushMenuChanges(): Promise<void> {
|
|
277
|
-
const body =
|
|
278
|
+
const body = superStringify({
|
|
278
279
|
'command': 'Menu',
|
|
279
280
|
'parameter': 'default',
|
|
280
281
|
'commandType': 'command',
|
|
@@ -283,7 +284,7 @@ export class TV {
|
|
|
283
284
|
}
|
|
284
285
|
|
|
285
286
|
async pushUpChanges(): Promise<void> {
|
|
286
|
-
const body =
|
|
287
|
+
const body = superStringify({
|
|
287
288
|
'command': 'Up',
|
|
288
289
|
'parameter': 'default',
|
|
289
290
|
'commandType': 'command',
|
|
@@ -292,7 +293,7 @@ export class TV {
|
|
|
292
293
|
}
|
|
293
294
|
|
|
294
295
|
async pushDownChanges(): Promise<void> {
|
|
295
|
-
const body =
|
|
296
|
+
const body = superStringify({
|
|
296
297
|
'command': 'Down',
|
|
297
298
|
'parameter': 'default',
|
|
298
299
|
'commandType': 'command',
|
|
@@ -301,7 +302,7 @@ export class TV {
|
|
|
301
302
|
}
|
|
302
303
|
|
|
303
304
|
async pushRightChanges(): Promise<void> {
|
|
304
|
-
const body =
|
|
305
|
+
const body = superStringify({
|
|
305
306
|
'command': 'Right',
|
|
306
307
|
'parameter': 'default',
|
|
307
308
|
'commandType': 'command',
|
|
@@ -310,7 +311,7 @@ export class TV {
|
|
|
310
311
|
}
|
|
311
312
|
|
|
312
313
|
async pushLeftChanges(): Promise<void> {
|
|
313
|
-
const body =
|
|
314
|
+
const body = superStringify({
|
|
314
315
|
'command': 'Left',
|
|
315
316
|
'parameter': 'default',
|
|
316
317
|
'commandType': 'command',
|
|
@@ -319,7 +320,7 @@ export class TV {
|
|
|
319
320
|
}
|
|
320
321
|
|
|
321
322
|
async pushVolumeUpChanges(): Promise<void> {
|
|
322
|
-
const body =
|
|
323
|
+
const body = superStringify({
|
|
323
324
|
'command': 'volumeAdd',
|
|
324
325
|
'parameter': 'default',
|
|
325
326
|
'commandType': 'command',
|
|
@@ -328,7 +329,7 @@ export class TV {
|
|
|
328
329
|
}
|
|
329
330
|
|
|
330
331
|
async pushVolumeDownChanges(): Promise<void> {
|
|
331
|
-
const body =
|
|
332
|
+
const body = superStringify({
|
|
332
333
|
'command': 'volumeSub',
|
|
333
334
|
'parameter': 'default',
|
|
334
335
|
'commandType': 'command',
|
|
@@ -374,14 +375,14 @@ export class TV {
|
|
|
374
375
|
});
|
|
375
376
|
req.write(body);
|
|
376
377
|
req.end();
|
|
377
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${
|
|
378
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
378
379
|
this.updateHomeKitCharacteristics();
|
|
379
380
|
} catch (e: any) {
|
|
380
381
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
381
382
|
if (this.deviceLogging.includes('debug')) {
|
|
382
383
|
this.errorLog(
|
|
383
384
|
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
384
|
-
` Error Message: ${
|
|
385
|
+
` Error Message: ${superStringify(e.message)}`,
|
|
385
386
|
);
|
|
386
387
|
}
|
|
387
388
|
this.apiError(e);
|
|
@@ -409,7 +410,7 @@ export class TV {
|
|
|
409
410
|
this.errorLog(
|
|
410
411
|
`${this.device.remoteType}: ` +
|
|
411
412
|
`${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
412
|
-
` Or command: ${
|
|
413
|
+
` Or command: ${superStringify(res)} format is invalid`,
|
|
413
414
|
);
|
|
414
415
|
break;
|
|
415
416
|
case 100:
|
|
@@ -435,7 +436,7 @@ export class TV {
|
|
|
435
436
|
config['logging'] = device.logging;
|
|
436
437
|
}
|
|
437
438
|
if (Object.entries(config).length !== 0) {
|
|
438
|
-
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${
|
|
439
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
439
440
|
}
|
|
440
441
|
}
|
|
441
442
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import https from 'https';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
|
+
import superStringify from 'super-stringify';
|
|
4
5
|
import { SwitchBotPlatform } from '../platform';
|
|
5
6
|
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
6
7
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
@@ -86,7 +87,7 @@ export class VacuumCleaner {
|
|
|
86
87
|
*/
|
|
87
88
|
async pushOnChanges(): Promise<void> {
|
|
88
89
|
if (this.On) {
|
|
89
|
-
const body =
|
|
90
|
+
const body = superStringify({
|
|
90
91
|
'command': 'turnOn',
|
|
91
92
|
'parameter': 'default',
|
|
92
93
|
'commandType': 'command',
|
|
@@ -97,7 +98,7 @@ export class VacuumCleaner {
|
|
|
97
98
|
|
|
98
99
|
async pushOffChanges(): Promise<void> {
|
|
99
100
|
if (!this.On) {
|
|
100
|
-
const body =
|
|
101
|
+
const body = superStringify({
|
|
101
102
|
'command': 'turnOff',
|
|
102
103
|
'parameter': 'default',
|
|
103
104
|
'commandType': 'command',
|
|
@@ -144,7 +145,7 @@ export class VacuumCleaner {
|
|
|
144
145
|
});
|
|
145
146
|
req.write(body);
|
|
146
147
|
req.end();
|
|
147
|
-
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushchanges: ${
|
|
148
|
+
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
148
149
|
this.OnCached = this.On;
|
|
149
150
|
this.accessory.context.On = this.OnCached;
|
|
150
151
|
this.updateHomeKitCharacteristics();
|
|
@@ -153,7 +154,7 @@ export class VacuumCleaner {
|
|
|
153
154
|
if (this.deviceLogging.includes('debug')) {
|
|
154
155
|
this.errorLog(
|
|
155
156
|
`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
156
|
-
` Error Message: ${
|
|
157
|
+
` Error Message: ${superStringify(e.message)}`,
|
|
157
158
|
);
|
|
158
159
|
}
|
|
159
160
|
this.apiError(e);
|
|
@@ -180,7 +181,7 @@ export class VacuumCleaner {
|
|
|
180
181
|
case 190:
|
|
181
182
|
this.errorLog(
|
|
182
183
|
`Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
183
|
-
` with server, Or command: ${
|
|
184
|
+
` with server, Or command: ${superStringify(res)} format is invalid`,
|
|
184
185
|
);
|
|
185
186
|
break;
|
|
186
187
|
case 100:
|
|
@@ -205,7 +206,7 @@ export class VacuumCleaner {
|
|
|
205
206
|
config['logging'] = device.logging;
|
|
206
207
|
}
|
|
207
208
|
if (Object.entries(config).length !== 0) {
|
|
208
|
-
this.infoLog(`Vacuum Cleaner: ${this.accessory.displayName} Config: ${
|
|
209
|
+
this.infoLog(`Vacuum Cleaner: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import https from 'https';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
|
+
import superStringify from 'super-stringify';
|
|
4
5
|
import { SwitchBotPlatform } from '../platform';
|
|
5
6
|
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
6
7
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
@@ -93,7 +94,7 @@ export class WaterHeater {
|
|
|
93
94
|
*/
|
|
94
95
|
async pushWaterHeaterOnChanges(): Promise<void> {
|
|
95
96
|
if (this.Active !== 1) {
|
|
96
|
-
const body =
|
|
97
|
+
const body = superStringify({
|
|
97
98
|
'command': 'turnOn',
|
|
98
99
|
'parameter': 'default',
|
|
99
100
|
'commandType': 'command',
|
|
@@ -104,7 +105,7 @@ export class WaterHeater {
|
|
|
104
105
|
|
|
105
106
|
async pushWaterHeaterOffChanges(): Promise<void> {
|
|
106
107
|
if (this.Active !== 0) {
|
|
107
|
-
const body =
|
|
108
|
+
const body = superStringify({
|
|
108
109
|
'command': 'turnOff',
|
|
109
110
|
'parameter': 'default',
|
|
110
111
|
'commandType': 'command',
|
|
@@ -151,13 +152,13 @@ export class WaterHeater {
|
|
|
151
152
|
});
|
|
152
153
|
req.write(body);
|
|
153
154
|
req.end();
|
|
154
|
-
this.debugLog(`Water Heater: ${this.accessory.displayName} pushchanges: ${
|
|
155
|
+
this.debugLog(`Water Heater: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
155
156
|
this.updateHomeKitCharacteristics();
|
|
156
157
|
} catch (e: any) {
|
|
157
158
|
this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
158
159
|
if (this.deviceLogging.includes('debug')) {
|
|
159
160
|
this.errorLog(
|
|
160
|
-
`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${
|
|
161
|
+
`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
|
|
161
162
|
);
|
|
162
163
|
}
|
|
163
164
|
this.apiError(e);
|
|
@@ -184,7 +185,7 @@ export class WaterHeater {
|
|
|
184
185
|
case 190:
|
|
185
186
|
this.errorLog(
|
|
186
187
|
`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
187
|
-
` with server, Or command: ${
|
|
188
|
+
` with server, Or command: ${superStringify(res)} format is invalid`,
|
|
188
189
|
);
|
|
189
190
|
break;
|
|
190
191
|
case 100:
|
|
@@ -209,7 +210,7 @@ export class WaterHeater {
|
|
|
209
210
|
config['logging'] = device.logging;
|
|
210
211
|
}
|
|
211
212
|
if (Object.entries(config).length !== 0) {
|
|
212
|
-
this.infoLog(`Water Heater: ${this.accessory.displayName} Config: ${
|
|
213
|
+
this.infoLog(`Water Heater: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
216
|
|
package/src/platform.ts
CHANGED
|
@@ -22,6 +22,7 @@ import https from 'https';
|
|
|
22
22
|
import crypto from 'crypto';
|
|
23
23
|
import { Buffer } from 'buffer';
|
|
24
24
|
import fakegato from 'fakegato-history';
|
|
25
|
+
import superStringify from 'super-stringify';
|
|
25
26
|
import { readFileSync, writeFileSync } from 'fs';
|
|
26
27
|
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
|
|
27
28
|
import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, DevicePath, HostDomain } from './settings';
|
|
@@ -65,9 +66,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
65
66
|
this.verifyConfig();
|
|
66
67
|
this.debugLog('Config OK');
|
|
67
68
|
} catch (e: any) {
|
|
68
|
-
this.errorLog(
|
|
69
|
+
this.errorLog(superStringify(e.message));
|
|
69
70
|
if (this.platformLogging?.includes('debug')) {
|
|
70
|
-
this.errorLog(
|
|
71
|
+
this.errorLog(superStringify(e));
|
|
71
72
|
}
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
@@ -89,9 +90,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
89
90
|
this.discoverDevices();
|
|
90
91
|
}
|
|
91
92
|
} catch (e: any) {
|
|
92
|
-
this.errorLog('Failed to Discover Devices.',
|
|
93
|
+
this.errorLog('Failed to Discover Devices.', superStringify(e.message));
|
|
93
94
|
if (this.platformLogging?.includes('debug')) {
|
|
94
|
-
this.errorLog(
|
|
95
|
+
this.errorLog(superStringify(e));
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
});
|
|
@@ -145,7 +146,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
145
146
|
platformConfig['pushRate'] = this.config.options.pushRate;
|
|
146
147
|
}
|
|
147
148
|
if (Object.entries(platformConfig).length !== 0) {
|
|
148
|
-
this.infoLog(`Platform Config: ${
|
|
149
|
+
this.infoLog(`Platform Config: ${superStringify(platformConfig)}`);
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
if (this.config.options) {
|
|
@@ -263,7 +264,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
263
264
|
this.warnLog(`Token: ${pluginConfig.credentials.token}`);
|
|
264
265
|
}
|
|
265
266
|
// save the config, ensuring we maintain pretty json
|
|
266
|
-
writeFileSync(this.api.user.configPath(),
|
|
267
|
+
writeFileSync(this.api.user.configPath(), superStringify(currentConfig, null, 4));
|
|
267
268
|
this.verifyConfig();
|
|
268
269
|
} catch (e: any) {
|
|
269
270
|
this.errorLog(e);
|
|
@@ -297,7 +298,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
297
298
|
};
|
|
298
299
|
const req = https.request(options, (res) => {
|
|
299
300
|
this.debugLog(`statusCode: ${res.statusCode}`);
|
|
300
|
-
this.debugLog(`headers: ${
|
|
301
|
+
this.debugLog(`headers: ${superStringify(res.headers)}`);
|
|
301
302
|
let rawData = '';
|
|
302
303
|
res.on('data', (d) => {
|
|
303
304
|
rawData += d;
|
|
@@ -306,7 +307,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
306
307
|
res.on('end', () => {
|
|
307
308
|
try {
|
|
308
309
|
const devicesAPI = JSON.parse(rawData);
|
|
309
|
-
this.debugLog(`devicesAPI: ${
|
|
310
|
+
this.debugLog(`devicesAPI: ${superStringify(devicesAPI.body)}`);
|
|
310
311
|
|
|
311
312
|
// SwitchBot Devices
|
|
312
313
|
if (devicesAPI.body.deviceList.length !== 0) {
|
|
@@ -316,7 +317,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
316
317
|
}
|
|
317
318
|
const deviceLists = devicesAPI.body.deviceList;
|
|
318
319
|
if (!this.config.options?.devices) {
|
|
319
|
-
this.debugLog(`SwitchBot Device Config Not Set: ${
|
|
320
|
+
this.debugLog(`SwitchBot Device Config Not Set: ${superStringify(this.config.options?.devices)}`);
|
|
320
321
|
const devices = deviceLists.map((v: any) => v);
|
|
321
322
|
for (const device of devices) {
|
|
322
323
|
if (device.deviceType) {
|
|
@@ -327,7 +328,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
330
|
} else if (this.config.credentials?.token && this.config.options.devices) {
|
|
330
|
-
this.debugLog(`SwitchBot Device Config Set: ${
|
|
331
|
+
this.debugLog(`SwitchBot Device Config Set: ${superStringify(this.config.options?.devices)}`);
|
|
331
332
|
const deviceConfigs = this.config.options?.devices;
|
|
332
333
|
|
|
333
334
|
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
@@ -340,7 +341,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
340
341
|
}));
|
|
341
342
|
|
|
342
343
|
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
343
|
-
this.debugLog(`SwitchBot Devices: ${
|
|
344
|
+
this.debugLog(`SwitchBot Devices: ${superStringify(devices)}`);
|
|
344
345
|
for (const device of devices) {
|
|
345
346
|
if (device.deviceType) {
|
|
346
347
|
if (device.configDeviceName) {
|
|
@@ -361,7 +362,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
361
362
|
}
|
|
362
363
|
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
363
364
|
if (!this.config.options?.irdevices) {
|
|
364
|
-
this.debugLog(`IR Device Config Not Set: ${
|
|
365
|
+
this.debugLog(`IR Device Config Not Set: ${superStringify(this.config.options?.irdevices)}`);
|
|
365
366
|
const devices = irDeviceLists.map((v: any) => v);
|
|
366
367
|
for (const device of devices) {
|
|
367
368
|
if (device.remoteType) {
|
|
@@ -369,7 +370,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
369
370
|
}
|
|
370
371
|
}
|
|
371
372
|
} else {
|
|
372
|
-
this.debugLog(`IR Device Config Set: ${
|
|
373
|
+
this.debugLog(`IR Device Config Set: ${superStringify(this.config.options?.irdevices)}`);
|
|
373
374
|
const irDeviceConfig = this.config.options?.irdevices;
|
|
374
375
|
|
|
375
376
|
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
@@ -382,7 +383,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
382
383
|
}));
|
|
383
384
|
|
|
384
385
|
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
385
|
-
this.debugLog(`IR Devices: ${
|
|
386
|
+
this.debugLog(`IR Devices: ${superStringify(devices)}`);
|
|
386
387
|
for (const device of devices) {
|
|
387
388
|
if (device.remoteType) {
|
|
388
389
|
this.createIRDevice(device);
|
|
@@ -399,7 +400,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
399
400
|
});
|
|
400
401
|
req.end();
|
|
401
402
|
} else if (!this.config.credentials?.token && this.config.options?.devices) {
|
|
402
|
-
this.debugLog(`SwitchBot Device Manual Config Set: ${
|
|
403
|
+
this.debugLog(`SwitchBot Device Manual Config Set: ${superStringify(this.config.options?.devices)}`);
|
|
403
404
|
const deviceConfigs = this.config.options?.devices;
|
|
404
405
|
const devices = deviceConfigs.map((v: any) => v);
|
|
405
406
|
for (const device of devices) {
|
|
@@ -452,10 +453,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
452
453
|
this.errorLog('Failed to Discover Devices');
|
|
453
454
|
}
|
|
454
455
|
if (this.platformLogging === 'debug') {
|
|
455
|
-
this.errorLog(`Failed to Discover Devices, Error Message: ${
|
|
456
|
+
this.errorLog(`Failed to Discover Devices, Error Message: ${superStringify(e.message)}`);
|
|
456
457
|
}
|
|
457
458
|
if (this.platformLogging === 'debugMode') {
|
|
458
|
-
this.errorLog(`Failed to Discover Devices, Error: ${
|
|
459
|
+
this.errorLog(`Failed to Discover Devices, Error: ${superStringify(e)}`);
|
|
459
460
|
}
|
|
460
461
|
}
|
|
461
462
|
|
|
@@ -659,7 +660,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
659
660
|
if (this.registerDevice(device)) {
|
|
660
661
|
this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`);
|
|
661
662
|
|
|
662
|
-
this.debugLog(
|
|
663
|
+
this.debugLog(superStringify(device.bot?.mode));
|
|
663
664
|
|
|
664
665
|
// if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
|
|
665
666
|
existingAccessory.context.model = device.deviceType;
|
|
@@ -680,7 +681,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
680
681
|
// the accessory does not yet exist, so we need to create it
|
|
681
682
|
this.infoLog(`Adding new accessory: ${device.deviceName} ${device.deviceType} DeviceID: ${device.deviceId}`);
|
|
682
683
|
|
|
683
|
-
this.debugLog(
|
|
684
|
+
this.debugLog(superStringify(device.bot?.mode));
|
|
684
685
|
|
|
685
686
|
// create a new accessory
|
|
686
687
|
const accessory = new this.api.platformAccessory(device.deviceName, uuid);
|
|
@@ -1787,13 +1788,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1787
1788
|
|
|
1788
1789
|
public deviceListInfo(devices) {
|
|
1789
1790
|
if (this.platformLogging?.includes('debug')) {
|
|
1790
|
-
this.warnLog(`deviceListInfoStatus: ${
|
|
1791
|
+
this.warnLog(`deviceListInfoStatus: ${superStringify(devices)}`);
|
|
1791
1792
|
}
|
|
1792
1793
|
}
|
|
1793
1794
|
|
|
1794
1795
|
public async deviceInfo(device: (irdevice & devicesConfig) | (device & devicesConfig)) {
|
|
1795
1796
|
if (this.platformLogging?.includes('debug')) {
|
|
1796
|
-
this.warnLog(
|
|
1797
|
+
this.warnLog(superStringify(device));
|
|
1797
1798
|
|
|
1798
1799
|
const t = Date.now();
|
|
1799
1800
|
const nonce = 'requestID';
|
|
@@ -1827,9 +1828,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1827
1828
|
|
|
1828
1829
|
this.deviceStatus = req;
|
|
1829
1830
|
if (this.deviceStatus.message === 'success') {
|
|
1830
|
-
this.warnLog(`${device.deviceName} deviceInfoStatus: ${
|
|
1831
|
+
this.warnLog(`${device.deviceName} deviceInfoStatus: ${superStringify(this.deviceStatus)}`);
|
|
1831
1832
|
} else {
|
|
1832
|
-
this.warnLog(`${device.deviceName} deviceInfoStatus: ${
|
|
1833
|
+
this.warnLog(`${device.deviceName} deviceInfoStatus: ${superStringify(this.deviceStatus.message)}`);
|
|
1833
1834
|
this.warnLog('Unable to retreive deviceInfoStatus.');
|
|
1834
1835
|
}
|
|
1835
1836
|
}
|