@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.4
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/dist/device/blindtilt.js +103 -103
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +84 -84
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +97 -97
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +139 -139
- 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 +91 -89
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +12 -12
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +42 -42
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +95 -95
- 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.js +84 -84
- 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 +118 -118
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +74 -74
- 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 +59 -59
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +73 -73
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +44 -44
- 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 +55 -55
- 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/package.json +9 -9
- package/src/device/blindtilt.ts +103 -103
- package/src/device/bot.ts +84 -84
- package/src/device/ceilinglight.ts +97 -97
- package/src/device/colorbulb.ts +139 -139
- package/src/device/contact.ts +47 -47
- package/src/device/curtain.ts +91 -89
- package/src/device/device.ts +42 -42
- package/src/device/fan.ts +95 -95
- package/src/device/hub.ts +46 -46
- package/src/device/humidifier.ts +84 -84
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +118 -118
- package/src/device/lock.ts +74 -74
- 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 +61 -61
- package/src/device/robotvacuumcleaner.ts +73 -73
- package/src/device/waterdetector.ts +44 -44
- 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 +55 -55
- 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()
|
|
@@ -503,29 +503,29 @@ export class Humidifier extends deviceBase {
|
|
|
503
503
|
if ((this.HumidifierDehumidifier.TargetHumidifierDehumidifierState
|
|
504
504
|
=== this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
|
|
505
505
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
506
|
-
|
|
506
|
+
this.debugLog('Pushing Auto')
|
|
507
507
|
const bodyChange: bodyChange = {
|
|
508
508
|
command: 'setMode',
|
|
509
509
|
parameter: 'auto',
|
|
510
510
|
commandType: 'command',
|
|
511
511
|
}
|
|
512
|
-
|
|
512
|
+
this.debugLog(`pushAutoChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
513
513
|
try {
|
|
514
|
-
const
|
|
515
|
-
const deviceStatus: any =
|
|
516
|
-
|
|
514
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
515
|
+
const deviceStatus: any = response.body
|
|
516
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
517
517
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
518
|
-
|
|
518
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
519
519
|
await this.updateHomeKitCharacteristics()
|
|
520
520
|
} else {
|
|
521
521
|
await this.statusCode(deviceStatus.statusCode)
|
|
522
522
|
}
|
|
523
523
|
} catch (e: any) {
|
|
524
524
|
await this.apiError(e)
|
|
525
|
-
|
|
525
|
+
this.errorLog(`failed pushAutoChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
526
526
|
}
|
|
527
527
|
} else {
|
|
528
|
-
|
|
528
|
+
this.debugLog(`No changes (pushAutoChanges), TargetHumidifierDehumidifierState: ${this.HumidifierDehumidifier.TargetHumidifierDehumidifierState}, Active: ${this.HumidifierDehumidifier.Active}`)
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
531
|
|
|
@@ -533,31 +533,31 @@ export class Humidifier extends deviceBase {
|
|
|
533
533
|
* Pushes the requested changes to the SwitchBot API
|
|
534
534
|
*/
|
|
535
535
|
async pushActiveChanges(): Promise<void> {
|
|
536
|
-
|
|
536
|
+
this.debugLog('pushActiveChanges')
|
|
537
537
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
538
|
-
|
|
538
|
+
this.debugLog('Pushing Off')
|
|
539
539
|
const bodyChange: bodyChange = {
|
|
540
540
|
command: 'turnOff',
|
|
541
541
|
parameter: 'default',
|
|
542
542
|
commandType: 'command',
|
|
543
543
|
}
|
|
544
|
-
|
|
544
|
+
this.debugLog(`pushActiveChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
545
545
|
try {
|
|
546
|
-
const
|
|
547
|
-
const deviceStatus: any =
|
|
548
|
-
|
|
546
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
547
|
+
const deviceStatus: any = response.body
|
|
548
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
549
549
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
550
|
-
|
|
550
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
551
551
|
await this.updateHomeKitCharacteristics()
|
|
552
552
|
} else {
|
|
553
553
|
await this.statusCode(deviceStatus.statusCode)
|
|
554
554
|
}
|
|
555
555
|
} catch (e: any) {
|
|
556
556
|
await this.apiError(e)
|
|
557
|
-
|
|
557
|
+
this.errorLog(`failed pushActiveChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
558
558
|
}
|
|
559
559
|
} else {
|
|
560
|
-
|
|
560
|
+
this.debugLog(`No changes (pushActiveChanges), Active: ${this.HumidifierDehumidifier.Active}`)
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
563
|
|
|
@@ -566,9 +566,9 @@ export class Humidifier extends deviceBase {
|
|
|
566
566
|
*/
|
|
567
567
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
568
568
|
if (this.HumidifierDehumidifier.Active !== this.accessory.context.Active) {
|
|
569
|
-
|
|
569
|
+
this.infoLog(`Set Active: ${value}`)
|
|
570
570
|
} else {
|
|
571
|
-
|
|
571
|
+
this.debugLog(`No Changes, Active: ${value}`)
|
|
572
572
|
}
|
|
573
573
|
|
|
574
574
|
this.HumidifierDehumidifier.Active = value
|
|
@@ -580,9 +580,9 @@ export class Humidifier extends deviceBase {
|
|
|
580
580
|
*/
|
|
581
581
|
async TargetHumidifierDehumidifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
582
582
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
583
|
-
|
|
583
|
+
this.infoLog(`Set TargetHumidifierDehumidifierState: ${value}`)
|
|
584
584
|
} else {
|
|
585
|
-
|
|
585
|
+
this.debugLog(`No Changes, TargetHumidifierDehumidifierState: ${value}`)
|
|
586
586
|
}
|
|
587
587
|
|
|
588
588
|
this.HumidifierDehumidifier.TargetHumidifierDehumidifierState = value
|
|
@@ -594,9 +594,9 @@ export class Humidifier extends deviceBase {
|
|
|
594
594
|
*/
|
|
595
595
|
async RelativeHumidityHumidifierThresholdSet(value: CharacteristicValue): Promise<void> {
|
|
596
596
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
597
|
-
|
|
597
|
+
this.infoLog(`Set RelativeHumidityHumidifierThreshold: ${value}`)
|
|
598
598
|
} else {
|
|
599
|
-
|
|
599
|
+
this.debugLog(`No Changes, RelativeHumidityHumidifierThreshold: ${value}`)
|
|
600
600
|
}
|
|
601
601
|
// If the Humidifier is off, turn it on
|
|
602
602
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
@@ -632,15 +632,15 @@ export class Humidifier extends deviceBase {
|
|
|
632
632
|
|
|
633
633
|
async BLEPushConnection() {
|
|
634
634
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
635
|
-
|
|
635
|
+
this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
636
636
|
await this.openAPIpushChanges()
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
639
|
|
|
640
640
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
641
|
-
|
|
641
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
642
642
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
643
|
-
|
|
643
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
644
644
|
await this.openAPIRefreshStatus()
|
|
645
645
|
}
|
|
646
646
|
}
|