@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
package/src/device/humidifier.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import https from 'https';
|
|
2
|
-
import crypto from 'crypto';
|
|
3
1
|
import { Context } from 'vm';
|
|
4
|
-
import {
|
|
2
|
+
import { request } from 'undici';
|
|
3
|
+
import { sleep } from '../utils';
|
|
5
4
|
import { interval, Subject } from 'rxjs';
|
|
6
|
-
import superStringify from 'super-stringify';
|
|
7
5
|
import { SwitchBotPlatform } from '../platform';
|
|
8
6
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
9
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
10
|
-
import { device, devicesConfig, serviceData, ad, deviceStatus,
|
|
11
|
-
import { sleep } from '../utils';
|
|
8
|
+
import { device, devicesConfig, serviceData, ad, deviceStatus, Devices } from '../settings';
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
11
|
* Platform Accessory
|
|
@@ -188,7 +185,7 @@ export class Humidifier {
|
|
|
188
185
|
} catch (e: any) {
|
|
189
186
|
this.apiError(e);
|
|
190
187
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
191
|
-
|
|
188
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
192
189
|
}
|
|
193
190
|
this.humidifierUpdateInProgress = false;
|
|
194
191
|
});
|
|
@@ -207,7 +204,7 @@ export class Humidifier {
|
|
|
207
204
|
} else {
|
|
208
205
|
await this.offlineOff();
|
|
209
206
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
210
|
-
|
|
207
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
211
208
|
}
|
|
212
209
|
}
|
|
213
210
|
|
|
@@ -261,7 +258,7 @@ export class Humidifier {
|
|
|
261
258
|
+ ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
262
259
|
this.debugLog(
|
|
263
260
|
`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
264
|
-
|
|
261
|
+
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
|
|
265
262
|
);
|
|
266
263
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
267
264
|
+ ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
@@ -297,7 +294,7 @@ export class Humidifier {
|
|
|
297
294
|
} else {
|
|
298
295
|
await this.offlineOff();
|
|
299
296
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
300
|
-
|
|
297
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
301
298
|
}
|
|
302
299
|
}
|
|
303
300
|
|
|
@@ -323,15 +320,15 @@ export class Humidifier {
|
|
|
323
320
|
switchbot.onadvertisement = async (ad: ad) => {
|
|
324
321
|
this.address = ad.address;
|
|
325
322
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
326
|
-
|
|
323
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
327
324
|
this.serviceData = ad.serviceData;
|
|
328
325
|
this.autoMode = ad.serviceData.autoMode;
|
|
329
326
|
this.onState = ad.serviceData.onState;
|
|
330
327
|
this.percentage = ad.serviceData.percentage;
|
|
331
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
328
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
332
329
|
this.debugLog(
|
|
333
330
|
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
|
|
334
|
-
|
|
331
|
+
`autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
|
|
335
332
|
);
|
|
336
333
|
|
|
337
334
|
if (this.serviceData) {
|
|
@@ -353,7 +350,7 @@ export class Humidifier {
|
|
|
353
350
|
.catch(async (e: any) => {
|
|
354
351
|
this.apiError(e);
|
|
355
352
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
356
|
-
|
|
353
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
357
354
|
await this.BLERefreshConnection(switchbot);
|
|
358
355
|
});
|
|
359
356
|
} else {
|
|
@@ -364,57 +361,29 @@ export class Humidifier {
|
|
|
364
361
|
async openAPIRefreshStatus(): Promise<void> {
|
|
365
362
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
366
363
|
try {
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
370
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
371
|
-
const sign = signTerm.toString('base64');
|
|
372
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
373
|
-
const options = {
|
|
374
|
-
hostname: HostDomain,
|
|
375
|
-
port: 443,
|
|
376
|
-
path: `${DevicePath}/${this.device.deviceId}/status`,
|
|
377
|
-
method: 'GET',
|
|
378
|
-
headers: {
|
|
379
|
-
Authorization: this.platform.config.credentials?.token,
|
|
380
|
-
sign: sign,
|
|
381
|
-
nonce: nonce,
|
|
382
|
-
t: t,
|
|
383
|
-
'Content-Type': 'application/json',
|
|
384
|
-
},
|
|
385
|
-
};
|
|
386
|
-
const req = https.request(options, (res) => {
|
|
387
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
388
|
-
let rawData = '';
|
|
389
|
-
res.on('data', (d) => {
|
|
390
|
-
rawData += d;
|
|
391
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
392
|
-
});
|
|
393
|
-
res.on('end', () => {
|
|
394
|
-
try {
|
|
395
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
396
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
397
|
-
this.auto = this.deviceStatus.body.auto;
|
|
398
|
-
this.power = this.deviceStatus.body.power;
|
|
399
|
-
this.lackWater = this.deviceStatus.body.lackWater;
|
|
400
|
-
this.humidity = this.deviceStatus.body.humidity;
|
|
401
|
-
this.temperature = this.deviceStatus.body.temperature;
|
|
402
|
-
this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
|
|
403
|
-
this.openAPIparseStatus();
|
|
404
|
-
this.updateHomeKitCharacteristics();
|
|
405
|
-
} catch (e: any) {
|
|
406
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
req.on('error', (e: any) => {
|
|
411
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
364
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
365
|
+
headers: this.platform.generateHeaders(),
|
|
412
366
|
});
|
|
413
|
-
|
|
367
|
+
const deviceStatus = await body.json();
|
|
368
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
369
|
+
this.statusCode(statusCode);
|
|
370
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
371
|
+
this.debugLog(
|
|
372
|
+
`${this.device.deviceType}: ${this.accessory.displayName
|
|
373
|
+
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
374
|
+
);
|
|
375
|
+
this.auto = deviceStatus.body.auto;
|
|
376
|
+
this.power = deviceStatus.body.power;
|
|
377
|
+
this.lackWater = deviceStatus.body.lackWater;
|
|
378
|
+
this.humidity = deviceStatus.body.humidity;
|
|
379
|
+
this.temperature = deviceStatus.body.temperature;
|
|
380
|
+
this.nebulizationEfficiency = deviceStatus.body.nebulizationEfficiency;
|
|
381
|
+
this.openAPIparseStatus();
|
|
382
|
+
this.updateHomeKitCharacteristics();
|
|
414
383
|
} catch (e: any) {
|
|
415
384
|
this.apiError(e);
|
|
416
385
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
417
|
-
|
|
386
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
418
387
|
}
|
|
419
388
|
}
|
|
420
389
|
|
|
@@ -431,7 +400,7 @@ export class Humidifier {
|
|
|
431
400
|
} else {
|
|
432
401
|
await this.offlineOff();
|
|
433
402
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
434
|
-
|
|
403
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
435
404
|
}
|
|
436
405
|
interval(5000)
|
|
437
406
|
.pipe(take(1))
|
|
@@ -465,71 +434,44 @@ export class Humidifier {
|
|
|
465
434
|
.catch(async (e: any) => {
|
|
466
435
|
this.apiError(e);
|
|
467
436
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
468
|
-
|
|
437
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
469
438
|
await this.BLEPushConnection();
|
|
470
439
|
});
|
|
471
440
|
}
|
|
472
441
|
|
|
473
442
|
async openAPIpushChanges(): Promise<void> {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
const
|
|
486
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
487
|
-
this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
488
|
-
const body = superStringify({
|
|
489
|
-
'command': 'setMode',
|
|
490
|
-
'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
|
|
491
|
-
'commandType': 'command',
|
|
492
|
-
});
|
|
493
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
494
|
-
const options = {
|
|
495
|
-
hostname: HostDomain,
|
|
496
|
-
port: 443,
|
|
497
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
443
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
444
|
+
if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
|
|
445
|
+
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
446
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
|
|
447
|
+
const body = JSON.stringify({
|
|
448
|
+
'command': 'setMode',
|
|
449
|
+
'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
|
|
450
|
+
'commandType': 'command',
|
|
451
|
+
});
|
|
452
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
453
|
+
try {
|
|
454
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
498
455
|
method: 'POST',
|
|
499
|
-
headers:
|
|
500
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
501
|
-
'sign': sign,
|
|
502
|
-
'nonce': nonce,
|
|
503
|
-
't': t,
|
|
504
|
-
'Content-Type': 'application/json',
|
|
505
|
-
'Content-Length': body.length,
|
|
506
|
-
},
|
|
507
|
-
};
|
|
508
|
-
const req = https.request(options, res => {
|
|
509
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
510
|
-
res.on('data', d => {
|
|
511
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
req.on('error', (e: any) => {
|
|
515
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
516
|
-
this.apiError(e);
|
|
456
|
+
headers: this.platform.generateHeaders(),
|
|
517
457
|
});
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
this.
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
this.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
await this.pushActiveChanges();
|
|
458
|
+
const deviceStatus = await body.json();
|
|
459
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
460
|
+
this.statusCode(statusCode);
|
|
461
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
462
|
+
} catch (e: any) {
|
|
463
|
+
this.apiError(e);
|
|
464
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
465
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
466
|
+
);
|
|
528
467
|
}
|
|
529
|
-
}
|
|
530
|
-
this.
|
|
531
|
-
this.
|
|
532
|
-
|
|
468
|
+
} else if (
|
|
469
|
+
this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
470
|
+
this.Active === this.platform.Characteristic.Active.ACTIVE
|
|
471
|
+
) {
|
|
472
|
+
await this.pushAutoChanges();
|
|
473
|
+
} else {
|
|
474
|
+
await this.pushActiveChanges();
|
|
533
475
|
}
|
|
534
476
|
}
|
|
535
477
|
|
|
@@ -537,63 +479,34 @@ export class Humidifier {
|
|
|
537
479
|
* Pushes the requested changes to the SwitchBot API
|
|
538
480
|
*/
|
|
539
481
|
async pushAutoChanges(): Promise<void> {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
.digest();
|
|
553
|
-
const sign = signTerm.toString('base64');
|
|
554
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
555
|
-
this.debugLog('Pushing Auto!');
|
|
556
|
-
const body = superStringify({
|
|
557
|
-
'command': 'setMode',
|
|
558
|
-
'parameter': 'auto',
|
|
559
|
-
'commandType': 'command',
|
|
560
|
-
});
|
|
561
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
562
|
-
const options = {
|
|
563
|
-
hostname: HostDomain,
|
|
564
|
-
port: 443,
|
|
565
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
482
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
|
|
483
|
+
if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
|
|
484
|
+
this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
485
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Auto`);
|
|
486
|
+
const body = JSON.stringify({
|
|
487
|
+
'command': 'setMode',
|
|
488
|
+
'parameter': 'auto',
|
|
489
|
+
'commandType': 'command',
|
|
490
|
+
});
|
|
491
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
492
|
+
try {
|
|
493
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
566
494
|
method: 'POST',
|
|
567
|
-
headers:
|
|
568
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
569
|
-
'sign': sign,
|
|
570
|
-
'nonce': nonce,
|
|
571
|
-
't': t,
|
|
572
|
-
'Content-Type': 'application/json',
|
|
573
|
-
'Content-Length': body.length,
|
|
574
|
-
},
|
|
575
|
-
};
|
|
576
|
-
const req = https.request(options, res => {
|
|
577
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
578
|
-
this.statusCode({ res });
|
|
579
|
-
res.on('data', d => {
|
|
580
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
581
|
-
});
|
|
495
|
+
headers: this.platform.generateHeaders(),
|
|
582
496
|
});
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
this.
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
497
|
+
const deviceStatus = await body.json();
|
|
498
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
499
|
+
this.statusCode(statusCode);
|
|
500
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
501
|
+
} catch (e: any) {
|
|
502
|
+
this.apiError(e);
|
|
503
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}`
|
|
504
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
505
|
+
);
|
|
592
506
|
}
|
|
593
|
-
}
|
|
594
|
-
this.
|
|
595
|
-
|
|
596
|
-
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
507
|
+
} else {
|
|
508
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges.` +
|
|
509
|
+
`TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`);
|
|
597
510
|
}
|
|
598
511
|
}
|
|
599
512
|
|
|
@@ -601,58 +514,32 @@ export class Humidifier {
|
|
|
601
514
|
* Pushes the requested changes to the SwitchBot API
|
|
602
515
|
*/
|
|
603
516
|
async pushActiveChanges(): Promise<void> {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
const
|
|
615
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
616
|
-
this.debugLog('Pushing Off!');
|
|
617
|
-
const body = superStringify({
|
|
618
|
-
'command': 'turnOff',
|
|
619
|
-
'parameter': 'default',
|
|
620
|
-
'commandType': 'command',
|
|
621
|
-
});
|
|
622
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
623
|
-
const options = {
|
|
624
|
-
hostname: HostDomain,
|
|
625
|
-
port: 443,
|
|
626
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
517
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
|
|
518
|
+
if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
|
|
519
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing Off`);
|
|
520
|
+
const body = JSON.stringify({
|
|
521
|
+
'command': 'turnOff',
|
|
522
|
+
'parameter': 'default',
|
|
523
|
+
'commandType': 'command',
|
|
524
|
+
});
|
|
525
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
526
|
+
try {
|
|
527
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
627
528
|
method: 'POST',
|
|
628
|
-
headers:
|
|
629
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
630
|
-
'sign': sign,
|
|
631
|
-
'nonce': nonce,
|
|
632
|
-
't': t,
|
|
633
|
-
'Content-Type': 'application/json',
|
|
634
|
-
'Content-Length': body.length,
|
|
635
|
-
},
|
|
636
|
-
};
|
|
637
|
-
const req = https.request(options, res => {
|
|
638
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges statusCode: ${res.statusCode}`);
|
|
639
|
-
this.statusCode({ res });
|
|
640
|
-
res.on('data', d => {
|
|
641
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
642
|
-
});
|
|
643
|
-
});
|
|
644
|
-
req.on('error', (e: any) => {
|
|
645
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
529
|
+
headers: this.platform.generateHeaders(),
|
|
646
530
|
});
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
this.
|
|
531
|
+
const deviceStatus = await body.json();
|
|
532
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
533
|
+
this.statusCode(statusCode);
|
|
534
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
535
|
+
} catch (e: any) {
|
|
536
|
+
this.apiError(e);
|
|
537
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
|
|
538
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
539
|
+
);
|
|
650
540
|
}
|
|
651
|
-
}
|
|
652
|
-
this.
|
|
653
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
|
|
654
|
-
+ ` Connection, Error Message: ${superStringify(e.message)}`,
|
|
655
|
-
);
|
|
541
|
+
} else {
|
|
542
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushActiveChanges. Active: ${this.Active}`);
|
|
656
543
|
}
|
|
657
544
|
}
|
|
658
545
|
|
|
@@ -711,7 +598,7 @@ export class Humidifier {
|
|
|
711
598
|
} else {
|
|
712
599
|
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
713
600
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
714
|
-
|
|
601
|
+
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
715
602
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
716
603
|
}
|
|
717
604
|
if (this.OpenAPI) {
|
|
@@ -725,22 +612,22 @@ export class Humidifier {
|
|
|
725
612
|
}
|
|
726
613
|
if (this.CurrentHumidifierDehumidifierState === undefined) {
|
|
727
614
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
728
|
-
|
|
615
|
+
+ ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
729
616
|
} else {
|
|
730
617
|
this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState,
|
|
731
618
|
this.CurrentHumidifierDehumidifierState);
|
|
732
619
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
733
|
-
|
|
620
|
+
` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
|
|
734
621
|
this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
|
|
735
622
|
}
|
|
736
623
|
if (this.TargetHumidifierDehumidifierState === undefined) {
|
|
737
624
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
738
|
-
|
|
625
|
+
+ ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
739
626
|
} else {
|
|
740
627
|
this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState,
|
|
741
628
|
this.TargetHumidifierDehumidifierState);
|
|
742
629
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
743
|
-
|
|
630
|
+
` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
|
|
744
631
|
this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
|
|
745
632
|
}
|
|
746
633
|
if (this.Active === undefined) {
|
|
@@ -757,7 +644,7 @@ export class Humidifier {
|
|
|
757
644
|
this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
|
|
758
645
|
this.RelativeHumidityHumidifierThreshold);
|
|
759
646
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
|
|
760
|
-
|
|
647
|
+
` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
|
|
761
648
|
this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
|
|
762
649
|
}
|
|
763
650
|
if (!this.device.humidifier?.hide_temperature && !this.BLE) {
|
|
@@ -790,7 +677,7 @@ export class Humidifier {
|
|
|
790
677
|
});
|
|
791
678
|
// Set an event handler
|
|
792
679
|
switchbot.onadvertisement = (ad: any) => {
|
|
793
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${
|
|
680
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
794
681
|
};
|
|
795
682
|
await sleep(10000);
|
|
796
683
|
// Stop to monitor
|
|
@@ -837,36 +724,41 @@ export class Humidifier {
|
|
|
837
724
|
}
|
|
838
725
|
}
|
|
839
726
|
|
|
840
|
-
async statusCode(
|
|
841
|
-
switch (
|
|
727
|
+
async statusCode(statusCode: number): Promise<void> {
|
|
728
|
+
switch (statusCode) {
|
|
842
729
|
case 151:
|
|
843
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this
|
|
730
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
844
731
|
break;
|
|
845
732
|
case 152:
|
|
846
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found
|
|
733
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
847
734
|
break;
|
|
848
735
|
case 160:
|
|
849
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported
|
|
736
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
850
737
|
break;
|
|
851
738
|
case 161:
|
|
852
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline
|
|
853
|
-
|
|
739
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
740
|
+
this.offlineOff();
|
|
854
741
|
break;
|
|
855
742
|
case 171:
|
|
856
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline
|
|
857
|
-
|
|
743
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
|
|
744
|
+
+ `Hub: ${this.device.hubDeviceId}`);
|
|
745
|
+
this.offlineOff();
|
|
858
746
|
break;
|
|
859
747
|
case 190:
|
|
860
748
|
this.errorLog(
|
|
861
749
|
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
862
|
-
|
|
750
|
+
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
863
751
|
);
|
|
864
752
|
break;
|
|
865
753
|
case 100:
|
|
866
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent
|
|
754
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
755
|
+
break;
|
|
756
|
+
case 200:
|
|
757
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
867
758
|
break;
|
|
868
759
|
default:
|
|
869
|
-
this.
|
|
760
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
|
|
761
|
+
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
870
762
|
}
|
|
871
763
|
}
|
|
872
764
|
|
|
@@ -898,7 +790,7 @@ export class Humidifier {
|
|
|
898
790
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
899
791
|
let FirmwareRevision: string;
|
|
900
792
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
901
|
-
|
|
793
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
902
794
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
903
795
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
904
796
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -987,7 +879,7 @@ export class Humidifier {
|
|
|
987
879
|
config['offline'] = device.offline;
|
|
988
880
|
}
|
|
989
881
|
if (Object.entries(config).length !== 0) {
|
|
990
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${
|
|
882
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
991
883
|
}
|
|
992
884
|
}
|
|
993
885
|
|