@switchbot/homebridge-switchbot 2.2.2-beta.0 → 2.2.2-beta.10
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.js +1 -1
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +4 -4
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +4 -4
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/curtain.js +1 -1
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +6 -6
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +15 -9
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.js +1 -1
- package/dist/device/lock.js.map +1 -1
- package/dist/device/plug.js +1 -1
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +7 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +142 -125
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.js +2 -2
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +2 -2
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js +2 -2
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.js +2 -2
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.js +2 -2
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +2 -2
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.js +2 -2
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -2
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +2 -2
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.js +67 -66
- package/dist/platform.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +1 -1
- package/src/device/ceilinglight.ts +4 -4
- package/src/device/colorbulb.ts +4 -4
- package/src/device/curtain.ts +1 -1
- package/src/device/humidifier.ts +13 -9
- package/src/device/lock.ts +1 -1
- package/src/device/plug.ts +1 -1
- package/src/device/striplight.ts +143 -122
- package/src/irdevice/airconditioner.ts +2 -2
- package/src/irdevice/airpurifier.ts +2 -2
- package/src/irdevice/camera.ts +2 -2
- package/src/irdevice/fan.ts +2 -2
- package/src/irdevice/light.ts +2 -2
- package/src/irdevice/other.ts +2 -2
- package/src/irdevice/tv.ts +2 -2
- package/src/irdevice/vacuumcleaner.ts +2 -2
- package/src/irdevice/waterheater.ts +2 -2
- package/src/platform.ts +74 -74
package/src/device/striplight.ts
CHANGED
|
@@ -54,6 +54,7 @@ export class StripLight {
|
|
|
54
54
|
|
|
55
55
|
// Others
|
|
56
56
|
cacheKelvin!: number;
|
|
57
|
+
change!: string;
|
|
57
58
|
|
|
58
59
|
// Updates
|
|
59
60
|
stripLightUpdateInProgress!: boolean;
|
|
@@ -474,68 +475,117 @@ export class StripLight {
|
|
|
474
475
|
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
475
476
|
await this.BLEPushConnection();
|
|
476
477
|
});
|
|
478
|
+
// Push Brightness Update
|
|
479
|
+
if (this.On) {
|
|
480
|
+
await this.BLEpushBrightnessChanges();
|
|
481
|
+
}
|
|
482
|
+
// Push Hue & Saturation Update
|
|
483
|
+
if (this.On) {
|
|
484
|
+
await this.BLEpushRGBChanges();
|
|
485
|
+
}
|
|
477
486
|
} else {
|
|
478
487
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
479
488
|
+`OnCached: ${this.accessory.context.On}`);
|
|
480
489
|
}
|
|
481
490
|
}
|
|
482
491
|
|
|
492
|
+
async BLEpushBrightnessChanges(): Promise<void> {
|
|
493
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushBrightnessChanges`);
|
|
494
|
+
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
495
|
+
const switchbot = await this.platform.connectBLE();
|
|
496
|
+
// Convert to BLE Address
|
|
497
|
+
this.device.bleMac = this.device
|
|
498
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
499
|
+
.join(':')
|
|
500
|
+
.toLowerCase();
|
|
501
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
502
|
+
switchbot
|
|
503
|
+
.discover({
|
|
504
|
+
model: 'u',
|
|
505
|
+
id: this.device.bleMac,
|
|
506
|
+
})
|
|
507
|
+
.then((device_list: any) => {
|
|
508
|
+
this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.Brightness}`);
|
|
509
|
+
return device_list[0].setBrightness(this.Brightness);
|
|
510
|
+
})
|
|
511
|
+
.then(() => {
|
|
512
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
513
|
+
this.On = false;
|
|
514
|
+
})
|
|
515
|
+
.catch(async (e: any) => {
|
|
516
|
+
this.apiError(e);
|
|
517
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
|
|
518
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
519
|
+
await this.BLEPushConnection();
|
|
520
|
+
});
|
|
521
|
+
} else {
|
|
522
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
|
|
523
|
+
+`BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
async BLEpushRGBChanges(): Promise<void> {
|
|
528
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushRGBChanges`);
|
|
529
|
+
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
530
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${superStringify(this.Hue)}`);
|
|
531
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${superStringify(this.Saturation)}`);
|
|
532
|
+
|
|
533
|
+
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
534
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${superStringify([red, green, blue])}`);
|
|
535
|
+
|
|
536
|
+
const switchbot = await this.platform.connectBLE();
|
|
537
|
+
// Convert to BLE Address
|
|
538
|
+
this.device.bleMac = this.device
|
|
539
|
+
.deviceId!.match(/.{1,2}/g)!
|
|
540
|
+
.join(':')
|
|
541
|
+
.toLowerCase();
|
|
542
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
543
|
+
switchbot
|
|
544
|
+
.discover({
|
|
545
|
+
model: 'u',
|
|
546
|
+
id: this.device.bleMac,
|
|
547
|
+
})
|
|
548
|
+
.then((device_list: any) => {
|
|
549
|
+
this.infoLog(`${this.accessory.displayName} Target RGB: ${this.Brightness, red, green, blue}`);
|
|
550
|
+
return device_list[0].setRGB(this.Brightness, red, green, blue);
|
|
551
|
+
})
|
|
552
|
+
.then(() => {
|
|
553
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
554
|
+
this.On = false;
|
|
555
|
+
})
|
|
556
|
+
.catch(async (e: any) => {
|
|
557
|
+
this.apiError(e);
|
|
558
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}`
|
|
559
|
+
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
560
|
+
await this.BLEPushConnection();
|
|
561
|
+
});
|
|
562
|
+
} else {
|
|
563
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushRGBChanges. Hue: ${this.Hue}, `
|
|
564
|
+
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
483
568
|
async openAPIpushChanges() {
|
|
569
|
+
const change = 'openAPIpushChanges';
|
|
484
570
|
try {
|
|
485
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
571
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${change}`);
|
|
486
572
|
if (this.On !== this.accessory.context.On) {
|
|
487
573
|
// Make Push On request to the API
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
491
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
492
|
-
.update(Buffer.from(data, 'utf-8'))
|
|
493
|
-
.digest();
|
|
494
|
-
const sign = signTerm.toString('base64');
|
|
495
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
496
|
-
|
|
497
|
-
let command = '';
|
|
498
|
-
if (this.On) {
|
|
574
|
+
const command = this.On ? 'turnOn' : 'turnOff';
|
|
575
|
+
/*if (this.On) {
|
|
499
576
|
command = 'turnOn';
|
|
500
577
|
} else {
|
|
501
578
|
command = 'turnOff';
|
|
502
|
-
}
|
|
579
|
+
}*/
|
|
503
580
|
const body = superStringify({
|
|
504
581
|
'command': `${command}`,
|
|
505
582
|
'parameter': 'default',
|
|
506
583
|
'commandType': 'command',
|
|
507
584
|
});
|
|
508
|
-
this.
|
|
509
|
-
const options = {
|
|
510
|
-
hostname: HostDomain,
|
|
511
|
-
port: 443,
|
|
512
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
513
|
-
method: 'POST',
|
|
514
|
-
headers: {
|
|
515
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
516
|
-
'sign': sign,
|
|
517
|
-
'nonce': nonce,
|
|
518
|
-
't': t,
|
|
519
|
-
'Content-Type': 'application/json',
|
|
520
|
-
'Content-Length': body.length,
|
|
521
|
-
},
|
|
522
|
-
};
|
|
523
|
-
const req = https.request(options, res => {
|
|
524
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
525
|
-
this.statusCode({ res });
|
|
526
|
-
res.on('data', d => {
|
|
527
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
req.on('error', (e: any) => {
|
|
531
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
532
|
-
});
|
|
533
|
-
req.write(body);
|
|
534
|
-
req.end();
|
|
535
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`);
|
|
585
|
+
await this.request({ body, change });
|
|
536
586
|
} else {
|
|
537
587
|
this.debugLog(
|
|
538
|
-
`${this.device.deviceType}: ${this.accessory.displayName} No
|
|
588
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No ${change}.` + `On: ${this.On}, `
|
|
539
589
|
+`OnCached: ${this.accessory.context.On}`,
|
|
540
590
|
);
|
|
541
591
|
}
|
|
@@ -549,15 +599,16 @@ export class StripLight {
|
|
|
549
599
|
}
|
|
550
600
|
} catch (e: any) {
|
|
551
601
|
this.apiError(e);
|
|
552
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed
|
|
602
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed ${change} with ${this.device.connectionType}`
|
|
553
603
|
+ ` Connection, Error Message: ${superStringify(e.message)}`,
|
|
554
604
|
);
|
|
555
605
|
}
|
|
556
606
|
}
|
|
557
607
|
|
|
558
608
|
async pushHueSaturationChanges(): Promise<void> {
|
|
609
|
+
const change = 'pushHueSaturationChanges';
|
|
559
610
|
try {
|
|
560
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
611
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${change}`);
|
|
561
612
|
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
562
613
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${superStringify(this.Hue)}`);
|
|
563
614
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${superStringify(this.Saturation)}`);
|
|
@@ -565,115 +616,85 @@ export class StripLight {
|
|
|
565
616
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
566
617
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${superStringify([red, green, blue])}`);
|
|
567
618
|
// Make Push On request to the API
|
|
568
|
-
const t = Date.now();
|
|
569
|
-
const nonce = 'requestID';
|
|
570
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
571
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
572
|
-
.update(Buffer.from(data, 'utf-8'))
|
|
573
|
-
.digest();
|
|
574
|
-
const sign = signTerm.toString('base64');
|
|
575
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
576
619
|
const body = superStringify({
|
|
577
620
|
'command': 'setColor',
|
|
578
621
|
'parameter': `${red}:${green}:${blue}`,
|
|
579
622
|
'commandType': 'command',
|
|
580
623
|
});
|
|
581
|
-
this.
|
|
582
|
-
const options = {
|
|
583
|
-
hostname: HostDomain,
|
|
584
|
-
port: 443,
|
|
585
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
586
|
-
method: 'POST',
|
|
587
|
-
headers: {
|
|
588
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
589
|
-
'sign': sign,
|
|
590
|
-
'nonce': nonce,
|
|
591
|
-
't': t,
|
|
592
|
-
'Content-Type': 'application/json',
|
|
593
|
-
'Content-Length': body.length,
|
|
594
|
-
},
|
|
595
|
-
};
|
|
596
|
-
const req = https.request(options, res => {
|
|
597
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges statusCode: ${res.statusCode}`);
|
|
598
|
-
this.statusCode({ res });
|
|
599
|
-
res.on('data', d => {
|
|
600
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
601
|
-
});
|
|
602
|
-
});
|
|
603
|
-
req.on('error', (e: any) => {
|
|
604
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
605
|
-
});
|
|
606
|
-
req.write(body);
|
|
607
|
-
req.end();
|
|
608
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges: ${superStringify(req)}`);
|
|
624
|
+
await this.request({ body, change });
|
|
609
625
|
} else {
|
|
610
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No
|
|
626
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No ${change}. Hue: ${this.Hue}, `
|
|
611
627
|
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
612
628
|
}
|
|
613
629
|
} catch (e: any) {
|
|
614
630
|
this.apiError(e);
|
|
615
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed
|
|
631
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed ${change} with ${this.device.connectionType}`
|
|
616
632
|
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
617
633
|
}
|
|
618
634
|
}
|
|
619
635
|
|
|
620
636
|
async pushBrightnessChanges(): Promise<void> {
|
|
637
|
+
const change = 'pushBrightnessChanges';
|
|
621
638
|
try {
|
|
622
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
639
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${change}`);
|
|
623
640
|
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
624
641
|
// Make Push On request to the API
|
|
625
|
-
const t = Date.now();
|
|
626
|
-
const nonce = 'requestID';
|
|
627
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
628
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
629
|
-
.update(Buffer.from(data, 'utf-8'))
|
|
630
|
-
.digest();
|
|
631
|
-
const sign = signTerm.toString('base64');
|
|
632
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
633
642
|
const body = superStringify({
|
|
634
643
|
'command': 'setBrightness',
|
|
635
644
|
'parameter': `${this.Brightness}`,
|
|
636
645
|
'commandType': 'command',
|
|
637
646
|
});
|
|
638
|
-
this.
|
|
639
|
-
const options = {
|
|
640
|
-
hostname: HostDomain,
|
|
641
|
-
port: 443,
|
|
642
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
643
|
-
method: 'POST',
|
|
644
|
-
headers: {
|
|
645
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
646
|
-
'sign': sign,
|
|
647
|
-
'nonce': nonce,
|
|
648
|
-
't': t,
|
|
649
|
-
'Content-Type': 'application/json',
|
|
650
|
-
'Content-Length': body.length,
|
|
651
|
-
},
|
|
652
|
-
};
|
|
653
|
-
const req = https.request(options, res => {
|
|
654
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges statusCode: ${res.statusCode}`);
|
|
655
|
-
this.statusCode({ res });
|
|
656
|
-
res.on('data', d => {
|
|
657
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
658
|
-
});
|
|
659
|
-
});
|
|
660
|
-
req.on('error', (e: any) => {
|
|
661
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
662
|
-
});
|
|
663
|
-
req.write(body);
|
|
664
|
-
req.end();
|
|
665
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges: ${superStringify(req)}`);
|
|
647
|
+
await this.request({ body, change });
|
|
666
648
|
} else {
|
|
667
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No
|
|
649
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No ${change},` + `Brightness: ${this.Brightness}, `
|
|
668
650
|
+`BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
669
651
|
}
|
|
670
652
|
} catch (e: any) {
|
|
671
653
|
this.apiError(e);
|
|
672
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed
|
|
654
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed ${change} with ${this.device.connectionType}`
|
|
673
655
|
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
674
656
|
}
|
|
675
657
|
}
|
|
676
658
|
|
|
659
|
+
async request({ body, change }: { body: any; change: string; }): Promise<void> {
|
|
660
|
+
const t = Date.now();
|
|
661
|
+
const nonce = 'requestID';
|
|
662
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
663
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
664
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
665
|
+
.digest();
|
|
666
|
+
const sign = signTerm.toString('base64');
|
|
667
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
668
|
+
const options = {
|
|
669
|
+
hostname: HostDomain,
|
|
670
|
+
port: 443,
|
|
671
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
672
|
+
method: 'POST',
|
|
673
|
+
headers: {
|
|
674
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
675
|
+
'sign': sign,
|
|
676
|
+
'nonce': nonce,
|
|
677
|
+
't': t,
|
|
678
|
+
'Content-Type': 'application/json',
|
|
679
|
+
'Content-Length': body.length,
|
|
680
|
+
},
|
|
681
|
+
};
|
|
682
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
683
|
+
const req = https.request(options, res => {
|
|
684
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${change} statusCode: ${res.statusCode}`);
|
|
685
|
+
this.statusCode({ res });
|
|
686
|
+
res.on('data', d => {
|
|
687
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
req.on('error', (e: any) => {
|
|
691
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
692
|
+
});
|
|
693
|
+
req.write(body);
|
|
694
|
+
req.end();
|
|
695
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${change} req: ${superStringify(req)}`);
|
|
696
|
+
}
|
|
697
|
+
|
|
677
698
|
/**
|
|
678
699
|
* Handle requests to set the value of the "On" characteristic
|
|
679
700
|
*/
|
|
@@ -1004,7 +1025,7 @@ export class StripLight {
|
|
|
1004
1025
|
} else {
|
|
1005
1026
|
this.Brightness = this.accessory.context.Brightness;
|
|
1006
1027
|
}
|
|
1007
|
-
if (this.
|
|
1028
|
+
if (this.Saturation === undefined) {
|
|
1008
1029
|
this.Saturation = 0;
|
|
1009
1030
|
} else {
|
|
1010
1031
|
this.Saturation = this.accessory.context.Saturation;
|
|
@@ -559,9 +559,9 @@ export class AirConditioner {
|
|
|
559
559
|
|
|
560
560
|
async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
561
561
|
if (device.allowPushOff) {
|
|
562
|
-
this.
|
|
562
|
+
this.allowPushOff = true;
|
|
563
563
|
} else {
|
|
564
|
-
this.
|
|
564
|
+
this.allowPushOff = false;
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
567
|
|
|
@@ -288,9 +288,9 @@ export class AirPurifier {
|
|
|
288
288
|
|
|
289
289
|
async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
290
290
|
if (device.allowPushOff) {
|
|
291
|
-
this.
|
|
291
|
+
this.allowPushOff = true;
|
|
292
292
|
} else {
|
|
293
|
-
this.
|
|
293
|
+
this.allowPushOff = false;
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
|
package/src/irdevice/camera.ts
CHANGED
|
@@ -185,9 +185,9 @@ export class Camera {
|
|
|
185
185
|
|
|
186
186
|
async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
187
187
|
if (device.allowPushOff) {
|
|
188
|
-
this.
|
|
188
|
+
this.allowPushOff = true;
|
|
189
189
|
} else {
|
|
190
|
-
this.
|
|
190
|
+
this.allowPushOff = false;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -316,9 +316,9 @@ export class Fan {
|
|
|
316
316
|
|
|
317
317
|
async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
318
318
|
if (device.allowPushOff) {
|
|
319
|
-
this.
|
|
319
|
+
this.allowPushOff = true;
|
|
320
320
|
} else {
|
|
321
|
-
this.
|
|
321
|
+
this.allowPushOff = false;
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
|
package/src/irdevice/light.ts
CHANGED
|
@@ -204,9 +204,9 @@ export class Light {
|
|
|
204
204
|
|
|
205
205
|
async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
206
206
|
if (device.allowPushOff) {
|
|
207
|
-
this.
|
|
207
|
+
this.allowPushOff = true;
|
|
208
208
|
} else {
|
|
209
|
-
this.
|
|
209
|
+
this.allowPushOff = false;
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
package/src/irdevice/other.ts
CHANGED
|
@@ -201,9 +201,9 @@ export class Others {
|
|
|
201
201
|
|
|
202
202
|
async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
203
203
|
if (device.allowPushOff) {
|
|
204
|
-
this.
|
|
204
|
+
this.allowPushOff = true;
|
|
205
205
|
} else {
|
|
206
|
-
this.
|
|
206
|
+
this.allowPushOff = false;
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -419,9 +419,9 @@ export class TV {
|
|
|
419
419
|
|
|
420
420
|
async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
421
421
|
if (device.allowPushOff) {
|
|
422
|
-
this.
|
|
422
|
+
this.allowPushOff = true;
|
|
423
423
|
} else {
|
|
424
|
-
this.
|
|
424
|
+
this.allowPushOff = false;
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
|
|
@@ -182,9 +182,9 @@ export class VacuumCleaner {
|
|
|
182
182
|
|
|
183
183
|
async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
184
184
|
if (device.allowPushOff) {
|
|
185
|
-
this.
|
|
185
|
+
this.allowPushOff = true;
|
|
186
186
|
} else {
|
|
187
|
-
this.
|
|
187
|
+
this.allowPushOff = false;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -190,9 +190,9 @@ export class WaterHeater {
|
|
|
190
190
|
|
|
191
191
|
async allowPushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
192
192
|
if (device.allowPushOff) {
|
|
193
|
-
this.
|
|
193
|
+
this.allowPushOff = true;
|
|
194
194
|
} else {
|
|
195
|
-
this.
|
|
195
|
+
this.allowPushOff = false;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
package/src/platform.ts
CHANGED
|
@@ -285,91 +285,91 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
285
285
|
this.debugLog(`d: ${d}`);
|
|
286
286
|
});
|
|
287
287
|
res.on('end', () => {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
this.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (device.deviceType) {
|
|
303
|
-
if (device.configDeviceName) {
|
|
304
|
-
device.deviceName = device.configDeviceName;
|
|
288
|
+
try {
|
|
289
|
+
const devicesAPI = JSON.parse(rawData);
|
|
290
|
+
this.debugLog(`devicesAPI: ${superStringify(devicesAPI.body)}`);
|
|
291
|
+
// SwitchBot Devices
|
|
292
|
+
const deviceLists = devicesAPI.body.deviceList;
|
|
293
|
+
if (!this.config.options?.devices) {
|
|
294
|
+
this.debugLog(`SwitchBot Device Config Not Set: ${JSON.stringify(this.config.options?.devices)}`);
|
|
295
|
+
const devices = deviceLists.map((v: any) => v);
|
|
296
|
+
for (const device of devices) {
|
|
297
|
+
if (device.deviceType) {
|
|
298
|
+
if (device.configDeviceName) {
|
|
299
|
+
device.deviceName = device.configDeviceName;
|
|
300
|
+
}
|
|
301
|
+
this.createDevice(device);
|
|
305
302
|
}
|
|
306
|
-
this.createDevice(device);
|
|
307
303
|
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
304
|
+
} else if (this.config.credentials?.token && this.config.options.devices) {
|
|
305
|
+
this.debugLog(`SwitchBot Device Config Set: ${superStringify(this.config.options?.devices)}`);
|
|
306
|
+
const deviceConfigs = this.config.options?.devices;
|
|
307
|
+
|
|
308
|
+
const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
309
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
310
|
+
...a2.find(
|
|
311
|
+
(item: { deviceId: string }) =>
|
|
312
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
313
|
+
),
|
|
314
|
+
...itm,
|
|
315
|
+
}));
|
|
316
|
+
|
|
317
|
+
const devices = mergeBydeviceId(deviceLists, deviceConfigs);
|
|
318
|
+
this.debugLog(`SwitchBot Devices: ${superStringify(devices)}`);
|
|
319
|
+
for (const device of devices) {
|
|
320
|
+
if (device.deviceType) {
|
|
321
|
+
if (device.configDeviceName) {
|
|
322
|
+
device.deviceName = device.configDeviceName;
|
|
323
|
+
}
|
|
324
|
+
this.createDevice(device);
|
|
328
325
|
}
|
|
329
|
-
this.createDevice(device);
|
|
330
326
|
}
|
|
327
|
+
} else {
|
|
328
|
+
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
329
|
+
}
|
|
330
|
+
if (devicesAPI.body.deviceList.length !== 0) {
|
|
331
|
+
this.infoLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
332
|
+
} else {
|
|
333
|
+
this.debugLog(`Total SwitchBot Devices Found: ${devicesAPI.body.deviceList.length}`);
|
|
331
334
|
}
|
|
332
|
-
} else {
|
|
333
|
-
this.errorLog('SwitchBot Token Supplied, Issue with Auth.');
|
|
334
|
-
}
|
|
335
335
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
this.
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
336
|
+
// IR Devices
|
|
337
|
+
const irDeviceLists = devicesAPI.body.infraredRemoteList;
|
|
338
|
+
if (!this.config.options?.irdevices) {
|
|
339
|
+
this.debugLog(`IR Device Config Not Set: ${JSON.stringify(this.config.options?.irdevices)}`);
|
|
340
|
+
const devices = irDeviceLists.map((v: any) => v);
|
|
341
|
+
for (const device of devices) {
|
|
342
|
+
if (device.remoteType) {
|
|
343
|
+
this.createIRDevice(device);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
this.debugLog(`IR Device Config Set: ${superStringify(this.config.options?.irdevices)}`);
|
|
348
|
+
const irDeviceConfig = this.config.options?.irdevices;
|
|
349
|
+
|
|
350
|
+
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
351
|
+
a1.map((itm: { deviceId: string }) => ({
|
|
352
|
+
...a2.find(
|
|
353
|
+
(item: { deviceId: string }) =>
|
|
354
|
+
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
355
|
+
),
|
|
356
|
+
...itm,
|
|
357
|
+
}));
|
|
358
|
+
|
|
359
|
+
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
360
|
+
this.debugLog(`IR Devices: ${superStringify(devices)}`);
|
|
361
|
+
for (const device of devices) {
|
|
348
362
|
this.createIRDevice(device);
|
|
349
363
|
}
|
|
350
364
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
|
|
356
|
-
a1.map((itm: { deviceId: string }) => ({
|
|
357
|
-
...a2.find(
|
|
358
|
-
(item: { deviceId: string }) =>
|
|
359
|
-
item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
|
|
360
|
-
),
|
|
361
|
-
...itm,
|
|
362
|
-
}));
|
|
363
|
-
|
|
364
|
-
const devices = mergeIRBydeviceId(irDeviceLists, irDeviceConfig);
|
|
365
|
-
this.debugLog(`IR Devices: ${superStringify(devices)}`);
|
|
366
|
-
for (const device of devices) {
|
|
367
|
-
this.createIRDevice(device);
|
|
365
|
+
if (devicesAPI.body.infraredRemoteList.length !== 0) {
|
|
366
|
+
this.infoLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
367
|
+
} else {
|
|
368
|
+
this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
|
|
368
369
|
}
|
|
370
|
+
} catch (e:any) {
|
|
371
|
+
this.errorLog(`API Request: ${e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
369
372
|
}
|
|
370
|
-
//} catch (e:any) {
|
|
371
|
-
// this.errorLog(`API Request: ${e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
372
|
-
// }
|
|
373
373
|
});
|
|
374
374
|
});
|
|
375
375
|
req.on('error', (e: any) => {
|