@switchbot/homebridge-switchbot 4.1.1-beta.0 → 4.1.1-beta.10
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.
- package/CHANGELOG.md +14 -0
- package/config.schema.json +2 -2
- package/dist/device/blindtilt.js +104 -104
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +86 -86
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +98 -98
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +140 -140
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +47 -47
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +95 -93
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +13 -13
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +46 -46
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +96 -96
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +46 -46
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +85 -87
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +44 -44
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +119 -119
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +75 -75
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +44 -44
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +42 -42
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/meterpro.js +42 -42
- package/dist/device/meterpro.js.map +1 -1
- package/dist/device/motion.js +44 -44
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +60 -60
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -74
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +54 -56
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -31
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +10 -10
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js +9 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.js +11 -11
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.js +11 -11
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.js +9 -9
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +93 -93
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.js +33 -33
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.js +228 -228
- package/dist/platform.js.map +1 -1
- package/docs/functions/default.html +1 -1
- package/package.json +9 -9
- package/src/device/blindtilt.ts +104 -104
- package/src/device/bot.ts +86 -86
- package/src/device/ceilinglight.ts +98 -98
- package/src/device/colorbulb.ts +140 -140
- package/src/device/contact.ts +47 -47
- package/src/device/curtain.ts +95 -93
- package/src/device/device.ts +46 -46
- package/src/device/fan.ts +96 -96
- package/src/device/hub.ts +46 -46
- package/src/device/humidifier.ts +85 -87
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +119 -119
- package/src/device/lock.ts +75 -75
- package/src/device/meter.ts +44 -44
- package/src/device/meterplus.ts +42 -42
- package/src/device/meterpro.ts +42 -42
- package/src/device/motion.ts +44 -44
- package/src/device/plug.ts +62 -62
- package/src/device/robotvacuumcleaner.ts +74 -74
- package/src/device/waterdetector.ts +54 -55
- package/src/irdevice/airconditioner.ts +31 -31
- package/src/irdevice/airpurifier.ts +10 -10
- package/src/irdevice/camera.ts +9 -9
- package/src/irdevice/fan.ts +11 -11
- package/src/irdevice/irdevice.ts +11 -11
- package/src/irdevice/light.ts +9 -9
- package/src/irdevice/other.ts +93 -93
- package/src/irdevice/tv.ts +33 -33
- package/src/irdevice/vacuumcleaner.ts +9 -9
- package/src/irdevice/waterheater.ts +9 -9
- package/src/platform.ts +228 -228
package/src/device/humidifier.ts
CHANGED
|
@@ -177,24 +177,24 @@ export class Humidifier extends deviceBase {
|
|
|
177
177
|
await this.pushChanges()
|
|
178
178
|
} catch (e: any) {
|
|
179
179
|
await this.apiError(e)
|
|
180
|
-
|
|
180
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
181
181
|
}
|
|
182
182
|
this.humidifierUpdateInProgress = false
|
|
183
183
|
})
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
async BLEparseStatus(): Promise<void> {
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
this.debugLog('BLEparseStatus')
|
|
188
|
+
this.debugLog(`(onState, percentage, autoMode) = BLE:(${this.serviceData.onState}, ${this.serviceData.percentage}, ${this.serviceData.autoMode}), current:(${this.HumidifierDehumidifier.Active}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity}, ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold})`,
|
|
189
189
|
)
|
|
190
190
|
|
|
191
191
|
// Active
|
|
192
192
|
this.HumidifierDehumidifier.Active = this.serviceData.onState ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE
|
|
193
|
-
|
|
193
|
+
this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`)
|
|
194
194
|
|
|
195
195
|
// Current Relative Humidity
|
|
196
196
|
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity)
|
|
197
|
-
|
|
197
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
198
198
|
|
|
199
199
|
// Target Humidifier Dehumidifier State
|
|
200
200
|
switch (this.serviceData.autoMode) {
|
|
@@ -215,27 +215,27 @@ export class Humidifier extends deviceBase {
|
|
|
215
215
|
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
|
|
218
|
+
this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}, CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`)
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
async openAPIparseStatus(): Promise<void> {
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
this.debugLog('openAPIparseStatus')
|
|
223
|
+
this.debugLog(`(power, auto, temperature, lackWater, nebulizationEfficiency, version) = OpenAPI:(${this.deviceStatus.power}, ${this.deviceStatus.auto}, ${this.deviceStatus.temperature}, ${this.deviceStatus.lackWater}, ${this.deviceStatus.nebulizationEfficiency}, ${this.deviceStatus.version}), current:(${this.HumidifierDehumidifier.Active}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity}, ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold})`)
|
|
224
224
|
|
|
225
225
|
// Active
|
|
226
226
|
this.HumidifierDehumidifier.Active = this.deviceStatus.power === 'on'
|
|
227
227
|
? this.hap.Characteristic.Active.ACTIVE
|
|
228
228
|
: this.hap.Characteristic.Active.INACTIVE
|
|
229
|
-
|
|
229
|
+
this.debugLog(`Active: ${this.HumidifierDehumidifier.Active}`)
|
|
230
230
|
|
|
231
231
|
// Current Relative Humidity
|
|
232
232
|
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.deviceStatus.humidity)
|
|
233
|
-
|
|
233
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
234
234
|
|
|
235
235
|
// Current Temperature
|
|
236
236
|
if (!(this.device as humidifierConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
237
237
|
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
238
|
-
|
|
238
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
239
239
|
}
|
|
240
240
|
// Target Humidifier Dehumidifier State
|
|
241
241
|
switch (this.deviceStatus.auto) {
|
|
@@ -258,7 +258,7 @@ export class Humidifier extends deviceBase {
|
|
|
258
258
|
this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState = this.hap.Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
|
-
|
|
261
|
+
this.debugLog(`TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}, CurrentHumidifierDehumidifierState: ${this.HumidifierDehumidifier.CurrentHumidifierDehumidifierState}`)
|
|
262
262
|
|
|
263
263
|
// Water Level
|
|
264
264
|
if (this.deviceStatus.lackWater) {
|
|
@@ -266,12 +266,12 @@ export class Humidifier extends deviceBase {
|
|
|
266
266
|
} else {
|
|
267
267
|
this.HumidifierDehumidifier.WaterLevel = 100
|
|
268
268
|
}
|
|
269
|
-
|
|
269
|
+
this.debugLog(`WaterLevel: ${this.HumidifierDehumidifier.WaterLevel}`)
|
|
270
270
|
|
|
271
271
|
// Firmware Version
|
|
272
272
|
if (this.deviceStatus.version) {
|
|
273
273
|
const version = this.deviceStatus.version.toString()
|
|
274
|
-
|
|
274
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
275
275
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
276
276
|
this.accessory
|
|
277
277
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -280,22 +280,22 @@ export class Humidifier extends deviceBase {
|
|
|
280
280
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
281
281
|
.updateValue(deviceVersion)
|
|
282
282
|
this.accessory.context.version = deviceVersion
|
|
283
|
-
|
|
283
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
async parseStatusWebhook(): Promise<void> {
|
|
288
|
-
|
|
289
|
-
|
|
288
|
+
this.debugLog('parseStatusWebhook')
|
|
289
|
+
this.debugLog(`(temperature, humidity) = Webhook:(${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as humidifierConfig).convertUnitTo)}, ${this.webhookContext.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumidifierDehumidifier.CurrentRelativeHumidity})`)
|
|
290
290
|
|
|
291
291
|
// CurrentRelativeHumidity
|
|
292
292
|
this.HumidifierDehumidifier.CurrentRelativeHumidity = validHumidity(this.webhookContext.humidity)
|
|
293
|
-
|
|
293
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
294
294
|
|
|
295
295
|
// CurrentTemperature
|
|
296
296
|
if (!(this.device as humidifierConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
297
297
|
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as humidifierConfig).convertUnitTo)
|
|
298
|
-
|
|
298
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
|
|
@@ -304,19 +304,19 @@ export class Humidifier extends deviceBase {
|
|
|
304
304
|
*/
|
|
305
305
|
async refreshStatus(): Promise<void> {
|
|
306
306
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
307
|
-
|
|
307
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
308
308
|
} else if (this.BLE) {
|
|
309
309
|
await this.BLERefreshStatus()
|
|
310
310
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
311
311
|
await this.openAPIRefreshStatus()
|
|
312
312
|
} else {
|
|
313
313
|
await this.offlineOff()
|
|
314
|
-
|
|
314
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
async BLERefreshStatus(): Promise<void> {
|
|
319
|
-
|
|
319
|
+
this.debugLog('BLERefreshStatus')
|
|
320
320
|
const switchBotBLE = await this.switchbotBLE()
|
|
321
321
|
if (switchBotBLE === undefined) {
|
|
322
322
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -331,7 +331,7 @@ export class Humidifier extends deviceBase {
|
|
|
331
331
|
await this.BLEparseStatus()
|
|
332
332
|
await this.updateHomeKitCharacteristics()
|
|
333
333
|
} else {
|
|
334
|
-
|
|
334
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
335
335
|
await this.BLERefreshConnection(switchBotBLE)
|
|
336
336
|
}
|
|
337
337
|
})()
|
|
@@ -339,63 +339,63 @@ export class Humidifier extends deviceBase {
|
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
async registerPlatformBLE(): Promise<void> {
|
|
342
|
-
|
|
342
|
+
this.debugLog('registerPlatformBLE')
|
|
343
343
|
if (this.config.options?.BLE) {
|
|
344
|
-
|
|
344
|
+
this.debugLog('is listening to Platform BLE.')
|
|
345
345
|
try {
|
|
346
346
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
347
347
|
this.device.bleMac = formattedDeviceId
|
|
348
|
-
|
|
348
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
349
349
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: humidifierServiceData) => {
|
|
350
350
|
try {
|
|
351
|
-
|
|
351
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
352
352
|
this.serviceData = context
|
|
353
353
|
await this.BLEparseStatus()
|
|
354
354
|
await this.updateHomeKitCharacteristics()
|
|
355
355
|
} catch (e: any) {
|
|
356
|
-
|
|
356
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
} catch (error) {
|
|
360
|
-
|
|
360
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
361
361
|
}
|
|
362
362
|
} else {
|
|
363
|
-
|
|
363
|
+
this.debugLog('is not listening to Platform BLE')
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
|
|
367
367
|
async openAPIRefreshStatus(): Promise<void> {
|
|
368
|
-
|
|
368
|
+
this.debugLog('openAPIRefreshStatus')
|
|
369
369
|
try {
|
|
370
|
-
const
|
|
371
|
-
const deviceStatus: any =
|
|
372
|
-
|
|
370
|
+
const response = await this.deviceRefreshStatus()
|
|
371
|
+
const deviceStatus: any = response.body
|
|
372
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
373
373
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
374
|
-
|
|
374
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
375
375
|
this.deviceStatus = deviceStatus.body
|
|
376
376
|
await this.openAPIparseStatus()
|
|
377
377
|
await this.updateHomeKitCharacteristics()
|
|
378
378
|
} else {
|
|
379
|
-
|
|
380
|
-
|
|
379
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
380
|
+
this.debugWarnLog(deviceStatus)
|
|
381
381
|
}
|
|
382
382
|
} catch (e: any) {
|
|
383
383
|
await this.apiError(e)
|
|
384
|
-
|
|
384
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
|
|
388
388
|
async registerWebhook() {
|
|
389
389
|
if (this.device.webhook) {
|
|
390
|
-
|
|
390
|
+
this.debugLog('is listening webhook.')
|
|
391
391
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: humidifierWebhookContext) => {
|
|
392
392
|
try {
|
|
393
|
-
|
|
393
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
394
394
|
this.webhookContext = context
|
|
395
395
|
await this.parseStatusWebhook()
|
|
396
396
|
await this.updateHomeKitCharacteristics()
|
|
397
397
|
} catch (e: any) {
|
|
398
|
-
|
|
398
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
}
|
|
@@ -406,14 +406,14 @@ export class Humidifier extends deviceBase {
|
|
|
406
406
|
*/
|
|
407
407
|
async pushChanges(): Promise<void> {
|
|
408
408
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
409
|
-
|
|
409
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
|
|
410
410
|
} else if (this.BLE) {
|
|
411
411
|
await this.BLEpushChanges()
|
|
412
412
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
413
413
|
await this.openAPIpushChanges()
|
|
414
414
|
} else {
|
|
415
415
|
await this.offlineOff()
|
|
416
|
-
|
|
416
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
417
417
|
}
|
|
418
418
|
// Refresh the status from the API
|
|
419
419
|
interval(15000)
|
|
@@ -425,7 +425,7 @@ export class Humidifier extends deviceBase {
|
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
async BLEpushChanges(): Promise<void> {
|
|
428
|
-
|
|
428
|
+
this.debugLog('BLEpushChanges')
|
|
429
429
|
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
|
|
430
430
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
431
431
|
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
@@ -433,7 +433,7 @@ export class Humidifier extends deviceBase {
|
|
|
433
433
|
try {
|
|
434
434
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
435
435
|
this.device.bleMac = formattedDeviceId
|
|
436
|
-
|
|
436
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
437
437
|
if (switchBotBLE !== false) {
|
|
438
438
|
switchBotBLE
|
|
439
439
|
.discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
|
|
@@ -442,51 +442,51 @@ export class Humidifier extends deviceBase {
|
|
|
442
442
|
return await deviceList[0].percentage(this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold)
|
|
443
443
|
})
|
|
444
444
|
.then(async () => {
|
|
445
|
-
|
|
445
|
+
this.successLog(`RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold} sent over BLE, sent successfully`)
|
|
446
446
|
await this.updateHomeKitCharacteristics()
|
|
447
447
|
})
|
|
448
448
|
.catch(async (e: any) => {
|
|
449
449
|
await this.apiError(e)
|
|
450
|
-
|
|
450
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
451
451
|
await this.BLEPushConnection()
|
|
452
452
|
})
|
|
453
453
|
} else {
|
|
454
|
-
|
|
454
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
455
455
|
await this.BLEPushConnection()
|
|
456
456
|
}
|
|
457
457
|
} catch (error) {
|
|
458
|
-
|
|
458
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
459
459
|
}
|
|
460
460
|
} else {
|
|
461
|
-
|
|
461
|
+
this.debugLog(`No changes (BLEpushChanges), Active: ${this.HumidifierDehumidifier.Active}, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}, CurrentRelativeHumidity: ${this.HumidifierDehumidifier.CurrentRelativeHumidity}`)
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
async openAPIpushChanges(): Promise<void> {
|
|
466
|
-
|
|
466
|
+
this.debugLog('openAPIpushChanges')
|
|
467
467
|
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER)
|
|
468
468
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
469
469
|
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
470
|
-
|
|
470
|
+
this.debugLog(`Auto Off, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`)
|
|
471
471
|
const bodyChange: bodyChange = {
|
|
472
472
|
command: 'setMode',
|
|
473
473
|
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
474
474
|
commandType: 'command',
|
|
475
475
|
}
|
|
476
|
-
|
|
476
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
477
477
|
try {
|
|
478
|
-
const
|
|
479
|
-
const deviceStatus: any =
|
|
480
|
-
|
|
478
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
479
|
+
const deviceStatus: any = response.body
|
|
480
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
481
481
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
482
|
-
|
|
482
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
483
483
|
await this.updateHomeKitCharacteristics()
|
|
484
484
|
} else {
|
|
485
485
|
await this.statusCode(deviceStatus.statusCode)
|
|
486
486
|
}
|
|
487
487
|
} catch (e: any) {
|
|
488
488
|
await this.apiError(e)
|
|
489
|
-
|
|
489
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
490
490
|
}
|
|
491
491
|
} else if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER) && (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
492
492
|
await this.pushAutoChanges()
|
|
@@ -500,32 +500,30 @@ export class Humidifier extends deviceBase {
|
|
|
500
500
|
*/
|
|
501
501
|
async pushAutoChanges(): Promise<void> {
|
|
502
502
|
this.debugLog('pushAutoChanges')
|
|
503
|
-
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState
|
|
504
|
-
|
|
505
|
-
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
506
|
-
await this.debugLog('Pushing Auto')
|
|
503
|
+
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState === this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER) && (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
504
|
+
this.debugLog('Pushing Auto')
|
|
507
505
|
const bodyChange: bodyChange = {
|
|
508
506
|
command: 'setMode',
|
|
509
507
|
parameter: 'auto',
|
|
510
508
|
commandType: 'command',
|
|
511
509
|
}
|
|
512
|
-
|
|
510
|
+
this.debugLog(`pushAutoChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
513
511
|
try {
|
|
514
|
-
const
|
|
515
|
-
const deviceStatus: any =
|
|
516
|
-
|
|
512
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
513
|
+
const deviceStatus: any = response.body
|
|
514
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
517
515
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
518
|
-
|
|
516
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
519
517
|
await this.updateHomeKitCharacteristics()
|
|
520
518
|
} else {
|
|
521
519
|
await this.statusCode(deviceStatus.statusCode)
|
|
522
520
|
}
|
|
523
521
|
} catch (e: any) {
|
|
524
522
|
await this.apiError(e)
|
|
525
|
-
|
|
523
|
+
this.errorLog(`failed pushAutoChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
526
524
|
}
|
|
527
525
|
} else {
|
|
528
|
-
|
|
526
|
+
this.debugLog(`No changes (pushAutoChanges), TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`)
|
|
529
527
|
}
|
|
530
528
|
}
|
|
531
529
|
|
|
@@ -533,31 +531,31 @@ export class Humidifier extends deviceBase {
|
|
|
533
531
|
* Pushes the requested changes to the SwitchBot API
|
|
534
532
|
*/
|
|
535
533
|
async pushActiveChanges(): Promise<void> {
|
|
536
|
-
|
|
534
|
+
this.debugLog('pushActiveChanges')
|
|
537
535
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
538
|
-
|
|
536
|
+
this.debugLog('Pushing Off')
|
|
539
537
|
const bodyChange: bodyChange = {
|
|
540
538
|
command: 'turnOff',
|
|
541
539
|
parameter: 'default',
|
|
542
540
|
commandType: 'command',
|
|
543
541
|
}
|
|
544
|
-
|
|
542
|
+
this.debugLog(`pushActiveChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
545
543
|
try {
|
|
546
|
-
const
|
|
547
|
-
const deviceStatus: any =
|
|
548
|
-
|
|
544
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
545
|
+
const deviceStatus: any = response.body
|
|
546
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
549
547
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
550
|
-
|
|
548
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
551
549
|
await this.updateHomeKitCharacteristics()
|
|
552
550
|
} else {
|
|
553
551
|
await this.statusCode(deviceStatus.statusCode)
|
|
554
552
|
}
|
|
555
553
|
} catch (e: any) {
|
|
556
554
|
await this.apiError(e)
|
|
557
|
-
|
|
555
|
+
this.errorLog(`failed pushActiveChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
558
556
|
}
|
|
559
557
|
} else {
|
|
560
|
-
|
|
558
|
+
this.debugLog(`No changes (pushActiveChanges), Active: ${this.HumidifierDehumidifier.Active}`)
|
|
561
559
|
}
|
|
562
560
|
}
|
|
563
561
|
|
|
@@ -566,9 +564,9 @@ export class Humidifier extends deviceBase {
|
|
|
566
564
|
*/
|
|
567
565
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
568
566
|
if (this.HumidifierDehumidifier.Active !== this.accessory.context.Active) {
|
|
569
|
-
|
|
567
|
+
this.infoLog(`Set Active: ${value}`)
|
|
570
568
|
} else {
|
|
571
|
-
|
|
569
|
+
this.debugLog(`No Changes, Active: ${value}`)
|
|
572
570
|
}
|
|
573
571
|
|
|
574
572
|
this.HumidifierDehumidifier.Active = value
|
|
@@ -580,9 +578,9 @@ export class Humidifier extends deviceBase {
|
|
|
580
578
|
*/
|
|
581
579
|
async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
582
580
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
583
|
-
|
|
581
|
+
this.infoLog(`Set TargetHumidifierDehumidifierState: ${value}`)
|
|
584
582
|
} else {
|
|
585
|
-
|
|
583
|
+
this.debugLog(`No Changes, TargetHumidifierDehumidifierState: ${value}`)
|
|
586
584
|
}
|
|
587
585
|
|
|
588
586
|
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value
|
|
@@ -594,9 +592,9 @@ export class Humidifier extends deviceBase {
|
|
|
594
592
|
*/
|
|
595
593
|
async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
596
594
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
597
|
-
|
|
595
|
+
this.infoLog(`Set RelativeHumidityHumidifierThreshold: ${value}`)
|
|
598
596
|
} else {
|
|
599
|
-
|
|
597
|
+
this.debugLog(`No Changes, RelativeHumidityHumidifierThreshold: ${value}`)
|
|
600
598
|
}
|
|
601
599
|
// If the Humidifier is off, turn it on
|
|
602
600
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
@@ -632,15 +630,15 @@ export class Humidifier extends deviceBase {
|
|
|
632
630
|
|
|
633
631
|
async BLEPushConnection() {
|
|
634
632
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
635
|
-
|
|
633
|
+
this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
636
634
|
await this.openAPIpushChanges()
|
|
637
635
|
}
|
|
638
636
|
}
|
|
639
637
|
|
|
640
638
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
641
|
-
|
|
639
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
642
640
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
643
|
-
|
|
641
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
644
642
|
await this.openAPIRefreshStatus()
|
|
645
643
|
}
|
|
646
644
|
}
|