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