@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/meterpro.ts
CHANGED
|
@@ -174,55 +174,55 @@ export class MeterPro extends deviceBase {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
async BLEparseStatus(): Promise<void> {
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
this.debugLog('BLEparseStatus')
|
|
178
|
+
this.debugLog(`(temperature, humidity) = BLE:(${this.serviceData.celsius}, ${this.serviceData.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
|
|
179
179
|
|
|
180
180
|
// CurrentRelativeHumidity
|
|
181
181
|
if (!(this.device as meterConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
182
182
|
this.HumiditySensor.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100)
|
|
183
|
-
|
|
183
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
184
184
|
}
|
|
185
185
|
// Current Temperature
|
|
186
186
|
if (!(this.device as meterConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
187
187
|
const CELSIUS = this.serviceData.celsius < 0 ? 0 : this.serviceData.celsius > 100 ? 100 : this.serviceData.celsius
|
|
188
188
|
this.TemperatureSensor.CurrentTemperature = CELSIUS
|
|
189
|
-
|
|
189
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
190
190
|
}
|
|
191
191
|
// BatteryLevel
|
|
192
192
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
193
|
-
|
|
193
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
194
194
|
// StatusLowBattery
|
|
195
195
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
196
196
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
197
197
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
198
|
-
|
|
198
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
async openAPIparseStatus(): Promise<void> {
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
this.debugLog('openAPIparseStatus')
|
|
203
|
+
this.debugLog(`(temperature, humidity) = OpenAPI:(${this.deviceStatus.temperature}, ${this.deviceStatus.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
|
|
204
204
|
|
|
205
205
|
// CurrentRelativeHumidity
|
|
206
206
|
if (!(this.device as meterConfig).hide_humidity && this.HumiditySensor?.Service) {
|
|
207
207
|
this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity
|
|
208
|
-
|
|
208
|
+
this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
// CurrentTemperature
|
|
212
212
|
if (!(this.device as meterConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
213
213
|
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
214
|
-
|
|
214
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
// BatteryLevel
|
|
218
218
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
219
|
-
|
|
219
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
220
220
|
|
|
221
221
|
// StatusLowBattery
|
|
222
222
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
223
223
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
224
224
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
225
|
-
|
|
225
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
226
226
|
|
|
227
227
|
// FirmwareVersion
|
|
228
228
|
if (this.deviceStatus.version) {
|
|
@@ -241,23 +241,23 @@ export class MeterPro extends deviceBase {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
async parseStatusWebhook(): Promise<void> {
|
|
244
|
-
|
|
245
|
-
|
|
244
|
+
this.debugLog('parseStatusWebhook')
|
|
245
|
+
this.debugLog(`(scale, temperature, humidity) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as meterConfig).convertUnitTo)}, ${this.webhookContext.humidity}) current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity})`)
|
|
246
246
|
// Check if the scale is not CELSIUS
|
|
247
247
|
if (this.webhookContext.scale !== 'CELSIUS' && (this.device as meterConfig).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 meterConfig).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 meterConfig).hide_temperature && this.TemperatureSensor?.Service) {
|
|
259
259
|
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, (this.device as meterConfig).convertUnitTo)
|
|
260
|
-
|
|
260
|
+
this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
|
|
@@ -266,19 +266,19 @@ export class MeterPro extends deviceBase {
|
|
|
266
266
|
*/
|
|
267
267
|
async refreshStatus(): Promise<void> {
|
|
268
268
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
269
|
-
|
|
269
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
270
270
|
} else if (this.BLE) {
|
|
271
271
|
await this.BLERefreshStatus()
|
|
272
272
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
273
273
|
await this.openAPIRefreshStatus()
|
|
274
274
|
} else {
|
|
275
275
|
await this.offlineOff()
|
|
276
|
-
|
|
276
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
async BLERefreshStatus(): Promise<void> {
|
|
281
|
-
|
|
281
|
+
this.debugLog('BLERefreshStatus')
|
|
282
282
|
const switchBotBLE = await this.switchbotBLE()
|
|
283
283
|
if (switchBotBLE === undefined) {
|
|
284
284
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -293,7 +293,7 @@ export class MeterPro extends deviceBase {
|
|
|
293
293
|
await this.BLEparseStatus()
|
|
294
294
|
await this.updateHomeKitCharacteristics()
|
|
295
295
|
} else {
|
|
296
|
-
|
|
296
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
297
297
|
await this.BLERefreshConnection(switchBotBLE)
|
|
298
298
|
}
|
|
299
299
|
})()
|
|
@@ -301,67 +301,67 @@ export class MeterPro extends deviceBase {
|
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
async registerPlatformBLE(): Promise<void> {
|
|
304
|
-
|
|
304
|
+
this.debugLog('registerPlatformBLE')
|
|
305
305
|
if (this.config.options?.BLE) {
|
|
306
|
-
|
|
306
|
+
this.debugLog('is listening to Platform BLE.')
|
|
307
307
|
try {
|
|
308
308
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
309
309
|
this.device.bleMac = formattedDeviceId
|
|
310
|
-
|
|
310
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
311
311
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: meterProServiceData) => {
|
|
312
312
|
try {
|
|
313
|
-
|
|
313
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
314
314
|
this.serviceData = context
|
|
315
315
|
await this.BLEparseStatus()
|
|
316
316
|
await this.updateHomeKitCharacteristics()
|
|
317
317
|
} catch (e: any) {
|
|
318
|
-
|
|
318
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
} catch (error) {
|
|
322
|
-
|
|
322
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
323
323
|
}
|
|
324
324
|
} else {
|
|
325
|
-
|
|
325
|
+
this.debugLog('is not listening to Platform BLE')
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
async openAPIRefreshStatus(): Promise<void> {
|
|
330
|
-
|
|
330
|
+
this.debugLog('openAPIRefreshStatus')
|
|
331
331
|
try {
|
|
332
|
-
const
|
|
333
|
-
const deviceStatus: any =
|
|
334
|
-
|
|
332
|
+
const response = await this.deviceRefreshStatus()
|
|
333
|
+
const deviceStatus: any = response.body
|
|
334
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
335
335
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
336
|
-
|
|
336
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
337
337
|
this.deviceStatus = deviceStatus.body
|
|
338
338
|
await this.openAPIparseStatus()
|
|
339
339
|
await this.updateHomeKitCharacteristics()
|
|
340
340
|
} else {
|
|
341
|
-
|
|
342
|
-
|
|
341
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
342
|
+
this.debugWarnLog(deviceStatus)
|
|
343
343
|
}
|
|
344
344
|
} catch (e: any) {
|
|
345
345
|
await this.apiError(e)
|
|
346
|
-
|
|
346
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
|
|
350
350
|
async registerWebhook() {
|
|
351
351
|
if (this.device.webhook) {
|
|
352
|
-
|
|
352
|
+
this.debugLog('is listening webhook.')
|
|
353
353
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: meterProWebhookContext) => {
|
|
354
354
|
try {
|
|
355
|
-
|
|
355
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
356
356
|
this.webhookContext = context
|
|
357
357
|
await this.parseStatusWebhook()
|
|
358
358
|
await this.updateHomeKitCharacteristics()
|
|
359
359
|
} catch (e: any) {
|
|
360
|
-
|
|
360
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
} else {
|
|
364
|
-
|
|
364
|
+
this.debugLog('is not listening webhook.')
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
|
|
@@ -384,9 +384,9 @@ export class MeterPro extends deviceBase {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
387
|
-
|
|
387
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
388
388
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
389
|
-
|
|
389
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
390
390
|
await this.openAPIRefreshStatus()
|
|
391
391
|
}
|
|
392
392
|
}
|
package/src/device/motion.ts
CHANGED
|
@@ -156,12 +156,12 @@ export class Motion extends deviceBase {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
async BLEparseStatus(): Promise<void> {
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
this.debugLog('BLEparseStatus')
|
|
160
|
+
this.debugLog(`(moveDetected) = BLE: (${this.serviceData.movement}), current: (${this.MotionSensor.MotionDetected})`)
|
|
161
161
|
|
|
162
162
|
// Movement
|
|
163
163
|
this.MotionSensor.MotionDetected = this.serviceData.movement
|
|
164
|
-
|
|
164
|
+
this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
|
|
165
165
|
|
|
166
166
|
// CurrentAmbientLightLevel
|
|
167
167
|
if (!(this.device as motionConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
@@ -169,27 +169,27 @@ export class Motion extends deviceBase {
|
|
|
169
169
|
const set_maxLux = (this.device as motionConfig).set_maxLux ?? 6001
|
|
170
170
|
const lightLevel = this.serviceData.lightLevel === 'bright' ? set_maxLux : set_minLux
|
|
171
171
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
172
|
-
|
|
172
|
+
this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
// BatteryLevel
|
|
176
176
|
this.Battery.BatteryLevel = this.serviceData.battery
|
|
177
|
-
|
|
177
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
178
178
|
|
|
179
179
|
// StatusLowBattery
|
|
180
180
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
181
181
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
182
182
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
183
|
-
|
|
183
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
async openAPIparseStatus(): Promise<void> {
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
this.debugLog('openAPIparseStatus')
|
|
188
|
+
this.debugLog(`(moveDetected) = OpenAPI: (${this.deviceStatus.moveDetected}), current: (${this.MotionSensor.MotionDetected})`)
|
|
189
189
|
|
|
190
190
|
// Motion State
|
|
191
191
|
this.MotionSensor.MotionDetected = this.deviceStatus.moveDetected
|
|
192
|
-
|
|
192
|
+
this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
|
|
193
193
|
|
|
194
194
|
// CurrentAmbientLightLevel
|
|
195
195
|
if (!(this.device as motionConfig).hide_lightsensor && this.LightSensor?.Service) {
|
|
@@ -197,22 +197,22 @@ export class Motion extends deviceBase {
|
|
|
197
197
|
const set_maxLux = (this.device as motionConfig).set_maxLux ?? 6001
|
|
198
198
|
const lightLevel = this.deviceStatus.brightness === 'bright' ? set_maxLux : set_minLux
|
|
199
199
|
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
|
|
200
|
-
|
|
200
|
+
this.debugLog(`LightLevel: ${this.deviceStatus.brightness}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
201
201
|
}
|
|
202
202
|
// BatteryLevel
|
|
203
203
|
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
204
|
-
|
|
204
|
+
this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
205
205
|
|
|
206
206
|
// StatusLowBattery
|
|
207
207
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
208
208
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
209
209
|
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
210
|
-
|
|
210
|
+
this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
211
211
|
|
|
212
212
|
// FirmwareVersion
|
|
213
213
|
if (this.deviceStatus.version) {
|
|
214
214
|
const version = this.deviceStatus.version.toString()
|
|
215
|
-
|
|
215
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
216
216
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
217
217
|
this.accessory
|
|
218
218
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -221,17 +221,17 @@ export class Motion extends deviceBase {
|
|
|
221
221
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
222
222
|
.updateValue(deviceVersion)
|
|
223
223
|
this.accessory.context.version = deviceVersion
|
|
224
|
-
|
|
224
|
+
this.debugLog(`version: ${this.accessory.context.version}`)
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
async parseStatusWebhook(): Promise<void> {
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
this.debugLog('parseStatusWebhook')
|
|
230
|
+
this.debugLog(`(detectionState) = Webhook: (${this.webhookContext.detectionState}), current: (${this.MotionSensor.MotionDetected})`)
|
|
231
231
|
|
|
232
232
|
// MotionDetected
|
|
233
233
|
this.MotionSensor.MotionDetected = this.webhookContext.detectionState === 'DETECTED'
|
|
234
|
-
|
|
234
|
+
this.debugLog(`MotionDetected: ${this.MotionSensor.MotionDetected}`)
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
/**
|
|
@@ -239,19 +239,19 @@ export class Motion extends deviceBase {
|
|
|
239
239
|
*/
|
|
240
240
|
async refreshStatus(): Promise<void> {
|
|
241
241
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
242
|
-
|
|
242
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
243
243
|
} else if (this.BLE) {
|
|
244
244
|
await this.BLERefreshStatus()
|
|
245
245
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
246
246
|
await this.openAPIRefreshStatus()
|
|
247
247
|
} else {
|
|
248
248
|
await this.offlineOff()
|
|
249
|
-
|
|
249
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
async BLERefreshStatus(): Promise<void> {
|
|
254
|
-
|
|
254
|
+
this.debugLog('BLERefreshStatus')
|
|
255
255
|
const switchBotBLE = await this.switchbotBLE()
|
|
256
256
|
if (switchBotBLE === undefined) {
|
|
257
257
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -266,7 +266,7 @@ export class Motion extends deviceBase {
|
|
|
266
266
|
await this.BLEparseStatus()
|
|
267
267
|
await this.updateHomeKitCharacteristics()
|
|
268
268
|
} else {
|
|
269
|
-
|
|
269
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
270
270
|
await this.BLERefreshConnection(switchBotBLE)
|
|
271
271
|
}
|
|
272
272
|
})()
|
|
@@ -274,67 +274,67 @@ export class Motion extends deviceBase {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
async registerPlatformBLE(): Promise<void> {
|
|
277
|
-
|
|
277
|
+
this.debugLog('registerPlatformBLE')
|
|
278
278
|
if (this.config.options?.BLE) {
|
|
279
|
-
|
|
279
|
+
this.debugLog('is listening to Platform BLE.')
|
|
280
280
|
try {
|
|
281
281
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
282
282
|
this.device.bleMac = formattedDeviceId
|
|
283
|
-
|
|
283
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
284
284
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: motionSensorServiceData) => {
|
|
285
285
|
try {
|
|
286
|
-
|
|
286
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
287
287
|
this.serviceData = context
|
|
288
288
|
await this.BLEparseStatus()
|
|
289
289
|
await this.updateHomeKitCharacteristics()
|
|
290
290
|
} catch (e: any) {
|
|
291
|
-
|
|
291
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
} catch (error) {
|
|
295
|
-
|
|
295
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
296
296
|
}
|
|
297
297
|
} else {
|
|
298
|
-
|
|
298
|
+
this.debugLog('is not listening to Platform BLE')
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
async openAPIRefreshStatus(): Promise<void> {
|
|
303
|
-
|
|
303
|
+
this.debugLog('openAPIRefreshStatus')
|
|
304
304
|
try {
|
|
305
|
-
const
|
|
306
|
-
const deviceStatus: any =
|
|
307
|
-
|
|
305
|
+
const response = await this.deviceRefreshStatus()
|
|
306
|
+
const deviceStatus: any = response.body
|
|
307
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
308
308
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
309
|
-
|
|
309
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
310
310
|
this.deviceStatus = deviceStatus.body
|
|
311
311
|
await this.openAPIparseStatus()
|
|
312
312
|
await this.updateHomeKitCharacteristics()
|
|
313
313
|
} else {
|
|
314
|
-
|
|
315
|
-
|
|
314
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
315
|
+
this.debugWarnLog(deviceStatus)
|
|
316
316
|
}
|
|
317
317
|
} catch (e: any) {
|
|
318
318
|
await this.apiError(e)
|
|
319
|
-
|
|
319
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
async registerWebhook() {
|
|
324
324
|
if (this.device.webhook) {
|
|
325
|
-
|
|
325
|
+
this.debugLog('is listening webhook.')
|
|
326
326
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: motionSensorWebhookContext) => {
|
|
327
327
|
try {
|
|
328
|
-
|
|
328
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
329
329
|
this.webhookContext = context
|
|
330
330
|
await this.parseStatusWebhook()
|
|
331
331
|
await this.updateHomeKitCharacteristics()
|
|
332
332
|
} catch (e: any) {
|
|
333
|
-
|
|
333
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
} else {
|
|
337
|
-
|
|
337
|
+
this.debugLog('is not listening webhook.')
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
|
|
@@ -355,9 +355,9 @@ export class Motion extends deviceBase {
|
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
358
|
-
|
|
358
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
359
359
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
360
|
-
|
|
360
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
361
361
|
await this.openAPIRefreshStatus()
|
|
362
362
|
}
|
|
363
363
|
}
|