@switchbot/homebridge-switchbot 2.10.1-beta.1 → 2.10.1

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 (55) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +23 -0
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +23 -0
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.d.ts.map +1 -1
  9. package/dist/device/ceilinglight.js +23 -0
  10. package/dist/device/ceilinglight.js.map +1 -1
  11. package/dist/device/colorbulb.d.ts.map +1 -1
  12. package/dist/device/colorbulb.js +36 -0
  13. package/dist/device/colorbulb.js.map +1 -1
  14. package/dist/device/contact.d.ts.map +1 -1
  15. package/dist/device/contact.js +25 -0
  16. package/dist/device/contact.js.map +1 -1
  17. package/dist/device/curtain.d.ts.map +1 -1
  18. package/dist/device/curtain.js +22 -0
  19. package/dist/device/curtain.js.map +1 -1
  20. package/dist/device/hub.d.ts.map +1 -1
  21. package/dist/device/hub.js +92 -6
  22. package/dist/device/hub.js.map +1 -1
  23. package/dist/device/humidifier.d.ts.map +1 -1
  24. package/dist/device/humidifier.js +24 -0
  25. package/dist/device/humidifier.js.map +1 -1
  26. package/dist/device/lightstrip.d.ts.map +1 -1
  27. package/dist/device/lightstrip.js +35 -0
  28. package/dist/device/lightstrip.js.map +1 -1
  29. package/dist/device/lock.d.ts.map +1 -1
  30. package/dist/device/lock.js +21 -0
  31. package/dist/device/lock.js.map +1 -1
  32. package/dist/device/motion.d.ts.map +1 -1
  33. package/dist/device/motion.js +21 -0
  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 +21 -0
  37. package/dist/device/plug.js.map +1 -1
  38. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  39. package/dist/device/robotvacuumcleaner.js +22 -0
  40. package/dist/device/robotvacuumcleaner.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/device/blindtilt.ts +23 -0
  43. package/src/device/bot.ts +23 -0
  44. package/src/device/ceilinglight.ts +23 -0
  45. package/src/device/colorbulb.ts +43 -0
  46. package/src/device/contact.ts +25 -0
  47. package/src/device/curtain.ts +22 -0
  48. package/src/device/hub.ts +94 -6
  49. package/src/device/humidifier.ts +24 -0
  50. package/src/device/lightstrip.ts +42 -0
  51. package/src/device/lock.ts +21 -0
  52. package/src/device/motion.ts +21 -0
  53. package/src/device/plug.ts +21 -0
  54. package/src/device/robotvacuumcleaner.ts +22 -0
  55. package/.github/npm-version-script.js +0 -81
@@ -88,6 +88,27 @@ export class Plug {
88
88
  await this.refreshStatus();
89
89
  });
90
90
 
91
+ //regisiter webhook event handler
92
+ if (this.device.webhook) {
93
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
94
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
95
+ try {
96
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
97
+ const { powerState } = context;
98
+ const { On } = this;
99
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
100
+ '(powerState) = ' +
101
+ `Webhook:(${powerState}), ` +
102
+ `current:(${On})`);
103
+ this.On = powerState === 'ON' ? true : false;
104
+ this.updateHomeKitCharacteristics();
105
+ } catch (e: any) {
106
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
107
+ + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
108
+ }
109
+ };
110
+ }
111
+
91
112
  // Watch for Plug change events
92
113
  // We put in a debounce of 100ms so we don't make duplicate calls
93
114
  this.doPlugUpdate
@@ -120,6 +120,28 @@ export class RobotVacuumCleaner {
120
120
  await this.refreshStatus();
121
121
  });
122
122
 
123
+ //regisiter webhook event handler
124
+ if (this.device.webhook) {
125
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
126
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
127
+ try {
128
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
129
+ const { onlineStatus, battery } = context;
130
+ const { On, BatteryLevel } = this;
131
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
132
+ '(onlineStatus, battery) = ' +
133
+ `Webhook:(${onlineStatus}, ${battery}), ` +
134
+ `current:(${On}, ${BatteryLevel})`);
135
+ this.On = onlineStatus === 'online' ? true : false;
136
+ this.BatteryLevel = battery;
137
+ this.updateHomeKitCharacteristics();
138
+ } catch (e: any) {
139
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
140
+ + `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
141
+ }
142
+ };
143
+ }
144
+
123
145
  // Watch for Plug change events
124
146
  // We put in a debounce of 100ms so we don't make duplicate calls
125
147
  this.doRobotVacuumCleanerUpdate
@@ -1,81 +0,0 @@
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));