@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.10.1-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 (122) hide show
  1. package/.eslintrc +14 -45
  2. package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
  3. package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
  4. package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
  5. package/.github/labeler.yml +1 -1
  6. package/.github/workflows/codeql-analysis.yml +29 -29
  7. package/.github/workflows/nodejs-beta.yml +1 -1
  8. package/.github/workflows/prerelease-beta.js +1 -1
  9. package/.github/workflows/stale.yml +1 -1
  10. package/.prettierrc +9 -0
  11. package/.vscode/extensions.json +2 -4
  12. package/.vscode/settings.json +14 -2
  13. package/CHANGELOG.md +16 -0
  14. package/README.md +100 -99
  15. package/SECURITY.md +2 -2
  16. package/config.schema.json +17 -0
  17. package/dist/devices/bots.d.ts +35 -32
  18. package/dist/devices/bots.d.ts.map +1 -1
  19. package/dist/devices/bots.js +168 -210
  20. package/dist/devices/bots.js.map +1 -1
  21. package/dist/devices/colorbulb.d.ts +35 -35
  22. package/dist/devices/colorbulb.d.ts.map +1 -1
  23. package/dist/devices/colorbulb.js +83 -108
  24. package/dist/devices/colorbulb.js.map +1 -1
  25. package/dist/devices/contact.d.ts +27 -25
  26. package/dist/devices/contact.d.ts.map +1 -1
  27. package/dist/devices/contact.js +110 -131
  28. package/dist/devices/contact.js.map +1 -1
  29. package/dist/devices/curtains.d.ts +29 -27
  30. package/dist/devices/curtains.d.ts.map +1 -1
  31. package/dist/devices/curtains.js +147 -182
  32. package/dist/devices/curtains.js.map +1 -1
  33. package/dist/devices/humidifiers.d.ts +31 -31
  34. package/dist/devices/humidifiers.d.ts.map +1 -1
  35. package/dist/devices/humidifiers.js +154 -181
  36. package/dist/devices/humidifiers.js.map +1 -1
  37. package/dist/devices/meters.d.ts +29 -28
  38. package/dist/devices/meters.d.ts.map +1 -1
  39. package/dist/devices/meters.js +98 -120
  40. package/dist/devices/meters.js.map +1 -1
  41. package/dist/devices/motion.d.ts +24 -23
  42. package/dist/devices/motion.d.ts.map +1 -1
  43. package/dist/devices/motion.js +97 -113
  44. package/dist/devices/motion.js.map +1 -1
  45. package/dist/devices/plugs.d.ts +16 -16
  46. package/dist/devices/plugs.d.ts.map +1 -1
  47. package/dist/devices/plugs.js +48 -71
  48. package/dist/devices/plugs.js.map +1 -1
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +3 -22
  52. package/dist/index.js.map +1 -1
  53. package/dist/irdevices/airconditioners.d.ts +7 -4
  54. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  55. package/dist/irdevices/airconditioners.js +72 -93
  56. package/dist/irdevices/airconditioners.js.map +1 -1
  57. package/dist/irdevices/airpurifiers.d.ts +3 -3
  58. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  59. package/dist/irdevices/airpurifiers.js +32 -51
  60. package/dist/irdevices/airpurifiers.js.map +1 -1
  61. package/dist/irdevices/cameras.d.ts +3 -3
  62. package/dist/irdevices/cameras.d.ts.map +1 -1
  63. package/dist/irdevices/cameras.js +19 -26
  64. package/dist/irdevices/cameras.js.map +1 -1
  65. package/dist/irdevices/fans.d.ts +3 -3
  66. package/dist/irdevices/fans.d.ts.map +1 -1
  67. package/dist/irdevices/fans.js +35 -44
  68. package/dist/irdevices/fans.js.map +1 -1
  69. package/dist/irdevices/lights.d.ts +3 -3
  70. package/dist/irdevices/lights.d.ts.map +1 -1
  71. package/dist/irdevices/lights.js +25 -32
  72. package/dist/irdevices/lights.js.map +1 -1
  73. package/dist/irdevices/others.d.ts +3 -3
  74. package/dist/irdevices/others.d.ts.map +1 -1
  75. package/dist/irdevices/others.js +21 -29
  76. package/dist/irdevices/others.js.map +1 -1
  77. package/dist/irdevices/tvs.d.ts +3 -3
  78. package/dist/irdevices/tvs.d.ts.map +1 -1
  79. package/dist/irdevices/tvs.js +66 -89
  80. package/dist/irdevices/tvs.js.map +1 -1
  81. package/dist/irdevices/vacuumcleaners.d.ts +3 -3
  82. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  83. package/dist/irdevices/vacuumcleaners.js +18 -24
  84. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  85. package/dist/irdevices/waterheaters.d.ts +3 -3
  86. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  87. package/dist/irdevices/waterheaters.js +19 -26
  88. package/dist/irdevices/waterheaters.js.map +1 -1
  89. package/dist/platform.d.ts +10 -10
  90. package/dist/platform.d.ts.map +1 -1
  91. package/dist/platform.js +163 -233
  92. package/dist/platform.js.map +1 -1
  93. package/dist/settings.d.ts +3 -1
  94. package/dist/settings.d.ts.map +1 -1
  95. package/dist/settings.js +4 -4
  96. package/dist/settings.js.map +1 -1
  97. package/homebridge-ui/public/index.html +231 -245
  98. package/homebridge-ui/server.js +2 -4
  99. package/nodemon.json +2 -4
  100. package/package.json +17 -12
  101. package/src/devices/bots.ts +411 -854
  102. package/src/devices/colorbulb.ts +187 -408
  103. package/src/devices/contact.ts +210 -376
  104. package/src/devices/curtains.ts +288 -563
  105. package/src/devices/humidifiers.ts +291 -537
  106. package/src/devices/meters.ts +189 -331
  107. package/src/devices/motion.ts +188 -322
  108. package/src/devices/plugs.ts +88 -160
  109. package/src/index.ts +5 -5
  110. package/src/irdevices/airconditioners.ts +139 -318
  111. package/src/irdevices/airpurifiers.ts +71 -170
  112. package/src/irdevices/cameras.ts +44 -103
  113. package/src/irdevices/fans.ts +70 -165
  114. package/src/irdevices/lights.ts +49 -104
  115. package/src/irdevices/others.ts +55 -131
  116. package/src/irdevices/tvs.ts +114 -247
  117. package/src/irdevices/vacuumcleaners.ts +44 -104
  118. package/src/irdevices/waterheaters.ts +49 -121
  119. package/src/platform.ts +341 -753
  120. package/src/settings.ts +8 -11
  121. package/tsconfig.json +5 -14
  122. package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
@@ -1,28 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
3
  exports.Humidifier = void 0;
23
- const rxjs = __importStar(require("rxjs"));
24
- const operators = __importStar(require("rxjs/operators"));
25
- const settings = __importStar(require("../settings"));
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const settings_1 = require("../settings");
26
7
  /**
27
8
  * Platform Accessory
28
9
  * An instance of this class is created for each accessory your platform registers
@@ -39,30 +20,30 @@ class Humidifier {
39
20
  this.refreshRate(device);
40
21
  this.config(device);
41
22
  this.CurrentRelativeHumidity = 0;
42
- this.TargetHumidifierDehumidifierState =
43
- this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
44
- this.CurrentHumidifierDehumidifierState =
45
- this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
23
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
24
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
46
25
  this.Active = this.platform.Characteristic.Active.ACTIVE;
47
26
  this.RelativeHumidityHumidifierThreshold = 0;
48
27
  this.CurrentTemperature = 0;
49
28
  this.WaterLevel = 0;
29
+ // Humidifiers Config
30
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: ` +
31
+ `${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`);
50
32
  // this is subject we use to track when we need to POST changes to the SwitchBot API
51
- this.doHumidifierUpdate = new rxjs.Subject();
33
+ this.doHumidifierUpdate = new rxjs_1.Subject();
52
34
  this.humidifierUpdateInProgress = false;
53
35
  // Retrieve initial values and updateHomekit
54
36
  this.refreshStatus();
55
37
  // set accessory information
56
38
  accessory
57
39
  .getService(this.platform.Service.AccessoryInformation)
58
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
59
- .setCharacteristic(this.platform.Characteristic.Model, "SWITCHBOT-HUMIDIFIER-W0801800")
40
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
41
+ .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-HUMIDIFIER-W0801800')
60
42
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
61
43
  // get the LightBulb service if it exists, otherwise create a new LightBulb service
62
44
  // you can create multiple services for each accessory
63
45
  (this.service =
64
- accessory.getService(this.platform.Service.HumidifierDehumidifier) ||
65
- accessory.addService(this.platform.Service.HumidifierDehumidifier)),
46
+ accessory.getService(this.platform.Service.HumidifierDehumidifier) || accessory.addService(this.platform.Service.HumidifierDehumidifier)),
66
47
  `${accessory.displayName} Humidifier`;
67
48
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
68
49
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -83,9 +64,7 @@ class Humidifier {
83
64
  validValues: [0, 1],
84
65
  })
85
66
  .onSet(this.handleTargetHumidifierDehumidifierStateSet.bind(this));
86
- this.service
87
- .getCharacteristic(this.platform.Characteristic.Active)
88
- .onSet(this.handleActiveSet.bind(this));
67
+ this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleActiveSet.bind(this));
89
68
  this.service
90
69
  .getCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold)
91
70
  .setProps({
@@ -105,8 +84,7 @@ class Humidifier {
105
84
  else if (!this.temperatureservice && !device.ble) {
106
85
  this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
107
86
  (this.temperatureservice =
108
- this.accessory.getService(this.platform.Service.TemperatureSensor) ||
109
- this.accessory.addService(this.platform.Service.TemperatureSensor)),
87
+ this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
110
88
  `${accessory.displayName} Temperature Sensor`;
111
89
  this.temperatureservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
112
90
  this.temperatureservice
@@ -127,27 +105,28 @@ class Humidifier {
127
105
  // Retrieve initial values and updateHomekit
128
106
  this.updateHomeKitCharacteristics();
129
107
  // Start an update interval
130
- rxjs
131
- .interval(this.deviceRefreshRate * 1000)
132
- .pipe(operators.skipWhile(() => this.humidifierUpdateInProgress))
108
+ (0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
109
+ .pipe((0, operators_1.skipWhile)(() => this.humidifierUpdateInProgress))
133
110
  .subscribe(() => {
134
111
  this.refreshStatus();
135
112
  });
136
113
  // Watch for Humidifier change events
137
114
  // We put in a debounce of 100ms so we don't make duplicate calls
138
115
  this.doHumidifierUpdate
139
- .pipe(operators.tap(() => {
116
+ .pipe((0, operators_1.tap)(() => {
140
117
  this.humidifierUpdateInProgress = true;
141
- }), operators.debounceTime(this.platform.config.options.pushRate * 1000))
118
+ }), (0, operators_1.debounceTime)(this.platform.config.options.pushRate * 1000))
142
119
  .subscribe(async () => {
143
120
  try {
144
121
  await this.pushChanges();
145
122
  }
146
123
  catch (e) {
147
124
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
148
- if (this.deviceLogging.includes("debug")) {
149
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` +
150
- ` Error Message: ${JSON.stringify(e.message)}`);
125
+ if (this.deviceLogging === 'debug') {
126
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
127
+ }
128
+ if (this.platform.debugMode) {
129
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
151
130
  }
152
131
  this.apiError(e);
153
132
  }
@@ -193,44 +172,34 @@ class Humidifier {
193
172
  // Target Humidifier Dehumidifier State
194
173
  switch (this.auto) {
195
174
  case true:
196
- this.TargetHumidifierDehumidifierState =
197
- this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
198
- this.CurrentHumidifierDehumidifierState =
199
- this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
200
- this.RelativeHumidityHumidifierThreshold =
201
- this.CurrentRelativeHumidity;
175
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
176
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
177
+ this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
202
178
  break;
203
179
  default:
204
- this.TargetHumidifierDehumidifierState =
205
- this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
180
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
206
181
  if (this.nebulizationEfficiency > 100) {
207
182
  this.RelativeHumidityHumidifierThreshold = 100;
208
183
  }
209
184
  else {
210
- this.RelativeHumidityHumidifierThreshold =
211
- this.nebulizationEfficiency;
185
+ this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency;
212
186
  }
213
- if (this.CurrentRelativeHumidity >
214
- this.RelativeHumidityHumidifierThreshold) {
215
- this.CurrentHumidifierDehumidifierState =
216
- this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
187
+ if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
188
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
217
189
  }
218
190
  else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
219
- this.CurrentHumidifierDehumidifierState =
220
- this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
191
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
221
192
  }
222
193
  else {
223
- this.CurrentHumidifierDehumidifierState =
224
- this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
194
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
225
195
  }
226
196
  }
227
197
  this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
228
- this.debugLog(`Humidifier: ${this.accessory.displayName}` +
229
- ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
198
+ this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
230
199
  this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
231
200
  // Active
232
201
  switch (this.power) {
233
- case "on":
202
+ case 'on':
234
203
  this.Active = this.platform.Characteristic.Active.ACTIVE;
235
204
  break;
236
205
  default:
@@ -264,82 +233,88 @@ class Humidifier {
264
233
  // Convert to BLE Address
265
234
  this.device.bleMac = this.device
266
235
  .deviceId.match(/.{1,2}/g)
267
- .join(":")
236
+ .join(':')
268
237
  .toLowerCase();
269
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
270
- try {
271
- await switchbot.discover({
272
- model: "e",
273
- quick: false,
274
- });
275
- // Start to monitor advertisement packets
276
- await switchbot.startScan({
277
- model: "e",
238
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
239
+ // Start to monitor advertisement packets
240
+ if (switchbot !== false) {
241
+ switchbot
242
+ .startScan({
243
+ model: 'e',
278
244
  id: this.device.bleMac,
279
- });
280
- // Set an event hander
281
- switchbot.onadvertisement = (ad) => {
282
- this.serviceData = ad.serviceData;
283
- this.autoMode = ad.serviceData.autoMode;
284
- this.onState = ad.serviceData.onState;
285
- this.percentage = ad.serviceData.percentage;
286
- this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
287
- this.debugLog(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
288
- `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
289
- if (this.serviceData) {
290
- this.connected = true;
291
- this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
245
+ })
246
+ .then(() => {
247
+ // Set an event hander
248
+ switchbot.onadvertisement = (ad) => {
249
+ this.serviceData = ad.serviceData;
250
+ this.autoMode = ad.serviceData.autoMode;
251
+ this.onState = ad.serviceData.onState;
252
+ this.percentage = ad.serviceData.percentage;
253
+ this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
254
+ this.debugLog(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
255
+ `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
256
+ if (this.serviceData) {
257
+ this.connected = true;
258
+ this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
259
+ }
260
+ else {
261
+ this.connected = false;
262
+ this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
263
+ }
264
+ };
265
+ // Wait 2 seconds
266
+ return switchbot.wait(this.scanDuration * 1000);
267
+ })
268
+ .then(async () => {
269
+ // Stop to monitor
270
+ switchbot.stopScan();
271
+ if (this.connected) {
272
+ this.parseStatus();
273
+ this.updateHomeKitCharacteristics();
292
274
  }
293
275
  else {
294
- this.connected = false;
295
- this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
276
+ await this.BLEconnection(switchbot);
277
+ }
278
+ })
279
+ .catch(async (e) => {
280
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
281
+ if (this.deviceLogging === 'debug') {
282
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
283
+ }
284
+ if (this.platform.debugMode) {
285
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
296
286
  }
297
- };
298
- // Wait 2 seconds
299
- await switchbot.wait(this.scanDuration * 1000);
300
- // Stop to monitor
301
- switchbot.stopScan();
302
- if (this.connected) {
303
- this.parseStatus();
304
- this.updateHomeKitCharacteristics();
305
- }
306
- else {
307
- this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
308
287
  if (this.platform.config.credentials?.openToken) {
309
288
  this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
310
- this.SwitchToOpenAPI = true;
311
289
  await this.openAPIRefreshStatus();
312
290
  }
313
- }
291
+ this.apiError(e);
292
+ });
314
293
  }
315
- catch (e) {
316
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
317
- if (this.deviceLogging.includes("debug")) {
318
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
319
- ` Error Message: ${JSON.stringify(e.message)}`);
320
- }
321
- if (this.platform.config.credentials?.openToken) {
322
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
323
- this.SwitchToOpenAPI = true;
324
- await this.openAPIRefreshStatus();
325
- }
326
- this.apiError(e);
294
+ else {
295
+ await this.BLEconnection(switchbot);
296
+ }
297
+ }
298
+ async BLEconnection(switchbot) {
299
+ this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
300
+ if (this.platform.config.credentials?.openToken) {
301
+ this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
302
+ await this.openAPIRefreshStatus();
327
303
  }
328
304
  }
329
305
  async openAPIRefreshStatus() {
330
306
  if (this.platform.config.credentials?.openToken) {
331
307
  this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
332
308
  try {
333
- this.deviceStatus = (await this.platform.axios.get(`${settings.DeviceURL}/${this.device.deviceId}/status`)).data;
334
- if (this.deviceStatus.message === "success") {
309
+ this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
310
+ if (this.deviceStatus.message === 'success') {
335
311
  this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
336
312
  this.auto = this.deviceStatus.body.auto;
337
313
  this.power = this.deviceStatus.body.power;
338
314
  this.lackWater = this.deviceStatus.body.lackWater;
339
315
  this.humidity = this.deviceStatus.body.humidity;
340
316
  this.temperature = this.deviceStatus.body.temperature;
341
- this.nebulizationEfficiency =
342
- this.deviceStatus.body.nebulizationEfficiency;
317
+ this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
343
318
  this.parseStatus();
344
319
  this.updateHomeKitCharacteristics();
345
320
  }
@@ -349,10 +324,13 @@ class Humidifier {
349
324
  }
350
325
  catch (e) {
351
326
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
352
- if (this.deviceLogging.includes("debug")) {
327
+ if (this.deviceLogging === 'debug') {
353
328
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
354
329
  ` Error Message: ${JSON.stringify(e.message)}`);
355
330
  }
331
+ if (this.platform.debugMode) {
332
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
333
+ }
356
334
  this.apiError(e);
357
335
  }
358
336
  }
@@ -366,10 +344,9 @@ class Humidifier {
366
344
  //} else {
367
345
  await this.openAPIpushChanges();
368
346
  //}
369
- rxjs
370
- .interval(5000)
371
- .pipe(operators.skipWhile(() => this.humidifierUpdateInProgress))
372
- .pipe(operators.take(1))
347
+ (0, rxjs_1.interval)(5000)
348
+ .pipe((0, operators_1.skipWhile)(() => this.humidifierUpdateInProgress))
349
+ .pipe((0, operators_1.take)(1))
373
350
  .subscribe(() => {
374
351
  this.refreshStatus();
375
352
  });
@@ -380,12 +357,12 @@ class Humidifier {
380
357
  // Convert to BLE Address
381
358
  this.device.bleMac = this.device
382
359
  .deviceId.match(/.{1,2}/g)
383
- .join(":")
360
+ .join(':')
384
361
  .toLowerCase();
385
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
362
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
386
363
  if (switchbot !== false) {
387
364
  switchbot
388
- .discover({ model: "e", quick: true, id: this.device.bleMac })
365
+ .discover({ model: 'e', quick: true, id: this.device.bleMac })
389
366
  .then((device_list) => {
390
367
  this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
391
368
  return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
@@ -395,9 +372,11 @@ class Humidifier {
395
372
  })
396
373
  .catch(async (e) => {
397
374
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
398
- if (this.deviceLogging.includes("debug")) {
399
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
400
- ` Error Message: ${JSON.stringify(e.message)}`);
375
+ if (this.deviceLogging === 'debug') {
376
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
377
+ }
378
+ if (this.platform.debugMode) {
379
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error: ${JSON.stringify(e)}`);
401
380
  }
402
381
  if (this.platform.config.credentials?.openToken) {
403
382
  this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
@@ -417,36 +396,35 @@ class Humidifier {
417
396
  async openAPIpushChanges() {
418
397
  if (this.platform.config.credentials?.openToken) {
419
398
  this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
420
- if (this.TargetHumidifierDehumidifierState ===
421
- this.platform.Characteristic.TargetHumidifierDehumidifierState
422
- .HUMIDIFIER &&
399
+ if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
423
400
  this.Active === this.platform.Characteristic.Active.ACTIVE) {
424
401
  try {
425
402
  this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
426
403
  const payload = {
427
- commandType: "command",
428
- command: "setMode",
404
+ commandType: 'command',
405
+ command: 'setMode',
429
406
  parameter: `${this.RelativeHumidityHumidifierThreshold}`,
430
407
  };
431
408
  this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
432
409
  ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
433
410
  // Make the API request
434
- const push = await this.platform.axios.post(`${settings.DeviceURL}/${this.device.deviceId}/commands`, payload);
411
+ const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
435
412
  this.debugLog(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
436
413
  this.statusCode(push);
437
414
  }
438
415
  catch (e) {
439
416
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
440
- if (this.deviceLogging.includes("debug")) {
417
+ if (this.deviceLogging === 'debug') {
441
418
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
442
419
  ` Error Message: ${JSON.stringify(e.message)}`);
443
420
  }
421
+ if (this.platform.debugMode) {
422
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
423
+ }
444
424
  this.apiError(e);
445
425
  }
446
426
  }
447
- else if (this.TargetHumidifierDehumidifierState ===
448
- this.platform.Characteristic.TargetHumidifierDehumidifierState
449
- .HUMIDIFIER_OR_DEHUMIDIFIER &&
427
+ else if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
450
428
  this.Active === this.platform.Characteristic.Active.ACTIVE) {
451
429
  await this.pushAutoChanges();
452
430
  }
@@ -460,30 +438,31 @@ class Humidifier {
460
438
  */
461
439
  async pushAutoChanges() {
462
440
  try {
463
- if (this.TargetHumidifierDehumidifierState ===
464
- this.platform.Characteristic.TargetHumidifierDehumidifierState
465
- .HUMIDIFIER_OR_DEHUMIDIFIER &&
441
+ if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
466
442
  this.Active === this.platform.Characteristic.Active.ACTIVE) {
467
- this.debugLog("Pushing Auto!");
443
+ this.debugLog('Pushing Auto!');
468
444
  const payload = {
469
- commandType: "command",
470
- command: "setMode",
471
- parameter: "auto",
445
+ commandType: 'command',
446
+ command: 'setMode',
447
+ parameter: 'auto',
472
448
  };
473
449
  this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
474
450
  ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
475
451
  // Make the API request
476
- const push = await this.platform.axios.post(`${settings.DeviceURL}/${this.device.deviceId}/commands`, payload);
452
+ const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
477
453
  this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(push.data)}`);
478
454
  this.statusCode(push);
479
455
  }
480
456
  }
481
457
  catch (e) {
482
458
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
483
- if (this.deviceLogging.includes("debug")) {
459
+ if (this.deviceLogging === 'debug') {
484
460
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` +
485
461
  ` Error Message: ${JSON.stringify(e.message)}`);
486
462
  }
463
+ if (this.platform.debugMode) {
464
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
465
+ }
487
466
  this.apiError(e);
488
467
  }
489
468
  }
@@ -493,26 +472,29 @@ class Humidifier {
493
472
  async pushActiveChanges() {
494
473
  try {
495
474
  if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
496
- this.debugLog("Pushing Off!");
475
+ this.debugLog('Pushing Off!');
497
476
  const payload = {
498
- commandType: "command",
499
- command: "turnOff",
500
- parameter: "default",
477
+ commandType: 'command',
478
+ command: 'turnOff',
479
+ parameter: 'default',
501
480
  };
502
481
  this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
503
482
  ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
504
483
  // Make the API request
505
- const push = await this.platform.axios.post(`${settings.DeviceURL}/${this.device.deviceId}/commands`, payload);
484
+ const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
506
485
  this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(push.data)}`);
507
486
  this.statusCode(push);
508
487
  }
509
488
  }
510
489
  catch (e) {
511
490
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
512
- if (this.deviceLogging.includes("debug")) {
491
+ if (this.deviceLogging === 'debug') {
513
492
  this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` +
514
493
  ` Error Message: ${JSON.stringify(e.message)}`);
515
494
  }
495
+ if (this.platform.debugMode) {
496
+ this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
497
+ }
516
498
  this.apiError(e);
517
499
  }
518
500
  }
@@ -525,8 +507,7 @@ class Humidifier {
525
507
  }
526
508
  else {
527
509
  this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
528
- this.debugLog(`Humidifier: ${this.accessory.displayName}` +
529
- ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
510
+ this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
530
511
  }
531
512
  if (!this.device.ble) {
532
513
  if (this.WaterLevel === undefined) {
@@ -561,8 +542,7 @@ class Humidifier {
561
542
  this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
562
543
  }
563
544
  if (this.RelativeHumidityHumidifierThreshold === undefined) {
564
- this.debugLog(`Humidifier: ${this.accessory.displayName}` +
565
- ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
545
+ this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
566
546
  }
567
547
  else {
568
548
  this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
@@ -626,9 +606,7 @@ class Humidifier {
626
606
  offlineOff() {
627
607
  if (this.device.offline) {
628
608
  this.Active = this.platform.Characteristic.Active.INACTIVE;
629
- this.service
630
- .getCharacteristic(this.platform.Characteristic.Active)
631
- .updateValue(this.Active);
609
+ this.service.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
632
610
  }
633
611
  }
634
612
  /**
@@ -655,8 +633,7 @@ class Humidifier {
655
633
  this.RelativeHumidityHumidifierThreshold = value;
656
634
  if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
657
635
  this.Active = this.platform.Characteristic.Active.ACTIVE;
658
- this.CurrentHumidifierDehumidifierState =
659
- this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
636
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
660
637
  }
661
638
  this.doHumidifierUpdate.next();
662
639
  }
@@ -666,16 +643,16 @@ class Humidifier {
666
643
  config = device.humidifier;
667
644
  }
668
645
  if (device.ble !== undefined) {
669
- config["ble"] = device.ble;
646
+ config['ble'] = device.ble;
670
647
  }
671
648
  if (device.logging !== undefined) {
672
- config["logging"] = device.logging;
649
+ config['logging'] = device.logging;
673
650
  }
674
651
  if (device.refreshRate !== undefined) {
675
- config["refreshRate"] = device.refreshRate;
652
+ config['refreshRate'] = device.refreshRate;
676
653
  }
677
654
  if (device.scanDuration !== undefined) {
678
- config["scanDuration"] = device.scanDuration;
655
+ config['scanDuration'] = device.scanDuration;
679
656
  }
680
657
  if (Object.entries(config).length !== 0) {
681
658
  this.warnLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
@@ -683,20 +660,17 @@ class Humidifier {
683
660
  }
684
661
  refreshRate(device) {
685
662
  if (device.refreshRate) {
686
- this.deviceRefreshRate = this.accessory.context.refreshRate =
687
- device.refreshRate;
663
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
688
664
  this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
689
665
  }
690
666
  else if (this.platform.config.options.refreshRate) {
691
- this.deviceRefreshRate = this.accessory.context.refreshRate =
692
- this.platform.config.options.refreshRate;
667
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
693
668
  this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
694
669
  }
695
670
  }
696
671
  scan(device) {
697
672
  if (device.scanDuration) {
698
- this.scanDuration = this.accessory.context.scanDuration =
699
- device.scanDuration;
673
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
700
674
  if (device.ble) {
701
675
  this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
702
676
  }
@@ -710,7 +684,7 @@ class Humidifier {
710
684
  }
711
685
  logs(device) {
712
686
  if (this.platform.debugMode) {
713
- this.deviceLogging = this.accessory.context.logging = "debugMode";
687
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
714
688
  this.debugLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
715
689
  }
716
690
  else if (device.logging) {
@@ -718,12 +692,11 @@ class Humidifier {
718
692
  this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
719
693
  }
720
694
  else if (this.platform.config.options?.logging) {
721
- this.deviceLogging = this.accessory.context.logging =
722
- this.platform.config.options?.logging;
695
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
723
696
  this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
724
697
  }
725
698
  else {
726
- this.deviceLogging = this.accessory.context.logging = "standard";
699
+ this.deviceLogging = this.accessory.context.logging = 'standard';
727
700
  this.debugLog(`Humidifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
728
701
  }
729
702
  }
@@ -756,8 +729,8 @@ class Humidifier {
756
729
  }
757
730
  debugLog(...log) {
758
731
  if (this.enablingDeviceLogging()) {
759
- if (this.deviceLogging === "debug") {
760
- this.platform.log.info("[DEBUG]", String(...log));
732
+ if (this.deviceLogging === 'debug') {
733
+ this.platform.log.info('[DEBUG]', String(...log));
761
734
  }
762
735
  else {
763
736
  this.platform.log.debug(String(...log));
@@ -765,7 +738,7 @@ class Humidifier {
765
738
  }
766
739
  }
767
740
  enablingDeviceLogging() {
768
- return (this.deviceLogging.includes("debug") || this.deviceLogging === "standard");
741
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
769
742
  }
770
743
  }
771
744
  exports.Humidifier = Humidifier;