@switchbot/homebridge-switchbot 1.15.1-beta.8 → 2.0.0-beta.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/.github/Old Releaser.zip +0 -0
- package/.github/npm-version-script.js +81 -0
- package/.github/workflows/beta-release.yml +31 -0
- package/.github/workflows/build.yml +18 -0
- package/.github/workflows/codeql-analysis.yml +5 -63
- package/.github/workflows/label.yml +2 -2
- package/.github/workflows/release-drafter.yml +14 -0
- package/.github/workflows/release.yml +24 -0
- package/.github/workflows/stale.yml +6 -22
- package/README.md +10 -3
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +33 -29
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +129 -97
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +1 -1
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +34 -26
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +88 -92
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +29 -25
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +1 -1
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +1 -1
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.js +1 -1
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +31 -27
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +81 -72
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -2
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +35 -32
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -2
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +35 -32
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -2
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +28 -26
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -2
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +47 -45
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -2
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +40 -38
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -2
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +28 -26
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -2
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -80
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -2
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +24 -22
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -2
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +28 -26
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +0 -5
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +79 -79
- package/src/device/bot.ts +34 -39
- package/src/device/colorbulb.ts +130 -119
- package/src/device/contact.ts +1 -1
- package/src/device/curtain.ts +35 -35
- package/src/device/humidifier.ts +89 -118
- package/src/device/lock.ts +29 -34
- package/src/device/meter.ts +1 -1
- package/src/device/meterplus.ts +1 -1
- package/src/device/motion.ts +1 -1
- package/src/device/plug.ts +32 -36
- package/src/device/striplight.ts +82 -98
- package/src/irdevice/airconditioner.ts +36 -41
- package/src/irdevice/airpurifier.ts +36 -43
- package/src/irdevice/camera.ts +29 -34
- package/src/irdevice/fan.ts +48 -53
- package/src/irdevice/light.ts +41 -46
- package/src/irdevice/other.ts +29 -34
- package/src/irdevice/tv.ts +83 -88
- package/src/irdevice/vacuumcleaner.ts +25 -30
- package/src/irdevice/waterheater.ts +29 -34
- package/src/settings.ts +0 -19
- package/.github/workflows/nodejs-beta.yml +0 -42
- package/.github/workflows/nodejs.yml +0 -47
- package/.github/workflows/prerelease-beta.js +0 -34
package/src/device/striplight.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
6
6
|
import { SwitchBotPlatform } from '../platform';
|
|
7
7
|
import { debounceTime, skipWhile, tap } from 'rxjs/operators';
|
|
8
8
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
9
|
-
import { device, devicesConfig, switchbot,
|
|
9
|
+
import { device, devicesConfig, switchbot, hs2rgb, rgb2hs, deviceStatus, HostDomain, DevicePath } from '../settings';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Platform Accessory
|
|
@@ -280,59 +280,54 @@ export class StripLight {
|
|
|
280
280
|
async pushChanges(): Promise<void> {
|
|
281
281
|
try {
|
|
282
282
|
if (this.On !== this.OnCached) {
|
|
283
|
-
// Push On
|
|
284
|
-
const payload = {
|
|
285
|
-
commandType: 'command',
|
|
286
|
-
parameter: 'default',
|
|
287
|
-
} as payload;
|
|
288
|
-
|
|
289
|
-
if (this.On) {
|
|
290
|
-
payload.command = 'turnOn';
|
|
291
|
-
} else {
|
|
292
|
-
payload.command = 'turnOff';
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
this.infoLog(
|
|
296
|
-
`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
297
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
// Make the API request
|
|
283
|
+
// Make Push On request to the API
|
|
301
284
|
const t = Date.now();
|
|
302
285
|
const nonce = 'requestID';
|
|
303
286
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
304
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
287
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
288
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
289
|
+
.digest();
|
|
305
290
|
const sign = signTerm.toString('base64');
|
|
306
291
|
this.debugLog(`Strip Light: ${this.accessory.displayName} sign: ${sign}`);
|
|
292
|
+
|
|
293
|
+
let command = '';
|
|
294
|
+
if (this.On) {
|
|
295
|
+
command = 'turnOn';
|
|
296
|
+
} else {
|
|
297
|
+
command = 'turnOff';
|
|
298
|
+
}
|
|
299
|
+
const body = JSON.stringify({
|
|
300
|
+
'command': `${command}`,
|
|
301
|
+
'parameter': 'default',
|
|
302
|
+
'commandType': 'command',
|
|
303
|
+
});
|
|
304
|
+
this.infoLog(`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
307
305
|
const options = {
|
|
308
|
-
hostname:
|
|
306
|
+
hostname: HostDomain,
|
|
309
307
|
port: 443,
|
|
310
|
-
path:
|
|
308
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
311
309
|
method: 'POST',
|
|
312
310
|
headers: {
|
|
313
|
-
Authorization: this.platform.config.credentials?.token,
|
|
314
|
-
sign: sign,
|
|
315
|
-
nonce: nonce,
|
|
316
|
-
t: t,
|
|
311
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
312
|
+
'sign': sign,
|
|
313
|
+
'nonce': nonce,
|
|
314
|
+
't': t,
|
|
317
315
|
'Content-Type': 'application/json',
|
|
316
|
+
'Content-Length': body.length,
|
|
318
317
|
},
|
|
319
318
|
};
|
|
320
|
-
|
|
321
|
-
const req = https.request(options, (res) => {
|
|
319
|
+
const req = https.request(options, res => {
|
|
322
320
|
this.debugLog(`Strip Light: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
323
321
|
this.statusCode({ res });
|
|
324
|
-
res.on('data',
|
|
322
|
+
res.on('data', d => {
|
|
325
323
|
this.debugLog(`Strip Light: ${this.accessory.displayName} d: ${d}`);
|
|
326
324
|
});
|
|
327
325
|
});
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} error: ${error}`);
|
|
326
|
+
req.on('error', (e: any) => {
|
|
327
|
+
this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
|
|
331
328
|
});
|
|
332
|
-
|
|
333
|
-
req.write(payload);
|
|
329
|
+
req.write(body);
|
|
334
330
|
req.end();
|
|
335
|
-
|
|
336
331
|
this.debugLog(`Strip Light: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
337
332
|
this.OnCached = this.On;
|
|
338
333
|
this.accessory.context.On = this.OnCached;
|
|
@@ -365,55 +360,48 @@ export class StripLight {
|
|
|
365
360
|
|
|
366
361
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
367
362
|
this.debugLog(`Strip Light: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
368
|
-
|
|
369
|
-
const payload = {
|
|
370
|
-
commandType: 'command',
|
|
371
|
-
command: 'setColor',
|
|
372
|
-
parameter: `${red}:${green}:${blue}`,
|
|
373
|
-
} as payload;
|
|
374
|
-
|
|
375
|
-
this.infoLog(
|
|
376
|
-
`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
377
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
// Make the API request
|
|
363
|
+
// Make Push On request to the API
|
|
381
364
|
const t = Date.now();
|
|
382
365
|
const nonce = 'requestID';
|
|
383
366
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
384
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
367
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
368
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
369
|
+
.digest();
|
|
385
370
|
const sign = signTerm.toString('base64');
|
|
386
371
|
this.debugLog(`Strip Light: ${this.accessory.displayName} sign: ${sign}`);
|
|
372
|
+
const body = JSON.stringify({
|
|
373
|
+
'command': 'setColor',
|
|
374
|
+
'parameter': `${red}:${green}:${blue}`,
|
|
375
|
+
'commandType': 'command',
|
|
376
|
+
});
|
|
377
|
+
this.infoLog(`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
387
378
|
const options = {
|
|
388
|
-
hostname:
|
|
379
|
+
hostname: HostDomain,
|
|
389
380
|
port: 443,
|
|
390
|
-
path:
|
|
381
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
391
382
|
method: 'POST',
|
|
392
383
|
headers: {
|
|
393
|
-
Authorization: this.platform.config.credentials?.token,
|
|
394
|
-
sign: sign,
|
|
395
|
-
nonce: nonce,
|
|
396
|
-
t: t,
|
|
384
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
385
|
+
'sign': sign,
|
|
386
|
+
'nonce': nonce,
|
|
387
|
+
't': t,
|
|
397
388
|
'Content-Type': 'application/json',
|
|
389
|
+
'Content-Length': body.length,
|
|
398
390
|
},
|
|
399
391
|
};
|
|
400
|
-
|
|
401
|
-
const req = https.request(options, (res) => {
|
|
392
|
+
const req = https.request(options, res => {
|
|
402
393
|
this.debugLog(`Strip Light: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
403
394
|
this.statusCode({ res });
|
|
404
|
-
res.on('data',
|
|
395
|
+
res.on('data', d => {
|
|
405
396
|
this.debugLog(`Strip Light: ${this.accessory.displayName} d: ${d}`);
|
|
406
397
|
});
|
|
407
398
|
});
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} error: ${error}`);
|
|
399
|
+
req.on('error', (e: any) => {
|
|
400
|
+
this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
|
|
411
401
|
});
|
|
412
|
-
|
|
413
|
-
req.write(payload);
|
|
402
|
+
req.write(body);
|
|
414
403
|
req.end();
|
|
415
|
-
|
|
416
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
404
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} pushHueSaturationChanges: ${JSON.stringify(req)}`);
|
|
417
405
|
this.HueCached = this.Hue;
|
|
418
406
|
this.SaturationCached = this.Saturation;
|
|
419
407
|
} else {
|
|
@@ -423,10 +411,11 @@ export class StripLight {
|
|
|
423
411
|
);
|
|
424
412
|
}
|
|
425
413
|
} catch (e: any) {
|
|
426
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed
|
|
414
|
+
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushHueSaturationChanges with OpenAPI Connection`);
|
|
427
415
|
if (this.deviceLogging.includes('debug')) {
|
|
428
416
|
this.errorLog(
|
|
429
|
-
`Strip Light: ${this.accessory.displayName} failed
|
|
417
|
+
`Strip Light: ${this.accessory.displayName} failed pushHueSaturationChanges with OpenAPI Connection,`
|
|
418
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`,
|
|
430
419
|
);
|
|
431
420
|
}
|
|
432
421
|
this.apiError(e);
|
|
@@ -436,54 +425,48 @@ export class StripLight {
|
|
|
436
425
|
async pushBrightnessChanges(): Promise<void> {
|
|
437
426
|
try {
|
|
438
427
|
if (this.Brightness !== this.BrightnessCached) {
|
|
439
|
-
|
|
440
|
-
commandType: 'command',
|
|
441
|
-
command: 'setBrightness',
|
|
442
|
-
parameter: `${this.Brightness}`,
|
|
443
|
-
} as payload;
|
|
444
|
-
|
|
445
|
-
this.infoLog(
|
|
446
|
-
`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
447
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
448
|
-
);
|
|
449
|
-
|
|
450
|
-
// Make the API request
|
|
428
|
+
// Make Push On request to the API
|
|
451
429
|
const t = Date.now();
|
|
452
430
|
const nonce = 'requestID';
|
|
453
431
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
454
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
432
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
433
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
434
|
+
.digest();
|
|
455
435
|
const sign = signTerm.toString('base64');
|
|
456
436
|
this.debugLog(`Strip Light: ${this.accessory.displayName} sign: ${sign}`);
|
|
437
|
+
const body = JSON.stringify({
|
|
438
|
+
'command': 'setBrightness',
|
|
439
|
+
'parameter': `${this.Brightness}`,
|
|
440
|
+
'commandType': 'command',
|
|
441
|
+
});
|
|
442
|
+
this.infoLog(`Strip Light: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
457
443
|
const options = {
|
|
458
|
-
hostname:
|
|
444
|
+
hostname: HostDomain,
|
|
459
445
|
port: 443,
|
|
460
|
-
path:
|
|
446
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
461
447
|
method: 'POST',
|
|
462
448
|
headers: {
|
|
463
|
-
Authorization: this.platform.config.credentials?.token,
|
|
464
|
-
sign: sign,
|
|
465
|
-
nonce: nonce,
|
|
466
|
-
t: t,
|
|
449
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
450
|
+
'sign': sign,
|
|
451
|
+
'nonce': nonce,
|
|
452
|
+
't': t,
|
|
467
453
|
'Content-Type': 'application/json',
|
|
454
|
+
'Content-Length': body.length,
|
|
468
455
|
},
|
|
469
456
|
};
|
|
470
|
-
|
|
471
|
-
const req = https.request(options, (res) => {
|
|
457
|
+
const req = https.request(options, res => {
|
|
472
458
|
this.debugLog(`Strip Light: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
473
459
|
this.statusCode({ res });
|
|
474
|
-
res.on('data',
|
|
460
|
+
res.on('data', d => {
|
|
475
461
|
this.debugLog(`Strip Light: ${this.accessory.displayName} d: ${d}`);
|
|
476
462
|
});
|
|
477
463
|
});
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} error: ${error}`);
|
|
464
|
+
req.on('error', (e: any) => {
|
|
465
|
+
this.errorLog(`Strip Light: ${this.accessory.displayName} error message: ${e.message}`);
|
|
481
466
|
});
|
|
482
|
-
|
|
483
|
-
req.write(payload);
|
|
467
|
+
req.write(body);
|
|
484
468
|
req.end();
|
|
485
|
-
|
|
486
|
-
this.debugLog(`Strip Light: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
469
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} pushBrightnessChanges: ${JSON.stringify(req)}`);
|
|
487
470
|
this.BrightnessCached = this.Brightness;
|
|
488
471
|
} else {
|
|
489
472
|
this.debugLog(
|
|
@@ -491,10 +474,11 @@ export class StripLight {
|
|
|
491
474
|
);
|
|
492
475
|
}
|
|
493
476
|
} catch (e: any) {
|
|
494
|
-
this.errorLog(`Strip Light: ${this.accessory.displayName} failed
|
|
477
|
+
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushBrightnessChanges with OpenAPI Connection`);
|
|
495
478
|
if (this.deviceLogging.includes('debug')) {
|
|
496
479
|
this.errorLog(
|
|
497
|
-
`Strip Light: ${this.accessory.displayName} failed
|
|
480
|
+
`Strip Light: ${this.accessory.displayName} failed pushBrightnessChanges with OpenAPI Connection,`
|
|
481
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`,
|
|
498
482
|
);
|
|
499
483
|
}
|
|
500
484
|
this.apiError(e);
|
|
@@ -2,7 +2,7 @@ import https from 'https';
|
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
|
-
import { irDevicesConfig, irdevice,
|
|
5
|
+
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
6
6
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -183,22 +183,22 @@ export class AirConditioner {
|
|
|
183
183
|
*/
|
|
184
184
|
async pushAirConditionerOnChanges(): Promise<void> {
|
|
185
185
|
if (this.Active !== this.platform.Characteristic.Active.ACTIVE || this.pushOn) {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
parameter: 'default',
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
await this.pushChanges(
|
|
186
|
+
const body = JSON.stringify({
|
|
187
|
+
'command': 'turnOn',
|
|
188
|
+
'parameter': 'default',
|
|
189
|
+
'commandType': 'command',
|
|
190
|
+
});
|
|
191
|
+
await this.pushChanges(body);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
async pushAirConditionerOffChanges(): Promise<void> {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
parameter: 'default',
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
await this.pushChanges(
|
|
196
|
+
const body = JSON.stringify({
|
|
197
|
+
'command': 'turnOff',
|
|
198
|
+
'parameter': 'default',
|
|
199
|
+
'commandType': 'command',
|
|
200
|
+
});
|
|
201
|
+
await this.pushChanges(body);
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
async pushAirConditionerStatusChanges(): Promise<void> {
|
|
@@ -213,11 +213,6 @@ export class AirConditioner {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
async pushAirConditionerDetailsChanges(): Promise<void> {
|
|
216
|
-
const payload = {
|
|
217
|
-
commandType: 'command',
|
|
218
|
-
command: 'setAll',
|
|
219
|
-
} as any;
|
|
220
|
-
|
|
221
216
|
this.CurrentTemperatureUndefined();
|
|
222
217
|
if (this.CurrentMode === undefined) {
|
|
223
218
|
this.CurrentMode = 1;
|
|
@@ -236,7 +231,7 @@ export class AirConditioner {
|
|
|
236
231
|
`Air Conditioner: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},` + ` CurrentTemperature: ${this.CurrentTemperature}`,
|
|
237
232
|
);
|
|
238
233
|
}
|
|
239
|
-
|
|
234
|
+
const parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
|
|
240
235
|
|
|
241
236
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
242
237
|
this.CurrentTemperatureUndefined();
|
|
@@ -248,53 +243,53 @@ export class AirConditioner {
|
|
|
248
243
|
} else {
|
|
249
244
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
250
245
|
}
|
|
246
|
+
const body = JSON.stringify({
|
|
247
|
+
'command': 'setAll',
|
|
248
|
+
'parameter': `${parameter}`,
|
|
249
|
+
'commandType': 'command',
|
|
250
|
+
});
|
|
251
251
|
|
|
252
|
-
await this.pushChanges(
|
|
252
|
+
await this.pushChanges(body);
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
async pushChanges(
|
|
255
|
+
async pushChanges(body): Promise<void> {
|
|
256
256
|
try {
|
|
257
|
-
|
|
258
|
-
`Air Conditioner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
259
|
-
` parameter: [${payload.parameter}], commandType: ${payload.commandType}`,
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
// Make the API request
|
|
257
|
+
// Make Push On request to the API
|
|
263
258
|
const t = Date.now();
|
|
264
259
|
const nonce = 'requestID';
|
|
265
260
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
266
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
261
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
262
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
263
|
+
.digest();
|
|
267
264
|
const sign = signTerm.toString('base64');
|
|
268
265
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} sign: ${sign}`);
|
|
266
|
+
this.infoLog(`Air Conditioner: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
269
267
|
const options = {
|
|
270
268
|
hostname: HostDomain,
|
|
271
269
|
port: 443,
|
|
272
270
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
273
271
|
method: 'POST',
|
|
274
272
|
headers: {
|
|
275
|
-
Authorization: this.platform.config.credentials?.token,
|
|
276
|
-
sign: sign,
|
|
277
|
-
nonce: nonce,
|
|
278
|
-
t: t,
|
|
273
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
274
|
+
'sign': sign,
|
|
275
|
+
'nonce': nonce,
|
|
276
|
+
't': t,
|
|
279
277
|
'Content-Type': 'application/json',
|
|
278
|
+
'Content-Length': body.length,
|
|
280
279
|
},
|
|
281
280
|
};
|
|
282
|
-
|
|
283
|
-
const req = https.request(options, (res) => {
|
|
281
|
+
const req = https.request(options, res => {
|
|
284
282
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
285
283
|
this.statusCode({ res });
|
|
286
|
-
res.on('data',
|
|
284
|
+
res.on('data', d => {
|
|
287
285
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} d: ${d}`);
|
|
288
286
|
});
|
|
289
287
|
});
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
this.errorLog(`Air Conditioner: ${this.accessory.displayName} error: ${error}`);
|
|
288
|
+
req.on('error', (e: any) => {
|
|
289
|
+
this.errorLog(`Air Conditioner: ${this.accessory.displayName} error message: ${e.message}`);
|
|
293
290
|
});
|
|
294
|
-
|
|
295
|
-
req.write(payload);
|
|
291
|
+
req.write(body);
|
|
296
292
|
req.end();
|
|
297
|
-
|
|
298
293
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
299
294
|
this.CurrentTemperatureCached = this.CurrentTemperature;
|
|
300
295
|
this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
|
|
@@ -2,7 +2,7 @@ import https from 'https';
|
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
|
-
import { irDevicesConfig, irdevice,
|
|
5
|
+
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
6
6
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -158,23 +158,23 @@ export class AirPurifier {
|
|
|
158
158
|
*/
|
|
159
159
|
async pushAirPurifierOnChanges(): Promise<void> {
|
|
160
160
|
if (this.Active !== 1) {
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
parameter: 'default',
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
await this.pushChanges(
|
|
161
|
+
const body = JSON.stringify({
|
|
162
|
+
'command': 'turnOn',
|
|
163
|
+
'parameter': 'default',
|
|
164
|
+
'commandType': 'command',
|
|
165
|
+
});
|
|
166
|
+
await this.pushChanges(body);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
async pushAirPurifierOffChanges(): Promise<void> {
|
|
171
171
|
if (this.Active !== 0) {
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
parameter: 'default',
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
await this.pushChanges(
|
|
172
|
+
const body = JSON.stringify({
|
|
173
|
+
'command': 'turnOff',
|
|
174
|
+
'parameter': 'default',
|
|
175
|
+
'commandType': 'command',
|
|
176
|
+
});
|
|
177
|
+
await this.pushChanges(body);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
@@ -190,17 +190,16 @@ export class AirPurifier {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
async pushAirConditionerDetailsChanges(): Promise<void> {
|
|
193
|
-
const payload = {
|
|
194
|
-
commandType: 'command',
|
|
195
|
-
command: 'setAll',
|
|
196
|
-
} as payload;
|
|
197
|
-
|
|
198
193
|
this.CurrentAPTemp = this.CurrentTemperature || 24;
|
|
199
194
|
this.CurrentAPMode = this.CurrentMode || 1;
|
|
200
195
|
this.CurrentAPFanSpeed = this.CurrentFanSpeed || 1;
|
|
201
196
|
this.APActive = this.Active === 1 ? 'on' : 'off';
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`;
|
|
198
|
+
const body = JSON.stringify({
|
|
199
|
+
'command': 'setAll',
|
|
200
|
+
'parameter': `${parameter}`,
|
|
201
|
+
'commandType': 'command',
|
|
202
|
+
});
|
|
204
203
|
if (this.Active === 1) {
|
|
205
204
|
if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
|
|
206
205
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
@@ -210,53 +209,47 @@ export class AirPurifier {
|
|
|
210
209
|
} else {
|
|
211
210
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
212
211
|
}
|
|
213
|
-
|
|
214
|
-
await this.pushChanges(payload);
|
|
212
|
+
await this.pushChanges(body);
|
|
215
213
|
}
|
|
216
214
|
|
|
217
|
-
async pushChanges(
|
|
215
|
+
async pushChanges(body): Promise<void> {
|
|
218
216
|
try {
|
|
219
|
-
|
|
220
|
-
`Air Purifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
221
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
// Make the API request
|
|
217
|
+
// Make Push On request to the API
|
|
225
218
|
const t = Date.now();
|
|
226
219
|
const nonce = 'requestID';
|
|
227
220
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
228
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
221
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
222
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
223
|
+
.digest();
|
|
229
224
|
const sign = signTerm.toString('base64');
|
|
230
225
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} sign: ${sign}`);
|
|
226
|
+
this.infoLog(`Air Purifier: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
231
227
|
const options = {
|
|
232
228
|
hostname: HostDomain,
|
|
233
229
|
port: 443,
|
|
234
230
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
235
231
|
method: 'POST',
|
|
236
232
|
headers: {
|
|
237
|
-
Authorization: this.platform.config.credentials?.token,
|
|
238
|
-
sign: sign,
|
|
239
|
-
nonce: nonce,
|
|
240
|
-
t: t,
|
|
233
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
234
|
+
'sign': sign,
|
|
235
|
+
'nonce': nonce,
|
|
236
|
+
't': t,
|
|
241
237
|
'Content-Type': 'application/json',
|
|
238
|
+
'Content-Length': body.length,
|
|
242
239
|
},
|
|
243
240
|
};
|
|
244
|
-
|
|
245
|
-
const req = https.request(options, (res) => {
|
|
241
|
+
const req = https.request(options, res => {
|
|
246
242
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
247
243
|
this.statusCode({ res });
|
|
248
|
-
res.on('data',
|
|
244
|
+
res.on('data', d => {
|
|
249
245
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} d: ${d}`);
|
|
250
246
|
});
|
|
251
247
|
});
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
this.errorLog(`Air Purifier: ${this.accessory.displayName} error: ${error}`);
|
|
248
|
+
req.on('error', (e: any) => {
|
|
249
|
+
this.errorLog(`Air Purifier: ${this.accessory.displayName} error message: ${e.message}`);
|
|
255
250
|
});
|
|
256
|
-
|
|
257
|
-
req.write(payload);
|
|
251
|
+
req.write(body);
|
|
258
252
|
req.end();
|
|
259
|
-
|
|
260
253
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
261
254
|
this.updateHomeKitCharacteristics();
|
|
262
255
|
this.CurrentTemperatureCached = this.CurrentTemperature;
|
package/src/irdevice/camera.ts
CHANGED
|
@@ -2,7 +2,7 @@ import https from 'https';
|
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
|
-
import { irDevicesConfig, irdevice,
|
|
5
|
+
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
6
6
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -86,69 +86,64 @@ export class Camera {
|
|
|
86
86
|
*/
|
|
87
87
|
async pushOnChanges(): Promise<void> {
|
|
88
88
|
if (this.On) {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
parameter: 'default',
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
await this.pushChanges(
|
|
89
|
+
const body = JSON.stringify({
|
|
90
|
+
'command': 'turnOn',
|
|
91
|
+
'parameter': 'default',
|
|
92
|
+
'commandType': 'command',
|
|
93
|
+
});
|
|
94
|
+
await this.pushChanges(body);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
async pushOffChanges(): Promise<void> {
|
|
99
99
|
if (!this.On) {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
parameter: 'default',
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
await this.pushChanges(
|
|
100
|
+
const body = JSON.stringify({
|
|
101
|
+
'command': 'turnOff',
|
|
102
|
+
'parameter': 'default',
|
|
103
|
+
'commandType': 'command',
|
|
104
|
+
});
|
|
105
|
+
await this.pushChanges(body);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
async pushChanges(
|
|
109
|
+
async pushChanges(body): Promise<void> {
|
|
110
110
|
try {
|
|
111
|
-
|
|
112
|
-
`Camera: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
113
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
// Make the API request
|
|
111
|
+
// Make Push On request to the API
|
|
117
112
|
const t = Date.now();
|
|
118
113
|
const nonce = 'requestID';
|
|
119
114
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
120
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
115
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
116
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
117
|
+
.digest();
|
|
121
118
|
const sign = signTerm.toString('base64');
|
|
122
119
|
this.debugLog(`Camera: ${this.accessory.displayName} sign: ${sign}`);
|
|
120
|
+
this.infoLog(`Camera: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
123
121
|
const options = {
|
|
124
122
|
hostname: HostDomain,
|
|
125
123
|
port: 443,
|
|
126
124
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
127
125
|
method: 'POST',
|
|
128
126
|
headers: {
|
|
129
|
-
Authorization: this.platform.config.credentials?.token,
|
|
130
|
-
sign: sign,
|
|
131
|
-
nonce: nonce,
|
|
132
|
-
t: t,
|
|
127
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
128
|
+
'sign': sign,
|
|
129
|
+
'nonce': nonce,
|
|
130
|
+
't': t,
|
|
133
131
|
'Content-Type': 'application/json',
|
|
132
|
+
'Content-Length': body.length,
|
|
134
133
|
},
|
|
135
134
|
};
|
|
136
|
-
|
|
137
|
-
const req = https.request(options, (res) => {
|
|
135
|
+
const req = https.request(options, res => {
|
|
138
136
|
this.debugLog(`Camera: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
139
137
|
this.statusCode({ res });
|
|
140
|
-
res.on('data',
|
|
138
|
+
res.on('data', d => {
|
|
141
139
|
this.debugLog(`Camera: ${this.accessory.displayName} d: ${d}`);
|
|
142
140
|
});
|
|
143
141
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.errorLog(`Camera: ${this.accessory.displayName} error: ${error}`);
|
|
142
|
+
req.on('error', (e: any) => {
|
|
143
|
+
this.errorLog(`Camera: ${this.accessory.displayName} error message: ${e.message}`);
|
|
147
144
|
});
|
|
148
|
-
|
|
149
|
-
req.write(payload);
|
|
145
|
+
req.write(body);
|
|
150
146
|
req.end();
|
|
151
|
-
|
|
152
147
|
this.debugLog(`Camera: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
153
148
|
this.updateHomeKitCharacteristics();
|
|
154
149
|
this.OnCached = this.On;
|