@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/hub.ts
CHANGED
|
@@ -174,19 +174,19 @@ export class Hub extends deviceBase {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
async BLEparseStatus(): Promise<void> {
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
this.debugLog('BLEparseStatus')
|
|
178
|
+
this.debugLog(`(temperature, humidity, lightLevel) = BLE:(${this.serviceData.celsius}, ${this.serviceData.humidity}, ${this.serviceData.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
|
|
179
179
|
|
|
180
180
|
// CurrentTemperature
|
|
181
181
|
if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
182
182
|
this.TemperatureSensor.CurrentTemperature = this.serviceData.celsius
|
|
183
|
-
|
|
183
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// CurrentRelativeHumidity
|
|
187
187
|
if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
188
188
|
this.HumiditySensor!.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100)
|
|
189
|
-
|
|
189
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
// CurrentAmbientLightLevel
|
|
@@ -195,24 +195,24 @@ export class Hub extends deviceBase {
|
|
|
195
195
|
const set_maxLux = (this.device as hubConfig).set_maxLux ?? 6001
|
|
196
196
|
const lightLevel = this.serviceData.lightLevel
|
|
197
197
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
198
|
-
|
|
198
|
+
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
async openAPIparseStatus(): Promise<void> {
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
this.debugLog('openAPIparseStatus')
|
|
204
|
+
this.debugLog(`(temperature, humidity, lightLevel) = OpenAPI:(${this.deviceStatus.temperature}, ${this.deviceStatus.humidity}, ${this.deviceStatus.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
|
|
205
205
|
|
|
206
206
|
// CurrentRelativeHumidity
|
|
207
207
|
if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
208
208
|
this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity
|
|
209
|
-
|
|
209
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
// CurrentTemperature
|
|
213
213
|
if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
214
214
|
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
215
|
-
|
|
215
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
// LightSensor
|
|
@@ -221,13 +221,13 @@ export class Hub extends deviceBase {
|
|
|
221
221
|
const set_maxLux = (this.device as hubConfig).set_maxLux ?? 6001
|
|
222
222
|
const lightLevel = this.deviceStatus.lightLevel
|
|
223
223
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
224
|
-
|
|
224
|
+
this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`)
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
// Firmware Version
|
|
228
228
|
if (this.deviceStatus.version) {
|
|
229
229
|
const version = this.deviceStatus.version.toString()
|
|
230
|
-
|
|
230
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
231
231
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
232
232
|
this.accessory
|
|
233
233
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -236,28 +236,28 @@ export class Hub extends deviceBase {
|
|
|
236
236
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
237
237
|
.updateValue(deviceVersion)
|
|
238
238
|
this.accessory.context.version = deviceVersion
|
|
239
|
-
|
|
239
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
async parseStatusWebhook(): Promise<void> {
|
|
244
|
-
|
|
245
|
-
|
|
244
|
+
this.debugLog('parseStatusWebhook')
|
|
245
|
+
this.debugLog(`(scale, temperature, humidity, lightLevel) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as hubConfig).convertUnitTo)}, ${this.webhookContext.humidity}, ${this.webhookContext.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
|
|
246
246
|
// Check if the scale is not CELSIUS
|
|
247
247
|
if (this.webhookContext.scale !== 'CELSIUS' && (this.device as hubConfig).convertUnitTo === undefined) {
|
|
248
|
-
|
|
248
|
+
this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings, if displaying incorrectly in HomeKit.`)
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
// CurrentRelativeHumidity
|
|
252
252
|
if (!(this.device as hubConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
253
253
|
this.HumiditySensor.CurrentRelativeHumidity = this.webhookContext.humidity
|
|
254
|
-
|
|
254
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`)
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
// CurrentTemperature
|
|
258
258
|
if (!(this.device as hubConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
259
259
|
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as hubConfig).convertUnitTo)
|
|
260
|
-
|
|
260
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
// CurrentAmbientLightLevel
|
|
@@ -265,7 +265,7 @@ export class Hub extends deviceBase {
|
|
|
265
265
|
const set_minLux = (this.device as hubConfig).set_minLux ?? 1
|
|
266
266
|
const set_maxLux = (this.device as hubConfig).set_maxLux ?? 6001
|
|
267
267
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(this.webhookContext.lightLevel, set_minLux, set_maxLux, 19)
|
|
268
|
-
|
|
268
|
+
this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
|
|
@@ -274,19 +274,19 @@ export class Hub extends deviceBase {
|
|
|
274
274
|
*/
|
|
275
275
|
async refreshStatus(): Promise<void> {
|
|
276
276
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
277
|
-
|
|
277
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
278
278
|
} else if (this.BLE) {
|
|
279
279
|
await this.BLERefreshStatus()
|
|
280
280
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
281
281
|
await this.openAPIRefreshStatus()
|
|
282
282
|
} else {
|
|
283
283
|
await this.offlineOff()
|
|
284
|
-
|
|
284
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
async BLERefreshStatus(): Promise<void> {
|
|
289
|
-
|
|
289
|
+
this.debugLog('BLERefreshStatus')
|
|
290
290
|
const switchBotBLE = await this.switchbotBLE()
|
|
291
291
|
if (switchBotBLE === undefined) {
|
|
292
292
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -301,7 +301,7 @@ export class Hub extends deviceBase {
|
|
|
301
301
|
await this.BLEparseStatus()
|
|
302
302
|
await this.updateHomeKitCharacteristics()
|
|
303
303
|
} else {
|
|
304
|
-
|
|
304
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
305
305
|
await this.BLERefreshConnection(switchBotBLE)
|
|
306
306
|
}
|
|
307
307
|
})()
|
|
@@ -309,67 +309,67 @@ export class Hub extends deviceBase {
|
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
async registerPlatformBLE(): Promise<void> {
|
|
312
|
-
|
|
312
|
+
this.debugLog('registerPlatformBLE')
|
|
313
313
|
if (this.config.options?.BLE) {
|
|
314
|
-
|
|
314
|
+
this.debugLog('is listening to Platform BLE.')
|
|
315
315
|
try {
|
|
316
316
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
317
317
|
this.device.bleMac = formattedDeviceId
|
|
318
|
-
|
|
318
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
319
319
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: hub2ServiceData) => {
|
|
320
320
|
try {
|
|
321
|
-
|
|
321
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
322
322
|
this.serviceData = context
|
|
323
323
|
await this.BLEparseStatus()
|
|
324
324
|
await this.updateHomeKitCharacteristics()
|
|
325
325
|
} catch (e: any) {
|
|
326
|
-
|
|
326
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
} catch (error) {
|
|
330
|
-
|
|
330
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
331
331
|
}
|
|
332
332
|
} else {
|
|
333
|
-
|
|
333
|
+
this.debugLog('is not listening to Platform BLE')
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
async openAPIRefreshStatus(): Promise<void> {
|
|
338
|
-
|
|
338
|
+
this.debugLog('openAPIRefreshStatus')
|
|
339
339
|
try {
|
|
340
|
-
const
|
|
341
|
-
const deviceStatus: any =
|
|
342
|
-
|
|
340
|
+
const response = await this.deviceRefreshStatus()
|
|
341
|
+
const deviceStatus: any = response.body
|
|
342
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
343
343
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
344
|
-
|
|
344
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
345
345
|
this.deviceStatus = deviceStatus.body
|
|
346
346
|
await this.openAPIparseStatus()
|
|
347
347
|
await this.updateHomeKitCharacteristics()
|
|
348
348
|
} else {
|
|
349
|
-
|
|
350
|
-
|
|
349
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
350
|
+
this.debugWarnLog(deviceStatus)
|
|
351
351
|
}
|
|
352
352
|
} catch (e: any) {
|
|
353
353
|
await this.apiError(e)
|
|
354
|
-
|
|
354
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
async registerWebhook(): Promise<void> {
|
|
359
359
|
if (this.device.webhook) {
|
|
360
|
-
|
|
360
|
+
this.debugLog('is listening webhook.')
|
|
361
361
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: hub2WebhookContext) => {
|
|
362
362
|
try {
|
|
363
|
-
|
|
363
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
364
364
|
this.webhookContext = context
|
|
365
365
|
await this.parseStatusWebhook()
|
|
366
366
|
await this.updateHomeKitCharacteristics()
|
|
367
367
|
} catch (e: any) {
|
|
368
|
-
|
|
368
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
} else {
|
|
372
|
-
|
|
372
|
+
this.debugLog('is not listening webhook.')
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
|
|
@@ -393,9 +393,9 @@ export class Hub extends deviceBase {
|
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
396
|
-
|
|
396
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
397
397
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
398
|
-
|
|
398
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
399
399
|
await this.openAPIRefreshStatus()
|
|
400
400
|
}
|
|
401
401
|
}
|