@switchbot/homebridge-switchbot 2.6.0-beta.4 → 2.6.0
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/.vscode/tasks.json +13 -0
- package/CHANGELOG.md +4 -2
- package/README.md +18 -9
- package/dist/device/blindtilt.d.ts +1 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +80 -140
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +79 -138
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +2 -6
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +157 -304
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -6
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +164 -311
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +36 -72
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +78 -138
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +2 -6
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +30 -63
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +115 -228
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +38 -74
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/{striplight.d.ts → lightstrip.d.ts} +2 -10
- package/dist/device/lightstrip.d.ts.map +1 -0
- package/dist/device/{striplight.js → lightstrip.js} +138 -194
- package/dist/device/lightstrip.js.map +1 -0
- package/dist/device/lock.d.ts +1 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +66 -126
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +38 -74
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +39 -75
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +35 -72
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +65 -126
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +79 -151
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +3 -7
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +34 -62
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +3 -7
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +31 -59
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -5
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +30 -57
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -6
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +39 -66
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -5
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +32 -59
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -5
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +30 -57
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +3 -7
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +46 -76
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +30 -58
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -23
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +41 -74
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -5
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +156 -149
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +5 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +122 -181
- package/src/device/bot.ts +96 -149
- package/src/device/ceilinglight.ts +172 -315
- package/src/device/colorbulb.ts +178 -324
- package/src/device/contact.ts +48 -78
- package/src/device/curtain.ts +93 -148
- package/src/device/hub.ts +34 -63
- package/src/device/humidifier.ts +135 -243
- package/src/device/iosensor.ts +49 -79
- package/src/device/{striplight.ts → lightstrip.ts} +148 -200
- package/src/device/lock.ts +78 -134
- package/src/device/meter.ts +48 -78
- package/src/device/meterplus.ts +50 -80
- package/src/device/motion.ts +46 -77
- package/src/device/plug.ts +76 -134
- package/src/device/robotvacuumcleaner.ts +91 -159
- package/src/irdevice/airconditioner.ts +56 -81
- package/src/irdevice/airpurifier.ts +41 -67
- package/src/irdevice/camera.ts +35 -60
- package/src/irdevice/fan.ts +46 -71
- package/src/irdevice/light.ts +38 -63
- package/src/irdevice/other.ts +35 -60
- package/src/irdevice/tv.ts +52 -80
- package/src/irdevice/vacuumcleaner.ts +36 -62
- package/src/irdevice/waterheater.ts +46 -76
- package/src/platform.ts +144 -158
- package/src/settings.ts +5 -0
- package/.github/npm-version-script.js +0 -81
- package/dist/device/striplight.d.ts.map +0 -1
- package/dist/device/striplight.js.map +0 -1
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.Humidifier = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const undici_1 = require("undici");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
9
6
|
const rxjs_1 = require("rxjs");
|
|
10
|
-
const super_stringify_1 = __importDefault(require("super-stringify"));
|
|
11
7
|
const operators_1 = require("rxjs/operators");
|
|
12
8
|
const settings_1 = require("../settings");
|
|
13
|
-
const utils_1 = require("../utils");
|
|
14
9
|
/**
|
|
15
10
|
* Platform Accessory
|
|
16
11
|
* An instance of this class is created for each accessory your platform registers
|
|
@@ -132,7 +127,7 @@ class Humidifier {
|
|
|
132
127
|
catch (e) {
|
|
133
128
|
this.apiError(e);
|
|
134
129
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
135
|
-
+ ` Error Message: ${
|
|
130
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
136
131
|
}
|
|
137
132
|
this.humidifierUpdateInProgress = false;
|
|
138
133
|
});
|
|
@@ -275,7 +270,7 @@ class Humidifier {
|
|
|
275
270
|
this.autoMode = ad.serviceData.autoMode;
|
|
276
271
|
this.onState = ad.serviceData.onState;
|
|
277
272
|
this.percentage = ad.serviceData.percentage;
|
|
278
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
273
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
279
274
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
280
275
|
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
|
|
281
276
|
if (this.serviceData) {
|
|
@@ -298,7 +293,7 @@ class Humidifier {
|
|
|
298
293
|
.catch(async (e) => {
|
|
299
294
|
this.apiError(e);
|
|
300
295
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
301
|
-
+ ` Connection, Error Message: ${
|
|
296
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
302
297
|
await this.BLERefreshConnection(switchbot);
|
|
303
298
|
});
|
|
304
299
|
}
|
|
@@ -309,59 +304,27 @@ class Humidifier {
|
|
|
309
304
|
async openAPIRefreshStatus() {
|
|
310
305
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
311
306
|
try {
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
315
|
-
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
316
|
-
const sign = signTerm.toString('base64');
|
|
317
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
318
|
-
const options = {
|
|
319
|
-
hostname: settings_1.HostDomain,
|
|
320
|
-
port: 443,
|
|
321
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
|
|
322
|
-
method: 'GET',
|
|
323
|
-
headers: {
|
|
324
|
-
Authorization: this.platform.config.credentials?.token,
|
|
325
|
-
sign: sign,
|
|
326
|
-
nonce: nonce,
|
|
327
|
-
t: t,
|
|
328
|
-
'Content-Type': 'application/json',
|
|
329
|
-
},
|
|
330
|
-
};
|
|
331
|
-
const req = https_1.default.request(options, (res) => {
|
|
332
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
333
|
-
let rawData = '';
|
|
334
|
-
res.on('data', (d) => {
|
|
335
|
-
rawData += d;
|
|
336
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
337
|
-
});
|
|
338
|
-
res.on('end', () => {
|
|
339
|
-
try {
|
|
340
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
341
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
342
|
-
this.auto = this.deviceStatus.body.auto;
|
|
343
|
-
this.power = this.deviceStatus.body.power;
|
|
344
|
-
this.lackWater = this.deviceStatus.body.lackWater;
|
|
345
|
-
this.humidity = this.deviceStatus.body.humidity;
|
|
346
|
-
this.temperature = this.deviceStatus.body.temperature;
|
|
347
|
-
this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
|
|
348
|
-
this.openAPIparseStatus();
|
|
349
|
-
this.updateHomeKitCharacteristics();
|
|
350
|
-
}
|
|
351
|
-
catch (e) {
|
|
352
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
307
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/status`, {
|
|
308
|
+
headers: this.platform.generateHeaders(),
|
|
355
309
|
});
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
310
|
+
const deviceStatus = await body.json();
|
|
311
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
312
|
+
this.statusCode(statusCode);
|
|
313
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
314
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
315
|
+
this.auto = deviceStatus.body.auto;
|
|
316
|
+
this.power = deviceStatus.body.power;
|
|
317
|
+
this.lackWater = deviceStatus.body.lackWater;
|
|
318
|
+
this.humidity = deviceStatus.body.humidity;
|
|
319
|
+
this.temperature = deviceStatus.body.temperature;
|
|
320
|
+
this.nebulizationEfficiency = deviceStatus.body.nebulizationEfficiency;
|
|
321
|
+
this.openAPIparseStatus();
|
|
322
|
+
this.updateHomeKitCharacteristics();
|
|
360
323
|
}
|
|
361
324
|
catch (e) {
|
|
362
325
|
this.apiError(e);
|
|
363
326
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
364
|
-
+ ` Connection, Error Message: ${
|
|
327
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
365
328
|
}
|
|
366
329
|
}
|
|
367
330
|
/**
|
|
@@ -412,192 +375,111 @@ class Humidifier {
|
|
|
412
375
|
.catch(async (e) => {
|
|
413
376
|
this.apiError(e);
|
|
414
377
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
415
|
-
+ ` Connection, Error Message: ${
|
|
378
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
416
379
|
await this.BLEPushConnection();
|
|
417
380
|
});
|
|
418
381
|
}
|
|
419
382
|
async openAPIpushChanges() {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
433
|
-
this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
434
|
-
const body = (0, super_stringify_1.default)({
|
|
435
|
-
'command': 'setMode',
|
|
436
|
-
'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
|
|
437
|
-
'commandType': 'command',
|
|
438
|
-
});
|
|
439
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
440
|
-
const options = {
|
|
441
|
-
hostname: settings_1.HostDomain,
|
|
442
|
-
port: 443,
|
|
443
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
383
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
384
|
+
if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
385
|
+
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
386
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
387
|
+
const body = JSON.stringify({
|
|
388
|
+
'command': 'setMode',
|
|
389
|
+
'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
|
|
390
|
+
'commandType': 'command',
|
|
391
|
+
});
|
|
392
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
393
|
+
try {
|
|
394
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
444
395
|
method: 'POST',
|
|
445
|
-
headers:
|
|
446
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
447
|
-
'sign': sign,
|
|
448
|
-
'nonce': nonce,
|
|
449
|
-
't': t,
|
|
450
|
-
'Content-Type': 'application/json',
|
|
451
|
-
'Content-Length': body.length,
|
|
452
|
-
},
|
|
453
|
-
};
|
|
454
|
-
const req = https_1.default.request(options, res => {
|
|
455
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
456
|
-
res.on('data', d => {
|
|
457
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
458
|
-
});
|
|
396
|
+
headers: this.platform.generateHeaders(),
|
|
459
397
|
});
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
});
|
|
464
|
-
req.write(body);
|
|
465
|
-
req.end();
|
|
466
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
467
|
-
}
|
|
468
|
-
else if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
469
|
-
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
470
|
-
await this.pushAutoChanges();
|
|
398
|
+
const deviceStatus = await body.json();
|
|
399
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
400
|
+
this.statusCode(statusCode);
|
|
401
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
471
402
|
}
|
|
472
|
-
|
|
473
|
-
|
|
403
|
+
catch (e) {
|
|
404
|
+
this.apiError(e);
|
|
405
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
406
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
474
407
|
}
|
|
475
408
|
}
|
|
476
|
-
|
|
477
|
-
this.
|
|
478
|
-
this.
|
|
479
|
-
|
|
409
|
+
else if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
410
|
+
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
411
|
+
await this.pushAutoChanges();
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
await this.pushActiveChanges();
|
|
480
415
|
}
|
|
481
416
|
}
|
|
482
417
|
/**
|
|
483
418
|
* Pushes the requested changes to the SwitchBot API
|
|
484
419
|
*/
|
|
485
420
|
async pushAutoChanges() {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
const
|
|
498
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
499
|
-
this.debugLog('Pushing Auto!');
|
|
500
|
-
const body = (0, super_stringify_1.default)({
|
|
501
|
-
'command': 'setMode',
|
|
502
|
-
'parameter': 'auto',
|
|
503
|
-
'commandType': 'command',
|
|
504
|
-
});
|
|
505
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
506
|
-
const options = {
|
|
507
|
-
hostname: settings_1.HostDomain,
|
|
508
|
-
port: 443,
|
|
509
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
421
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
422
|
+
if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
423
|
+
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
424
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
425
|
+
const body = JSON.stringify({
|
|
426
|
+
'command': 'setMode',
|
|
427
|
+
'parameter': 'auto',
|
|
428
|
+
'commandType': 'command',
|
|
429
|
+
});
|
|
430
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
431
|
+
try {
|
|
432
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
510
433
|
method: 'POST',
|
|
511
|
-
headers:
|
|
512
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
513
|
-
'sign': sign,
|
|
514
|
-
'nonce': nonce,
|
|
515
|
-
't': t,
|
|
516
|
-
'Content-Type': 'application/json',
|
|
517
|
-
'Content-Length': body.length,
|
|
518
|
-
},
|
|
519
|
-
};
|
|
520
|
-
const req = https_1.default.request(options, res => {
|
|
521
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
522
|
-
this.statusCode({ res });
|
|
523
|
-
res.on('data', d => {
|
|
524
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
525
|
-
});
|
|
526
|
-
});
|
|
527
|
-
req.on('error', (e) => {
|
|
528
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
434
|
+
headers: this.platform.generateHeaders(),
|
|
529
435
|
});
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
this.
|
|
436
|
+
const deviceStatus = await body.json();
|
|
437
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
438
|
+
this.statusCode(statusCode);
|
|
439
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
533
440
|
}
|
|
534
|
-
|
|
535
|
-
this.
|
|
536
|
-
|
|
441
|
+
catch (e) {
|
|
442
|
+
this.apiError(e);
|
|
443
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}`
|
|
444
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
537
445
|
}
|
|
538
446
|
}
|
|
539
|
-
|
|
540
|
-
this.
|
|
541
|
-
|
|
542
|
-
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
447
|
+
else {
|
|
448
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges.` +
|
|
449
|
+
`TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`);
|
|
543
450
|
}
|
|
544
451
|
}
|
|
545
452
|
/**
|
|
546
453
|
* Pushes the requested changes to the SwitchBot API
|
|
547
454
|
*/
|
|
548
455
|
async pushActiveChanges() {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
const
|
|
560
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
561
|
-
this.debugLog('Pushing Off!');
|
|
562
|
-
const body = (0, super_stringify_1.default)({
|
|
563
|
-
'command': 'turnOff',
|
|
564
|
-
'parameter': 'default',
|
|
565
|
-
'commandType': 'command',
|
|
566
|
-
});
|
|
567
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
568
|
-
const options = {
|
|
569
|
-
hostname: settings_1.HostDomain,
|
|
570
|
-
port: 443,
|
|
571
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
456
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
457
|
+
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
458
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
459
|
+
const body = JSON.stringify({
|
|
460
|
+
'command': 'turnOff',
|
|
461
|
+
'parameter': 'default',
|
|
462
|
+
'commandType': 'command',
|
|
463
|
+
});
|
|
464
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
465
|
+
try {
|
|
466
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
572
467
|
method: 'POST',
|
|
573
|
-
headers:
|
|
574
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
575
|
-
'sign': sign,
|
|
576
|
-
'nonce': nonce,
|
|
577
|
-
't': t,
|
|
578
|
-
'Content-Type': 'application/json',
|
|
579
|
-
'Content-Length': body.length,
|
|
580
|
-
},
|
|
581
|
-
};
|
|
582
|
-
const req = https_1.default.request(options, res => {
|
|
583
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges statusCode: ${res.statusCode}`);
|
|
584
|
-
this.statusCode({ res });
|
|
585
|
-
res.on('data', d => {
|
|
586
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
587
|
-
});
|
|
468
|
+
headers: this.platform.generateHeaders(),
|
|
588
469
|
});
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
470
|
+
const deviceStatus = await body.json();
|
|
471
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
472
|
+
this.statusCode(statusCode);
|
|
473
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
474
|
+
}
|
|
475
|
+
catch (e) {
|
|
476
|
+
this.apiError(e);
|
|
477
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
|
|
478
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
595
479
|
}
|
|
596
480
|
}
|
|
597
|
-
|
|
598
|
-
this.
|
|
599
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
|
|
600
|
-
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
481
|
+
else {
|
|
482
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.Active}`);
|
|
601
483
|
}
|
|
602
484
|
}
|
|
603
485
|
/**
|
|
@@ -734,7 +616,7 @@ class Humidifier {
|
|
|
734
616
|
});
|
|
735
617
|
// Set an event handler
|
|
736
618
|
switchbot.onadvertisement = (ad) => {
|
|
737
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${
|
|
619
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
738
620
|
};
|
|
739
621
|
await (0, utils_1.sleep)(10000);
|
|
740
622
|
// Stop to monitor
|
|
@@ -778,34 +660,39 @@ class Humidifier {
|
|
|
778
660
|
}
|
|
779
661
|
}
|
|
780
662
|
}
|
|
781
|
-
async statusCode(
|
|
782
|
-
switch (
|
|
663
|
+
async statusCode(statusCode) {
|
|
664
|
+
switch (statusCode) {
|
|
783
665
|
case 151:
|
|
784
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this
|
|
666
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
785
667
|
break;
|
|
786
668
|
case 152:
|
|
787
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found
|
|
669
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
788
670
|
break;
|
|
789
671
|
case 160:
|
|
790
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported
|
|
672
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
791
673
|
break;
|
|
792
674
|
case 161:
|
|
793
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline
|
|
794
|
-
|
|
675
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
676
|
+
this.offlineOff();
|
|
795
677
|
break;
|
|
796
678
|
case 171:
|
|
797
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline
|
|
798
|
-
|
|
679
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
|
|
680
|
+
+ `Hub: ${this.device.hubDeviceId}`);
|
|
681
|
+
this.offlineOff();
|
|
799
682
|
break;
|
|
800
683
|
case 190:
|
|
801
684
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
802
|
-
` Or command
|
|
685
|
+
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
803
686
|
break;
|
|
804
687
|
case 100:
|
|
805
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent
|
|
688
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
689
|
+
break;
|
|
690
|
+
case 200:
|
|
691
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
806
692
|
break;
|
|
807
693
|
default:
|
|
808
|
-
this.
|
|
694
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
|
|
695
|
+
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
809
696
|
}
|
|
810
697
|
}
|
|
811
698
|
async offlineOff() {
|
|
@@ -932,7 +819,7 @@ class Humidifier {
|
|
|
932
819
|
config['offline'] = device.offline;
|
|
933
820
|
}
|
|
934
821
|
if (Object.entries(config).length !== 0) {
|
|
935
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${
|
|
822
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
936
823
|
}
|
|
937
824
|
}
|
|
938
825
|
async logs(device) {
|