@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.3
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/dist/device/blindtilt.js +102 -102
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +85 -85
- 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 +44 -44
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +82 -82
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +11 -11
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +41 -41
- 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 +43 -43
- 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 +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 +42 -42
- package/dist/device/motion.js.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.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 +1 -1
- package/src/device/blindtilt.ts +102 -102
- package/src/device/bot.ts +85 -85
- package/src/device/ceilinglight.ts +98 -98
- package/src/device/colorbulb.ts +140 -140
- package/src/device/contact.ts +44 -44
- package/src/device/curtain.ts +82 -82
- package/src/device/device.ts +41 -41
- package/src/device/fan.ts +96 -96
- package/src/device/hub.ts +43 -43
- package/src/device/humidifier.ts +84 -84
- 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 +42 -42
- package/src/device/plug.ts +60 -60
- package/src/device/robotvacuumcleaner.ts +74 -74
- 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/contact.ts
CHANGED
|
@@ -186,15 +186,15 @@ export class Contact extends deviceBase {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
async BLEparseStatus(): Promise<void> {
|
|
189
|
-
|
|
189
|
+
this.debugLog('BLEparseStatus')
|
|
190
190
|
// ContactSensorState
|
|
191
191
|
this.ContactSensor.ContactSensorState = this.getContactSensorState(this.serviceData.doorState)
|
|
192
|
-
|
|
192
|
+
this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
|
|
193
193
|
|
|
194
194
|
// MotionDetected
|
|
195
195
|
if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
|
|
196
196
|
this.MotionSensor.MotionDetected = this.serviceData.movement
|
|
197
|
-
|
|
197
|
+
this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
|
|
198
198
|
}
|
|
199
199
|
// CurrentAmbientLightLevel
|
|
200
200
|
if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
@@ -202,28 +202,28 @@ export class Contact extends deviceBase {
|
|
|
202
202
|
const set_maxLux = (this.device as contactConfig).set_maxLux ?? 6001
|
|
203
203
|
const lightLevel = this.serviceData.lightLevel === 'bright' ? set_maxLux : set_minLux
|
|
204
204
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
205
|
-
|
|
205
|
+
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
206
206
|
}
|
|
207
207
|
// BatteryLevel
|
|
208
208
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
209
|
-
|
|
209
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
210
210
|
// StatusLowBattery
|
|
211
211
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
212
212
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
213
213
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
214
|
-
|
|
214
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
async openAPIparseStatus(): Promise<void> {
|
|
218
|
-
|
|
218
|
+
this.debugLog('openAPIparseStatus')
|
|
219
219
|
// Contact State
|
|
220
220
|
this.ContactSensor.ContactSensorState = this.getContactSensorState(this.deviceStatus.openState)
|
|
221
|
-
|
|
221
|
+
this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
|
|
222
222
|
|
|
223
223
|
// MotionDetected
|
|
224
224
|
if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
|
|
225
225
|
this.MotionSensor.MotionDetected = this.deviceStatus.moveDetected
|
|
226
|
-
|
|
226
|
+
this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
|
|
227
227
|
}
|
|
228
228
|
// Light Level
|
|
229
229
|
if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
@@ -231,20 +231,20 @@ export class Contact extends deviceBase {
|
|
|
231
231
|
const set_maxLux = (this.device as contactConfig).set_maxLux ?? 6001
|
|
232
232
|
const lightLevel = this.deviceStatus.brightness === 'bright' ? set_maxLux : set_minLux
|
|
233
233
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
234
|
-
|
|
234
|
+
this.debugLog(`LightLevel: ${this.deviceStatus.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
235
235
|
}
|
|
236
236
|
// BatteryLevel
|
|
237
237
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
238
|
-
|
|
238
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
239
239
|
// StatusLowBattery
|
|
240
240
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
241
241
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
242
242
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
243
|
-
|
|
243
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
244
244
|
// FirmwareVersion
|
|
245
245
|
if (this.deviceStatus.version) {
|
|
246
246
|
const version = this.deviceStatus.version.toString()
|
|
247
|
-
|
|
247
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
248
248
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
249
249
|
this.accessory
|
|
250
250
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -253,27 +253,27 @@ export class Contact extends deviceBase {
|
|
|
253
253
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
254
254
|
.updateValue(deviceVersion)
|
|
255
255
|
this.accessory.context.version = deviceVersion
|
|
256
|
-
|
|
256
|
+
this.debugLog(`version: ${this.accessory.context.version}`)
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
async parseStatusWebhook(): Promise<void> {
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
this.debugLog('parseStatusWebhook')
|
|
262
|
+
this.debugLog(`(detectionState, brightness, openState) = Webhook:(${this.webhookContext.detectionState}, ${this.webhookContext.brightness}, ${this.webhookContext.openState}), current:(${this.MotionSensor?.MotionDetected}, ${this.LightSensor?.CurrentAmbientLightLevel}, ${this.ContactSensor.ContactSensorState})`)
|
|
263
263
|
// ContactSensorState
|
|
264
264
|
this.ContactSensor.ContactSensorState = this.getContactSensorState(this.webhookContext.openState)
|
|
265
|
-
|
|
265
|
+
this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
|
|
266
266
|
if (!(this.device as contactConfig).hide_motionsensor && this.MotionSensor?.Service) {
|
|
267
267
|
// MotionDetected
|
|
268
268
|
this.MotionSensor.MotionDetected = this.webhookContext.detectionState === 'DETECTED'
|
|
269
|
-
|
|
269
|
+
this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
|
|
270
270
|
}
|
|
271
271
|
if (!(this.device as contactConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
272
272
|
const set_minLux = (this.device as contactConfig).set_minLux ?? 1
|
|
273
273
|
const set_maxLux = (this.device as contactConfig).set_maxLux ?? 6001
|
|
274
274
|
const lightLevel = this.webhookContext.brightness === 'bright' ? set_maxLux : set_minLux
|
|
275
275
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
276
|
-
|
|
276
|
+
this.debugLog(`LightLevel: ${this.webhookContext.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
@@ -282,19 +282,19 @@ export class Contact extends deviceBase {
|
|
|
282
282
|
*/
|
|
283
283
|
async refreshStatus(): Promise<void> {
|
|
284
284
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
285
|
-
|
|
285
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
286
286
|
} else if (this.BLE) {
|
|
287
287
|
await this.BLERefreshStatus()
|
|
288
288
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
289
289
|
await this.openAPIRefreshStatus()
|
|
290
290
|
} else {
|
|
291
291
|
await this.offlineOff()
|
|
292
|
-
|
|
292
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
async BLERefreshStatus(): Promise<void> {
|
|
297
|
-
|
|
297
|
+
this.debugLog('BLERefreshStatus')
|
|
298
298
|
const switchBotBLE = await this.switchbotBLE()
|
|
299
299
|
if (switchBotBLE === undefined) {
|
|
300
300
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -309,7 +309,7 @@ export class Contact extends deviceBase {
|
|
|
309
309
|
await this.BLEparseStatus()
|
|
310
310
|
await this.updateHomeKitCharacteristics()
|
|
311
311
|
} else {
|
|
312
|
-
|
|
312
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
313
313
|
await this.BLERefreshConnection(switchBotBLE)
|
|
314
314
|
}
|
|
315
315
|
})()
|
|
@@ -317,67 +317,67 @@ export class Contact extends deviceBase {
|
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
async registerPlatformBLE(): Promise<void> {
|
|
320
|
-
|
|
320
|
+
this.debugLog('registerPlatformBLE')
|
|
321
321
|
if (this.config.options?.BLE) {
|
|
322
|
-
|
|
322
|
+
this.debugLog('is listening to Platform BLE.')
|
|
323
323
|
try {
|
|
324
324
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
325
325
|
this.device.bleMac = formattedDeviceId
|
|
326
|
-
|
|
326
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
327
327
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: contactSensorServiceData) => {
|
|
328
328
|
try {
|
|
329
|
-
|
|
329
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
330
330
|
this.serviceData = context
|
|
331
331
|
await this.BLEparseStatus()
|
|
332
332
|
await this.updateHomeKitCharacteristics()
|
|
333
333
|
} catch (e: any) {
|
|
334
|
-
|
|
334
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
} catch (error) {
|
|
338
|
-
|
|
338
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
339
339
|
}
|
|
340
340
|
} else {
|
|
341
|
-
|
|
341
|
+
this.debugLog('is not listening to Platform BLE')
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
async openAPIRefreshStatus(): Promise<void> {
|
|
346
|
-
|
|
346
|
+
this.debugLog('openAPIRefreshStatus')
|
|
347
347
|
try {
|
|
348
|
-
const
|
|
349
|
-
const deviceStatus: any =
|
|
350
|
-
|
|
348
|
+
const response = await this.deviceRefreshStatus()
|
|
349
|
+
const deviceStatus: any = response.body
|
|
350
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
351
351
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
352
|
-
|
|
352
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
353
353
|
this.deviceStatus = deviceStatus.body
|
|
354
354
|
await this.openAPIparseStatus()
|
|
355
355
|
await this.updateHomeKitCharacteristics()
|
|
356
356
|
} else {
|
|
357
|
-
|
|
358
|
-
|
|
357
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
358
|
+
this.debugWarnLog(deviceStatus)
|
|
359
359
|
}
|
|
360
360
|
} catch (e: any) {
|
|
361
361
|
await this.apiError(e)
|
|
362
|
-
|
|
362
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
async registerWebhook() {
|
|
367
367
|
if (this.device.webhook) {
|
|
368
|
-
|
|
368
|
+
this.debugLog('is listening webhook.')
|
|
369
369
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: contactSensorWebhookContext) => {
|
|
370
370
|
try {
|
|
371
|
-
|
|
371
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
372
372
|
this.webhookContext = context
|
|
373
373
|
await this.parseStatusWebhook()
|
|
374
374
|
await this.updateHomeKitCharacteristics()
|
|
375
375
|
} catch (e: any) {
|
|
376
|
-
|
|
376
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
} else {
|
|
380
|
-
|
|
380
|
+
this.debugLog('is not listening webhook.')
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
|
|
@@ -402,9 +402,9 @@ export class Contact extends deviceBase {
|
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
405
|
-
|
|
405
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
406
406
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
407
|
-
|
|
407
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
408
408
|
await this.openAPIRefreshStatus()
|
|
409
409
|
}
|
|
410
410
|
}
|