@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/.eslintrc +1 -1
  2. package/.vscode/extensions.json +5 -0
  3. package/.vscode/settings.json +15 -0
  4. package/dist/devices/bots.d.ts +34 -35
  5. package/dist/devices/bots.d.ts.map +1 -1
  6. package/dist/devices/bots.js +241 -184
  7. package/dist/devices/bots.js.map +1 -1
  8. package/dist/devices/colorbulb.d.ts +50 -50
  9. package/dist/devices/colorbulb.d.ts.map +1 -1
  10. package/dist/devices/colorbulb.js +145 -131
  11. package/dist/devices/colorbulb.js.map +1 -1
  12. package/dist/devices/contact.d.ts +27 -29
  13. package/dist/devices/contact.d.ts.map +1 -1
  14. package/dist/devices/contact.js +138 -115
  15. package/dist/devices/contact.js.map +1 -1
  16. package/dist/devices/curtains.d.ts +29 -31
  17. package/dist/devices/curtains.d.ts.map +1 -1
  18. package/dist/devices/curtains.js +211 -176
  19. package/dist/devices/curtains.js.map +1 -1
  20. package/dist/devices/humidifiers.d.ts +33 -33
  21. package/dist/devices/humidifiers.d.ts.map +1 -1
  22. package/dist/devices/humidifiers.js +214 -189
  23. package/dist/devices/humidifiers.js.map +1 -1
  24. package/dist/devices/meters.d.ts +30 -31
  25. package/dist/devices/meters.d.ts.map +1 -1
  26. package/dist/devices/meters.js +124 -100
  27. package/dist/devices/meters.js.map +1 -1
  28. package/dist/devices/motion.d.ts +25 -26
  29. package/dist/devices/motion.d.ts.map +1 -1
  30. package/dist/devices/motion.js +120 -102
  31. package/dist/devices/motion.js.map +1 -1
  32. package/dist/devices/plugs.d.ts +23 -23
  33. package/dist/devices/plugs.d.ts.map +1 -1
  34. package/dist/devices/plugs.js +81 -63
  35. package/dist/devices/plugs.js.map +1 -1
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +22 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/irdevices/airconditioners.d.ts +6 -6
  41. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  42. package/dist/irdevices/airconditioners.js +105 -79
  43. package/dist/irdevices/airconditioners.js.map +1 -1
  44. package/dist/irdevices/airpurifiers.d.ts +5 -5
  45. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  46. package/dist/irdevices/airpurifiers.js +56 -42
  47. package/dist/irdevices/airpurifiers.js.map +1 -1
  48. package/dist/irdevices/cameras.d.ts +5 -5
  49. package/dist/irdevices/cameras.d.ts.map +1 -1
  50. package/dist/irdevices/cameras.js +31 -27
  51. package/dist/irdevices/cameras.js.map +1 -1
  52. package/dist/irdevices/fans.d.ts +5 -5
  53. package/dist/irdevices/fans.d.ts.map +1 -1
  54. package/dist/irdevices/fans.js +45 -38
  55. package/dist/irdevices/fans.js.map +1 -1
  56. package/dist/irdevices/lights.d.ts +5 -5
  57. package/dist/irdevices/lights.d.ts.map +1 -1
  58. package/dist/irdevices/lights.js +37 -33
  59. package/dist/irdevices/lights.js.map +1 -1
  60. package/dist/irdevices/others.d.ts +5 -5
  61. package/dist/irdevices/others.d.ts.map +1 -1
  62. package/dist/irdevices/others.js +34 -29
  63. package/dist/irdevices/others.js.map +1 -1
  64. package/dist/irdevices/tvs.d.ts +5 -5
  65. package/dist/irdevices/tvs.d.ts.map +1 -1
  66. package/dist/irdevices/tvs.js +91 -76
  67. package/dist/irdevices/tvs.js.map +1 -1
  68. package/dist/irdevices/vacuumcleaners.d.ts +5 -5
  69. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  70. package/dist/irdevices/vacuumcleaners.js +31 -27
  71. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  72. package/dist/irdevices/waterheaters.d.ts +5 -5
  73. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  74. package/dist/irdevices/waterheaters.js +31 -27
  75. package/dist/irdevices/waterheaters.js.map +1 -1
  76. package/dist/platform.d.ts +12 -12
  77. package/dist/platform.d.ts.map +1 -1
  78. package/dist/platform.js +241 -172
  79. package/dist/platform.js.map +1 -1
  80. package/dist/settings.d.ts +1 -1
  81. package/dist/settings.d.ts.map +1 -1
  82. package/dist/settings.js +4 -4
  83. package/dist/settings.js.map +1 -1
  84. package/package.json +72 -71
  85. package/src/devices/bots.ts +927 -442
  86. package/src/devices/colorbulb.ts +473 -246
  87. package/src/devices/contact.ts +381 -208
  88. package/src/devices/curtains.ts +613 -321
  89. package/src/devices/humidifiers.ts +594 -323
  90. package/src/devices/meters.ts +331 -186
  91. package/src/devices/motion.ts +327 -184
  92. package/src/devices/plugs.ts +175 -107
  93. package/src/index.ts +5 -5
  94. package/src/irdevices/airconditioners.ts +360 -149
  95. package/src/irdevices/airpurifiers.ts +178 -80
  96. package/src/irdevices/cameras.ts +109 -51
  97. package/src/irdevices/fans.ts +174 -77
  98. package/src/irdevices/lights.ts +110 -57
  99. package/src/irdevices/others.ts +137 -62
  100. package/src/irdevices/tvs.ts +249 -124
  101. package/src/irdevices/vacuumcleaners.ts +112 -52
  102. package/src/irdevices/waterheaters.ts +115 -53
  103. package/src/platform.ts +768 -357
  104. package/src/settings.ts +17 -23
@@ -1,9 +1,9 @@
1
- import { AxiosResponse } from 'axios';
2
- import { interval, Subject } from 'rxjs';
3
- import { SwitchBotPlatform } from '../platform';
4
- import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
5
- import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
6
- import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse, payload, deviceStatus } from '../settings';
1
+ import * as axios from "axios";
2
+ import * as rxjs from "rxjs";
3
+ import * as platform_1 from "../platform";
4
+ import * as operators from "rxjs/operators";
5
+ import * as homebridge from "homebridge";
6
+ import * as settings from "../settings";
7
7
 
8
8
  /**
9
9
  * Platform Accessory
@@ -12,33 +12,34 @@ import { DeviceURL, device, devicesConfig, serviceData, ad, deviceStatusResponse
12
12
  */
13
13
  export class Humidifier {
14
14
  // Services
15
- private service: Service;
16
- temperatureservice?: Service;
15
+ private service: homebridge.Service;
16
+ temperatureservice?: homebridge.Service;
17
17
 
18
18
  // Characteristic Values
19
- CurrentRelativeHumidity!: CharacteristicValue;
20
- CurrentTemperature!: CharacteristicValue;
21
- TargetHumidifierDehumidifierState!: CharacteristicValue;
22
- CurrentHumidifierDehumidifierState!: CharacteristicValue;
23
- RelativeHumidityHumidifierThreshold!: CharacteristicValue;
24
- Active!: CharacteristicValue;
25
- WaterLevel!: CharacteristicValue;
19
+ CurrentRelativeHumidity!: homebridge.CharacteristicValue;
20
+ CurrentTemperature!: homebridge.CharacteristicValue;
21
+ TargetHumidifierDehumidifierState!: homebridge.CharacteristicValue;
22
+ CurrentHumidifierDehumidifierState!: homebridge.CharacteristicValue;
23
+ RelativeHumidityHumidifierThreshold!: homebridge.CharacteristicValue;
24
+ Active!: homebridge.CharacteristicValue;
25
+ WaterLevel!: homebridge.CharacteristicValue;
26
26
 
27
27
  // OpenAPI
28
- auto: deviceStatus['auto'];
29
- power: deviceStatus['power'];
30
- humidity: deviceStatus['humidity'];
31
- lackWater: deviceStatus['lackWater'];
32
- temperature: deviceStatus['temperature'];
33
- nebulizationEfficiency: deviceStatus['nebulizationEfficiency'];
34
- deviceStatus!: deviceStatusResponse;
28
+ auto: settings.deviceStatus["auto"];
29
+ power: settings.deviceStatus["power"];
30
+ humidity: settings.deviceStatus["humidity"];
31
+ lackWater: settings.deviceStatus["lackWater"];
32
+ temperature: settings.deviceStatus["temperature"];
33
+ nebulizationEfficiency: settings.deviceStatus["nebulizationEfficiency"];
34
+ deviceStatus!: settings.deviceStatusResponse;
35
35
 
36
36
  // BLE Others
37
37
  connected?: boolean;
38
- serviceData!: serviceData;
39
- onState!: serviceData['onState'];
40
- autoMode!: serviceData['autoMode'];
41
- percentage!: serviceData['percentage'];
38
+ SwitchToOpenAPI?: boolean;
39
+ serviceData!: settings.serviceData;
40
+ onState!: settings.serviceData["onState"];
41
+ autoMode!: settings.serviceData["autoMode"];
42
+ percentage!: settings.serviceData["percentage"];
42
43
 
43
44
  // Config
44
45
  set_minStep?: number;
@@ -48,12 +49,12 @@ export class Humidifier {
48
49
 
49
50
  // Updates
50
51
  humidifierUpdateInProgress!: boolean;
51
- doHumidifierUpdate!: Subject<void>;
52
+ doHumidifierUpdate!: rxjs.Subject<void>;
52
53
 
53
54
  constructor(
54
- private readonly platform: SwitchBotPlatform,
55
- private accessory: PlatformAccessory,
56
- public device: device & devicesConfig,
55
+ private readonly platform: platform_1.SwitchBotPlatform,
56
+ private accessory: homebridge.PlatformAccessory,
57
+ public device: settings.device & settings.devicesConfig,
57
58
  ) {
58
59
  // default placeholders
59
60
  this.logs(device);
@@ -61,19 +62,17 @@ export class Humidifier {
61
62
  this.refreshRate(device);
62
63
  this.config(device);
63
64
  this.CurrentRelativeHumidity = 0;
64
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
65
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
65
+ this.TargetHumidifierDehumidifierState =
66
+ this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
67
+ this.CurrentHumidifierDehumidifierState =
68
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
66
69
  this.Active = this.platform.Characteristic.Active.ACTIVE;
67
70
  this.RelativeHumidityHumidifierThreshold = 0;
68
71
  this.CurrentTemperature = 0;
69
72
  this.WaterLevel = 0;
70
73
 
71
- // Humidifiers Config
72
- this.debugLog(`Humidifier: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, hide_temperature: `
73
- + `${device.humidifier?.hide_temperature}, set_minStep: ${device.humidifier?.set_minStep})`);
74
-
75
74
  // this is subject we use to track when we need to POST changes to the SwitchBot API
76
- this.doHumidifierUpdate = new Subject();
75
+ this.doHumidifierUpdate = new rxjs.Subject();
77
76
  this.humidifierUpdateInProgress = false;
78
77
 
79
78
  // Retrieve initial values and updateHomekit
@@ -82,15 +81,22 @@ export class Humidifier {
82
81
  // set accessory information
83
82
  accessory
84
83
  .getService(this.platform.Service.AccessoryInformation)!
85
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
86
- .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-HUMIDIFIER-W0801800')
87
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
84
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
85
+ .setCharacteristic(
86
+ this.platform.Characteristic.Model,
87
+ "SWITCHBOT-HUMIDIFIER-W0801800",
88
+ )
89
+ .setCharacteristic(
90
+ this.platform.Characteristic.SerialNumber,
91
+ device.deviceId!,
92
+ );
88
93
 
89
94
  // get the LightBulb service if it exists, otherwise create a new LightBulb service
90
95
  // you can create multiple services for each accessory
91
96
  (this.service =
92
97
  accessory.getService(this.platform.Service.HumidifierDehumidifier) ||
93
- accessory.addService(this.platform.Service.HumidifierDehumidifier)), `${accessory.displayName} Humidifier`;
98
+ accessory.addService(this.platform.Service.HumidifierDehumidifier)),
99
+ `${accessory.displayName} Humidifier`;
94
100
 
95
101
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
96
102
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -98,7 +104,10 @@ export class Humidifier {
98
104
 
99
105
  // set the service name, this is what is displayed as the default name on the Home app
100
106
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
101
- this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
107
+ this.service.setCharacteristic(
108
+ this.platform.Characteristic.Name,
109
+ accessory.displayName,
110
+ );
102
111
 
103
112
  // each service must implement at-minimum the "required characteristics" for the given service type
104
113
  // see https://developers.homebridge.io/#/service/HumidifierDehumidifier
@@ -110,7 +119,9 @@ export class Humidifier {
110
119
  );
111
120
 
112
121
  this.service
113
- .getCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState)
122
+ .getCharacteristic(
123
+ this.platform.Characteristic.TargetHumidifierDehumidifierState,
124
+ )
114
125
  .setProps({
115
126
  validValueRanges: [0, 1],
116
127
  minValue: 0,
@@ -119,10 +130,14 @@ export class Humidifier {
119
130
  })
120
131
  .onSet(this.handleTargetHumidifierDehumidifierStateSet.bind(this));
121
132
 
122
- this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleActiveSet.bind(this));
133
+ this.service
134
+ .getCharacteristic(this.platform.Characteristic.Active)
135
+ .onSet(this.handleActiveSet.bind(this));
123
136
 
124
137
  this.service
125
- .getCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold)
138
+ .getCharacteristic(
139
+ this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
140
+ )
126
141
  .setProps({
127
142
  validValueRanges: [0, 100],
128
143
  minValue: 0,
@@ -134,16 +149,26 @@ export class Humidifier {
134
149
  // create a new Temperature Sensor service
135
150
  // Temperature Sensor Service
136
151
  if (device.humidifier?.hide_temperature || device.ble) {
137
- this.debugLog(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
138
- this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
152
+ this.debugLog(
153
+ `Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`,
154
+ );
155
+ this.temperatureservice = this.accessory.getService(
156
+ this.platform.Service.TemperatureSensor,
157
+ );
139
158
  accessory.removeService(this.temperatureservice!);
140
159
  } else if (!this.temperatureservice && !device.ble) {
141
- this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
160
+ this.debugLog(
161
+ `Humidifier: ${accessory.displayName} Add Temperature Sensor Service`,
162
+ );
142
163
  (this.temperatureservice =
143
164
  this.accessory.getService(this.platform.Service.TemperatureSensor) ||
144
- this.accessory.addService(this.platform.Service.TemperatureSensor)), `${accessory.displayName} Temperature Sensor`;
165
+ this.accessory.addService(this.platform.Service.TemperatureSensor)),
166
+ `${accessory.displayName} Temperature Sensor`;
145
167
 
146
- this.temperatureservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
168
+ this.temperatureservice.setCharacteristic(
169
+ this.platform.Characteristic.Name,
170
+ `${accessory.displayName} Temperature Sensor`,
171
+ );
147
172
 
148
173
  this.temperatureservice
149
174
  .getCharacteristic(this.platform.Characteristic.CurrentTemperature)
@@ -157,15 +182,18 @@ export class Humidifier {
157
182
  return this.CurrentTemperature;
158
183
  });
159
184
  } else {
160
- this.debugLog(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
185
+ this.debugLog(
186
+ `Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`,
187
+ );
161
188
  }
162
189
 
163
190
  // Retrieve initial values and updateHomekit
164
191
  this.updateHomeKitCharacteristics();
165
192
 
166
193
  // Start an update interval
167
- interval(this.deviceRefreshRate * 1000)
168
- .pipe(skipWhile(() => this.humidifierUpdateInProgress))
194
+ rxjs
195
+ .interval(this.deviceRefreshRate * 1000)
196
+ .pipe(operators.skipWhile(() => this.humidifierUpdateInProgress))
169
197
  .subscribe(() => {
170
198
  this.refreshStatus();
171
199
  });
@@ -174,23 +202,23 @@ export class Humidifier {
174
202
  // We put in a debounce of 100ms so we don't make duplicate calls
175
203
  this.doHumidifierUpdate
176
204
  .pipe(
177
- tap(() => {
205
+ operators.tap(() => {
178
206
  this.humidifierUpdateInProgress = true;
179
207
  }),
180
- debounceTime(this.platform.config.options!.pushRate! * 1000),
208
+ operators.debounceTime(this.platform.config.options!.pushRate! * 1000),
181
209
  )
182
210
  .subscribe(async () => {
183
211
  try {
184
212
  await this.pushChanges();
185
213
  } catch (e: any) {
186
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
187
- if (this.deviceLogging === 'debug') {
188
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
189
- + ` Error Message: ${JSON.stringify(e.message)}`);
190
- }
191
- if (this.platform.debugMode) {
192
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,`
193
- + ` Error: ${JSON.stringify(e)}`);
214
+ this.errorLog(
215
+ `Humidifier: ${this.accessory.displayName} failed pushChanges`,
216
+ );
217
+ if (this.deviceLogging.includes("debug")) {
218
+ this.errorLog(
219
+ `Humidifier: ${this.accessory.displayName} failed pushChanges,` +
220
+ ` Error Message: ${JSON.stringify(e.message)}`,
221
+ );
194
222
  }
195
223
  this.apiError(e);
196
224
  }
@@ -201,7 +229,7 @@ export class Humidifier {
201
229
  /**
202
230
  * Parse the device status from the SwitchBot api
203
231
  */
204
- parseStatus() {
232
+ parseStatus(): void {
205
233
  if (this.device.ble) {
206
234
  this.BLEparseStatus();
207
235
  } else {
@@ -209,73 +237,106 @@ export class Humidifier {
209
237
  }
210
238
  }
211
239
 
212
- private BLEparseStatus() {
240
+ private BLEparseStatus(): void {
213
241
  this.debugLog(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
214
242
  // Current Relative Humidity
215
243
  this.CurrentRelativeHumidity = this.percentage!;
216
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
244
+ this.debugLog(
245
+ `Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
246
+ );
217
247
  // Active
218
248
  if (this.onState) {
219
249
  this.Active = this.platform.Characteristic.Active.ACTIVE;
220
250
  } else {
221
251
  this.Active = this.platform.Characteristic.Active.INACTIVE;
222
252
  }
223
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
253
+ this.debugLog(
254
+ `Humidifier: ${this.accessory.displayName} Active: ${this.Active}`,
255
+ );
224
256
  }
225
257
 
226
258
  private openAPIparseStatus() {
227
259
  if (this.platform.config.credentials?.openToken) {
228
- this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
260
+ this.debugLog(
261
+ `Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`,
262
+ );
229
263
  // Current Relative Humidity
230
264
  this.CurrentRelativeHumidity = this.humidity!;
231
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
265
+ this.debugLog(
266
+ `Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
267
+ );
232
268
  // Current Temperature
233
269
  if (!this.device.humidifier?.hide_temperature) {
234
270
  this.CurrentTemperature = this.temperature!;
235
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
271
+ this.debugLog(
272
+ `Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`,
273
+ );
236
274
  }
237
275
  // Target Humidifier Dehumidifier State
238
276
  switch (this.auto) {
239
277
  case true:
240
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
241
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
242
- this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
278
+ this.TargetHumidifierDehumidifierState =
279
+ this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
280
+ this.CurrentHumidifierDehumidifierState =
281
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
282
+ this.RelativeHumidityHumidifierThreshold =
283
+ this.CurrentRelativeHumidity;
243
284
  break;
244
285
  default:
245
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
286
+ this.TargetHumidifierDehumidifierState =
287
+ this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
246
288
  if (this.nebulizationEfficiency! > 100) {
247
289
  this.RelativeHumidityHumidifierThreshold = 100;
248
290
  } else {
249
- this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency!;
291
+ this.RelativeHumidityHumidifierThreshold =
292
+ this.nebulizationEfficiency!;
250
293
  }
251
- if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
252
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
253
- } else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
254
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
294
+ if (
295
+ this.CurrentRelativeHumidity >
296
+ this.RelativeHumidityHumidifierThreshold
297
+ ) {
298
+ this.CurrentHumidifierDehumidifierState =
299
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
300
+ } else if (
301
+ this.Active === this.platform.Characteristic.Active.INACTIVE
302
+ ) {
303
+ this.CurrentHumidifierDehumidifierState =
304
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
255
305
  } else {
256
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
306
+ this.CurrentHumidifierDehumidifierState =
307
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
257
308
  }
258
309
  }
259
- this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
260
- this.debugLog(`Humidifier: ${this.accessory.displayName}`
261
- + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
262
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
310
+ this.debugLog(
311
+ `Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
312
+ );
313
+ this.debugLog(
314
+ `Humidifier: ${this.accessory.displayName}` +
315
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
316
+ );
317
+ this.debugLog(
318
+ `Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
319
+ );
263
320
  // Active
264
321
  switch (this.power) {
265
- case 'on':
322
+ case "on":
266
323
  this.Active = this.platform.Characteristic.Active.ACTIVE;
267
324
  break;
268
325
  default:
269
326
  this.Active = this.platform.Characteristic.Active.INACTIVE;
270
327
  }
271
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
328
+ this.debugLog(
329
+ `Humidifier: ${this.accessory.displayName} Active: ${this.Active}`,
330
+ );
272
331
  // Water Level
273
332
  if (this.lackWater) {
274
333
  this.WaterLevel = 0;
275
334
  } else {
276
335
  this.WaterLevel = 100;
277
336
  }
278
- this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
337
+ this.debugLog(
338
+ `Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`,
339
+ );
279
340
  }
280
341
  }
281
342
 
@@ -291,102 +352,138 @@ export class Humidifier {
291
352
  }
292
353
 
293
354
  private async BLERefreshStatus() {
294
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
355
+ this.debugLog(
356
+ `Humidifier: ${this.accessory.displayName} BLE refreshStatus`,
357
+ );
295
358
  const switchbot = await this.platform.connectBLE();
296
359
  // Convert to BLE Address
297
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
298
- this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
299
- // Start to monitor advertisement packets
300
- if (switchbot !== false) {
301
- switchbot.startScan({
302
- model: 'e',
360
+ this.device.bleMac = this.device
361
+ .deviceId!.match(/.{1,2}/g)!
362
+ .join(":")
363
+ .toLowerCase();
364
+ this.debugLog(
365
+ `Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
366
+ );
367
+ try {
368
+ await switchbot.discover({
369
+ model: "e",
370
+ quick: false,
371
+ });
372
+ // Start to monitor advertisement packets
373
+ await switchbot.startScan({
374
+ model: "e",
303
375
  id: this.device.bleMac,
304
- }).then(() => {
305
- // Set an event hander
306
- switchbot.onadvertisement = (ad: ad) => {
307
- this.serviceData = ad.serviceData;
308
- this.autoMode = ad.serviceData.autoMode;
309
- this.onState = ad.serviceData.onState;
310
- this.percentage = ad.serviceData.percentage;
311
- this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
312
- this.debugLog(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},`
313
- + `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
314
-
315
- if (this.serviceData) {
316
- this.connected = true;
317
- this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
318
- } else {
319
- this.connected = false;
320
- this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
321
- }
322
- };
323
- // Wait 2 seconds
324
- return switchbot.wait(this.scanDuration * 1000);
325
- }).then(async () => {
326
- // Stop to monitor
327
- switchbot.stopScan();
328
- if (this.connected) {
329
- this.parseStatus();
330
- this.updateHomeKitCharacteristics();
376
+ });
377
+ // Set an event hander
378
+ switchbot.onadvertisement = (ad: settings.ad) => {
379
+ this.serviceData = ad.serviceData;
380
+ this.autoMode = ad.serviceData.autoMode;
381
+ this.onState = ad.serviceData.onState;
382
+ this.percentage = ad.serviceData.percentage;
383
+ this.debugLog(
384
+ `Humidifier: ${
385
+ this.accessory.displayName
386
+ } serviceData: ${JSON.stringify(ad.serviceData)}`,
387
+ );
388
+ this.debugLog(
389
+ `Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
390
+ `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`,
391
+ );
392
+
393
+ if (this.serviceData) {
394
+ this.connected = true;
395
+ this.debugLog(
396
+ `Humidifier: ${this.accessory.displayName} connected: ${this.connected}`,
397
+ );
331
398
  } else {
332
- await this.BLEconnection(switchbot);
333
- }
334
- }).catch(async (e: any) => {
335
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
336
- if (this.deviceLogging === 'debug') {
337
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
338
- + ` Error Message: ${JSON.stringify(e.message)}`);
339
- }
340
- if (this.platform.debugMode) {
341
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
342
- + ` Error: ${JSON.stringify(e)}`);
399
+ this.connected = false;
400
+ this.debugLog(
401
+ `Humidifier: ${this.accessory.displayName} connected: ${this.connected}`,
402
+ );
343
403
  }
404
+ };
405
+ // Wait 2 seconds
406
+ await switchbot.wait(this.scanDuration * 1000);
407
+ // Stop to monitor
408
+ switchbot.stopScan();
409
+ if (this.connected) {
410
+ this.parseStatus();
411
+ this.updateHomeKitCharacteristics();
412
+ } else {
413
+ this.errorLog(
414
+ `Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
415
+ );
344
416
  if (this.platform.config.credentials?.openToken) {
345
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
417
+ this.warnLog(
418
+ `Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
419
+ );
420
+ this.SwitchToOpenAPI = true;
346
421
  await this.openAPIRefreshStatus();
347
422
  }
348
- this.apiError(e);
349
- });
350
- } else {
351
- await this.BLEconnection(switchbot);
352
- }
353
- }
354
-
355
- public async BLEconnection(switchbot: any) {
356
- this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
357
- if (this.platform.config.credentials?.openToken) {
358
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
359
- await this.openAPIRefreshStatus();
423
+ }
424
+ } catch (e: any) {
425
+ this.errorLog(
426
+ `Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`,
427
+ );
428
+ if (this.deviceLogging.includes("debug")) {
429
+ this.errorLog(
430
+ `Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` +
431
+ ` Error Message: ${JSON.stringify(e.message)}`,
432
+ );
433
+ }
434
+ if (this.platform.config.credentials?.openToken) {
435
+ this.warnLog(
436
+ `Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
437
+ );
438
+ this.SwitchToOpenAPI = true;
439
+ await this.openAPIRefreshStatus();
440
+ }
441
+ this.apiError(e);
360
442
  }
361
443
  }
362
444
 
363
445
  private async openAPIRefreshStatus() {
364
446
  if (this.platform.config.credentials?.openToken) {
365
- this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
447
+ this.debugLog(
448
+ `Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`,
449
+ );
366
450
  try {
367
- this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
368
- if (this.deviceStatus.message === 'success') {
369
- this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
451
+ this.deviceStatus = (
452
+ await this.platform.axios.get(
453
+ `${settings.DeviceURL}/${this.device.deviceId}/status`,
454
+ )
455
+ ).data;
456
+ if (this.deviceStatus.message === "success") {
457
+ this.debugLog(
458
+ `Humidifier: ${
459
+ this.accessory.displayName
460
+ } refreshStatus: ${JSON.stringify(this.deviceStatus)}`,
461
+ );
370
462
  this.auto = this.deviceStatus.body.auto;
371
463
  this.power = this.deviceStatus.body.power;
372
464
  this.lackWater = this.deviceStatus.body.lackWater;
373
465
  this.humidity = this.deviceStatus.body.humidity;
374
466
  this.temperature = this.deviceStatus.body.temperature;
375
- this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
467
+ this.nebulizationEfficiency =
468
+ this.deviceStatus.body.nebulizationEfficiency;
376
469
  this.parseStatus();
377
470
  this.updateHomeKitCharacteristics();
378
471
  } else {
379
- this.errorLog(`Humidifier: ${this.accessory.displayName} message: ${JSON.stringify(this.deviceStatus.message)}`);
472
+ this.errorLog(
473
+ `Humidifier: ${
474
+ this.accessory.displayName
475
+ } message: ${JSON.stringify(this.deviceStatus.message)}`,
476
+ );
380
477
  }
381
478
  } catch (e: any) {
382
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
383
- if (this.deviceLogging === 'debug') {
384
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
385
- + ` Error Message: ${JSON.stringify(e.message)}`);
386
- }
387
- if (this.platform.debugMode) {
388
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
389
- + ` Error: ${JSON.stringify(e)}`);
479
+ this.errorLog(
480
+ `Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`,
481
+ );
482
+ if (this.deviceLogging.includes("debug")) {
483
+ this.errorLog(
484
+ `Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
485
+ ` Error Message: ${JSON.stringify(e.message)}`,
486
+ );
390
487
  }
391
488
  this.apiError(e);
392
489
  }
@@ -402,9 +499,10 @@ export class Humidifier {
402
499
  //} else {
403
500
  await this.openAPIpushChanges();
404
501
  //}
405
- interval(5000)
406
- .pipe(skipWhile(() => this.humidifierUpdateInProgress))
407
- .pipe(take(1))
502
+ rxjs
503
+ .interval(5000)
504
+ .pipe(operators.skipWhile(() => this.humidifierUpdateInProgress))
505
+ .pipe(operators.take(1))
408
506
  .subscribe(() => {
409
507
  this.refreshStatus();
410
508
  });
@@ -414,34 +512,53 @@ export class Humidifier {
414
512
  this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
415
513
  const switchbot = await this.platform.connectBLE();
416
514
  // Convert to BLE Address
417
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
418
- this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
515
+ this.device.bleMac = this.device
516
+ .deviceId!.match(/.{1,2}/g)!
517
+ .join(":")
518
+ .toLowerCase();
519
+ this.debugLog(
520
+ `Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`,
521
+ );
419
522
  if (switchbot !== false) {
420
- switchbot.discover({ model: 'e', quick: true, id: this.device.bleMac }).then((device_list) => {
421
- this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
422
- return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
423
- }).then(() => {
424
- this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
425
- }).catch(async (e: any) => {
426
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
427
- if (this.deviceLogging === 'debug') {
428
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
429
- + ` Error Message: ${JSON.stringify(e.message)}`);
430
- }
431
- if (this.platform.debugMode) {
432
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
433
- + ` Error: ${JSON.stringify(e)}`);
434
- }
435
- if (this.platform.config.credentials?.openToken) {
436
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
437
- await this.openAPIpushChanges();
438
- }
439
- this.apiError(e);
440
- });
523
+ switchbot
524
+ .discover({ model: "e", quick: true, id: this.device.bleMac })
525
+ .then((device_list) => {
526
+ this.infoLog(
527
+ `${this.accessory.displayName} Target Position: ${this.Active}`,
528
+ );
529
+ return device_list[0].percentage(
530
+ this.RelativeHumidityHumidifierThreshold,
531
+ );
532
+ })
533
+ .then(() => {
534
+ this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
535
+ })
536
+ .catch(async (e: any) => {
537
+ this.errorLog(
538
+ `Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`,
539
+ );
540
+ if (this.deviceLogging.includes("debug")) {
541
+ this.errorLog(
542
+ `Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` +
543
+ ` Error Message: ${JSON.stringify(e.message)}`,
544
+ );
545
+ }
546
+ if (this.platform.config.credentials?.openToken) {
547
+ this.warnLog(
548
+ `Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
549
+ );
550
+ await this.openAPIpushChanges();
551
+ }
552
+ this.apiError(e);
553
+ });
441
554
  } else {
442
- this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
555
+ this.errorLog(
556
+ `Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`,
557
+ );
443
558
  if (this.platform.config.credentials?.openToken) {
444
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
559
+ this.warnLog(
560
+ `Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`,
561
+ );
445
562
  await this.openAPIpushChanges();
446
563
  }
447
564
  }
@@ -449,42 +566,57 @@ export class Humidifier {
449
566
 
450
567
  private async openAPIpushChanges() {
451
568
  if (this.platform.config.credentials?.openToken) {
452
- this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
569
+ this.debugLog(
570
+ `Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`,
571
+ );
453
572
  if (
454
573
  this.TargetHumidifierDehumidifierState ===
455
- this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
574
+ this.platform.Characteristic.TargetHumidifierDehumidifierState
575
+ .HUMIDIFIER &&
456
576
  this.Active === this.platform.Characteristic.Active.ACTIVE
457
577
  ) {
458
578
  try {
459
- this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
579
+ this.debugLog(
580
+ `Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`,
581
+ );
460
582
  const payload = {
461
- commandType: 'command',
462
- command: 'setMode',
583
+ commandType: "command",
584
+ command: "setMode",
463
585
  parameter: `${this.RelativeHumidityHumidifierThreshold}`,
464
- } as payload;
586
+ } as settings.payload;
465
587
 
466
- this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
467
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
588
+ this.infoLog(
589
+ `Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
590
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
591
+ );
468
592
 
469
593
  // Make the API request
470
- const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
471
- this.debugLog(`Humidifier: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
594
+ const push: any = await this.platform.axios.post(
595
+ `${settings.DeviceURL}/${this.device.deviceId}/commands`,
596
+ payload,
597
+ );
598
+ this.debugLog(
599
+ `Humidifier: ${
600
+ this.accessory.displayName
601
+ } pushChanges: ${JSON.stringify(push.data)}`,
602
+ );
472
603
  this.statusCode(push);
473
604
  } catch (e: any) {
474
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
475
- if (this.deviceLogging === 'debug') {
476
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
477
- + ` Error Message: ${JSON.stringify(e.message)}`);
478
- }
479
- if (this.platform.debugMode) {
480
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
481
- + ` Error: ${JSON.stringify(e)}`);
605
+ this.errorLog(
606
+ `Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
607
+ );
608
+ if (this.deviceLogging.includes("debug")) {
609
+ this.errorLog(
610
+ `Humidifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
611
+ ` Error Message: ${JSON.stringify(e.message)}`,
612
+ );
482
613
  }
483
614
  this.apiError(e);
484
615
  }
485
616
  } else if (
486
617
  this.TargetHumidifierDehumidifierState ===
487
- this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
618
+ this.platform.Characteristic.TargetHumidifierDehumidifierState
619
+ .HUMIDIFIER_OR_DEHUMIDIFIER &&
488
620
  this.Active === this.platform.Characteristic.Active.ACTIVE
489
621
  ) {
490
622
  await this.pushAutoChanges();
@@ -501,33 +633,43 @@ export class Humidifier {
501
633
  try {
502
634
  if (
503
635
  this.TargetHumidifierDehumidifierState ===
504
- this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
636
+ this.platform.Characteristic.TargetHumidifierDehumidifierState
637
+ .HUMIDIFIER_OR_DEHUMIDIFIER &&
505
638
  this.Active === this.platform.Characteristic.Active.ACTIVE
506
639
  ) {
507
- this.debugLog('Pushing Auto!');
640
+ this.debugLog("Pushing Auto!");
508
641
  const payload = {
509
- commandType: 'command',
510
- command: 'setMode',
511
- parameter: 'auto',
512
- } as payload;
642
+ commandType: "command",
643
+ command: "setMode",
644
+ parameter: "auto",
645
+ } as settings.payload;
513
646
 
514
- this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
515
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
647
+ this.infoLog(
648
+ `Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
649
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
650
+ );
516
651
 
517
652
  // Make the API request
518
- const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
519
- this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(push.data)}`);
653
+ const push: any = await this.platform.axios.post(
654
+ `${settings.DeviceURL}/${this.device.deviceId}/commands`,
655
+ payload,
656
+ );
657
+ this.debugLog(
658
+ `Humidifier: ${
659
+ this.accessory.displayName
660
+ } pushAutoChanges: ${JSON.stringify(push.data)}`,
661
+ );
520
662
  this.statusCode(push);
521
663
  }
522
664
  } catch (e: any) {
523
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
524
- if (this.deviceLogging === 'debug') {
525
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
526
- + ` Error Message: ${JSON.stringify(e.message)}`);
527
- }
528
- if (this.platform.debugMode) {
529
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,`
530
- + ` Error: ${JSON.stringify(e)}`);
665
+ this.errorLog(
666
+ `Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`,
667
+ );
668
+ if (this.deviceLogging.includes("debug")) {
669
+ this.errorLog(
670
+ `Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` +
671
+ ` Error Message: ${JSON.stringify(e.message)}`,
672
+ );
531
673
  }
532
674
  this.apiError(e);
533
675
  }
@@ -539,30 +681,39 @@ export class Humidifier {
539
681
  async pushActiveChanges() {
540
682
  try {
541
683
  if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
542
- this.debugLog('Pushing Off!');
684
+ this.debugLog("Pushing Off!");
543
685
  const payload = {
544
- commandType: 'command',
545
- command: 'turnOff',
546
- parameter: 'default',
547
- } as payload;
686
+ commandType: "command",
687
+ command: "turnOff",
688
+ parameter: "default",
689
+ } as settings.payload;
548
690
 
549
- this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
550
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
691
+ this.infoLog(
692
+ `Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
693
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
694
+ );
551
695
 
552
696
  // Make the API request
553
- const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
554
- this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(push.data)}`);
697
+ const push: any = await this.platform.axios.post(
698
+ `${settings.DeviceURL}/${this.device.deviceId}/commands`,
699
+ payload,
700
+ );
701
+ this.debugLog(
702
+ `Humidifier: ${
703
+ this.accessory.displayName
704
+ } pushActiveChanges: ${JSON.stringify(push.data)}`,
705
+ );
555
706
  this.statusCode(push);
556
707
  }
557
708
  } catch (e: any) {
558
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
559
- if (this.deviceLogging === 'debug') {
560
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
561
- + ` Error Message: ${JSON.stringify(e.message)}`);
562
- }
563
- if (this.platform.debugMode) {
564
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,`
565
- + ` Error: ${JSON.stringify(e)}`);
709
+ this.errorLog(
710
+ `Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`,
711
+ );
712
+ if (this.deviceLogging.includes("debug")) {
713
+ this.errorLog(
714
+ `Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` +
715
+ ` Error Message: ${JSON.stringify(e.message)}`,
716
+ );
566
717
  }
567
718
  this.apiError(e);
568
719
  }
@@ -573,116 +724,205 @@ export class Humidifier {
573
724
  */
574
725
  updateHomeKitCharacteristics() {
575
726
  if (this.CurrentRelativeHumidity === undefined) {
576
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
727
+ this.debugLog(
728
+ `Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
729
+ );
577
730
  } else {
578
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
579
- this.debugLog(`Humidifier: ${this.accessory.displayName}`
580
- + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
731
+ this.service.updateCharacteristic(
732
+ this.platform.Characteristic.CurrentRelativeHumidity,
733
+ this.CurrentRelativeHumidity,
734
+ );
735
+ this.debugLog(
736
+ `Humidifier: ${this.accessory.displayName}` +
737
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
738
+ );
581
739
  }
582
740
  if (!this.device.ble) {
583
741
  if (this.WaterLevel === undefined) {
584
- this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
742
+ this.debugLog(
743
+ `Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`,
744
+ );
585
745
  } else {
586
- this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
587
- this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
746
+ this.service.updateCharacteristic(
747
+ this.platform.Characteristic.WaterLevel,
748
+ this.WaterLevel,
749
+ );
750
+ this.debugLog(
751
+ `Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`,
752
+ );
588
753
  }
589
754
  }
590
755
  if (this.CurrentHumidifierDehumidifierState === undefined) {
591
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
756
+ this.debugLog(
757
+ `Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
758
+ );
592
759
  } else {
593
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
594
- this.debugLog(`Humidifier: ${this.accessory.displayName}`
595
- + ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
760
+ this.service.updateCharacteristic(
761
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState,
762
+ this.CurrentHumidifierDehumidifierState,
763
+ );
764
+ this.debugLog(
765
+ `Humidifier: ${this.accessory.displayName}` +
766
+ ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`,
767
+ );
596
768
  }
597
769
  if (this.TargetHumidifierDehumidifierState === undefined) {
598
- this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
770
+ this.debugLog(
771
+ `Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
772
+ );
599
773
  } else {
600
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
601
- this.debugLog(`Humidifier: ${this.accessory.displayName}`
602
- + ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
774
+ this.service.updateCharacteristic(
775
+ this.platform.Characteristic.TargetHumidifierDehumidifierState,
776
+ this.TargetHumidifierDehumidifierState,
777
+ );
778
+ this.debugLog(
779
+ `Humidifier: ${this.accessory.displayName}` +
780
+ ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`,
781
+ );
603
782
  }
604
783
  if (this.Active === undefined) {
605
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
784
+ this.debugLog(
785
+ `Humidifier: ${this.accessory.displayName} Active: ${this.Active}`,
786
+ );
606
787
  } else {
607
- this.service.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
608
- this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
788
+ this.service.updateCharacteristic(
789
+ this.platform.Characteristic.Active,
790
+ this.Active,
791
+ );
792
+ this.debugLog(
793
+ `Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
794
+ );
609
795
  }
610
796
  if (this.RelativeHumidityHumidifierThreshold === undefined) {
611
- this.debugLog(`Humidifier: ${this.accessory.displayName}`
612
- + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
797
+ this.debugLog(
798
+ `Humidifier: ${this.accessory.displayName}` +
799
+ ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
800
+ );
613
801
  } else {
614
- this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
615
- this.debugLog(`Humidifier: ${this.accessory.displayName}`
616
- + ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
802
+ this.service.updateCharacteristic(
803
+ this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
804
+ this.RelativeHumidityHumidifierThreshold,
805
+ );
806
+ this.debugLog(
807
+ `Humidifier: ${this.accessory.displayName}` +
808
+ ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`,
809
+ );
617
810
  }
618
811
  if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
619
812
  if (this.CurrentTemperature === undefined) {
620
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
813
+ this.debugLog(
814
+ `Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`,
815
+ );
621
816
  } else {
622
- this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
623
- this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
817
+ this.temperatureservice?.updateCharacteristic(
818
+ this.platform.Characteristic.CurrentTemperature,
819
+ this.CurrentTemperature,
820
+ );
821
+ this.debugLog(
822
+ `Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`,
823
+ );
624
824
  }
625
825
  }
626
826
  }
627
827
 
628
- public apiError(e: any) {
629
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
828
+ public apiError(e: any): void {
829
+ this.service.updateCharacteristic(
830
+ this.platform.Characteristic.CurrentRelativeHumidity,
831
+ e,
832
+ );
630
833
  if (!this.device.ble) {
631
- this.service.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
834
+ this.service.updateCharacteristic(
835
+ this.platform.Characteristic.WaterLevel,
836
+ e,
837
+ );
632
838
  }
633
- this.service.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
634
- this.service.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
839
+ this.service.updateCharacteristic(
840
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState,
841
+ e,
842
+ );
843
+ this.service.updateCharacteristic(
844
+ this.platform.Characteristic.TargetHumidifierDehumidifierState,
845
+ e,
846
+ );
635
847
  this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
636
- this.service.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
848
+ this.service.updateCharacteristic(
849
+ this.platform.Characteristic.RelativeHumidityHumidifierThreshold,
850
+ e,
851
+ );
637
852
  if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
638
- this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
853
+ this.temperatureservice?.updateCharacteristic(
854
+ this.platform.Characteristic.CurrentTemperature,
855
+ e,
856
+ );
639
857
  }
640
858
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
641
859
  }
642
860
 
643
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
861
+ private statusCode(push: axios.AxiosResponse<{ statusCode: number }>): void {
644
862
  switch (push.data.statusCode) {
645
863
  case 151:
646
- this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
864
+ this.errorLog(
865
+ `Humidifier: ${this.accessory.displayName} Command not supported by this device type.`,
866
+ );
647
867
  break;
648
868
  case 152:
649
- this.errorLog(`Humidifier: ${this.accessory.displayName} Device not found.`);
869
+ this.errorLog(
870
+ `Humidifier: ${this.accessory.displayName} Device not found.`,
871
+ );
650
872
  break;
651
873
  case 160:
652
- this.errorLog(`Humidifier: ${this.accessory.displayName} Command is not supported.`);
874
+ this.errorLog(
875
+ `Humidifier: ${this.accessory.displayName} Command is not supported.`,
876
+ );
653
877
  break;
654
878
  case 161:
655
- this.errorLog(`Humidifier: ${this.accessory.displayName} Device is offline.`);
879
+ this.errorLog(
880
+ `Humidifier: ${this.accessory.displayName} Device is offline.`,
881
+ );
656
882
  this.offlineOff();
657
883
  break;
658
884
  case 171:
659
- this.errorLog(`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
885
+ this.errorLog(
886
+ `Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
887
+ );
660
888
  this.offlineOff();
661
889
  break;
662
890
  case 190:
663
- this.errorLog(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
664
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
891
+ this.errorLog(
892
+ `Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
893
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`,
894
+ );
665
895
  break;
666
896
  case 100:
667
- this.debugLog(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
897
+ this.debugLog(
898
+ `Humidifier: ${this.accessory.displayName} Command successfully sent.`,
899
+ );
668
900
  break;
669
901
  default:
670
- this.debugLog(`Humidifier: ${this.accessory.displayName} Unknown statusCode.`);
902
+ this.debugLog(
903
+ `Humidifier: ${this.accessory.displayName} Unknown statusCode.`,
904
+ );
671
905
  }
672
906
  }
673
907
 
674
908
  private offlineOff() {
675
909
  if (this.device.offline) {
676
910
  this.Active = this.platform.Characteristic.Active.INACTIVE;
677
- this.service.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
911
+ this.service
912
+ .getCharacteristic(this.platform.Characteristic.Active)
913
+ .updateValue(this.Active);
678
914
  }
679
915
  }
680
916
 
681
917
  /**
682
918
  * Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
683
919
  */
684
- private handleTargetHumidifierDehumidifierStateSet(value: CharacteristicValue) {
685
- this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
920
+ private handleTargetHumidifierDehumidifierStateSet(
921
+ value: homebridge.CharacteristicValue,
922
+ ) {
923
+ this.debugLog(
924
+ `Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`,
925
+ );
686
926
 
687
927
  this.TargetHumidifierDehumidifierState = value;
688
928
  this.doHumidifierUpdate.next();
@@ -691,7 +931,7 @@ export class Humidifier {
691
931
  /**
692
932
  * Handle requests to set the "Active" characteristic
693
933
  */
694
- private handleActiveSet(value: CharacteristicValue) {
934
+ private handleActiveSet(value: homebridge.CharacteristicValue) {
695
935
  this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
696
936
  this.Active = value;
697
937
  this.doHumidifierUpdate.next();
@@ -700,76 +940,105 @@ export class Humidifier {
700
940
  /**
701
941
  * Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
702
942
  */
703
- private handleRelativeHumidityHumidifierThresholdSet(value: CharacteristicValue) {
704
- this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
943
+ private handleRelativeHumidityHumidifierThresholdSet(
944
+ value: homebridge.CharacteristicValue,
945
+ ) {
946
+ this.debugLog(
947
+ `Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`,
948
+ );
705
949
 
706
950
  this.RelativeHumidityHumidifierThreshold = value;
707
951
  if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
708
952
  this.Active = this.platform.Characteristic.Active.ACTIVE;
709
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
953
+ this.CurrentHumidifierDehumidifierState =
954
+ this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
710
955
  }
711
956
  this.doHumidifierUpdate.next();
712
957
  }
713
958
 
714
- config(device: device & devicesConfig) {
959
+ config(device: settings.device & settings.devicesConfig) {
715
960
  let config = {};
716
961
  if (device.humidifier) {
717
962
  config = device.humidifier;
718
963
  }
719
964
  if (device.ble !== undefined) {
720
- config['ble'] = device.ble;
965
+ config["ble"] = device.ble;
721
966
  }
722
967
  if (device.logging !== undefined) {
723
- config['logging'] = device.logging;
968
+ config["logging"] = device.logging;
724
969
  }
725
970
  if (device.refreshRate !== undefined) {
726
- config['refreshRate'] = device.refreshRate;
971
+ config["refreshRate"] = device.refreshRate;
727
972
  }
728
973
  if (device.scanDuration !== undefined) {
729
- config['scanDuration'] = device.scanDuration;
974
+ config["scanDuration"] = device.scanDuration;
730
975
  }
731
976
  if (Object.entries(config).length !== 0) {
732
- this.warnLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
977
+ this.warnLog(
978
+ `Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(
979
+ config,
980
+ )}`,
981
+ );
733
982
  }
734
983
  }
735
984
 
736
- refreshRate(device: device & devicesConfig) {
985
+ refreshRate(device: settings.device & settings.devicesConfig) {
737
986
  if (device.refreshRate) {
738
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
739
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
987
+ this.deviceRefreshRate = this.accessory.context.refreshRate =
988
+ device.refreshRate;
989
+ this.debugLog(
990
+ `Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
991
+ );
740
992
  } else if (this.platform.config.options!.refreshRate) {
741
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
742
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
993
+ this.deviceRefreshRate = this.accessory.context.refreshRate =
994
+ this.platform.config.options!.refreshRate;
995
+ this.debugLog(
996
+ `Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
997
+ );
743
998
  }
744
999
  }
745
1000
 
746
- scan(device: device & devicesConfig) {
1001
+ scan(device: settings.device & settings.devicesConfig) {
747
1002
  if (device.scanDuration) {
748
- this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
1003
+ this.scanDuration = this.accessory.context.scanDuration =
1004
+ device.scanDuration;
749
1005
  if (device.ble) {
750
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
1006
+ this.debugLog(
1007
+ `Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`,
1008
+ );
751
1009
  }
752
1010
  } else {
753
1011
  this.scanDuration = this.accessory.context.scanDuration = 1;
754
1012
  if (this.device.ble) {
755
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
1013
+ this.debugLog(
1014
+ `Humidifier: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`,
1015
+ );
756
1016
  }
757
1017
  }
758
1018
  }
759
1019
 
760
- logs(device: device & devicesConfig) {
1020
+ logs(device: settings.device & settings.devicesConfig) {
761
1021
  if (this.platform.debugMode) {
762
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
763
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
1022
+ this.deviceLogging = this.accessory.context.logging = "debugMode";
1023
+ this.debugLog(
1024
+ `Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
1025
+ );
764
1026
  } else if (device.logging) {
765
1027
  this.deviceLogging = this.accessory.context.logging = device.logging;
766
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
1028
+ this.debugLog(
1029
+ `Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
1030
+ );
767
1031
  } else if (this.platform.config.options?.logging) {
768
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
769
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
1032
+ this.deviceLogging = this.accessory.context.logging =
1033
+ this.platform.config.options?.logging;
1034
+ this.debugLog(
1035
+ `Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
1036
+ );
770
1037
  } else {
771
- this.deviceLogging = this.accessory.context.logging = 'standard';
772
- this.debugLog(`Humidifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
1038
+ this.deviceLogging = this.accessory.context.logging = "standard";
1039
+ this.debugLog(
1040
+ `Humidifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
1041
+ );
773
1042
  }
774
1043
  }
775
1044
 
@@ -783,30 +1052,30 @@ export class Humidifier {
783
1052
  }
784
1053
 
785
1054
  /**
786
- * Logging for Device
787
- */
788
- infoLog(...log: any[]) {
1055
+ * Logging for Device
1056
+ */
1057
+ infoLog(...log: any[]): void {
789
1058
  if (this.enablingDeviceLogging()) {
790
1059
  this.platform.log.info(String(...log));
791
1060
  }
792
1061
  }
793
1062
 
794
- warnLog(...log: any[]) {
1063
+ warnLog(...log: any[]): void {
795
1064
  if (this.enablingDeviceLogging()) {
796
1065
  this.platform.log.warn(String(...log));
797
1066
  }
798
1067
  }
799
1068
 
800
- errorLog(...log: any[]) {
1069
+ errorLog(...log: any[]): void {
801
1070
  if (this.enablingDeviceLogging()) {
802
1071
  this.platform.log.error(String(...log));
803
1072
  }
804
1073
  }
805
1074
 
806
- debugLog(...log: any[]) {
1075
+ debugLog(...log: any[]): void {
807
1076
  if (this.enablingDeviceLogging()) {
808
- if (this.deviceLogging === 'debug') {
809
- this.platform.log.info('[DEBUG]', String(...log));
1077
+ if (this.deviceLogging === "debug") {
1078
+ this.platform.log.info("[DEBUG]", String(...log));
810
1079
  } else {
811
1080
  this.platform.log.debug(String(...log));
812
1081
  }
@@ -814,6 +1083,8 @@ export class Humidifier {
814
1083
  }
815
1084
 
816
1085
  enablingDeviceLogging(): boolean {
817
- return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
1086
+ return (
1087
+ this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
1088
+ );
818
1089
  }
819
1090
  }