@switchbot/homebridge-switchbot 2.14.1-beta.0 → 3.0.0-beta.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 (147) hide show
  1. package/.github/{npm-version-script.js → npm-version-script.cjs} +1 -1
  2. package/.github/workflows/dependabot.yml +10 -11
  3. package/CHANGELOG.md +11 -2
  4. package/LICENSE +1 -1
  5. package/dist/device/blindtilt.d.ts +10 -6
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +152 -91
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts +10 -6
  10. package/dist/device/bot.d.ts.map +1 -1
  11. package/dist/device/bot.js +234 -184
  12. package/dist/device/bot.js.map +1 -1
  13. package/dist/device/ceilinglight.d.ts +10 -6
  14. package/dist/device/ceilinglight.d.ts.map +1 -1
  15. package/dist/device/ceilinglight.js +110 -64
  16. package/dist/device/ceilinglight.js.map +1 -1
  17. package/dist/device/colorbulb.d.ts +10 -6
  18. package/dist/device/colorbulb.d.ts.map +1 -1
  19. package/dist/device/colorbulb.js +121 -69
  20. package/dist/device/colorbulb.js.map +1 -1
  21. package/dist/device/contact.d.ts +10 -6
  22. package/dist/device/contact.d.ts.map +1 -1
  23. package/dist/device/contact.js +111 -66
  24. package/dist/device/contact.js.map +1 -1
  25. package/dist/device/curtain.d.ts +10 -6
  26. package/dist/device/curtain.d.ts.map +1 -1
  27. package/dist/device/curtain.js +165 -107
  28. package/dist/device/curtain.js.map +1 -1
  29. package/dist/device/hub.d.ts +10 -6
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +88 -51
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts +10 -6
  34. package/dist/device/humidifier.d.ts.map +1 -1
  35. package/dist/device/humidifier.js +133 -90
  36. package/dist/device/humidifier.js.map +1 -1
  37. package/dist/device/iosensor.d.ts +10 -6
  38. package/dist/device/iosensor.d.ts.map +1 -1
  39. package/dist/device/iosensor.js +109 -66
  40. package/dist/device/iosensor.js.map +1 -1
  41. package/dist/device/lightstrip.d.ts +10 -6
  42. package/dist/device/lightstrip.d.ts.map +1 -1
  43. package/dist/device/lightstrip.js +110 -65
  44. package/dist/device/lightstrip.js.map +1 -1
  45. package/dist/device/lock.d.ts +11 -7
  46. package/dist/device/lock.d.ts.map +1 -1
  47. package/dist/device/lock.js +125 -84
  48. package/dist/device/lock.js.map +1 -1
  49. package/dist/device/meter.d.ts +10 -6
  50. package/dist/device/meter.d.ts.map +1 -1
  51. package/dist/device/meter.js +103 -63
  52. package/dist/device/meter.js.map +1 -1
  53. package/dist/device/meterplus.d.ts +10 -6
  54. package/dist/device/meterplus.d.ts.map +1 -1
  55. package/dist/device/meterplus.js +103 -63
  56. package/dist/device/meterplus.js.map +1 -1
  57. package/dist/device/motion.d.ts +10 -6
  58. package/dist/device/motion.d.ts.map +1 -1
  59. package/dist/device/motion.js +95 -54
  60. package/dist/device/motion.js.map +1 -1
  61. package/dist/device/plug.d.ts +10 -6
  62. package/dist/device/plug.d.ts.map +1 -1
  63. package/dist/device/plug.js +68 -40
  64. package/dist/device/plug.js.map +1 -1
  65. package/dist/device/robotvacuumcleaner.d.ts +10 -6
  66. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  67. package/dist/device/robotvacuumcleaner.js +86 -52
  68. package/dist/device/robotvacuumcleaner.js.map +1 -1
  69. package/dist/homebridge-ui/server.js +5 -10
  70. package/dist/homebridge-ui/server.js.map +1 -1
  71. package/dist/index.d.ts +1 -4
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +9 -5
  74. package/dist/index.js.map +1 -1
  75. package/dist/irdevice/airconditioner.d.ts +9 -5
  76. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  77. package/dist/irdevice/airconditioner.js +105 -71
  78. package/dist/irdevice/airconditioner.js.map +1 -1
  79. package/dist/irdevice/airpurifier.d.ts +9 -5
  80. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  81. package/dist/irdevice/airpurifier.js +78 -46
  82. package/dist/irdevice/airpurifier.js.map +1 -1
  83. package/dist/irdevice/camera.d.ts +9 -5
  84. package/dist/irdevice/camera.d.ts.map +1 -1
  85. package/dist/irdevice/camera.js +41 -25
  86. package/dist/irdevice/camera.js.map +1 -1
  87. package/dist/irdevice/fan.d.ts +9 -5
  88. package/dist/irdevice/fan.d.ts.map +1 -1
  89. package/dist/irdevice/fan.js +62 -39
  90. package/dist/irdevice/fan.js.map +1 -1
  91. package/dist/irdevice/light.d.ts +9 -5
  92. package/dist/irdevice/light.d.ts.map +1 -1
  93. package/dist/irdevice/light.js +67 -45
  94. package/dist/irdevice/light.js.map +1 -1
  95. package/dist/irdevice/other.d.ts +9 -5
  96. package/dist/irdevice/other.d.ts.map +1 -1
  97. package/dist/irdevice/other.js +176 -150
  98. package/dist/irdevice/other.js.map +1 -1
  99. package/dist/irdevice/tv.d.ts +9 -5
  100. package/dist/irdevice/tv.d.ts.map +1 -1
  101. package/dist/irdevice/tv.js +81 -62
  102. package/dist/irdevice/tv.js.map +1 -1
  103. package/dist/irdevice/vacuumcleaner.d.ts +9 -5
  104. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  105. package/dist/irdevice/vacuumcleaner.js +41 -25
  106. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  107. package/dist/irdevice/waterheater.d.ts +9 -5
  108. package/dist/irdevice/waterheater.d.ts.map +1 -1
  109. package/dist/irdevice/waterheater.js +48 -32
  110. package/dist/irdevice/waterheater.js.map +1 -1
  111. package/dist/platform.d.ts +8 -9
  112. package/dist/platform.d.ts.map +1 -1
  113. package/dist/platform.js +151 -162
  114. package/dist/platform.js.map +1 -1
  115. package/dist/settings.js +7 -14
  116. package/dist/settings.js.map +1 -1
  117. package/dist/utils.js +1 -5
  118. package/dist/utils.js.map +1 -1
  119. package/package.json +20 -9
  120. package/src/device/blindtilt.ts +84 -72
  121. package/src/device/bot.ts +191 -180
  122. package/src/device/ceilinglight.ts +57 -44
  123. package/src/device/colorbulb.ts +53 -40
  124. package/src/device/contact.ts +71 -60
  125. package/src/device/curtain.ts +98 -86
  126. package/src/device/hub.ts +57 -45
  127. package/src/device/humidifier.ts +88 -77
  128. package/src/device/iosensor.ts +67 -55
  129. package/src/device/lightstrip.ts +56 -43
  130. package/src/device/lock.ts +91 -81
  131. package/src/device/meter.ts +63 -51
  132. package/src/device/meterplus.ts +67 -55
  133. package/src/device/motion.ts +58 -47
  134. package/src/device/plug.ts +38 -27
  135. package/src/device/robotvacuumcleaner.ts +49 -38
  136. package/src/index.ts +10 -7
  137. package/src/irdevice/airconditioner.ts +71 -63
  138. package/src/irdevice/airpurifier.ts +48 -40
  139. package/src/irdevice/camera.ts +28 -20
  140. package/src/irdevice/fan.ts +42 -34
  141. package/src/irdevice/light.ts +48 -40
  142. package/src/irdevice/other.ts +164 -156
  143. package/src/irdevice/tv.ts +66 -58
  144. package/src/irdevice/vacuumcleaner.ts +28 -20
  145. package/src/irdevice/waterheater.ts +35 -27
  146. package/src/platform.ts +65 -47
  147. package/tsconfig.json +11 -13
package/src/platform.ts CHANGED
@@ -1,41 +1,45 @@
1
- import { Bot } from './device/bot';
2
- import { Plug } from './device/plug';
3
- import { Lock } from './device/lock';
4
- import { Meter } from './device/meter';
5
- import { Motion } from './device/motion';
6
- import { Hub } from './device/hub';
7
- import { Contact } from './device/contact';
8
- import { Curtain } from './device/curtain';
9
- import { IOSensor } from './device/iosensor';
10
- import { MeterPlus } from './device/meterplus';
11
- import { ColorBulb } from './device/colorbulb';
12
- import { CeilingLight } from './device/ceilinglight';
13
- import { StripLight } from './device/lightstrip';
14
- import { Humidifier } from './device/humidifier';
15
- import { RobotVacuumCleaner } from './device/robotvacuumcleaner';
16
- import { TV } from './irdevice/tv';
17
- import { Fan } from './irdevice/fan';
18
- import { Light } from './irdevice/light';
19
- import { Others } from './irdevice/other';
20
- import { Camera } from './irdevice/camera';
21
- import { BlindTilt } from './device/blindtilt';
22
- import { AirPurifier } from './irdevice/airpurifier';
23
- import { WaterHeater } from './irdevice/waterheater';
24
- import { VacuumCleaner } from './irdevice/vacuumcleaner';
25
- import { AirConditioner } from './irdevice/airconditioner';
26
- import { request } from 'undici';
27
- import crypto, { randomUUID } from 'crypto';
1
+ /* Copyright(C) 2017-2023, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * protect-platform.ts: homebridge-cloudflared-tunnel platform class.
4
+ */
5
+ import { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
6
+ import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, irDevicesConfig, Devices } from './settings.js';
7
+ import { Bot } from './device/bot.js';
8
+ import { Plug } from './device/plug.js';
9
+ import { Lock } from './device/lock.js';
10
+ import { Meter } from './device/meter.js';
11
+ import { Motion } from './device/motion.js';
12
+ import { Hub } from './device/hub.js';
13
+ import { Contact } from './device/contact.js';
14
+ import { Curtain } from './device/curtain.js';
15
+ import { IOSensor } from './device/iosensor.js';
16
+ import { MeterPlus } from './device/meterplus.js';
17
+ import { ColorBulb } from './device/colorbulb.js';
18
+ import { CeilingLight } from './device/ceilinglight.js';
19
+ import { StripLight } from './device/lightstrip.js';
20
+ import { Humidifier } from './device/humidifier.js';
21
+ import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
22
+ import { TV } from './irdevice/tv.js';
23
+ import { Fan } from './irdevice/fan.js';
24
+ import { Light } from './irdevice/light.js';
25
+ import { Others } from './irdevice/other.js';
26
+ import { Camera } from './irdevice/camera.js';
27
+ import { BlindTilt } from './device/blindtilt.js';
28
+ import { AirPurifier } from './irdevice/airpurifier.js';
29
+ import { WaterHeater } from './irdevice/waterheater.js';
30
+ import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
31
+ import { AirConditioner } from './irdevice/airconditioner.js';
32
+ import * as http from 'http';
28
33
  import { Buffer } from 'buffer';
34
+ import { request } from 'undici';
35
+ import { MqttClient } from 'mqtt';
29
36
  import { queueScheduler } from 'rxjs';
30
37
  import fakegato from 'fakegato-history';
31
- import { EveHomeKitTypes } from 'homebridge-lib';
32
- import { MqttClient } from 'mqtt';
33
- import { connectAsync } from 'async-mqtt';
34
- import * as http from 'http';
35
-
38
+ import asyncmqtt from 'async-mqtt';
39
+ import crypto, { randomUUID } from 'crypto';
36
40
  import { readFileSync, writeFileSync } from 'fs';
37
- import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
38
- import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, irDevicesConfig, Devices } from './settings';
41
+ import hbLib from 'homebridge-lib';
42
+
39
43
 
40
44
  /**
41
45
  * HomebridgePlatform
@@ -43,15 +47,15 @@ import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig,
43
47
  * parse the user config and discover/register accessories with Homebridge.
44
48
  */
45
49
  export class SwitchBotPlatform implements DynamicPlatformPlugin {
46
- public readonly Service: typeof Service = this.api.hap.Service;
47
- public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic;
48
-
49
- // this is used to track restored cached accessories
50
- public readonly accessories: PlatformAccessory[] = [];
50
+ public accessories: PlatformAccessory[];
51
+ public readonly api: API;
52
+ public readonly log: Logging;
51
53
 
52
- version = process.env.npm_package_version || '2.9.0';
54
+ version = process.env.npm_package_version || '2.13.0';
55
+ Logging?: string;
53
56
  debugMode!: boolean;
54
57
  platformLogging?: string;
58
+ config!: SwitchBotPlatformConfig;
55
59
  webhookEventListener: http.Server | null = null;
56
60
  mqttClient: MqttClient | null = null;
57
61
 
@@ -59,18 +63,30 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
59
63
  public readonly eve: any;
60
64
  public readonly webhookEventHandler: { [x: string]: (context: { [x: string]: any }) => void } = {};
61
65
 
62
- constructor(
63
- public readonly log: Logger,
64
- public readonly config: SwitchBotPlatformConfig,
65
- public readonly api: API,
66
- ) {
67
- this.logs();
68
- this.debugLog('Finished initializing platform:', this.config.name);
66
+ constructor(log: Logging, config: SwitchBotPlatformConfig, api: API) {
67
+ this.accessories = [];
68
+ this.api = api;
69
+ this.log = log;
69
70
  // only load if configured
70
71
  if (!this.config) {
71
72
  return;
72
73
  }
73
74
 
75
+ // Plugin options into our config variables.
76
+ this.config = {
77
+ platform: 'SwitchBotPlatform',
78
+ name: config.name,
79
+ credentials: config.credentials as object,
80
+ url: config.url as string,
81
+ port: config.port as number,
82
+ hostname: config.hostname as string,
83
+ protocol: config.protocol as string,
84
+ verifyTLS: config.verifyTLS as boolean,
85
+ logging: config.logging as string,
86
+ };
87
+ this.logs();
88
+ this.debugLog(`Finished initializing platform: ${config.name}`);
89
+
74
90
  // HOOBS notice
75
91
  if (__dirname.includes('hoobs')) {
76
92
  this.warnLog(
@@ -90,6 +106,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
90
106
  }
91
107
 
92
108
  // import fakegato-history module and EVE characteristics
109
+ const { EveHomeKitTypes } = hbLib;
93
110
  this.fakegatoAPI = fakegato(api);
94
111
  this.eve = new EveHomeKitTypes(api);
95
112
 
@@ -122,6 +139,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
122
139
  async setupMqtt(): Promise<void> {
123
140
  if (this.config.options?.mqttURL) {
124
141
  try {
142
+ const { connectAsync } = asyncmqtt;
125
143
  this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
126
144
  this.debugLog('MQTT connection has been established successfully.');
127
145
  this.mqttClient.on('error', (e: Error) => {
package/tsconfig.json CHANGED
@@ -1,27 +1,25 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2021",
4
- "module": "commonjs",
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
5
  "lib": [
6
- "ES2015",
7
- "ES2016",
8
- "ES2017",
9
- "ES2018",
10
- "ES2019",
11
- "ES2020",
12
- "ES2021"
6
+ "DOM",
7
+ "ES2022"
13
8
  ],
14
9
  "declaration": true,
15
10
  "declarationMap": true,
16
11
  "sourceMap": true,
17
- "outDir": "./dist",
18
- "rootDir": "./src",
12
+ "outDir": "dist",
13
+ "rootDir": "src",
19
14
  "strict": true,
20
15
  "esModuleInterop": true,
21
- "noImplicitAny": false
16
+ "noImplicitAny": false,
17
+ "allowSyntheticDefaultImports": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "moduleResolution": "node",
22
20
  },
23
21
  "include": [
24
- "src/"
22
+ "src"
25
23
  ],
26
24
  "exclude": [
27
25
  "**/*.spec.ts"