@switchbot/homebridge-switchbot 1.15.1-beta.8 → 1.15.1-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +32 -28
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +96 -90
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +26 -24
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +87 -91
- 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/plug.d.ts.map +1 -1
- package/dist/device/plug.js +30 -26
- 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.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 +6 -5
- 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.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.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.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.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.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.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.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 +1 -1
- package/src/device/bot.ts +33 -38
- package/src/device/colorbulb.ts +97 -110
- package/src/device/curtain.ts +27 -33
- package/src/device/humidifier.ts +88 -117
- package/src/device/lock.ts +29 -34
- package/src/device/plug.ts +31 -35
- package/src/device/striplight.ts +82 -98
- package/src/irdevice/airconditioner.ts +2 -2
- package/src/irdevice/airpurifier.ts +10 -10
- package/src/irdevice/camera.ts +4 -4
- package/src/irdevice/fan.ts +7 -7
- package/src/irdevice/light.ts +6 -6
- package/src/irdevice/other.ts +4 -4
- package/src/irdevice/tv.ts +13 -13
- package/src/irdevice/vacuumcleaner.ts +4 -4
- package/src/irdevice/waterheater.ts +4 -4
- package/src/settings.ts +0 -19
package/src/device/colorbulb.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, deviceStatus, switchbot,
|
|
9
|
+
import { device, devicesConfig, deviceStatus, switchbot, hs2rgb, rgb2hs, m2hs, serviceData, ad, HostDomain, DevicePath } from '../settings';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Platform Accessory
|
|
@@ -478,68 +478,66 @@ export class ColorBulb {
|
|
|
478
478
|
async pushChanges(): Promise<void> {
|
|
479
479
|
try {
|
|
480
480
|
if (this.On !== this.OnCached) {
|
|
481
|
-
// Push On
|
|
482
|
-
const payload = {
|
|
483
|
-
commandType: 'command',
|
|
484
|
-
parameter: 'default',
|
|
485
|
-
} as payload;
|
|
486
|
-
|
|
487
|
-
if (this.On) {
|
|
488
|
-
payload.command = 'turnOn';
|
|
489
|
-
} else {
|
|
490
|
-
payload.command = 'turnOff';
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
this.infoLog(
|
|
494
|
-
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
495
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
496
|
-
);
|
|
497
|
-
|
|
498
|
-
// Make the API request
|
|
481
|
+
// Make Push On request to the API
|
|
499
482
|
const t = Date.now();
|
|
500
483
|
const nonce = 'requestID';
|
|
501
484
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
502
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
485
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
486
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
487
|
+
.digest();
|
|
503
488
|
const sign = signTerm.toString('base64');
|
|
504
489
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
|
|
490
|
+
|
|
491
|
+
let command = '';
|
|
492
|
+
if (this.On) {
|
|
493
|
+
command = 'turnOn';
|
|
494
|
+
} else {
|
|
495
|
+
command = 'turnOff';
|
|
496
|
+
}
|
|
497
|
+
const body = JSON.stringify({
|
|
498
|
+
'command': `${command}`,
|
|
499
|
+
'parameter': 'default',
|
|
500
|
+
'commandType': 'command',
|
|
501
|
+
});
|
|
502
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
505
503
|
const options = {
|
|
506
504
|
hostname: HostDomain,
|
|
507
505
|
port: 443,
|
|
508
506
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
509
507
|
method: 'POST',
|
|
510
508
|
headers: {
|
|
511
|
-
Authorization: this.platform.config.credentials?.token,
|
|
512
|
-
sign: sign,
|
|
513
|
-
nonce: nonce,
|
|
514
|
-
t: t,
|
|
509
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
510
|
+
'sign': sign,
|
|
511
|
+
'nonce': nonce,
|
|
512
|
+
't': t,
|
|
515
513
|
'Content-Type': 'application/json',
|
|
514
|
+
'Content-Length': body.length,
|
|
516
515
|
},
|
|
517
516
|
};
|
|
518
|
-
const req = https.request(options,
|
|
517
|
+
const req = https.request(options, res => {
|
|
519
518
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
520
519
|
this.statusCode({ res });
|
|
521
|
-
res.on('data',
|
|
522
|
-
this.debugLog(`d: ${d}`);
|
|
520
|
+
res.on('data', d => {
|
|
521
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
|
|
523
522
|
});
|
|
524
523
|
});
|
|
525
|
-
req.on('error', (
|
|
526
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} error: ${
|
|
524
|
+
req.on('error', (e: any) => {
|
|
525
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
|
|
527
526
|
});
|
|
528
|
-
req.write(
|
|
527
|
+
req.write(body);
|
|
529
528
|
req.end();
|
|
530
|
-
|
|
531
529
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(req)}`);
|
|
532
530
|
this.OnCached = this.On;
|
|
533
531
|
this.accessory.context.On = this.OnCached;
|
|
534
532
|
}
|
|
535
533
|
// Push Brightness Update
|
|
536
534
|
if (this.On) {
|
|
537
|
-
await this.pushBrightnessChanges();
|
|
535
|
+
//await this.pushBrightnessChanges();
|
|
538
536
|
}
|
|
539
537
|
|
|
540
538
|
// Push ColorTemperature Update
|
|
541
539
|
if (this.On) {
|
|
542
|
-
await this.pushColorTemperatureChanges();
|
|
540
|
+
//await this.pushColorTemperatureChanges();
|
|
543
541
|
}
|
|
544
542
|
|
|
545
543
|
// Push Hue & Saturation Update
|
|
@@ -566,51 +564,47 @@ export class ColorBulb {
|
|
|
566
564
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
567
565
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
568
566
|
|
|
569
|
-
|
|
570
|
-
commandType: 'command',
|
|
571
|
-
command: 'setColor',
|
|
572
|
-
parameter: `${red}:${green}:${blue}`,
|
|
573
|
-
} as payload;
|
|
574
|
-
|
|
575
|
-
this.infoLog(
|
|
576
|
-
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
577
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
578
|
-
);
|
|
579
|
-
|
|
580
|
-
// Make the API request
|
|
567
|
+
// Make Push Hue/Saturation request to the API
|
|
581
568
|
const t = Date.now();
|
|
582
569
|
const nonce = 'requestID';
|
|
583
570
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
584
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
571
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
572
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
573
|
+
.digest();
|
|
585
574
|
const sign = signTerm.toString('base64');
|
|
586
575
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
|
|
576
|
+
const body = JSON.stringify({
|
|
577
|
+
'command': 'setColor',
|
|
578
|
+
'parameter': `${red}:${green}:${blue}`,
|
|
579
|
+
'commandType': 'command',
|
|
580
|
+
});
|
|
581
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
587
582
|
const options = {
|
|
588
583
|
hostname: HostDomain,
|
|
589
584
|
port: 443,
|
|
590
585
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
591
586
|
method: 'POST',
|
|
592
587
|
headers: {
|
|
593
|
-
Authorization: this.platform.config.credentials?.token,
|
|
594
|
-
sign: sign,
|
|
595
|
-
nonce: nonce,
|
|
596
|
-
t: t,
|
|
588
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
589
|
+
'sign': sign,
|
|
590
|
+
'nonce': nonce,
|
|
591
|
+
't': t,
|
|
597
592
|
'Content-Type': 'application/json',
|
|
593
|
+
'Content-Length': body.length,
|
|
598
594
|
},
|
|
599
595
|
};
|
|
600
|
-
const req = https.request(options,
|
|
596
|
+
const req = https.request(options, res => {
|
|
601
597
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
this.debugLog(`d: ${d}`);
|
|
598
|
+
res.on('data', d => {
|
|
599
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
|
|
605
600
|
});
|
|
606
601
|
});
|
|
607
|
-
req.on('error', (
|
|
608
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} error: ${
|
|
602
|
+
req.on('error', (e: any) => {
|
|
603
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
|
|
609
604
|
});
|
|
610
|
-
req.write(
|
|
605
|
+
req.write(body);
|
|
611
606
|
req.end();
|
|
612
|
-
|
|
613
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(req)}`);
|
|
607
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushHueSaturationChanges: ${JSON.stringify(req)}`);
|
|
614
608
|
this.HueCached = this.Hue;
|
|
615
609
|
this.SaturationCached = this.Saturation;
|
|
616
610
|
} else {
|
|
@@ -636,51 +630,48 @@ export class ColorBulb {
|
|
|
636
630
|
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
637
631
|
this.cacheKelvin = kelvin;
|
|
638
632
|
|
|
639
|
-
|
|
640
|
-
commandType: 'command',
|
|
641
|
-
command: 'setColorTemperature',
|
|
642
|
-
parameter: `${kelvin}`,
|
|
643
|
-
} as payload;
|
|
644
|
-
|
|
645
|
-
this.infoLog(
|
|
646
|
-
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
647
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
648
|
-
);
|
|
649
|
-
|
|
650
|
-
// Make the API request
|
|
633
|
+
// Make Push On request to the API
|
|
651
634
|
const t = Date.now();
|
|
652
635
|
const nonce = 'requestID';
|
|
653
636
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
654
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
637
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
638
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
639
|
+
.digest();
|
|
655
640
|
const sign = signTerm.toString('base64');
|
|
656
641
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
|
|
642
|
+
const body = JSON.stringify({
|
|
643
|
+
'command': 'setColorTemperature',
|
|
644
|
+
'parameter': `${kelvin}`,
|
|
645
|
+
'commandType': 'command',
|
|
646
|
+
});
|
|
647
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
657
648
|
const options = {
|
|
658
649
|
hostname: HostDomain,
|
|
659
650
|
port: 443,
|
|
660
651
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
661
652
|
method: 'POST',
|
|
662
653
|
headers: {
|
|
663
|
-
Authorization: this.platform.config.credentials?.token,
|
|
664
|
-
sign: sign,
|
|
665
|
-
nonce: nonce,
|
|
666
|
-
t: t,
|
|
654
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
655
|
+
'sign': sign,
|
|
656
|
+
'nonce': nonce,
|
|
657
|
+
't': t,
|
|
667
658
|
'Content-Type': 'application/json',
|
|
659
|
+
'Content-Length': body.length,
|
|
668
660
|
},
|
|
669
661
|
};
|
|
670
|
-
const req = https.request(options,
|
|
662
|
+
const req = https.request(options, res => {
|
|
671
663
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
this.debugLog(`d: ${d}`);
|
|
664
|
+
res.on('data', d => {
|
|
665
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
|
|
675
666
|
});
|
|
676
667
|
});
|
|
677
|
-
req.on('error', (
|
|
678
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} error: ${
|
|
668
|
+
req.on('error', (e: any) => {
|
|
669
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
|
|
679
670
|
});
|
|
680
|
-
req.write(
|
|
671
|
+
req.write(body);
|
|
681
672
|
req.end();
|
|
682
673
|
|
|
683
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName}
|
|
674
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushColorTemperatureChanges: ${JSON.stringify(req)}`);
|
|
684
675
|
this.ColorTemperatureCached = this.ColorTemperature;
|
|
685
676
|
} else {
|
|
686
677
|
this.debugLog(
|
|
@@ -702,51 +693,47 @@ export class ColorBulb {
|
|
|
702
693
|
async pushBrightnessChanges(): Promise<void> {
|
|
703
694
|
try {
|
|
704
695
|
if (this.Brightness !== this.BrightnessCached) {
|
|
705
|
-
|
|
706
|
-
commandType: 'command',
|
|
707
|
-
command: 'setBrightness',
|
|
708
|
-
parameter: `${this.Brightness}`,
|
|
709
|
-
} as payload;
|
|
710
|
-
|
|
711
|
-
this.infoLog(
|
|
712
|
-
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
713
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
714
|
-
);
|
|
715
|
-
|
|
716
|
-
// Make the API request
|
|
696
|
+
// Make Push On request to the API
|
|
717
697
|
const t = Date.now();
|
|
718
698
|
const nonce = 'requestID';
|
|
719
699
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
720
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
700
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
701
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
702
|
+
.digest();
|
|
721
703
|
const sign = signTerm.toString('base64');
|
|
722
704
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} sign: ${sign}`);
|
|
705
|
+
const body = JSON.stringify({
|
|
706
|
+
'command': 'setBrightness',
|
|
707
|
+
'parameter': `${this.Brightness}`,
|
|
708
|
+
'commandType': 'command',
|
|
709
|
+
});
|
|
710
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
723
711
|
const options = {
|
|
724
712
|
hostname: HostDomain,
|
|
725
713
|
port: 443,
|
|
726
714
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
727
715
|
method: 'POST',
|
|
728
716
|
headers: {
|
|
729
|
-
Authorization: this.platform.config.credentials?.token,
|
|
730
|
-
sign: sign,
|
|
731
|
-
nonce: nonce,
|
|
732
|
-
t: t,
|
|
717
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
718
|
+
'sign': sign,
|
|
719
|
+
'nonce': nonce,
|
|
720
|
+
't': t,
|
|
733
721
|
'Content-Type': 'application/json',
|
|
722
|
+
'Content-Length': body.length,
|
|
734
723
|
},
|
|
735
724
|
};
|
|
736
|
-
const req = https.request(options,
|
|
725
|
+
const req = https.request(options, res => {
|
|
737
726
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
this.debugLog(`d: ${d}`);
|
|
727
|
+
res.on('data', d => {
|
|
728
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
|
|
741
729
|
});
|
|
742
730
|
});
|
|
743
|
-
req.on('error', (
|
|
744
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} error: ${
|
|
731
|
+
req.on('error', (e: any) => {
|
|
732
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
|
|
745
733
|
});
|
|
746
|
-
req.write(
|
|
734
|
+
req.write(body);
|
|
747
735
|
req.end();
|
|
748
|
-
|
|
749
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(req)}`);
|
|
736
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushBrightnessChanges: ${JSON.stringify(req)}`);
|
|
750
737
|
this.BrightnessCached = this.Brightness;
|
|
751
738
|
} else {
|
|
752
739
|
this.debugLog(
|
package/src/device/curtain.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { connectAsync } from 'async-mqtt';
|
|
|
8
8
|
import { SwitchBotPlatform } from '../platform';
|
|
9
9
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
10
10
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
11
|
-
import { device, devicesConfig, serviceData, switchbot,
|
|
11
|
+
import { device, devicesConfig, serviceData, switchbot, deviceStatus, ad, HostDomain, DevicePath } from '../settings';
|
|
12
12
|
|
|
13
13
|
export class Curtain {
|
|
14
14
|
// Services
|
|
@@ -679,6 +679,15 @@ export class Curtain {
|
|
|
679
679
|
try {
|
|
680
680
|
this.debugLog(`Curtain: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
681
681
|
if (this.TargetPosition !== this.CurrentPosition) {
|
|
682
|
+
// Make Push On request to the API
|
|
683
|
+
const t = Date.now();
|
|
684
|
+
const nonce = 'requestID';
|
|
685
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
686
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
687
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
688
|
+
.digest();
|
|
689
|
+
const sign = signTerm.toString('base64');
|
|
690
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} sign: ${sign}`);
|
|
682
691
|
this.debugLog(`Pushing ${this.TargetPosition}`);
|
|
683
692
|
const adjustedTargetPosition = 100 - Number(this.TargetPosition);
|
|
684
693
|
if (this.TargetPosition > 50) {
|
|
@@ -695,54 +704,39 @@ export class Curtain {
|
|
|
695
704
|
}
|
|
696
705
|
this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
|
|
697
706
|
const adjustedMode = this.setPositionMode || 'ff';
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
this.infoLog(
|
|
705
|
-
`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
706
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
707
|
-
);
|
|
708
|
-
|
|
709
|
-
// Make the API request
|
|
710
|
-
const t = Date.now();
|
|
711
|
-
const nonce = 'requestID';
|
|
712
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
713
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
714
|
-
const sign = signTerm.toString('base64');
|
|
715
|
-
this.debugLog(`Curtain: ${this.accessory.displayName} sign: ${sign}`);
|
|
707
|
+
const body = JSON.stringify({
|
|
708
|
+
'command': 'setPosition',
|
|
709
|
+
'parameter': `0,${adjustedMode},${adjustedTargetPosition}`,
|
|
710
|
+
'commandType': 'command',
|
|
711
|
+
});
|
|
712
|
+
this.infoLog(`Curtain: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
716
713
|
const options = {
|
|
717
714
|
hostname: HostDomain,
|
|
718
715
|
port: 443,
|
|
719
716
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
720
717
|
method: 'POST',
|
|
721
718
|
headers: {
|
|
722
|
-
Authorization: this.platform.config.credentials?.token,
|
|
723
|
-
sign: sign,
|
|
724
|
-
nonce: nonce,
|
|
725
|
-
t: t,
|
|
719
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
720
|
+
'sign': sign,
|
|
721
|
+
'nonce': nonce,
|
|
722
|
+
't': t,
|
|
726
723
|
'Content-Type': 'application/json',
|
|
724
|
+
'Content-Length': body.length,
|
|
727
725
|
},
|
|
728
726
|
};
|
|
729
|
-
|
|
730
|
-
const req = https.request(options, (res) => {
|
|
727
|
+
const req = https.request(options, res => {
|
|
731
728
|
this.debugLog(`Curtain: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
732
729
|
this.statusCode({ res });
|
|
733
|
-
res.on('data',
|
|
730
|
+
res.on('data', d => {
|
|
734
731
|
this.debugLog(`Curtain: ${this.accessory.displayName} d: ${d}`);
|
|
735
732
|
});
|
|
736
733
|
});
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
this.errorLog(`Curtain: ${this.accessory.displayName} error: ${error}`);
|
|
734
|
+
req.on('error', (e: any) => {
|
|
735
|
+
this.errorLog(`Curtain: ${this.accessory.displayName} error message: ${e.message}`);
|
|
740
736
|
});
|
|
741
|
-
|
|
742
|
-
req.write(payload);
|
|
737
|
+
req.write(body);
|
|
743
738
|
req.end();
|
|
744
|
-
|
|
745
|
-
this.debugLog(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
739
|
+
this.debugLog(`Curtain: ${this.accessory.displayName} openAPIpushChanges: ${JSON.stringify(req)}`);
|
|
746
740
|
} else {
|
|
747
741
|
this.debugLog(
|
|
748
742
|
`Curtain: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.` +
|