@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.
Files changed (104) hide show
  1. package/.github/Old Releaser.zip +0 -0
  2. package/.github/npm-version-script.js +81 -0
  3. package/.github/workflows/beta-release.yml +31 -0
  4. package/.github/workflows/build.yml +18 -0
  5. package/.github/workflows/codeql-analysis.yml +5 -63
  6. package/.github/workflows/label.yml +2 -2
  7. package/.github/workflows/release-drafter.yml +14 -0
  8. package/.github/workflows/release.yml +24 -0
  9. package/.github/workflows/stale.yml +6 -22
  10. package/README.md +10 -3
  11. package/dist/device/bot.d.ts.map +1 -1
  12. package/dist/device/bot.js +33 -29
  13. package/dist/device/bot.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +1 -0
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +129 -97
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.js +1 -1
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts.map +1 -1
  21. package/dist/device/curtain.js +34 -26
  22. package/dist/device/curtain.js.map +1 -1
  23. package/dist/device/humidifier.d.ts.map +1 -1
  24. package/dist/device/humidifier.js +88 -92
  25. package/dist/device/humidifier.js.map +1 -1
  26. package/dist/device/lock.d.ts.map +1 -1
  27. package/dist/device/lock.js +29 -25
  28. package/dist/device/lock.js.map +1 -1
  29. package/dist/device/meter.js +1 -1
  30. package/dist/device/meter.js.map +1 -1
  31. package/dist/device/meterplus.js +1 -1
  32. package/dist/device/meterplus.js.map +1 -1
  33. package/dist/device/motion.js +1 -1
  34. package/dist/device/motion.js.map +1 -1
  35. package/dist/device/plug.d.ts.map +1 -1
  36. package/dist/device/plug.js +31 -27
  37. package/dist/device/plug.js.map +1 -1
  38. package/dist/device/striplight.d.ts.map +1 -1
  39. package/dist/device/striplight.js +81 -72
  40. package/dist/device/striplight.js.map +1 -1
  41. package/dist/irdevice/airconditioner.d.ts +2 -2
  42. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  43. package/dist/irdevice/airconditioner.js +35 -32
  44. package/dist/irdevice/airconditioner.js.map +1 -1
  45. package/dist/irdevice/airpurifier.d.ts +2 -2
  46. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  47. package/dist/irdevice/airpurifier.js +35 -32
  48. package/dist/irdevice/airpurifier.js.map +1 -1
  49. package/dist/irdevice/camera.d.ts +2 -2
  50. package/dist/irdevice/camera.d.ts.map +1 -1
  51. package/dist/irdevice/camera.js +28 -26
  52. package/dist/irdevice/camera.js.map +1 -1
  53. package/dist/irdevice/fan.d.ts +2 -2
  54. package/dist/irdevice/fan.d.ts.map +1 -1
  55. package/dist/irdevice/fan.js +47 -45
  56. package/dist/irdevice/fan.js.map +1 -1
  57. package/dist/irdevice/light.d.ts +2 -2
  58. package/dist/irdevice/light.d.ts.map +1 -1
  59. package/dist/irdevice/light.js +40 -38
  60. package/dist/irdevice/light.js.map +1 -1
  61. package/dist/irdevice/other.d.ts +2 -2
  62. package/dist/irdevice/other.d.ts.map +1 -1
  63. package/dist/irdevice/other.js +28 -26
  64. package/dist/irdevice/other.js.map +1 -1
  65. package/dist/irdevice/tv.d.ts +2 -2
  66. package/dist/irdevice/tv.d.ts.map +1 -1
  67. package/dist/irdevice/tv.js +82 -80
  68. package/dist/irdevice/tv.js.map +1 -1
  69. package/dist/irdevice/vacuumcleaner.d.ts +2 -2
  70. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  71. package/dist/irdevice/vacuumcleaner.js +24 -22
  72. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  73. package/dist/irdevice/waterheater.d.ts +2 -2
  74. package/dist/irdevice/waterheater.d.ts.map +1 -1
  75. package/dist/irdevice/waterheater.js +28 -26
  76. package/dist/irdevice/waterheater.js.map +1 -1
  77. package/dist/settings.d.ts +0 -5
  78. package/dist/settings.d.ts.map +1 -1
  79. package/dist/settings.js.map +1 -1
  80. package/package.json +79 -79
  81. package/src/device/bot.ts +34 -39
  82. package/src/device/colorbulb.ts +130 -119
  83. package/src/device/contact.ts +1 -1
  84. package/src/device/curtain.ts +35 -35
  85. package/src/device/humidifier.ts +89 -118
  86. package/src/device/lock.ts +29 -34
  87. package/src/device/meter.ts +1 -1
  88. package/src/device/meterplus.ts +1 -1
  89. package/src/device/motion.ts +1 -1
  90. package/src/device/plug.ts +32 -36
  91. package/src/device/striplight.ts +82 -98
  92. package/src/irdevice/airconditioner.ts +36 -41
  93. package/src/irdevice/airpurifier.ts +36 -43
  94. package/src/irdevice/camera.ts +29 -34
  95. package/src/irdevice/fan.ts +48 -53
  96. package/src/irdevice/light.ts +41 -46
  97. package/src/irdevice/other.ts +29 -34
  98. package/src/irdevice/tv.ts +83 -88
  99. package/src/irdevice/vacuumcleaner.ts +25 -30
  100. package/src/irdevice/waterheater.ts +29 -34
  101. package/src/settings.ts +0 -19
  102. package/.github/workflows/nodejs-beta.yml +0 -42
  103. package/.github/workflows/nodejs.yml +0 -47
  104. package/.github/workflows/prerelease-beta.js +0 -34
Binary file
@@ -0,0 +1,81 @@
1
+ #!/bin/env node
2
+
3
+ /**
4
+ * This scripts queries the npm registry to pull out the latest version for a given tag.
5
+ */
6
+
7
+ const fs = require("fs");
8
+ const semver = require("semver");
9
+ const child_process = require("child_process");
10
+ const assert = require("assert");
11
+
12
+ const BRANCH_VERSION_PATTERN = /^([A-Za-z]*)-(\d+.\d+.\d+)$/
13
+
14
+ // Load the contents of the package.json file
15
+ const packageJSON = JSON.parse(fs.readFileSync("package.json", "utf8"));
16
+
17
+ let refArgument = process.argv[2];
18
+ let tagArgument = process.argv[3] || "latest";
19
+
20
+ if (refArgument == null) {
21
+ console.error("ref argument is missing");
22
+ console.error("Usage: npm-version-script.js <ref> [tag]");
23
+ process.exit(1);
24
+ }
25
+
26
+ /**
27
+ * Queries the NPM registry for the latest version for the provided tag.
28
+ * @param tag The tag to query for.
29
+ * @returns {string} Returns the version.
30
+ */
31
+ function getTagVersionFromNpm(tag) {
32
+ try {
33
+ return child_process.execSync(`npm info ${packageJSON.name} version --tag="${tag}"`).toString("utf8").trim();
34
+ } catch (e) {
35
+ throw e;
36
+ }
37
+ }
38
+
39
+ function desiredTargetVersion(ref) {
40
+ // ref is a GitHub action ref string
41
+ if (ref.startsWith("refs/pull/")) {
42
+ throw Error("The version script was executed inside a PR!");
43
+ }
44
+
45
+ assert(ref.startsWith("refs/heads/"))
46
+ let branchName = ref.slice("refs/heads/".length);
47
+
48
+ let results = branchName.match(BRANCH_VERSION_PATTERN);
49
+ if (results != null) {
50
+ if (results[1] !== tagArgument) {
51
+ console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`);
52
+ }
53
+
54
+ return results[2];
55
+ }
56
+
57
+ // legacy mode were we use the `betaVersion` property in the package.json
58
+ if (branchName === "beta" && packageJSON.betaVersion) {
59
+ return packageJSON.betaVersion
60
+ }
61
+
62
+ throw new Error("Malformed branch name for ref: " + ref + ". Can't derive the base version. Use a branch name like: beta-x.x.x!");
63
+ }
64
+
65
+ // derive the base version from the branch ref
66
+ const baseVersion = desiredTargetVersion(refArgument);
67
+
68
+ // query the npm registry for the latest version of the provided tag name
69
+ const latestReleasedVersion = getTagVersionFromNpm(tagArgument); // e.g. 0.7.0-beta.12
70
+ const latestReleaseBase = semver.inc(latestReleasedVersion, "patch"); // will produce 0.7.0 (removing the preid, needed for the equality check below)
71
+
72
+ let publishTag;
73
+ if (semver.eq(baseVersion, latestReleaseBase)) { // check if we are releasing another version for the latest beta
74
+ publishTag = latestReleasedVersion; // set the current latest beta to be incremented
75
+ } else {
76
+ publishTag = baseVersion; // start of with a new beta version
77
+ }
78
+
79
+ // save the package.json
80
+ packageJSON.version = publishTag;
81
+ fs.writeFileSync("package.json", JSON.stringify(packageJSON, null, 2));
@@ -0,0 +1,31 @@
1
+ name: Node-CI Beta
2
+
3
+ on:
4
+ push:
5
+ branches: [beta-*.*.*, beta]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ build_and_test:
10
+ uses: OpenWonderLabs/.github/.github/workflows/nodejs-build-and-test.yml@latest
11
+ with:
12
+ enable_coverage: true
13
+ secrets:
14
+ token: ${{ secrets.GITHUB_TOKEN }}
15
+ lint:
16
+ needs: build_and_test
17
+ uses: OpenWonderLabs/.github/.github/workflows/eslint.yml@latest
18
+
19
+ publish:
20
+ needs: lint
21
+
22
+ if: ${{ github.repository == 'OpenWonderLabs/homebridge-switchbot' }}
23
+
24
+ uses: OpenWonderLabs/.github/.github/workflows/npm-publish.yml@latest
25
+ with:
26
+ tag: 'beta'
27
+ dynamically_adjust_version: true
28
+ npm_version_command: 'pre'
29
+ pre_id: 'beta'
30
+ secrets:
31
+ npm_auth_token: ${{ secrets.npm_token }}
@@ -0,0 +1,18 @@
1
+ name: Node Build
2
+
3
+ on:
4
+ push:
5
+ branches: [latest]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ build_and_test:
11
+ uses: OpenWonderLabs/.github/.github/workflows/nodejs-build-and-test.yml@latest
12
+ with:
13
+ enable_coverage: true
14
+ secrets:
15
+ token: ${{ secrets.GITHUB_TOKEN }}
16
+ lint:
17
+ needs: build_and_test
18
+ uses: OpenWonderLabs/.github/.github/workflows/eslint.yml@latest
@@ -1,71 +1,13 @@
1
- # For most projects, this workflow file will not need changing; you simply need
2
- # to commit it to your repository.
3
- #
4
- # You may wish to alter this file to override the set of languages analyzed,
5
- # or to provide custom queries or build logic.
6
- #
7
- # ******** NOTE ********
8
- # We have attempted to detect the languages in your repository. Please check
9
- # the `language` matrix defined below to confirm you have the correct set of
10
- # supported CodeQL languages.
11
- #
12
- name: 'CodeQL'
1
+ name: "CodeQL"
13
2
 
14
3
  on:
15
4
  push:
16
- branches: [beta]
5
+ branches: [ latest, beta* ]
17
6
  pull_request:
18
- # The branches below must be a subset of the branches above
19
- branches: [beta]
7
+ branches: [ latest, beta* ]
20
8
  schedule:
21
- - cron: '39 20 * * 5'
9
+ - cron: '17 9 * * 2'
22
10
 
23
11
  jobs:
24
12
  analyze:
25
- name: Analyze
26
- runs-on: ubuntu-latest
27
- permissions:
28
- actions: read
29
- contents: read
30
- security-events: write
31
-
32
- strategy:
33
- fail-fast: false
34
- matrix:
35
- language: ['javascript']
36
- # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37
- # Learn more:
38
- # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39
-
40
- steps:
41
- - name: Checkout repository
42
- uses: actions/checkout@v3
43
-
44
- # Initializes the CodeQL tools for scanning.
45
- - name: Initialize CodeQL
46
- uses: github/codeql-action/init@v2
47
- with:
48
- languages: ${{ matrix.language }}
49
- # If you wish to specify custom queries, you can do so here or in a config file.
50
- # By default, queries listed here will override any specified in a config file.
51
- # Prefix the list here with "+" to use these queries and those in the config file.
52
- # queries: ./path/to/local/query, your-org/your-repo/queries@main
53
-
54
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55
- # If this step fails, then you should remove it and run the build manually (see below)
56
- - name: Autobuild
57
- uses: github/codeql-action/autobuild@v2
58
-
59
- # ℹ️ Command-line programs to run using the OS shell.
60
- # 📚 https://git.io/JvXDl
61
-
62
- # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63
- # and modify them (or add more) to build your code if your project
64
- # uses a compiled language
65
-
66
- #- run: |
67
- # make bootstrap
68
- # make release
69
-
70
- - name: Perform CodeQL Analysis
71
- uses: github/codeql-action/analyze@v2
13
+ uses: OpenWonderLabs/.github/.github/workflows/codeql-analysis.yml@latest
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # To use this workflow, you will need to set up a .github/labeler.yml
5
5
  # file with configuration. For more information, see:
6
- # https://github.com/actions/labeler/blob/master/README.md
6
+ # https://github.com/actions/labeler/blob/main/README.md
7
7
 
8
8
  name: Labeler
9
9
  on: [pull_request]
@@ -13,6 +13,6 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
 
15
15
  steps:
16
- - uses: actions/labeler@v4
16
+ - uses: OpenWonderLabs/.github/.github/workflows/labeler.yml@latest
17
17
  with:
18
18
  repo-token: '${{ secrets.GITHUB_TOKEN }}'
@@ -0,0 +1,14 @@
1
+ name: Release Drafter
2
+
3
+ on:
4
+ push:
5
+ branches: [latest]
6
+ pull_request: # required for autolabeler
7
+ types: [opened, reopened, synchronize]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ stale:
12
+ uses: OpenWonderLabs/.github/.github/workflows/release-drafter.yml@latest
13
+ secrets:
14
+ token: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,24 @@
1
+ name: Node Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*.*.*'
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ build_and_test:
11
+ uses: OpenWonderLabs/.github/.github/workflows/nodejs-build-and-test.yml@latest
12
+ with:
13
+ enable_coverage: true
14
+ secrets:
15
+ token: ${{ secrets.GITHUB_TOKEN }}
16
+
17
+ publish:
18
+ needs: build_and_test
19
+
20
+ if: ${{ github.repository == 'OpenWonderLabs/homebridge-switchbot' }}
21
+
22
+ uses: OpenWonderLabs/.github/.github/workflows/npm-publish.yml@latest
23
+ secrets:
24
+ npm_auth_token: ${{ secrets.npm_token }}
@@ -1,28 +1,12 @@
1
- name: Stale
1
+ name: Stale workflow
2
2
 
3
3
  on:
4
- issues:
5
- types: [reopened]
4
+ workflow_dispatch:
6
5
  schedule:
7
- - cron: '*/60 * * * *'
6
+ - cron: '45 11 * * *'
8
7
 
9
8
  jobs:
10
9
  stale:
11
- runs-on: ubuntu-latest
12
- env:
13
- ACTIONS_STEP_DEBUG: true
14
- steps:
15
- - uses: actions/stale@v5
16
- with:
17
- repo-token: ${{ secrets.GITHUB_TOKEN }}
18
- stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
19
- stale-pr-message: 'This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
20
- stale-issue-label: 'stale'
21
- stale-pr-label: 'stale'
22
- days-before-stale: 15
23
- days-before-close: 2
24
- exempt-issue-labels: 'pinned'
25
- exempt-pr-labels: 'awaiting-approval,work-in-progress'
26
- remove-stale-when-updated: true
27
- close-issue-message: 'This issue has been automatically closed because it has not had recent activity. Thank you for your contributions.'
28
- close-pr-message: 'This pull request has been automatically closed because it has not had recent activity. Thank you for your contributions.'
10
+ uses: OpenWonderLabs/.github/.github/workflows/stale.yml@latest
11
+ secrets:
12
+ token: ${{ secrets.GITHUB_TOKEN }}
package/README.md CHANGED
@@ -27,13 +27,20 @@ plugin allows you to access your SwitchBot Device(s) from HomeKit with
27
27
  - ### If using OpenAPI Connection
28
28
  1. Download SwitchBot App on App Store or Google Play Store
29
29
  2. Register a SwitchBot account and log in into your account
30
- 3. Generate an Open Token within the App
30
+ 3. Generate an Token within the App
31
31
  - Click Bottom Profile Tab
32
32
  - Click Preference
33
33
  - Click App version 10 Times, this will enable Developer Options
34
34
  - Click Developer Options
35
- - Click Copy to Clipboard
36
- 4. Input your `openToken` into the config paramter
35
+ - Click Copy `token` to Clipboard
36
+ 4. Input your `token` into the config parameter
37
+ 5. Generate an Secret within the App
38
+ - Click Bottom Profile Tab
39
+ - Click Preference
40
+ - Click App version 10 Times, this will enable Developer Options
41
+ - Click Developer Options
42
+ - Click Copy `secret` to Clipboard
43
+ 6. Input your `secret` into the config parameter
37
44
  - ### If using BLE Connection
38
45
  1. Download SwitchBot App on App Store or Google Play Store
39
46
  2. Register a SwitchBot account and log in into your account
@@ -1 +1 @@
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,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AG,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"}
@@ -478,7 +478,7 @@ class Bot {
478
478
  });
479
479
  // Set an event handler
480
480
  switchbot.onadvertisement = (ad) => {
481
- this.warnLog(JSON.stringify(ad, null, ' '));
481
+ this.warnLog(`Bot: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
482
482
  };
483
483
  await switchbot.wait(10000);
484
484
  // Stop to monitor
@@ -669,63 +669,67 @@ class Bot {
669
669
  try {
670
670
  if (this.On !== this.OnCached || this.allowPush) {
671
671
  this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI pushChanges`);
672
- const payload = {
673
- commandType: 'command',
674
- parameter: 'default',
675
- };
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 = '';
676
682
  if (this.botMode === 'switch' && this.On) {
677
- payload.command = 'turnOn';
683
+ command = 'turnOn';
678
684
  this.On = true;
679
685
  this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
680
686
  }
681
687
  else if (this.botMode === 'switch' && !this.On) {
682
- payload.command = 'turnOff';
688
+ command = 'turnOff';
683
689
  this.On = false;
684
690
  this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`);
685
691
  }
686
692
  else if (this.botMode === 'press') {
687
- payload.command = 'press';
693
+ command = 'press';
688
694
  this.debugLog(`Bot: ${this.accessory.displayName} Press Mode`);
689
695
  this.On = false;
690
696
  }
691
697
  else {
692
698
  throw new Error(`Bot: ${this.accessory.displayName} Device Paramters not set for this Bot.`);
693
699
  }
694
- this.infoLog(`Bot: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
695
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
696
- // Make the API request
697
- const t = Date.now();
698
- const nonce = 'requestID';
699
- const data = this.platform.config.credentials?.token + t + nonce;
700
- const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
701
- const sign = signTerm.toString('base64');
702
- this.debugLog(`Bot: ${this.accessory.displayName} sign: ${sign}`);
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},`);
703
706
  const options = {
704
707
  hostname: settings_1.HostDomain,
705
708
  port: 443,
706
709
  path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
707
710
  method: 'POST',
708
711
  headers: {
709
- Authorization: this.platform.config.credentials?.token,
710
- sign: sign,
711
- nonce: nonce,
712
- t: t,
712
+ 'Authorization': this.platform.config.credentials?.token,
713
+ 'sign': sign,
714
+ 'nonce': nonce,
715
+ 't': t,
713
716
  'Content-Type': 'application/json',
717
+ 'Content-Length': body.length,
714
718
  },
715
719
  };
716
- const req = https_1.default.request(options, (res) => {
717
- this.debugLog(`Bot: ${this.accessory.displayName} Push statusCode: ${res.statusCode}`);
720
+ const req = https_1.default.request(options, res => {
721
+ this.debugLog(`Bot: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
718
722
  this.statusCode({ res });
719
- res.on('data', (d) => {
720
- this.debugLog(`d: ${d}`);
723
+ res.on('data', d => {
724
+ this.debugLog(`Bot: ${this.accessory.displayName} d: ${d}`);
721
725
  });
722
726
  });
723
- req.on('error', (error) => {
724
- this.errorLog(`Bot: ${this.accessory.displayName} error: ${error}`);
727
+ req.on('error', (e) => {
728
+ this.errorLog(`Bot: ${this.accessory.displayName} error message: ${e.message}`);
725
729
  });
726
- req.write(payload);
730
+ req.write(body);
727
731
  req.end();
728
- this.debugLog(`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
732
+ this.debugLog(`Bot: ${this.accessory.displayName} openAPIpushChanges: ${JSON.stringify(req)}`);
729
733
  this.OnCached = this.On;
730
734
  this.accessory.context.On = this.OnCached;
731
735
  }