@switchbot/homebridge-switchbot 1.15.1-beta.0 → 1.15.1-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/.github/ISSUE_TEMPLATE/bug-report.yml +1 -0
- package/.github/ISSUE_TEMPLATE/feature-request.yml +1 -0
- package/.github/ISSUE_TEMPLATE/support-request.yml +1 -0
- package/.prettierrc +1 -1
- package/CHANGELOG.md +9 -0
- package/config.schema.json +11 -4
- package/dist/device/bot.d.ts +8 -7
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +104 -28
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +8 -7
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +223 -58
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +3 -3
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +54 -11
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -8
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +102 -28
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +8 -7
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +187 -66
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +8 -7
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +98 -22
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +4 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +55 -12
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +3 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +53 -10
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +3 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +53 -13
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +8 -7
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +100 -24
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +8 -7
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +186 -47
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +7 -6
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +40 -6
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +7 -6
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +46 -11
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -6
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +40 -6
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -7
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +40 -6
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +7 -6
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +40 -6
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +7 -6
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -6
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -7
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +40 -6
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +40 -6
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -6
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +40 -6
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +10 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +211 -93
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -21
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +3 -3
- package/dist/settings.js.map +1 -1
- package/package.json +12 -12
- package/src/device/bot.ts +104 -37
- package/src/device/colorbulb.ts +227 -95
- package/src/device/contact.ts +53 -14
- package/src/device/curtain.ts +105 -38
- package/src/device/humidifier.ts +189 -84
- package/src/device/lock.ts +97 -30
- package/src/device/meter.ts +55 -16
- package/src/device/meterplus.ts +52 -13
- package/src/device/motion.ts +52 -16
- package/src/device/plug.ts +101 -33
- package/src/device/striplight.ts +189 -68
- package/src/irdevice/airconditioner.ts +44 -9
- package/src/irdevice/airpurifier.ts +52 -17
- package/src/irdevice/camera.ts +46 -11
- package/src/irdevice/fan.ts +50 -15
- package/src/irdevice/light.ts +48 -13
- package/src/irdevice/other.ts +46 -11
- package/src/irdevice/tv.ts +56 -21
- package/src/irdevice/vacuumcleaner.ts +46 -11
- package/src/irdevice/waterheater.ts +46 -11
- package/src/platform.ts +232 -107
- package/src/settings.ts +4 -25
package/.prettierrc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
|
|
4
4
|
|
|
5
|
+
## [Beta - Version 2.0.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.0.0) (2022-XX-XX)
|
|
6
|
+
|
|
7
|
+
## What's Changed
|
|
8
|
+
|
|
9
|
+
- Moved from v1.0 to v1.1 of [OpenAPI](https://github.com/OpenWonderLabs/SwitchBotAPI)
|
|
10
|
+
- Housekeeping and updated dependencies.
|
|
11
|
+
|
|
12
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.15.0...v2.0.0
|
|
13
|
+
|
|
5
14
|
## [Version 1.15.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.15.0) (2022-08-27)
|
|
6
15
|
|
|
7
16
|
## What's Changed
|
package/config.schema.json
CHANGED
|
@@ -16,20 +16,27 @@
|
|
|
16
16
|
"credentials": {
|
|
17
17
|
"type": "object",
|
|
18
18
|
"properties": {
|
|
19
|
-
"
|
|
19
|
+
"token": {
|
|
20
20
|
"title": "Token",
|
|
21
21
|
"type": "string",
|
|
22
22
|
"x-schema-form": {
|
|
23
23
|
"type": "password"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
+
"secret": {
|
|
27
|
+
"title": "Secret",
|
|
28
|
+
"type": "string",
|
|
29
|
+
"x-schema-form": {
|
|
30
|
+
"type": "password"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
26
33
|
"notice": {
|
|
27
34
|
"title": "Notice",
|
|
28
35
|
"type": "string",
|
|
29
|
-
"default": "Keep your
|
|
36
|
+
"default": "Keep your Token & Secret a secret!"
|
|
30
37
|
}
|
|
31
38
|
},
|
|
32
|
-
"required": ["
|
|
39
|
+
"required": ["token", "secret", "notice"]
|
|
33
40
|
},
|
|
34
41
|
"options": {
|
|
35
42
|
"type": "object",
|
|
@@ -861,7 +868,7 @@
|
|
|
861
868
|
"title": "SwitchBot Account Info",
|
|
862
869
|
"expandable": true,
|
|
863
870
|
"expanded": false,
|
|
864
|
-
"items": ["credentials.
|
|
871
|
+
"items": ["credentials.token","credentials.secret"]
|
|
865
872
|
},
|
|
866
873
|
{
|
|
867
874
|
"type": "fieldset",
|
package/dist/device/bot.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Context } from 'vm';
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
3
5
|
import { Subject } from 'rxjs';
|
|
4
6
|
import { SwitchBotPlatform } from '../platform';
|
|
5
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
6
|
-
import { device, devicesConfig,
|
|
7
|
-
import { Context } from 'vm';
|
|
8
|
+
import { device, devicesConfig, deviceStatus, ad, serviceData, switchbot } from '../settings';
|
|
8
9
|
/**
|
|
9
10
|
* Platform Accessory
|
|
10
11
|
* An instance of this class is created for each accessory your platform registers
|
|
@@ -30,7 +31,7 @@ export declare class Bot {
|
|
|
30
31
|
BatteryLevel: CharacteristicValue;
|
|
31
32
|
StatusLowBattery: CharacteristicValue;
|
|
32
33
|
power: deviceStatus['power'];
|
|
33
|
-
deviceStatus:
|
|
34
|
+
deviceStatus: any;
|
|
34
35
|
connected?: boolean;
|
|
35
36
|
switchbot: switchbot;
|
|
36
37
|
SwitchToOpenAPI?: boolean;
|
|
@@ -77,9 +78,9 @@ export declare class Bot {
|
|
|
77
78
|
*/
|
|
78
79
|
updateHomeKitCharacteristics(): Promise<void>;
|
|
79
80
|
apiError(e: any): Promise<void>;
|
|
80
|
-
statusCode(
|
|
81
|
-
|
|
82
|
-
}
|
|
81
|
+
statusCode({ res }: {
|
|
82
|
+
res: IncomingMessage;
|
|
83
|
+
}): Promise<void>;
|
|
83
84
|
offlineOff(): Promise<void>;
|
|
84
85
|
/**
|
|
85
86
|
* Handle requests to set the "On" characteristic
|
package/dist/device/bot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../../src/device/bot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../../src/device/bot.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAY,OAAO,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD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AI,CAAC;IAS9D,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAShE,gBAAgB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7D,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAShE,2BAA2B,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IASxE,uCAAuC,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IASpF,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAStE;;OAEG;IACH,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5B,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5B,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAM7B,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAU7B,qBAAqB,IAAI,OAAO;CAGjC"}
|
package/dist/device/bot.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Bot = void 0;
|
|
7
|
+
const https_1 = __importDefault(require("https"));
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
4
9
|
const rxjs_1 = require("rxjs");
|
|
5
10
|
const operators_1 = require("rxjs/operators");
|
|
6
11
|
const settings_1 = require("../settings");
|
|
@@ -350,7 +355,7 @@ class Bot {
|
|
|
350
355
|
if (this.device.ble) {
|
|
351
356
|
this.SwitchToOpenAPI = false;
|
|
352
357
|
}
|
|
353
|
-
if (this.platform.config.credentials?.
|
|
358
|
+
if (this.platform.config.credentials?.token) {
|
|
354
359
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
355
360
|
if (this.botMode === 'press') {
|
|
356
361
|
this.On = false;
|
|
@@ -444,7 +449,7 @@ class Bot {
|
|
|
444
449
|
}
|
|
445
450
|
else {
|
|
446
451
|
this.errorLog(`Bot: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
447
|
-
if (this.platform.config.credentials?.
|
|
452
|
+
if (this.platform.config.credentials?.token) {
|
|
448
453
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
449
454
|
this.SwitchToOpenAPI = true;
|
|
450
455
|
await this.openAPIRefreshStatus();
|
|
@@ -456,7 +461,7 @@ class Bot {
|
|
|
456
461
|
if (this.deviceLogging.includes('debug')) {
|
|
457
462
|
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
458
463
|
}
|
|
459
|
-
if (this.platform.config.credentials?.
|
|
464
|
+
if (this.platform.config.credentials?.token) {
|
|
460
465
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
461
466
|
this.SwitchToOpenAPI = true;
|
|
462
467
|
await this.openAPIRefreshStatus();
|
|
@@ -482,14 +487,52 @@ class Bot {
|
|
|
482
487
|
}
|
|
483
488
|
}
|
|
484
489
|
async openAPIRefreshStatus() {
|
|
485
|
-
if (this.platform.config.credentials?.
|
|
490
|
+
if (this.platform.config.credentials?.token) {
|
|
486
491
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI refreshStatus`);
|
|
487
492
|
try {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
this.
|
|
492
|
-
|
|
493
|
+
const t = Date.now();
|
|
494
|
+
const nonce = 'requestID';
|
|
495
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
496
|
+
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
497
|
+
const sign = signTerm.toString('base64');
|
|
498
|
+
this.debugLog(`Bot: ${this.accessory.displayName} sign: ${sign}`);
|
|
499
|
+
const options = {
|
|
500
|
+
hostname: settings_1.HostDomain,
|
|
501
|
+
port: 443,
|
|
502
|
+
path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
|
|
503
|
+
method: 'GET',
|
|
504
|
+
headers: {
|
|
505
|
+
Authorization: this.platform.config.credentials?.token,
|
|
506
|
+
sign: sign,
|
|
507
|
+
nonce: nonce,
|
|
508
|
+
t: t,
|
|
509
|
+
'Content-Type': 'application/json',
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
const req = https_1.default.request(options, (res) => {
|
|
513
|
+
this.debugLog(`Bot: ${this.accessory.displayName} Refresh statusCode: ${res.statusCode}`);
|
|
514
|
+
let rawData = '';
|
|
515
|
+
res.on('data', (d) => {
|
|
516
|
+
rawData += d;
|
|
517
|
+
this.debugLog(`d: ${d}`);
|
|
518
|
+
});
|
|
519
|
+
res.on('end', () => {
|
|
520
|
+
try {
|
|
521
|
+
this.deviceStatus = JSON.parse(rawData);
|
|
522
|
+
this.debugLog(`Bot: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
523
|
+
this.power = this.deviceStatus.body.power;
|
|
524
|
+
this.parseStatus();
|
|
525
|
+
this.updateHomeKitCharacteristics();
|
|
526
|
+
}
|
|
527
|
+
catch (e) {
|
|
528
|
+
this.errorLog(`Bot: ${this.accessory.displayName} error message: ${e.message}`);
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
req.on('error', (e) => {
|
|
533
|
+
this.errorLog(`Bot: ${this.accessory.displayName} error message: ${e.message}`);
|
|
534
|
+
});
|
|
535
|
+
req.end();
|
|
493
536
|
}
|
|
494
537
|
catch (e) {
|
|
495
538
|
this.errorLog(`Bot: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
@@ -566,7 +609,7 @@ class Bot {
|
|
|
566
609
|
if (this.platform.debugMode) {
|
|
567
610
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
568
611
|
}
|
|
569
|
-
if (this.platform.config.credentials?.
|
|
612
|
+
if (this.platform.config.credentials?.token) {
|
|
570
613
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
571
614
|
await this.openAPIpushChanges();
|
|
572
615
|
}
|
|
@@ -594,7 +637,7 @@ class Bot {
|
|
|
594
637
|
if (this.platform.debugMode) {
|
|
595
638
|
this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
596
639
|
}
|
|
597
|
-
if (this.platform.config.credentials?.
|
|
640
|
+
if (this.platform.config.credentials?.token) {
|
|
598
641
|
this.warnLog(`Bot: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
599
642
|
await this.openAPIpushChanges();
|
|
600
643
|
}
|
|
@@ -622,38 +665,71 @@ class Bot {
|
|
|
622
665
|
});
|
|
623
666
|
}
|
|
624
667
|
async openAPIpushChanges() {
|
|
625
|
-
if (this.platform.config.credentials?.
|
|
668
|
+
if (this.platform.config.credentials?.token) {
|
|
626
669
|
try {
|
|
627
670
|
if (this.On !== this.OnCached || this.allowPush) {
|
|
628
671
|
this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
672
|
+
// Make Push On request to the API
|
|
673
|
+
const t = Date.now();
|
|
674
|
+
const nonce = 'requestID';
|
|
675
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
676
|
+
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
677
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
678
|
+
.digest();
|
|
679
|
+
const sign = signTerm.toString('base64');
|
|
680
|
+
this.debugLog(`Bot: ${this.accessory.displayName} sign: ${sign}`);
|
|
681
|
+
let command = '';
|
|
633
682
|
if (this.botMode === 'switch' && this.On) {
|
|
634
|
-
|
|
683
|
+
command = 'turnOn';
|
|
635
684
|
this.On = true;
|
|
636
685
|
this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
|
|
637
686
|
}
|
|
638
687
|
else if (this.botMode === 'switch' && !this.On) {
|
|
639
|
-
|
|
688
|
+
command = 'turnOff';
|
|
640
689
|
this.On = false;
|
|
641
690
|
this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
|
|
642
691
|
}
|
|
643
692
|
else if (this.botMode === 'press') {
|
|
644
|
-
|
|
693
|
+
command = 'press';
|
|
645
694
|
this.debugLog(`Bot: ${this.accessory.displayName} Press Mode`);
|
|
646
695
|
this.On = false;
|
|
647
696
|
}
|
|
648
697
|
else {
|
|
649
698
|
throw new Error(`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
|
|
650
699
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
this.
|
|
700
|
+
const body = JSON.stringify({
|
|
701
|
+
'command': `${command}`,
|
|
702
|
+
'parameter': 'default',
|
|
703
|
+
'commandType': 'command',
|
|
704
|
+
});
|
|
705
|
+
this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
706
|
+
const options = {
|
|
707
|
+
hostname: settings_1.HostDomain,
|
|
708
|
+
port: 443,
|
|
709
|
+
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
710
|
+
method: 'POST',
|
|
711
|
+
headers: {
|
|
712
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
713
|
+
'sign': sign,
|
|
714
|
+
'nonce': nonce,
|
|
715
|
+
't': t,
|
|
716
|
+
'Content-Type': 'application/json',
|
|
717
|
+
'Content-Length': body.length,
|
|
718
|
+
},
|
|
719
|
+
};
|
|
720
|
+
const req = https_1.default.request(options, res => {
|
|
721
|
+
this.debugLog(`Bot: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
722
|
+
this.statusCode({ res });
|
|
723
|
+
res.on('data', d => {
|
|
724
|
+
this.debugLog(`Bot: ${this.accessory.displayName} d: ${d}`);
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
req.on('error', (e) => {
|
|
728
|
+
this.errorLog(`Bot: ${this.accessory.displayName} error message: ${e.message}`);
|
|
729
|
+
});
|
|
730
|
+
req.write(body);
|
|
731
|
+
req.end();
|
|
732
|
+
this.debugLog(`Bot: ${this.accessory.displayName} openAPIpushChanges: ${JSON.stringify(req)}`);
|
|
657
733
|
this.OnCached = this.On;
|
|
658
734
|
this.accessory.context.On = this.OnCached;
|
|
659
735
|
}
|
|
@@ -902,8 +978,8 @@ class Bot {
|
|
|
902
978
|
}
|
|
903
979
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
904
980
|
}
|
|
905
|
-
async statusCode(
|
|
906
|
-
switch (
|
|
981
|
+
async statusCode({ res }) {
|
|
982
|
+
switch (res.statusCode) {
|
|
907
983
|
case 151:
|
|
908
984
|
this.errorLog(`Bot: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
909
985
|
break;
|
|
@@ -923,7 +999,7 @@ class Bot {
|
|
|
923
999
|
break;
|
|
924
1000
|
case 190:
|
|
925
1001
|
this.errorLog(`Bot: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
926
|
-
` Or command: ${JSON.stringify(
|
|
1002
|
+
` Or command: ${JSON.stringify(res)} format is invalid`);
|
|
927
1003
|
break;
|
|
928
1004
|
case 100:
|
|
929
1005
|
this.debugLog(`Bot: ${this.accessory.displayName} Command successfully sent.`);
|