@switchbot/homebridge-switchbot 2.14.0 → 3.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 (154) hide show
  1. package/.github/npm-version-script.cjs +81 -0
  2. package/.github/workflows/dependabot.yml +10 -11
  3. package/CHANGELOG.md +11 -2
  4. package/LICENSE +1 -1
  5. package/config.schema.json +1 -0
  6. package/dist/device/blindtilt.d.ts +9 -5
  7. package/dist/device/blindtilt.d.ts.map +1 -1
  8. package/dist/device/blindtilt.js +151 -91
  9. package/dist/device/blindtilt.js.map +1 -1
  10. package/dist/device/bot.d.ts +9 -5
  11. package/dist/device/bot.d.ts.map +1 -1
  12. package/dist/device/bot.js +234 -184
  13. package/dist/device/bot.js.map +1 -1
  14. package/dist/device/ceilinglight.d.ts +9 -5
  15. package/dist/device/ceilinglight.d.ts.map +1 -1
  16. package/dist/device/ceilinglight.js +110 -64
  17. package/dist/device/ceilinglight.js.map +1 -1
  18. package/dist/device/colorbulb.d.ts +9 -5
  19. package/dist/device/colorbulb.d.ts.map +1 -1
  20. package/dist/device/colorbulb.js +121 -69
  21. package/dist/device/colorbulb.js.map +1 -1
  22. package/dist/device/contact.d.ts +9 -5
  23. package/dist/device/contact.d.ts.map +1 -1
  24. package/dist/device/contact.js +111 -66
  25. package/dist/device/contact.js.map +1 -1
  26. package/dist/device/curtain.d.ts +9 -5
  27. package/dist/device/curtain.d.ts.map +1 -1
  28. package/dist/device/curtain.js +164 -107
  29. package/dist/device/curtain.js.map +1 -1
  30. package/dist/device/hub.d.ts +9 -5
  31. package/dist/device/hub.d.ts.map +1 -1
  32. package/dist/device/hub.js +87 -51
  33. package/dist/device/hub.js.map +1 -1
  34. package/dist/device/humidifier.d.ts +9 -5
  35. package/dist/device/humidifier.d.ts.map +1 -1
  36. package/dist/device/humidifier.js +133 -90
  37. package/dist/device/humidifier.js.map +1 -1
  38. package/dist/device/iosensor.d.ts +9 -5
  39. package/dist/device/iosensor.d.ts.map +1 -1
  40. package/dist/device/iosensor.js +108 -66
  41. package/dist/device/iosensor.js.map +1 -1
  42. package/dist/device/lightstrip.d.ts +9 -5
  43. package/dist/device/lightstrip.d.ts.map +1 -1
  44. package/dist/device/lightstrip.js +110 -65
  45. package/dist/device/lightstrip.js.map +1 -1
  46. package/dist/device/lock.d.ts +10 -6
  47. package/dist/device/lock.d.ts.map +1 -1
  48. package/dist/device/lock.js +125 -84
  49. package/dist/device/lock.js.map +1 -1
  50. package/dist/device/meter.d.ts +9 -5
  51. package/dist/device/meter.d.ts.map +1 -1
  52. package/dist/device/meter.js +102 -63
  53. package/dist/device/meter.js.map +1 -1
  54. package/dist/device/meterplus.d.ts +9 -5
  55. package/dist/device/meterplus.d.ts.map +1 -1
  56. package/dist/device/meterplus.js +102 -63
  57. package/dist/device/meterplus.js.map +1 -1
  58. package/dist/device/motion.d.ts +9 -5
  59. package/dist/device/motion.d.ts.map +1 -1
  60. package/dist/device/motion.js +95 -54
  61. package/dist/device/motion.js.map +1 -1
  62. package/dist/device/plug.d.ts +9 -5
  63. package/dist/device/plug.d.ts.map +1 -1
  64. package/dist/device/plug.js +68 -40
  65. package/dist/device/plug.js.map +1 -1
  66. package/dist/device/robotvacuumcleaner.d.ts +9 -5
  67. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  68. package/dist/device/robotvacuumcleaner.js +86 -52
  69. package/dist/device/robotvacuumcleaner.js.map +1 -1
  70. package/dist/homebridge-ui/server.d.ts +2 -0
  71. package/dist/homebridge-ui/server.d.ts.map +1 -0
  72. package/dist/homebridge-ui/server.js +44 -0
  73. package/dist/homebridge-ui/server.js.map +1 -0
  74. package/dist/index.d.ts +1 -4
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +9 -5
  77. package/dist/index.js.map +1 -1
  78. package/dist/irdevice/airconditioner.d.ts +8 -4
  79. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  80. package/dist/irdevice/airconditioner.js +105 -71
  81. package/dist/irdevice/airconditioner.js.map +1 -1
  82. package/dist/irdevice/airpurifier.d.ts +8 -4
  83. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  84. package/dist/irdevice/airpurifier.js +78 -46
  85. package/dist/irdevice/airpurifier.js.map +1 -1
  86. package/dist/irdevice/camera.d.ts +8 -4
  87. package/dist/irdevice/camera.d.ts.map +1 -1
  88. package/dist/irdevice/camera.js +41 -25
  89. package/dist/irdevice/camera.js.map +1 -1
  90. package/dist/irdevice/fan.d.ts +8 -4
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +62 -39
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/light.d.ts +8 -4
  95. package/dist/irdevice/light.d.ts.map +1 -1
  96. package/dist/irdevice/light.js +67 -45
  97. package/dist/irdevice/light.js.map +1 -1
  98. package/dist/irdevice/other.d.ts +8 -4
  99. package/dist/irdevice/other.d.ts.map +1 -1
  100. package/dist/irdevice/other.js +176 -150
  101. package/dist/irdevice/other.js.map +1 -1
  102. package/dist/irdevice/tv.d.ts +8 -4
  103. package/dist/irdevice/tv.d.ts.map +1 -1
  104. package/dist/irdevice/tv.js +81 -62
  105. package/dist/irdevice/tv.js.map +1 -1
  106. package/dist/irdevice/vacuumcleaner.d.ts +8 -4
  107. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  108. package/dist/irdevice/vacuumcleaner.js +41 -25
  109. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  110. package/dist/irdevice/waterheater.d.ts +8 -4
  111. package/dist/irdevice/waterheater.d.ts.map +1 -1
  112. package/dist/irdevice/waterheater.js +48 -32
  113. package/dist/irdevice/waterheater.js.map +1 -1
  114. package/dist/platform.d.ts +8 -9
  115. package/dist/platform.d.ts.map +1 -1
  116. package/dist/platform.js +147 -162
  117. package/dist/platform.js.map +1 -1
  118. package/dist/settings.js +7 -14
  119. package/dist/settings.js.map +1 -1
  120. package/dist/utils.js +1 -5
  121. package/dist/utils.js.map +1 -1
  122. package/package.json +28 -16
  123. package/src/device/blindtilt.ts +80 -69
  124. package/src/device/bot.ts +189 -178
  125. package/src/device/ceilinglight.ts +55 -42
  126. package/src/device/colorbulb.ts +51 -38
  127. package/src/device/contact.ts +69 -58
  128. package/src/device/curtain.ts +94 -83
  129. package/src/device/hub.ts +54 -43
  130. package/src/device/humidifier.ts +86 -75
  131. package/src/device/iosensor.ts +63 -52
  132. package/src/device/lightstrip.ts +54 -41
  133. package/src/device/lock.ts +89 -79
  134. package/src/device/meter.ts +59 -48
  135. package/src/device/meterplus.ts +63 -52
  136. package/src/device/motion.ts +56 -45
  137. package/src/device/plug.ts +36 -25
  138. package/src/device/robotvacuumcleaner.ts +47 -36
  139. package/src/homebridge-ui/public/index.html +240 -0
  140. package/src/homebridge-ui/server.ts +48 -0
  141. package/src/index.ts +10 -7
  142. package/src/irdevice/airconditioner.ts +70 -62
  143. package/src/irdevice/airpurifier.ts +47 -39
  144. package/src/irdevice/camera.ts +27 -19
  145. package/src/irdevice/fan.ts +41 -33
  146. package/src/irdevice/light.ts +47 -39
  147. package/src/irdevice/other.ts +163 -155
  148. package/src/irdevice/tv.ts +65 -57
  149. package/src/irdevice/vacuumcleaner.ts +27 -19
  150. package/src/irdevice/waterheater.ts +34 -26
  151. package/src/platform.ts +35 -21
  152. package/tsconfig.json +11 -13
  153. package/homebridge-ui/server.js +0 -50
  154. /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
@@ -1,60 +1,118 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Curtain = void 0;
4
- const undici_1 = require("undici");
5
- const utils_1 = require("../utils");
6
- const rxjs_1 = require("rxjs");
7
- const async_mqtt_1 = require("async-mqtt");
8
- const operators_1 = require("rxjs/operators");
9
- const settings_1 = require("../settings");
10
- const os_1 = require("os");
11
- class Curtain {
1
+ import { request } from 'undici';
2
+ import { sleep } from '../utils';
3
+ import { interval, Subject } from 'rxjs';
4
+ import { connectAsync } from 'async-mqtt';
5
+ import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
+ import { Devices } from '../settings';
7
+ import { hostname } from 'os';
8
+ export class Curtain {
9
+ platform;
10
+ accessory;
11
+ device;
12
+ api;
13
+ log;
14
+ config;
15
+ hap;
16
+ // Services
17
+ batteryService;
18
+ lightSensorService;
19
+ windowCoveringService;
20
+ // Characteristic Values
21
+ BatteryLevel;
22
+ HoldPosition;
23
+ PositionState;
24
+ TargetPosition;
25
+ CurrentPosition;
26
+ FirmwareRevision;
27
+ StatusLowBattery;
28
+ CurrentAmbientLightLevel;
29
+ // OpenAPI Status
30
+ OpenAPI_InMotion;
31
+ OpenAPI_BatteryLevel;
32
+ OpenAPI_FirmwareRevision;
33
+ OpenAPI_CurrentPosition;
34
+ OpenAPI_CurrentAmbientLightLevel;
35
+ // OpenAPI Others
36
+ Mode;
37
+ setPositionMode;
38
+ // BLE Status
39
+ BLE_InMotion;
40
+ BLE_BatteryLevel;
41
+ BLE_Calibration;
42
+ BLE_CurrentPosition;
43
+ BLE_CurrentAmbientLightLevel;
44
+ // BLE Others
45
+ BLE_IsConnected;
46
+ spaceBetweenLevels;
47
+ // Target
48
+ setNewTarget;
49
+ setNewTargetTimer;
50
+ //MQTT stuff
51
+ mqttClient = null;
52
+ // Config
53
+ updateRate;
54
+ set_minLux;
55
+ set_maxLux;
56
+ set_minStep;
57
+ setOpenMode;
58
+ setCloseMode;
59
+ scanDuration;
60
+ deviceLogging;
61
+ deviceRefreshRate;
62
+ // Updates
63
+ curtainUpdateInProgress;
64
+ doCurtainUpdate;
65
+ // Connection
66
+ OpenAPI;
67
+ BLE;
68
+ // EVE history service handler
69
+ historyService = null;
12
70
  constructor(platform, accessory, device) {
13
71
  this.platform = platform;
14
72
  this.accessory = accessory;
15
73
  this.device = device;
16
- //MQTT stuff
17
- this.mqttClient = null;
74
+ this.api = this.platform.api;
75
+ this.log = this.platform.log;
76
+ this.config = this.platform.config;
77
+ this.hap = this.api.hap;
18
78
  // Connection
19
79
  this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
20
80
  this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
21
- // EVE history service handler
22
- this.historyService = null;
23
81
  // default placeholders
24
- this.logs(device);
82
+ this.deviceLogs(device);
25
83
  this.refreshRate(device);
26
84
  this.scan(device);
27
85
  this.setupMqtt(device);
28
86
  this.context();
29
- this.config(device);
87
+ this.deviceConfig(device);
30
88
  // this is subject we use to track when we need to POST changes to the SwitchBot API
31
- this.doCurtainUpdate = new rxjs_1.Subject();
89
+ this.doCurtainUpdate = new Subject();
32
90
  this.curtainUpdateInProgress = false;
33
91
  this.setNewTarget = false;
34
92
  // Retrieve initial values and updateHomekit
35
93
  this.refreshStatus();
36
94
  // set accessory information
37
95
  accessory
38
- .getService(this.platform.Service.AccessoryInformation)
39
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
- .setCharacteristic(this.platform.Characteristic.Model, 'W0701600')
41
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
42
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
96
+ .getService(this.hap.Service.AccessoryInformation)
97
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
98
+ .setCharacteristic(this.hap.Characteristic.Model, 'W0701600')
99
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
100
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
43
101
  // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
44
102
  // you can create multiple services for each accessory
45
103
  const windowCoveringService = `${accessory.displayName} ${device.deviceType}`;
46
- (this.windowCoveringService = accessory.getService(this.platform.Service.WindowCovering)
47
- || accessory.addService(this.platform.Service.WindowCovering)), windowCoveringService;
48
- this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
49
- if (!this.windowCoveringService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
50
- this.windowCoveringService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
104
+ (this.windowCoveringService = accessory.getService(this.hap.Service.WindowCovering)
105
+ || accessory.addService(this.hap.Service.WindowCovering)), windowCoveringService;
106
+ this.windowCoveringService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
107
+ if (!this.windowCoveringService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
108
+ this.windowCoveringService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
51
109
  }
52
110
  // each service must implement at-minimum the "required characteristics" for the given service type
53
111
  // see https://developers.homebridge.io/#/service/WindowCovering
54
112
  // create handlers for required characteristics
55
- this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
113
+ this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.PositionState);
56
114
  this.windowCoveringService
57
- .getCharacteristic(this.platform.Characteristic.CurrentPosition)
115
+ .getCharacteristic(this.hap.Characteristic.CurrentPosition)
58
116
  .setProps({
59
117
  minStep: this.minStep(device),
60
118
  minValue: 0,
@@ -65,7 +123,7 @@ class Curtain {
65
123
  return this.CurrentPosition;
66
124
  });
67
125
  this.windowCoveringService
68
- .getCharacteristic(this.platform.Characteristic.TargetPosition)
126
+ .getCharacteristic(this.hap.Characteristic.TargetPosition)
69
127
  .setProps({
70
128
  minStep: this.minStep(device),
71
129
  minValue: 0,
@@ -74,7 +132,7 @@ class Curtain {
74
132
  })
75
133
  .onSet(this.TargetPositionSet.bind(this));
76
134
  this.windowCoveringService
77
- .getCharacteristic(this.platform.Characteristic.HoldPosition)
135
+ .getCharacteristic(this.hap.Characteristic.HoldPosition)
78
136
  .setProps({
79
137
  minStep: this.minStep(device),
80
138
  minValue: 0,
@@ -85,17 +143,17 @@ class Curtain {
85
143
  // Light Sensor Service
86
144
  if (device.curtain?.hide_lightsensor) {
87
145
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
88
- this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor);
146
+ this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor);
89
147
  accessory.removeService(this.lightSensorService);
90
148
  }
91
149
  else if (!this.lightSensorService) {
92
150
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
93
151
  const lightSensorService = `${accessory.displayName} Light Sensor`;
94
- (this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor)
95
- || this.accessory.addService(this.platform.Service.LightSensor)), lightSensorService;
96
- this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
97
- if (!this.lightSensorService?.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
98
- this.lightSensorService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
152
+ (this.lightSensorService = this.accessory.getService(this.hap.Service.LightSensor)
153
+ || this.accessory.addService(this.hap.Service.LightSensor)), lightSensorService;
154
+ this.lightSensorService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Light Sensor`);
155
+ if (!this.lightSensorService?.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
156
+ this.lightSensorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
99
157
  }
100
158
  }
101
159
  else {
@@ -103,17 +161,17 @@ class Curtain {
103
161
  }
104
162
  // Battery Service
105
163
  const batteryService = `${accessory.displayName} Battery`;
106
- (this.batteryService = this.accessory.getService(this.platform.Service.Battery)
107
- || accessory.addService(this.platform.Service.Battery)), batteryService;
108
- this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
109
- if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
110
- this.batteryService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
164
+ (this.batteryService = this.accessory.getService(this.hap.Service.Battery)
165
+ || accessory.addService(this.hap.Service.Battery)), batteryService;
166
+ this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
167
+ if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
168
+ this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
111
169
  }
112
170
  // Update Homekit
113
171
  this.updateHomeKitCharacteristics();
114
172
  // Start an update interval
115
- (0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
116
- .pipe((0, operators_1.skipWhile)(() => this.curtainUpdateInProgress))
173
+ interval(this.deviceRefreshRate * 1000)
174
+ .pipe(skipWhile(() => this.curtainUpdateInProgress))
117
175
  .subscribe(async () => {
118
176
  await this.refreshStatus();
119
177
  });
@@ -140,10 +198,10 @@ class Curtain {
140
198
  };
141
199
  }
142
200
  // update slide progress
143
- (0, rxjs_1.interval)(this.updateRate * 1000)
201
+ interval(this.updateRate * 1000)
144
202
  //.pipe(skipWhile(() => this.curtainUpdateInProgress))
145
203
  .subscribe(async () => {
146
- if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) {
204
+ if (this.PositionState === this.hap.Characteristic.PositionState.STOPPED) {
147
205
  return;
148
206
  }
149
207
  this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`);
@@ -152,9 +210,9 @@ class Curtain {
152
210
  // Watch for Curtain change events
153
211
  // We put in a debounce of 100ms so we don't make duplicate calls
154
212
  this.doCurtainUpdate
155
- .pipe((0, operators_1.tap)(() => {
213
+ .pipe(tap(() => {
156
214
  this.curtainUpdateInProgress = true;
157
- }), (0, operators_1.debounceTime)(this.platform.config.options.pushRate * 1000))
215
+ }), debounceTime(this.platform.config.options.pushRate * 1000))
158
216
  .subscribe(async () => {
159
217
  try {
160
218
  await this.pushChanges();
@@ -183,10 +241,10 @@ class Curtain {
183
241
  this.historyService = new this.platform.fakegatoAPI('custom', this.accessory, {
184
242
  log: this.platform.log,
185
243
  storage: 'fs',
186
- filename: `${(0, os_1.hostname)().split('.')[0]}_${mac}_persist.json`,
244
+ filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
187
245
  });
188
- const motion = this.accessory.getService(this.platform.Service.MotionSensor) ||
189
- this.accessory.addService(this.platform.Service.MotionSensor, `${this.accessory.displayName} Motion`);
246
+ const motion = this.accessory.getService(this.hap.Service.MotionSensor) ||
247
+ this.accessory.addService(this.hap.Service.MotionSensor, `${this.accessory.displayName} Motion`);
190
248
  motion.addOptionalCharacteristic(this.platform.eve.Characteristics.LastActivation);
191
249
  motion.getCharacteristic(this.platform.eve.Characteristics.LastActivation).onGet(() => {
192
250
  const lastActivation = this.accessory.context.lastActivation
@@ -195,9 +253,9 @@ class Curtain {
195
253
  return lastActivation;
196
254
  });
197
255
  await this.setMinMax();
198
- motion.getCharacteristic(this.platform.Characteristic.MotionDetected).on('change', (event) => {
256
+ motion.getCharacteristic(this.hap.Characteristic.MotionDetected).on('change', (event) => {
199
257
  if (event.newValue !== event.oldValue) {
200
- const sensor = this.accessory.getService(this.platform.Service.MotionSensor);
258
+ const sensor = this.accessory.getService(this.hap.Service.MotionSensor);
201
259
  const entry = {
202
260
  time: Math.round(new Date().valueOf() / 1000),
203
261
  motion: event.newValue,
@@ -248,27 +306,27 @@ class Curtain {
248
306
  await this.setMinMax();
249
307
  if (Number(this.TargetPosition) > this.CurrentPosition) {
250
308
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition}`);
251
- this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
252
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
309
+ this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
310
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
253
311
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
254
312
  }
255
313
  else if (Number(this.TargetPosition) < this.CurrentPosition) {
256
314
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition}`);
257
- this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
258
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
315
+ this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
316
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
259
317
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
260
318
  }
261
319
  else {
262
320
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
263
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
264
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
321
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
322
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
265
323
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
266
324
  }
267
325
  }
268
326
  else {
269
327
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
270
328
  this.TargetPosition = this.CurrentPosition;
271
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
329
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
272
330
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
273
331
  }
274
332
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
@@ -327,10 +385,10 @@ class Curtain {
327
385
  // Battery
328
386
  this.BatteryLevel = Number(this.BLE_BatteryLevel);
329
387
  if (this.BatteryLevel < 10) {
330
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
388
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
331
389
  }
332
390
  else {
333
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
391
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
334
392
  }
335
393
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`);
336
394
  }
@@ -347,27 +405,27 @@ class Curtain {
347
405
  await this.setMinMax();
348
406
  if (Number(this.TargetPosition) > this.CurrentPosition) {
349
407
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `);
350
- this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
351
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
408
+ this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
409
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
352
410
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} INCREASING PositionState: ${this.PositionState}`);
353
411
  }
354
412
  else if (Number(this.TargetPosition) < this.CurrentPosition) {
355
413
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Opening, CurrentPosition: ${this.CurrentPosition} `);
356
- this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
357
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
414
+ this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
415
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
358
416
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} DECREASING PositionState: ${this.PositionState}`);
359
417
  }
360
418
  else {
361
419
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} Standby, CurrentPosition: ${this.CurrentPosition}`);
362
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
363
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
420
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
421
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
364
422
  this.debugLog(`${this.device.deviceType}: ${this.CurrentPosition} STOPPED PositionState: ${this.PositionState}`);
365
423
  }
366
424
  }
367
425
  else {
368
426
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Standby, CurrentPosition: ${this.CurrentPosition}`);
369
427
  this.TargetPosition = this.CurrentPosition;
370
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
428
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
371
429
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Stopped`);
372
430
  }
373
431
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` +
@@ -389,10 +447,10 @@ class Curtain {
389
447
  // BatteryLevel
390
448
  this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
391
449
  if (this.BatteryLevel < 10) {
392
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
450
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
393
451
  }
394
452
  else {
395
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
453
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
396
454
  }
397
455
  if (Number.isNaN(this.BatteryLevel)) {
398
456
  this.BatteryLevel = 100;
@@ -461,7 +519,7 @@ class Curtain {
461
519
  }
462
520
  };
463
521
  // Wait
464
- return await (0, utils_1.sleep)(this.scanDuration * 1000);
522
+ return await sleep(this.scanDuration * 1000);
465
523
  })
466
524
  .then(async () => {
467
525
  // Stop to monitor
@@ -481,7 +539,7 @@ class Curtain {
481
539
  async openAPIRefreshStatus() {
482
540
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
483
541
  try {
484
- const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/status`, {
542
+ const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
485
543
  headers: this.platform.generateHeaders(),
486
544
  });
487
545
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} body: ${JSON.stringify(body)}`);
@@ -528,9 +586,9 @@ class Curtain {
528
586
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, pushChanges will not happen.`);
529
587
  }
530
588
  // Refresh the status from the API
531
- (0, rxjs_1.interval)(15000)
532
- .pipe((0, operators_1.skipWhile)(() => this.curtainUpdateInProgress))
533
- .pipe((0, operators_1.take)(1))
589
+ interval(15000)
590
+ .pipe(skipWhile(() => this.curtainUpdateInProgress))
591
+ .pipe(take(1))
534
592
  .subscribe(async () => {
535
593
  await this.refreshStatus();
536
594
  });
@@ -591,7 +649,7 @@ class Curtain {
591
649
  }
592
650
  this.infoLog(e);
593
651
  this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
594
- await (0, utils_1.sleep)(1000);
652
+ await sleep(1000);
595
653
  return this.retry({ max: max - 1, fn });
596
654
  });
597
655
  }
@@ -645,7 +703,7 @@ class Curtain {
645
703
  });
646
704
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
647
705
  try {
648
- const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
706
+ const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
649
707
  body: bodyChange,
650
708
  method: 'POST',
651
709
  headers: this.platform.generateHeaders(),
@@ -689,7 +747,7 @@ class Curtain {
689
747
  }
690
748
  // Set HoldPosition to false when TargetPosition is changed
691
749
  this.HoldPosition = false;
692
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.HoldPosition, this.HoldPosition);
750
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.HoldPosition);
693
751
  this.TargetPosition = value;
694
752
  if (this.device.mqttURL) {
695
753
  this.mqttPublish('TargetPosition', this.TargetPosition);
@@ -697,22 +755,22 @@ class Curtain {
697
755
  }
698
756
  await this.setMinMax();
699
757
  if (value > this.CurrentPosition) {
700
- this.PositionState = this.platform.Characteristic.PositionState.INCREASING;
758
+ this.PositionState = this.hap.Characteristic.PositionState.INCREASING;
701
759
  this.setNewTarget = true;
702
760
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
703
761
  }
704
762
  else if (value < this.CurrentPosition) {
705
- this.PositionState = this.platform.Characteristic.PositionState.DECREASING;
763
+ this.PositionState = this.hap.Characteristic.PositionState.DECREASING;
706
764
  this.setNewTarget = true;
707
765
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
708
766
  }
709
767
  else {
710
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
768
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
711
769
  this.setNewTarget = false;
712
770
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} value: ${value}, CurrentPosition: ${this.CurrentPosition}`);
713
771
  }
714
- this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState);
715
- this.windowCoveringService.getCharacteristic(this.platform.Characteristic.PositionState).updateValue(this.PositionState);
772
+ this.windowCoveringService.setCharacteristic(this.hap.Characteristic.PositionState, this.PositionState);
773
+ this.windowCoveringService.getCharacteristic(this.hap.Characteristic.PositionState).updateValue(this.PositionState);
716
774
  /**
717
775
  * If Curtain movement time is short, the moving flag from backend is always false.
718
776
  * The minimum time depends on the network control latency.
@@ -745,7 +803,7 @@ class Curtain {
745
803
  this.mqttPublish('CurrentPosition', this.CurrentPosition);
746
804
  }
747
805
  this.accessory.context.CurrentPosition = this.CurrentPosition;
748
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition));
806
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.CurrentPosition, Number(this.CurrentPosition));
749
807
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`);
750
808
  }
751
809
  if (this.PositionState === undefined) {
@@ -756,7 +814,7 @@ class Curtain {
756
814
  this.mqttPublish('PositionState', this.PositionState);
757
815
  }
758
816
  this.accessory.context.PositionState = this.PositionState;
759
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.PositionState, Number(this.PositionState));
817
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.PositionState, Number(this.PositionState));
760
818
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`);
761
819
  }
762
820
  if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) {
@@ -767,7 +825,7 @@ class Curtain {
767
825
  this.mqttPublish('TargetPosition', this.TargetPosition);
768
826
  }
769
827
  this.accessory.context.TargetPosition = this.TargetPosition;
770
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
828
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.TargetPosition, Number(this.TargetPosition));
771
829
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
772
830
  }
773
831
  if (this.HoldPosition === undefined) {
@@ -778,7 +836,7 @@ class Curtain {
778
836
  this.mqttPublish('HoldPosition', this.HoldPosition);
779
837
  }
780
838
  this.accessory.context.HoldPosition = this.HoldPosition;
781
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.HoldPosition, this.HoldPosition);
839
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.HoldPosition, this.HoldPosition);
782
840
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic HoldPosition: ${this.HoldPosition}`);
783
841
  }
784
842
  if (!this.device.curtain?.hide_lightsensor) {
@@ -790,7 +848,7 @@ class Curtain {
790
848
  this.mqttPublish('CurrentAmbientLightLevel', this.CurrentAmbientLightLevel);
791
849
  }
792
850
  this.accessory.context.CurrentAmbientLightLevel = this.CurrentAmbientLightLevel;
793
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
851
+ this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel);
794
852
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
795
853
  ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
796
854
  if (this.device.history) {
@@ -809,7 +867,7 @@ class Curtain {
809
867
  this.mqttPublish('BatteryLevel', this.BatteryLevel);
810
868
  }
811
869
  this.accessory.context.BatteryLevel = this.BatteryLevel;
812
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
870
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
813
871
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
814
872
  }
815
873
  if (this.StatusLowBattery === undefined) {
@@ -820,7 +878,7 @@ class Curtain {
820
878
  this.mqttPublish('StatusLowBattery', this.StatusLowBattery);
821
879
  }
822
880
  this.accessory.context.StatusLowBattery = this.StatusLowBattery;
823
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
881
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
824
882
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
825
883
  }
826
884
  }
@@ -843,7 +901,7 @@ class Curtain {
843
901
  async setupMqtt(device) {
844
902
  if (device.mqttURL) {
845
903
  try {
846
- this.mqttClient = await (0, async_mqtt_1.connectAsync)(device.mqttURL, device.mqttOptions || {});
904
+ this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
847
905
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
848
906
  this.mqttClient.on('error', (e) => {
849
907
  this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
@@ -876,7 +934,7 @@ class Curtain {
876
934
  switchbot.onadvertisement = (ad) => {
877
935
  this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
878
936
  };
879
- await (0, utils_1.sleep)(10000);
937
+ await sleep(10000);
880
938
  // Stop to monitor
881
939
  await switchbot.stopScan();
882
940
  })();
@@ -929,9 +987,9 @@ class Curtain {
929
987
  }
930
988
  }
931
989
  if (this.device.history) {
932
- const motion = this.accessory.getService(this.platform.Service.MotionSensor);
990
+ const motion = this.accessory.getService(this.hap.Service.MotionSensor);
933
991
  const state = Number(this.CurrentPosition) > 0 ? 1 : 0;
934
- motion?.updateCharacteristic(this.platform.Characteristic.MotionDetected, state);
992
+ motion?.updateCharacteristic(this.hap.Characteristic.MotionDetected, state);
935
993
  }
936
994
  }
937
995
  minStep(device) {
@@ -1031,14 +1089,14 @@ class Curtain {
1031
1089
  }
1032
1090
  }
1033
1091
  async apiError(e) {
1034
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
1035
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.PositionState, e);
1036
- this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
1092
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
1093
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.PositionState, e);
1094
+ this.windowCoveringService.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
1037
1095
  if (!this.device.curtain?.hide_lightsensor) {
1038
- this.lightSensorService?.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e);
1096
+ this.lightSensorService?.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e);
1039
1097
  }
1040
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
1041
- this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
1098
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
1099
+ this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
1042
1100
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
1043
1101
  }
1044
1102
  async context() {
@@ -1055,7 +1113,7 @@ class Curtain {
1055
1113
  this.TargetPosition = this.accessory.context.TargetPosition;
1056
1114
  }
1057
1115
  if (this.accessory.context.PositionState === undefined) {
1058
- this.PositionState = this.platform.Characteristic.PositionState.STOPPED;
1116
+ this.PositionState = this.hap.Characteristic.PositionState.STOPPED;
1059
1117
  }
1060
1118
  else {
1061
1119
  this.PositionState = this.accessory.context.PositionState;
@@ -1073,7 +1131,7 @@ class Curtain {
1073
1131
  this.BatteryLevel = this.accessory.context.BatteryLevel;
1074
1132
  }
1075
1133
  if (this.accessory.context.StatusLowBattery === undefined) {
1076
- this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
1134
+ this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
1077
1135
  }
1078
1136
  else {
1079
1137
  this.StatusLowBattery = this.accessory.context.StatusLowBattery;
@@ -1112,7 +1170,7 @@ class Curtain {
1112
1170
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default Curtain updateRate: ${this.updateRate}`);
1113
1171
  }
1114
1172
  }
1115
- async config(device) {
1173
+ async deviceConfig(device) {
1116
1174
  let config = {};
1117
1175
  if (device.curtain) {
1118
1176
  config = device.curtain;
@@ -1142,7 +1200,7 @@ class Curtain {
1142
1200
  this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
1143
1201
  }
1144
1202
  }
1145
- async logs(device) {
1203
+ async deviceLogs(device) {
1146
1204
  if (this.platform.debugMode) {
1147
1205
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
1148
1206
  this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -1206,5 +1264,4 @@ class Curtain {
1206
1264
  return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
1207
1265
  }
1208
1266
  }
1209
- exports.Curtain = Curtain;
1210
1267
  //# sourceMappingURL=curtain.js.map