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