@switchbot/homebridge-switchbot 2.0.0-beta.8 → 2.0.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 (120) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +3 -2
  3. package/config.schema.json +91 -19
  4. package/dist/device/bot.d.ts +34 -28
  5. package/dist/device/bot.d.ts.map +1 -1
  6. package/dist/device/bot.js +657 -648
  7. package/dist/device/bot.js.map +1 -1
  8. package/dist/device/ceilinglight.d.ts +137 -0
  9. package/dist/device/ceilinglight.d.ts.map +1 -0
  10. package/dist/device/ceilinglight.js +1127 -0
  11. package/dist/device/ceilinglight.js.map +1 -0
  12. package/dist/device/colorbulb.d.ts +36 -19
  13. package/dist/device/colorbulb.d.ts.map +1 -1
  14. package/dist/device/colorbulb.js +486 -309
  15. package/dist/device/colorbulb.js.map +1 -1
  16. package/dist/device/contact.d.ts +18 -8
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +306 -237
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts +23 -16
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +566 -502
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/humidifier.d.ts +24 -18
  25. package/dist/device/humidifier.d.ts.map +1 -1
  26. package/dist/device/humidifier.js +453 -369
  27. package/dist/device/humidifier.js.map +1 -1
  28. package/dist/device/lock.d.ts +27 -8
  29. package/dist/device/lock.d.ts.map +1 -1
  30. package/dist/device/lock.js +305 -148
  31. package/dist/device/lock.js.map +1 -1
  32. package/dist/device/meter.d.ts +22 -16
  33. package/dist/device/meter.d.ts.map +1 -1
  34. package/dist/device/meter.js +367 -267
  35. package/dist/device/meter.js.map +1 -1
  36. package/dist/device/meterplus.d.ts +24 -12
  37. package/dist/device/meterplus.d.ts.map +1 -1
  38. package/dist/device/meterplus.js +381 -213
  39. package/dist/device/meterplus.js.map +1 -1
  40. package/dist/device/motion.d.ts +18 -8
  41. package/dist/device/motion.d.ts.map +1 -1
  42. package/dist/device/motion.js +279 -216
  43. package/dist/device/motion.js.map +1 -1
  44. package/dist/device/plug.d.ts +27 -17
  45. package/dist/device/plug.d.ts.map +1 -1
  46. package/dist/device/plug.js +295 -251
  47. package/dist/device/plug.js.map +1 -1
  48. package/dist/device/striplight.d.ts +43 -19
  49. package/dist/device/striplight.d.ts.map +1 -1
  50. package/dist/device/striplight.js +506 -262
  51. package/dist/device/striplight.js.map +1 -1
  52. package/dist/irdevice/airconditioner.d.ts +9 -12
  53. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  54. package/dist/irdevice/airconditioner.js +278 -230
  55. package/dist/irdevice/airconditioner.js.map +1 -1
  56. package/dist/irdevice/airpurifier.d.ts +5 -3
  57. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  58. package/dist/irdevice/airpurifier.js +154 -104
  59. package/dist/irdevice/airpurifier.js.map +1 -1
  60. package/dist/irdevice/camera.d.ts +11 -8
  61. package/dist/irdevice/camera.d.ts.map +1 -1
  62. package/dist/irdevice/camera.js +133 -86
  63. package/dist/irdevice/camera.js.map +1 -1
  64. package/dist/irdevice/fan.d.ts +10 -7
  65. package/dist/irdevice/fan.d.ts.map +1 -1
  66. package/dist/irdevice/fan.js +160 -109
  67. package/dist/irdevice/fan.js.map +1 -1
  68. package/dist/irdevice/light.d.ts +11 -8
  69. package/dist/irdevice/light.d.ts.map +1 -1
  70. package/dist/irdevice/light.js +137 -103
  71. package/dist/irdevice/light.js.map +1 -1
  72. package/dist/irdevice/other.d.ts +11 -8
  73. package/dist/irdevice/other.d.ts.map +1 -1
  74. package/dist/irdevice/other.js +145 -98
  75. package/dist/irdevice/other.js.map +1 -1
  76. package/dist/irdevice/tv.d.ts +12 -9
  77. package/dist/irdevice/tv.d.ts.map +1 -1
  78. package/dist/irdevice/tv.js +143 -93
  79. package/dist/irdevice/tv.js.map +1 -1
  80. package/dist/irdevice/vacuumcleaner.d.ts +9 -10
  81. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  82. package/dist/irdevice/vacuumcleaner.js +132 -89
  83. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  84. package/dist/irdevice/waterheater.d.ts +8 -9
  85. package/dist/irdevice/waterheater.d.ts.map +1 -1
  86. package/dist/irdevice/waterheater.js +132 -89
  87. package/dist/irdevice/waterheater.js.map +1 -1
  88. package/dist/platform.d.ts +13 -12
  89. package/dist/platform.d.ts.map +1 -1
  90. package/dist/platform.js +524 -418
  91. package/dist/platform.js.map +1 -1
  92. package/dist/settings.d.ts +19 -11
  93. package/dist/settings.d.ts.map +1 -1
  94. package/dist/settings.js.map +1 -1
  95. package/homebridge-ui/public/index.html +1 -0
  96. package/package.json +11 -9
  97. package/src/device/bot.ts +656 -659
  98. package/src/device/ceilinglight.ts +1208 -0
  99. package/src/device/colorbulb.ts +490 -344
  100. package/src/device/contact.ts +309 -241
  101. package/src/device/curtain.ts +571 -516
  102. package/src/device/humidifier.ts +456 -403
  103. package/src/device/lock.ts +314 -149
  104. package/src/device/meter.ts +378 -280
  105. package/src/device/meterplus.ts +391 -219
  106. package/src/device/motion.ts +285 -222
  107. package/src/device/plug.ts +299 -260
  108. package/src/device/striplight.ts +522 -289
  109. package/src/irdevice/airconditioner.ts +282 -241
  110. package/src/irdevice/airpurifier.ts +151 -103
  111. package/src/irdevice/camera.ts +131 -85
  112. package/src/irdevice/fan.ts +157 -106
  113. package/src/irdevice/light.ts +135 -103
  114. package/src/irdevice/other.ts +143 -97
  115. package/src/irdevice/tv.ts +142 -93
  116. package/src/irdevice/vacuumcleaner.ts +131 -89
  117. package/src/irdevice/waterheater.ts +130 -89
  118. package/src/platform.ts +522 -446
  119. package/src/settings.ts +20 -11
  120. package/.github/npm-version-script.js +0 -81
@@ -7,6 +7,7 @@ exports.Humidifier = void 0;
7
7
  const https_1 = __importDefault(require("https"));
8
8
  const crypto_1 = __importDefault(require("crypto"));
9
9
  const rxjs_1 = require("rxjs");
10
+ const super_stringify_1 = __importDefault(require("super-stringify"));
10
11
  const operators_1 = require("rxjs/operators");
11
12
  const settings_1 = require("../settings");
12
13
  /**
@@ -19,18 +20,15 @@ class Humidifier {
19
20
  this.platform = platform;
20
21
  this.accessory = accessory;
21
22
  this.device = device;
23
+ // Connection
24
+ this.BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
25
+ this.OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
22
26
  // default placeholders
23
27
  this.logs(device);
24
28
  this.scan(device);
25
29
  this.refreshRate(device);
26
30
  this.config(device);
27
- this.CurrentRelativeHumidity = 0;
28
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
29
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
30
- this.Active = this.platform.Characteristic.Active.ACTIVE;
31
- this.RelativeHumidityHumidifierThreshold = 0;
32
- this.CurrentTemperature = 0;
33
- this.WaterLevel = 0;
31
+ this.context();
34
32
  // this is subject we use to track when we need to POST changes to the SwitchBot API
35
33
  this.doHumidifierUpdate = new rxjs_1.Subject();
36
34
  this.humidifierUpdateInProgress = false;
@@ -68,8 +66,8 @@ class Humidifier {
68
66
  maxValue: 1,
69
67
  validValues: [0, 1],
70
68
  })
71
- .onSet(this.handleTargetHumidifierDehumidifierStateSet.bind(this));
72
- this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.handleActiveSet.bind(this));
69
+ .onSet(this.TargetHumidifierDehumidifierStateSet.bind(this));
70
+ this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
73
71
  this.humidifierService
74
72
  .getCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold)
75
73
  .setProps({
@@ -78,15 +76,15 @@ class Humidifier {
78
76
  maxValue: 100,
79
77
  minStep: this.minStep(),
80
78
  })
81
- .onSet(this.handleRelativeHumidityHumidifierThresholdSet.bind(this));
79
+ .onSet(this.RelativeHumidityHumidifierThresholdSet.bind(this));
82
80
  // Temperature Sensor Service
83
- if (device.humidifier?.hide_temperature || device.ble) {
84
- this.debugLog(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`);
81
+ if (device.humidifier?.hide_temperature || this.BLE) {
82
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
85
83
  this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
86
84
  accessory.removeService(this.temperatureservice);
87
85
  }
88
- else if (!this.temperatureservice && !device.ble) {
89
- this.debugLog(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`);
86
+ else if (!this.temperatureservice && !this.BLE) {
87
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
90
88
  (this.temperatureservice =
91
89
  this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
92
90
  `${accessory.displayName} Temperature Sensor`;
@@ -104,7 +102,7 @@ class Humidifier {
104
102
  });
105
103
  }
106
104
  else {
107
- this.debugLog(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`);
105
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
108
106
  }
109
107
  // Retrieve initial values and updateHomekit
110
108
  this.updateHomeKitCharacteristics();
@@ -125,11 +123,9 @@ class Humidifier {
125
123
  await this.pushChanges();
126
124
  }
127
125
  catch (e) {
128
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges`);
129
- if (this.deviceLogging.includes('debug')) {
130
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
131
- }
132
126
  this.apiError(e);
127
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
128
+ + ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
133
129
  }
134
130
  this.humidifierUpdateInProgress = false;
135
131
  });
@@ -138,18 +134,22 @@ class Humidifier {
138
134
  * Parse the device status from the SwitchBot api
139
135
  */
140
136
  async parseStatus() {
141
- if (this.device.ble) {
137
+ if (this.BLE) {
142
138
  await this.BLEparseStatus();
143
139
  }
144
- else {
140
+ else if (this.OpenAPI && this.platform.config.credentials?.token) {
145
141
  await this.openAPIparseStatus();
146
142
  }
143
+ else {
144
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
145
+ + ` ${this.device.connectionType}, parseStatus will not happen.`);
146
+ }
147
147
  }
148
148
  async BLEparseStatus() {
149
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE parseStatus`);
149
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
150
150
  // Current Relative Humidity
151
151
  this.CurrentRelativeHumidity = this.percentage;
152
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
152
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
153
153
  // Active
154
154
  if (this.onState) {
155
155
  this.Active = this.platform.Characteristic.Active.ACTIVE;
@@ -157,86 +157,91 @@ class Humidifier {
157
157
  else {
158
158
  this.Active = this.platform.Characteristic.Active.INACTIVE;
159
159
  }
160
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
160
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
161
161
  }
162
162
  async openAPIparseStatus() {
163
- if (this.platform.config.credentials?.token) {
164
- this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI parseStatus`);
165
- // Current Relative Humidity
166
- this.CurrentRelativeHumidity = this.humidity;
167
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
168
- // Current Temperature
169
- if (!this.device.humidifier?.hide_temperature) {
170
- this.CurrentTemperature = this.temperature;
171
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
172
- }
173
- // Target Humidifier Dehumidifier State
174
- switch (this.auto) {
175
- case true:
176
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
163
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
164
+ // Current Relative Humidity
165
+ this.CurrentRelativeHumidity = this.humidity;
166
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
167
+ // Current Temperature
168
+ if (!this.device.humidifier?.hide_temperature) {
169
+ this.CurrentTemperature = this.temperature;
170
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
171
+ }
172
+ // Target Humidifier Dehumidifier State
173
+ switch (this.auto) {
174
+ case true:
175
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER;
176
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
177
+ this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
178
+ break;
179
+ default:
180
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
181
+ if (this.nebulizationEfficiency > 100) {
182
+ this.RelativeHumidityHumidifierThreshold = 100;
183
+ }
184
+ else {
185
+ this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency;
186
+ }
187
+ if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
188
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
189
+ }
190
+ else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
191
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
192
+ }
193
+ else {
177
194
  this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
178
- this.RelativeHumidityHumidifierThreshold = this.CurrentRelativeHumidity;
179
- break;
180
- default:
181
- this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
182
- if (this.nebulizationEfficiency > 100) {
183
- this.RelativeHumidityHumidifierThreshold = 100;
184
- }
185
- else {
186
- this.RelativeHumidityHumidifierThreshold = this.nebulizationEfficiency;
187
- }
188
- if (this.CurrentRelativeHumidity > this.RelativeHumidityHumidifierThreshold) {
189
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
190
- }
191
- else if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
192
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
193
- }
194
- else {
195
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING;
196
- }
197
- }
198
- this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
199
- this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
200
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
201
- // Active
202
- switch (this.power) {
203
- case 'on':
204
- this.Active = this.platform.Characteristic.Active.ACTIVE;
205
- break;
206
- default:
207
- this.Active = this.platform.Characteristic.Active.INACTIVE;
208
- }
209
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
210
- // Water Level
211
- if (this.lackWater) {
212
- this.WaterLevel = 0;
213
- }
214
- else {
215
- this.WaterLevel = 100;
216
- }
217
- this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
195
+ }
196
+ }
197
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
198
+ + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
199
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
200
+ + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
201
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
202
+ + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
203
+ // Active
204
+ switch (this.power) {
205
+ case 'on':
206
+ this.Active = this.platform.Characteristic.Active.ACTIVE;
207
+ break;
208
+ default:
209
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
210
+ }
211
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
212
+ // Water Level
213
+ if (this.lackWater) {
214
+ this.WaterLevel = 0;
218
215
  }
216
+ else {
217
+ this.WaterLevel = 100;
218
+ }
219
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
219
220
  }
220
221
  /**
221
222
  * Asks the SwitchBot API for the latest device information
222
223
  */
223
224
  async refreshStatus() {
224
- if (this.device.ble) {
225
+ if (this.BLE) {
225
226
  await this.BLERefreshStatus();
226
227
  }
227
- else {
228
+ else if (this.OpenAPI && this.platform.config.credentials?.token) {
228
229
  await this.openAPIRefreshStatus();
229
230
  }
231
+ else {
232
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
233
+ + ` ${this.device.connectionType}, refreshStatus will not happen.`);
234
+ }
230
235
  }
231
236
  async BLERefreshStatus() {
232
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE refreshStatus`);
237
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
233
238
  const switchbot = await this.platform.connectBLE();
234
239
  // Convert to BLE Address
235
240
  this.device.bleMac = this.device
236
241
  .deviceId.match(/.{1,2}/g)
237
242
  .join(':')
238
243
  .toLowerCase();
239
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
244
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
240
245
  this.getCustomBLEAddress(switchbot);
241
246
  // Start to monitor advertisement packets
242
247
  if (switchbot !== false) {
@@ -249,26 +254,22 @@ class Humidifier {
249
254
  // Set an event hander
250
255
  switchbot.onadvertisement = (ad) => {
251
256
  this.address = ad.address;
252
- if (this.deviceLogging.includes('debug')) {
253
- this.infoLog(this.address);
254
- this.infoLog(this.device.bleMac);
255
- this.infoLog(`Humidifier: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
256
- this.infoLog(`Humidifier: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
257
- }
257
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
258
+ + ` BLE Address Found: ${this.address}`);
258
259
  this.serviceData = ad.serviceData;
259
260
  this.autoMode = ad.serviceData.autoMode;
260
261
  this.onState = ad.serviceData.onState;
261
262
  this.percentage = ad.serviceData.percentage;
262
- this.debugLog(`Humidifier: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
263
- this.debugLog(`Humidifier: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
263
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
264
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName},` +
264
265
  `autoMode: ${ad.serviceData.autoMode}, onState: ${ad.serviceData.onState}, percentage: ${ad.serviceData.percentage}`);
265
266
  if (this.serviceData) {
266
267
  this.connected = true;
267
- this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
268
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
268
269
  }
269
270
  else {
270
271
  this.connected = false;
271
- this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`);
272
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
272
273
  }
273
274
  };
274
275
  // Wait 2 seconds
@@ -278,125 +279,95 @@ class Humidifier {
278
279
  // Stop to monitor
279
280
  switchbot.stopScan();
280
281
  if (this.connected) {
281
- this.parseStatus();
282
+ this.BLEparseStatus();
282
283
  this.updateHomeKitCharacteristics();
283
284
  }
284
285
  else {
285
- await this.BLEconnection(switchbot);
286
+ await this.BLERefreshConnection(switchbot);
286
287
  }
287
288
  })
288
289
  .catch(async (e) => {
289
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
290
- if (this.deviceLogging.includes('debug')) {
291
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
292
- }
293
- if (this.platform.config.credentials?.token) {
294
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
295
- await this.openAPIRefreshStatus();
296
- }
297
290
  this.apiError(e);
291
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
292
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
293
+ await this.BLERefreshConnection(switchbot);
298
294
  });
299
295
  }
300
296
  else {
301
- await this.BLEconnection(switchbot);
302
- }
303
- }
304
- async getCustomBLEAddress(switchbot) {
305
- if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
306
- (async () => {
307
- // Start to monitor advertisement packets
308
- await switchbot.startScan({
309
- model: 'e',
310
- });
311
- // Set an event handler
312
- switchbot.onadvertisement = (ad) => {
313
- this.warnLog(`Humidifier: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
314
- };
315
- await switchbot.wait(10000);
316
- // Stop to monitor
317
- switchbot.stopScan();
318
- })();
319
- }
320
- }
321
- async BLEconnection(switchbot) {
322
- this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
323
- if (this.platform.config.credentials?.token) {
324
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
325
- await this.openAPIRefreshStatus();
297
+ await this.BLERefreshConnection(switchbot);
326
298
  }
327
299
  }
328
300
  async openAPIRefreshStatus() {
329
- if (this.platform.config.credentials?.token) {
330
- this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI refreshStatus`);
331
- try {
332
- const t = Date.now();
333
- const nonce = 'requestID';
334
- const data = this.platform.config.credentials?.token + t + nonce;
335
- const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
336
- const sign = signTerm.toString('base64');
337
- this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
338
- const options = {
339
- hostname: settings_1.HostDomain,
340
- port: 443,
341
- path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
342
- method: 'GET',
343
- headers: {
344
- Authorization: this.platform.config.credentials?.token,
345
- sign: sign,
346
- nonce: nonce,
347
- t: t,
348
- 'Content-Type': 'application/json',
349
- },
350
- };
351
- const req = https_1.default.request(options, (res) => {
352
- this.debugLog(`Humidifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
353
- let rawData = '';
354
- res.on('data', (d) => {
355
- rawData += d;
356
- this.debugLog(`Humidifier: ${this.accessory.displayName} d: ${d}`);
357
- });
358
- res.on('end', () => {
359
- try {
360
- this.deviceStatus = JSON.parse(rawData);
361
- this.debugLog(`Humidifier: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
362
- this.auto = this.deviceStatus.body.auto;
363
- this.power = this.deviceStatus.body.power;
364
- this.lackWater = this.deviceStatus.body.lackWater;
365
- this.humidity = this.deviceStatus.body.humidity;
366
- this.temperature = this.deviceStatus.body.temperature;
367
- this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
368
- this.parseStatus();
369
- this.updateHomeKitCharacteristics();
370
- }
371
- catch (e) {
372
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
373
- }
374
- });
301
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
302
+ try {
303
+ const t = Date.now();
304
+ const nonce = 'requestID';
305
+ const data = this.platform.config.credentials?.token + t + nonce;
306
+ const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
307
+ const sign = signTerm.toString('base64');
308
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
309
+ const options = {
310
+ hostname: settings_1.HostDomain,
311
+ port: 443,
312
+ path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
313
+ method: 'GET',
314
+ headers: {
315
+ Authorization: this.platform.config.credentials?.token,
316
+ sign: sign,
317
+ nonce: nonce,
318
+ t: t,
319
+ 'Content-Type': 'application/json',
320
+ },
321
+ };
322
+ const req = https_1.default.request(options, (res) => {
323
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
324
+ let rawData = '';
325
+ res.on('data', (d) => {
326
+ rawData += d;
327
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
375
328
  });
376
- req.on('error', (e) => {
377
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
329
+ res.on('end', () => {
330
+ try {
331
+ this.deviceStatus = JSON.parse(rawData);
332
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
333
+ this.auto = this.deviceStatus.body.auto;
334
+ this.power = this.deviceStatus.body.power;
335
+ this.lackWater = this.deviceStatus.body.lackWater;
336
+ this.humidity = this.deviceStatus.body.humidity;
337
+ this.temperature = this.deviceStatus.body.temperature;
338
+ this.nebulizationEfficiency = this.deviceStatus.body.nebulizationEfficiency;
339
+ this.openAPIparseStatus();
340
+ this.updateHomeKitCharacteristics();
341
+ }
342
+ catch (e) {
343
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
344
+ }
378
345
  });
379
- req.end();
380
- }
381
- catch (e) {
382
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
383
- if (this.deviceLogging.includes('debug')) {
384
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
385
- ` Error Message: ${JSON.stringify(e.message)}`);
386
- }
387
- this.apiError(e);
388
- }
346
+ });
347
+ req.on('error', (e) => {
348
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
349
+ });
350
+ req.end();
351
+ }
352
+ catch (e) {
353
+ this.apiError(e);
354
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
355
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
389
356
  }
390
357
  }
391
358
  /**
392
359
  * Pushes the requested changes to the SwitchBot API
393
360
  */
394
361
  async pushChanges() {
395
- //if (this.device.ble) {
396
- // await this.BLEpushChanges();
397
- //} else {
398
- await this.openAPIpushChanges();
399
- //}
362
+ /*if (this.BLE) {
363
+ await this.BLEpushChanges();
364
+ } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
365
+ await this.openAPIpushChanges();
366
+ }
367
+ else {
368
+ this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
369
+ + ` ${this.device.connectionType}, pushChanges will not happen.`);
370
+ }
400
371
  (0, rxjs_1.interval)(5000)
401
372
  .pipe((0, operators_1.take)(1))
402
373
  .subscribe(async () => {
@@ -404,47 +375,37 @@ class Humidifier {
404
375
  });
405
376
  }
406
377
  async BLEpushChanges() {
407
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE pushChanges`);
378
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
408
379
  const switchbot = await this.platform.connectBLE();
409
380
  // Convert to BLE Address
410
381
  this.device.bleMac = this.device
411
382
  .deviceId.match(/.{1,2}/g)
412
383
  .join(':')
413
384
  .toLowerCase();
414
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
415
- if (switchbot !== false) {
416
- switchbot
417
- .discover({ model: 'e', quick: true, id: this.device.bleMac })
418
- .then((device_list) => {
419
- this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
420
- return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
421
- })
422
- .then(() => {
423
- this.debugLog(`Humidifier: ${this.accessory.displayName} Done.`);
424
- })
425
- .catch(async (e) => {
426
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
427
- if (this.deviceLogging.includes('debug')) {
428
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushChanges with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
429
- }
430
- if (this.platform.config.credentials?.token) {
431
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
432
- await this.openAPIpushChanges();
433
- }
434
- this.apiError(e);
435
- });
436
- }
437
- else {
438
- this.errorLog(`Humidifier: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
439
- if (this.platform.config.credentials?.token) {
440
- this.warnLog(`Humidifier: ${this.accessory.displayName} Using OpenAPI Connection`);
441
- await this.openAPIpushChanges();
442
- }
443
- }
385
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
386
+ switchbot
387
+ .discover({
388
+ model: 'e',
389
+ quick: true,
390
+ id: this.device.bleMac,
391
+ })
392
+ .then((device_list) => {
393
+ this.infoLog(`${this.accessory.displayName} Target Position: ${this.Active}`);
394
+ return device_list[0].percentage(this.RelativeHumidityHumidifierThreshold);
395
+ })
396
+ .then(() => {
397
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
398
+ })
399
+ .catch(async (e) => {
400
+ this.apiError(e);
401
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
402
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
403
+ await this.BLEPushConnection();
404
+ });
444
405
  }
445
406
  async openAPIpushChanges() {
446
- if (this.platform.config.credentials?.token) {
447
- this.debugLog(`Humidifier: ${this.accessory.displayName} OpenAPI pushChanges`);
407
+ try {
408
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
448
409
  if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER &&
449
410
  this.Active === this.platform.Characteristic.Active.ACTIVE) {
450
411
  // Make Push On request to the API
@@ -455,14 +416,14 @@ class Humidifier {
455
416
  .update(Buffer.from(data, 'utf-8'))
456
417
  .digest();
457
418
  const sign = signTerm.toString('base64');
458
- this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
419
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
459
420
  this.debugLog(`Pushing Manual: ${this.RelativeHumidityHumidifierThreshold}!`);
460
- const body = JSON.stringify({
421
+ const body = (0, super_stringify_1.default)({
461
422
  'command': 'setMode',
462
423
  'parameter': `${this.RelativeHumidityHumidifierThreshold}`,
463
424
  'commandType': 'command',
464
425
  });
465
- this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
426
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
466
427
  const options = {
467
428
  hostname: settings_1.HostDomain,
468
429
  port: 443,
@@ -478,18 +439,18 @@ class Humidifier {
478
439
  },
479
440
  };
480
441
  const req = https_1.default.request(options, res => {
481
- this.debugLog(`Humidifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
442
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
482
443
  res.on('data', d => {
483
- this.debugLog(`Humidifier: ${this.accessory.displayName} d: ${d}`);
444
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
484
445
  });
485
446
  });
486
447
  req.on('error', (e) => {
487
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
448
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
488
449
  this.apiError(e);
489
450
  });
490
451
  req.write(body);
491
452
  req.end();
492
- this.debugLog(`Humidifier: ${this.accessory.displayName} openAPIpushChanges: ${JSON.stringify(req)}`);
453
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${(0, super_stringify_1.default)(req)}`);
493
454
  }
494
455
  else if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
495
456
  this.Active === this.platform.Characteristic.Active.ACTIVE) {
@@ -499,12 +460,18 @@ class Humidifier {
499
460
  await this.pushActiveChanges();
500
461
  }
501
462
  }
463
+ catch (e) {
464
+ this.apiError(e);
465
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
466
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
467
+ }
502
468
  }
503
469
  /**
504
470
  * Pushes the requested changes to the SwitchBot API
505
471
  */
506
472
  async pushAutoChanges() {
507
473
  try {
474
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges`);
508
475
  if (this.TargetHumidifierDehumidifierState === this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER &&
509
476
  this.Active === this.platform.Characteristic.Active.ACTIVE) {
510
477
  // Make Push On request to the API
@@ -515,14 +482,14 @@ class Humidifier {
515
482
  .update(Buffer.from(data, 'utf-8'))
516
483
  .digest();
517
484
  const sign = signTerm.toString('base64');
518
- this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
485
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
519
486
  this.debugLog('Pushing Auto!');
520
- const body = JSON.stringify({
487
+ const body = (0, super_stringify_1.default)({
521
488
  'command': 'setMode',
522
489
  'parameter': 'auto',
523
490
  'commandType': 'command',
524
491
  });
525
- this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
492
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
526
493
  const options = {
527
494
  hostname: settings_1.HostDomain,
528
495
  port: 443,
@@ -538,27 +505,28 @@ class Humidifier {
538
505
  },
539
506
  };
540
507
  const req = https_1.default.request(options, res => {
541
- this.debugLog(`Humidifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
508
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
542
509
  this.statusCode({ res });
543
510
  res.on('data', d => {
544
- this.debugLog(`Humidifier: ${this.accessory.displayName} d: ${d}`);
511
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
545
512
  });
546
513
  });
547
514
  req.on('error', (e) => {
548
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
515
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
549
516
  });
550
517
  req.write(body);
551
518
  req.end();
552
- this.debugLog(`Humidifier: ${this.accessory.displayName} pushAutoChanges: ${JSON.stringify(req)}`);
519
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushAutoChanges: ${(0, super_stringify_1.default)(req)}`);
520
+ }
521
+ else {
522
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushAutoChanges.` +
523
+ `TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}, Active: ${this.Active}`);
553
524
  }
554
525
  }
555
526
  catch (e) {
556
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection`);
557
- if (this.deviceLogging.includes('debug')) {
558
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushAutoChanges with OpenAPI Connection,` +
559
- ` Error Message: ${JSON.stringify(e.message)}`);
560
- }
561
527
  this.apiError(e);
528
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushAutoChanges with ${this.device.connectionType}`
529
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
562
530
  }
563
531
  }
564
532
  /**
@@ -566,6 +534,7 @@ class Humidifier {
566
534
  */
567
535
  async pushActiveChanges() {
568
536
  try {
537
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges`);
569
538
  if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
570
539
  // Make Push On request to the API
571
540
  const t = Date.now();
@@ -575,14 +544,14 @@ class Humidifier {
575
544
  .update(Buffer.from(data, 'utf-8'))
576
545
  .digest();
577
546
  const sign = signTerm.toString('base64');
578
- this.debugLog(`Humidifier: ${this.accessory.displayName} sign: ${sign}`);
547
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
579
548
  this.debugLog('Pushing Off!');
580
- const body = JSON.stringify({
549
+ const body = (0, super_stringify_1.default)({
581
550
  'command': 'turnOff',
582
551
  'parameter': 'default',
583
552
  'commandType': 'command',
584
553
  });
585
- this.infoLog(`Humidifier: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
554
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
586
555
  const options = {
587
556
  hostname: settings_1.HostDomain,
588
557
  port: 443,
@@ -598,175 +567,325 @@ class Humidifier {
598
567
  },
599
568
  };
600
569
  const req = https_1.default.request(options, res => {
601
- this.debugLog(`Humidifier: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
570
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges statusCode: ${res.statusCode}`);
602
571
  this.statusCode({ res });
603
572
  res.on('data', d => {
604
- this.debugLog(`Humidifier: ${this.accessory.displayName} d: ${d}`);
573
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
605
574
  });
606
575
  });
607
576
  req.on('error', (e) => {
608
- this.errorLog(`Humidifier: ${this.accessory.displayName} error message: ${e.message}`);
577
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
609
578
  });
610
579
  req.write(body);
611
580
  req.end();
612
- this.debugLog(`Humidifier: ${this.accessory.displayName} pushActiveChanges: ${JSON.stringify(req)}`);
581
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushActiveChanges: ${(0, super_stringify_1.default)(req)}`);
613
582
  }
614
583
  }
615
584
  catch (e) {
616
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection`);
617
- if (this.deviceLogging.includes('debug')) {
618
- this.errorLog(`Humidifier: ${this.accessory.displayName} failed pushActiveChanges with OpenAPI Connection,` +
619
- ` Error Message: ${JSON.stringify(e.message)}`);
620
- }
621
585
  this.apiError(e);
586
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushActiveChanges with ${this.device.connectionType}`
587
+ + ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
622
588
  }
623
589
  }
590
+ /**
591
+ * Handle requests to set the "Active" characteristic
592
+ */
593
+ async ActiveSet(value) {
594
+ if (this.Active === this.accessory.context.Active) {
595
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Active: ${value}`);
596
+ }
597
+ else {
598
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Active: ${value}`);
599
+ }
600
+ this.Active = value;
601
+ this.doHumidifierUpdate.next();
602
+ }
603
+ /**
604
+ * Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
605
+ */
606
+ async TargetHumidifierDehumidifierStateSet(value) {
607
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
608
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
609
+ }
610
+ else {
611
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetHumidifierDehumidifierState: ${value}`);
612
+ }
613
+ this.TargetHumidifierDehumidifierState = value;
614
+ this.doHumidifierUpdate.next();
615
+ }
616
+ /**
617
+ * Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
618
+ */
619
+ async RelativeHumidityHumidifierThresholdSet(value) {
620
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
621
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
622
+ }
623
+ else {
624
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set RelativeHumidityHumidifierThreshold: ${value}`);
625
+ }
626
+ this.RelativeHumidityHumidifierThreshold = value;
627
+ if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
628
+ this.Active = this.platform.Characteristic.Active.ACTIVE;
629
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
630
+ }
631
+ this.doHumidifierUpdate.next();
632
+ }
624
633
  /**
625
634
  * Updates the status for each of the HomeKit Characteristics
626
635
  */
627
636
  async updateHomeKitCharacteristics() {
628
637
  if (this.CurrentRelativeHumidity === undefined) {
629
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
638
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
630
639
  }
631
640
  else {
641
+ this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
632
642
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
633
- this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
643
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
644
+ + ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
634
645
  }
635
- if (!this.device.ble) {
646
+ if (this.OpenAPI) {
636
647
  if (this.WaterLevel === undefined) {
637
- this.debugLog(`Humidifier: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
648
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} WaterLevel: ${this.WaterLevel}`);
638
649
  }
639
650
  else {
651
+ this.accessory.context.WaterLevel = this.WaterLevel;
640
652
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, this.WaterLevel);
641
- this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
653
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic WaterLevel: ${this.WaterLevel}`);
642
654
  }
643
655
  }
644
656
  if (this.CurrentHumidifierDehumidifierState === undefined) {
645
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
657
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
658
+ + ` CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
646
659
  }
647
660
  else {
661
+ this.accessory.context.CurrentHumidifierDehumidifierState = this.CurrentHumidifierDehumidifierState;
648
662
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, this.CurrentHumidifierDehumidifierState);
649
- this.debugLog(`Humidifier: ${this.accessory.displayName}` +
663
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
650
664
  ` updateCharacteristic CurrentHumidifierDehumidifierState: ${this.CurrentHumidifierDehumidifierState}`);
651
665
  }
652
666
  if (this.TargetHumidifierDehumidifierState === undefined) {
653
- this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
667
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
668
+ + ` TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
654
669
  }
655
670
  else {
671
+ this.accessory.context.TargetHumidifierDehumidifierState = this.TargetHumidifierDehumidifierState;
656
672
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, this.TargetHumidifierDehumidifierState);
657
- this.debugLog(`Humidifier: ${this.accessory.displayName}` +
673
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
658
674
  ` updateCharacteristic TargetHumidifierDehumidifierState: ${this.TargetHumidifierDehumidifierState}`);
659
675
  }
660
676
  if (this.Active === undefined) {
661
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${this.Active}`);
677
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Active: ${this.Active}`);
662
678
  }
663
679
  else {
680
+ this.accessory.context.Active = this.Active;
664
681
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
665
- this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
682
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
666
683
  }
667
684
  if (this.RelativeHumidityHumidifierThreshold === undefined) {
668
- this.debugLog(`Humidifier: ${this.accessory.displayName}` + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
685
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
686
+ + ` RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
669
687
  }
670
688
  else {
689
+ this.accessory.context.RelativeHumidityHumidifierThreshold = this.RelativeHumidityHumidifierThreshold;
671
690
  this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, this.RelativeHumidityHumidifierThreshold);
672
- this.debugLog(`Humidifier: ${this.accessory.displayName}` +
691
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` +
673
692
  ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`);
674
693
  }
675
- if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
694
+ if (!this.device.humidifier?.hide_temperature && !this.BLE) {
676
695
  if (this.CurrentTemperature === undefined) {
677
- this.debugLog(`Humidifier: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
696
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
678
697
  }
679
698
  else {
699
+ this.accessory.context.CurrentTemperature = this.CurrentTemperature;
680
700
  this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
681
- this.debugLog(`Humidifier: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
701
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
682
702
  }
683
703
  }
684
704
  }
685
- async apiError(e) {
686
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
687
- if (!this.device.ble) {
688
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
705
+ async getCustomBLEAddress(switchbot) {
706
+ if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
707
+ (async () => {
708
+ // Start to monitor advertisement packets
709
+ await switchbot.startScan({
710
+ model: 'e',
711
+ });
712
+ // Set an event handler
713
+ switchbot.onadvertisement = (ad) => {
714
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
715
+ };
716
+ await switchbot.wait(10000);
717
+ // Stop to monitor
718
+ switchbot.stopScan();
719
+ })();
689
720
  }
690
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
691
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
692
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
693
- this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
694
- if (!this.device.humidifier?.hide_temperature && !this.device.ble) {
695
- this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
721
+ }
722
+ async BLEPushConnection() {
723
+ if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
724
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
725
+ await this.openAPIpushChanges();
726
+ }
727
+ }
728
+ async BLERefreshConnection(switchbot) {
729
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
730
+ if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
731
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
732
+ await this.openAPIRefreshStatus();
733
+ }
734
+ }
735
+ minStep() {
736
+ if (this.device.humidifier?.set_minStep) {
737
+ this.set_minStep = this.device.humidifier?.set_minStep;
738
+ }
739
+ else {
740
+ this.set_minStep = 1;
741
+ }
742
+ return this.set_minStep;
743
+ }
744
+ async scan(device) {
745
+ if (device.scanDuration) {
746
+ this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
747
+ if (this.BLE) {
748
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
749
+ }
750
+ }
751
+ else {
752
+ this.scanDuration = this.accessory.context.scanDuration = 1;
753
+ if (this.BLE) {
754
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
755
+ }
696
756
  }
697
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
698
757
  }
699
758
  async statusCode({ res }) {
700
759
  switch (res.statusCode) {
701
760
  case 151:
702
- this.errorLog(`Humidifier: ${this.accessory.displayName} Command not supported by this device type.`);
761
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
703
762
  break;
704
763
  case 152:
705
- this.errorLog(`Humidifier: ${this.accessory.displayName} Device not found.`);
764
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
706
765
  break;
707
766
  case 160:
708
- this.errorLog(`Humidifier: ${this.accessory.displayName} Command is not supported.`);
767
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
709
768
  break;
710
769
  case 161:
711
- this.errorLog(`Humidifier: ${this.accessory.displayName} Device is offline.`);
770
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
712
771
  this.offlineOff();
713
772
  break;
714
773
  case 171:
715
- this.errorLog(`Humidifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
774
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
716
775
  this.offlineOff();
717
776
  break;
718
777
  case 190:
719
- this.errorLog(`Humidifier: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
720
- ` Or command: ${JSON.stringify(res)} format is invalid`);
778
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
779
+ ` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
721
780
  break;
722
781
  case 100:
723
- this.debugLog(`Humidifier: ${this.accessory.displayName} Command successfully sent.`);
782
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
724
783
  break;
725
784
  default:
726
- this.debugLog(`Humidifier: ${this.accessory.displayName} Unknown statusCode.`);
785
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
727
786
  }
728
787
  }
729
788
  async offlineOff() {
730
789
  if (this.device.offline) {
731
790
  this.Active = this.platform.Characteristic.Active.INACTIVE;
732
791
  this.humidifierService.getCharacteristic(this.platform.Characteristic.Active).updateValue(this.Active);
792
+ await this.updateHomeKitCharacteristics();
733
793
  }
734
794
  }
735
- /**
736
- * Handle requests to set the "Target Humidifier Dehumidifier State" characteristic
737
- */
738
- async handleTargetHumidifierDehumidifierStateSet(value) {
739
- this.debugLog(`Humidifier: ${this.accessory.displayName} TargetHumidifierDehumidifierState: ${value}`);
740
- this.TargetHumidifierDehumidifierState = value;
741
- this.doHumidifierUpdate.next();
795
+ async apiError(e) {
796
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, e);
797
+ if (!this.BLE) {
798
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.WaterLevel, e);
799
+ }
800
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.CurrentHumidifierDehumidifierState, e);
801
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.TargetHumidifierDehumidifierState, e);
802
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
803
+ this.humidifierService.updateCharacteristic(this.platform.Characteristic.RelativeHumidityHumidifierThreshold, e);
804
+ if (!this.device.humidifier?.hide_temperature && !this.BLE) {
805
+ this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
806
+ }
742
807
  }
743
- /**
744
- * Handle requests to set the "Active" characteristic
745
- */
746
- async handleActiveSet(value) {
747
- this.debugLog(`Humidifier: ${this.accessory.displayName} Active: ${value}`);
748
- this.Active = value;
749
- this.doHumidifierUpdate.next();
808
+ FirmwareRevision(accessory, device) {
809
+ let FirmwareRevision;
810
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
811
+ + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
812
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
813
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
814
+ if (accessory.context.FirmwareRevision) {
815
+ FirmwareRevision = accessory.context.FirmwareRevision;
816
+ }
817
+ else if (device.firmware) {
818
+ FirmwareRevision = device.firmware;
819
+ }
820
+ else {
821
+ FirmwareRevision = this.platform.version;
822
+ }
823
+ return FirmwareRevision;
750
824
  }
751
- /**
752
- * Handle requests to set the "Relative Humidity Humidifier Threshold" characteristic
753
- */
754
- async handleRelativeHumidityHumidifierThresholdSet(value) {
755
- this.debugLog(`Humidifier: ${this.accessory.displayName} RelativeHumidityHumidifierThreshold: ${value}`);
756
- this.RelativeHumidityHumidifierThreshold = value;
757
- if (this.Active === this.platform.Characteristic.Active.INACTIVE) {
825
+ async context() {
826
+ if (this.Active === undefined) {
758
827
  this.Active = this.platform.Characteristic.Active.ACTIVE;
759
- this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.IDLE;
760
828
  }
761
- this.doHumidifierUpdate.next();
829
+ else {
830
+ this.Active = this.accessory.context.Active;
831
+ }
832
+ if (this.CurrentTemperature === undefined) {
833
+ this.CurrentTemperature = 0;
834
+ }
835
+ else {
836
+ this.CurrentTemperature = this.accessory.context.CurrentTemperature;
837
+ }
838
+ if (this.CurrentRelativeHumidity === undefined) {
839
+ this.CurrentRelativeHumidity = 0;
840
+ }
841
+ else {
842
+ this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
843
+ }
844
+ if (this.TargetHumidifierDehumidifierState === undefined) {
845
+ this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
846
+ }
847
+ else {
848
+ this.TargetHumidifierDehumidifierState = this.accessory.context.TargetHumidifierDehumidifierState;
849
+ }
850
+ if (this.CurrentHumidifierDehumidifierState === undefined) {
851
+ this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
852
+ }
853
+ else {
854
+ this.CurrentHumidifierDehumidifierState = this.accessory.context.CurrentHumidifierDehumidifierState;
855
+ }
856
+ if (this.RelativeHumidityHumidifierThreshold === undefined) {
857
+ this.RelativeHumidityHumidifierThreshold = 0;
858
+ }
859
+ else {
860
+ this.RelativeHumidityHumidifierThreshold = this.accessory.context.RelativeHumidityHumidifierThreshold;
861
+ }
862
+ if (this.WaterLevel === undefined) {
863
+ this.WaterLevel = 0;
864
+ }
865
+ else {
866
+ this.WaterLevel = this.accessory.context.WaterLevel;
867
+ }
868
+ }
869
+ async refreshRate(device) {
870
+ if (device.refreshRate) {
871
+ this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
872
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
873
+ }
874
+ else if (this.platform.config.options.refreshRate) {
875
+ this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
876
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
877
+ }
762
878
  }
763
879
  async config(device) {
764
880
  let config = {};
765
881
  if (device.humidifier) {
766
882
  config = device.humidifier;
767
883
  }
768
- if (device.ble !== undefined) {
769
- config['ble'] = device.ble;
884
+ if (device.connectionType !== undefined) {
885
+ config['connectionType'] = device.connectionType;
886
+ }
887
+ if (device.external !== undefined) {
888
+ config['external'] = device.external;
770
889
  }
771
890
  if (device.logging !== undefined) {
772
891
  config['logging'] = device.logging;
@@ -781,76 +900,27 @@ class Humidifier {
781
900
  config['offline'] = device.offline;
782
901
  }
783
902
  if (Object.entries(config).length !== 0) {
784
- this.infoLog(`Humidifier: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
785
- }
786
- }
787
- async refreshRate(device) {
788
- if (device.refreshRate) {
789
- this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
790
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
791
- }
792
- else if (this.platform.config.options.refreshRate) {
793
- this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
794
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
795
- }
796
- }
797
- async scan(device) {
798
- if (device.scanDuration) {
799
- this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
800
- if (device.ble) {
801
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
802
- }
803
- }
804
- else {
805
- this.scanDuration = this.accessory.context.scanDuration = 1;
806
- if (this.device.ble) {
807
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
808
- }
903
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
809
904
  }
810
905
  }
811
906
  async logs(device) {
812
907
  if (this.platform.debugMode) {
813
908
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
814
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
909
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
815
910
  }
816
911
  else if (device.logging) {
817
912
  this.deviceLogging = this.accessory.context.logging = device.logging;
818
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
913
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
819
914
  }
820
915
  else if (this.platform.config.options?.logging) {
821
916
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
822
- this.debugLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
917
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
823
918
  }
824
919
  else {
825
920
  this.deviceLogging = this.accessory.context.logging = 'standard';
826
- this.debugLog(`Humidifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
921
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
827
922
  }
828
923
  }
829
- FirmwareRevision(accessory, device) {
830
- let FirmwareRevision;
831
- this.debugLog(`Humidifier: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
832
- this.debugLog(`Humidifier: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
833
- this.debugLog(`Humidifier: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
834
- if (accessory.context.FirmwareRevision) {
835
- FirmwareRevision = accessory.context.FirmwareRevision;
836
- }
837
- else if (device.firmware) {
838
- FirmwareRevision = device.firmware;
839
- }
840
- else {
841
- FirmwareRevision = this.platform.version;
842
- }
843
- return FirmwareRevision;
844
- }
845
- minStep() {
846
- if (this.device.humidifier?.set_minStep) {
847
- this.set_minStep = this.device.humidifier?.set_minStep;
848
- }
849
- else {
850
- this.set_minStep = 1;
851
- }
852
- return this.set_minStep;
853
- }
854
924
  /**
855
925
  * Logging for Device
856
926
  */
@@ -864,11 +934,25 @@ class Humidifier {
864
934
  this.platform.log.warn(String(...log));
865
935
  }
866
936
  }
937
+ debugWarnLog(...log) {
938
+ if (this.enablingDeviceLogging()) {
939
+ if (this.deviceLogging?.includes('debug')) {
940
+ this.platform.log.warn('[DEBUG]', String(...log));
941
+ }
942
+ }
943
+ }
867
944
  errorLog(...log) {
868
945
  if (this.enablingDeviceLogging()) {
869
946
  this.platform.log.error(String(...log));
870
947
  }
871
948
  }
949
+ debugErrorLog(...log) {
950
+ if (this.enablingDeviceLogging()) {
951
+ if (this.deviceLogging?.includes('debug')) {
952
+ this.platform.log.error('[DEBUG]', String(...log));
953
+ }
954
+ }
955
+ }
872
956
  debugLog(...log) {
873
957
  if (this.enablingDeviceLogging()) {
874
958
  if (this.deviceLogging === 'debug') {