@switchbot/homebridge-switchbot 1.6.2-beta.1 → 1.6.4-beta.0
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 +24 -0
- package/config.schema.json +6 -0
- package/dist/devices/bots.d.ts +6 -1
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +212 -141
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/contact.d.ts +1 -0
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +63 -51
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +2 -1
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +92 -71
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +2 -1
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +87 -70
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +1 -0
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +66 -58
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +1 -0
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +58 -50
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.js +2 -2
- package/dist/devices/plugs.js.map +1 -1
- package/package.json +4 -4
- package/src/devices/bots.ts +197 -122
- package/src/devices/contact.ts +63 -51
- package/src/devices/curtains.ts +91 -71
- package/src/devices/humidifiers.ts +86 -70
- package/src/devices/meters.ts +66 -58
- package/src/devices/motion.ts +58 -50
- package/src/devices/plugs.ts +2 -2
package/src/devices/meters.ts
CHANGED
|
@@ -199,12 +199,12 @@ export class Meter {
|
|
|
199
199
|
if (this.device.scanDuration) {
|
|
200
200
|
this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
|
|
201
201
|
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
202
|
-
this.warnLog(`
|
|
202
|
+
this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
203
203
|
}
|
|
204
204
|
} else {
|
|
205
205
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
206
206
|
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
207
|
-
this.warnLog(`
|
|
207
|
+
this.warnLog(`Meter: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
}
|
|
@@ -306,77 +306,85 @@ export class Meter {
|
|
|
306
306
|
private connectBLE() {
|
|
307
307
|
// Convert to BLE Address
|
|
308
308
|
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
309
|
-
this.debugLog(`
|
|
309
|
+
this.debugLog(`Meter: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
310
310
|
const switchbot = this.platform.connectBLE();
|
|
311
311
|
return switchbot;
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
|
|
315
|
-
private BLErefreshStatus() {
|
|
315
|
+
private async BLErefreshStatus() {
|
|
316
316
|
this.debugLog(`Meter: ${this.accessory.displayName} BLE RefreshStatus`);
|
|
317
317
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
318
318
|
const switchbot = this.connectBLE();
|
|
319
319
|
// Start to monitor advertisement packets
|
|
320
|
-
switchbot
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
this.
|
|
337
|
-
|
|
320
|
+
if (switchbot !== false) {
|
|
321
|
+
switchbot.startScan({
|
|
322
|
+
model: 'T',
|
|
323
|
+
id: this.device.bleMac,
|
|
324
|
+
}).then(() => {
|
|
325
|
+
// Set an event hander
|
|
326
|
+
switchbot.onadvertisement = (ad: ad) => {
|
|
327
|
+
this.serviceData = ad.serviceData;
|
|
328
|
+
this.temperature = ad.serviceData.temperature!.c;
|
|
329
|
+
this.humidity = ad.serviceData.humidity;
|
|
330
|
+
this.battery = ad.serviceData.battery;
|
|
331
|
+
this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
332
|
+
this.debugLog(`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, `
|
|
333
|
+
+ `temperature: ${JSON.stringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, `
|
|
334
|
+
+ `battery: ${ad.serviceData.battery}`);
|
|
335
|
+
|
|
336
|
+
if (this.serviceData) {
|
|
337
|
+
this.connected = true;
|
|
338
|
+
this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
339
|
+
} else {
|
|
340
|
+
this.connected = false;
|
|
341
|
+
this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
// Wait 10 seconds
|
|
345
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
346
|
+
}).then(async () => {
|
|
347
|
+
// Stop to monitor
|
|
348
|
+
switchbot.stopScan();
|
|
349
|
+
if (this.connected) {
|
|
350
|
+
this.CurrentTemperatureCached = this.temperature;
|
|
351
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
|
|
352
|
+
this.CurrentRelativeHumidityCached = this.humidity!;
|
|
353
|
+
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidityCached;
|
|
354
|
+
this.BatteryLevelCached = this.battery!;
|
|
355
|
+
this.accessory.context.BatteryLevel = this.BatteryLevelCached;
|
|
356
|
+
this.parseStatus();
|
|
357
|
+
this.updateHomeKitCharacteristics();
|
|
338
358
|
} else {
|
|
339
|
-
this.
|
|
340
|
-
|
|
359
|
+
await this.BLEconnection();
|
|
360
|
+
}
|
|
361
|
+
}).catch(async (e: any) => {
|
|
362
|
+
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
363
|
+
if (this.deviceLogging === 'debug') {
|
|
364
|
+
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
365
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
366
|
+
}
|
|
367
|
+
if (this.platform.debugMode) {
|
|
368
|
+
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
369
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
341
370
|
}
|
|
342
|
-
};
|
|
343
|
-
// Wait 10 seconds
|
|
344
|
-
return switchbot.wait(this.scanDuration * 1000);
|
|
345
|
-
}).then(async () => {
|
|
346
|
-
// Stop to monitor
|
|
347
|
-
switchbot.stopScan();
|
|
348
|
-
if (this.connected) {
|
|
349
|
-
this.CurrentTemperatureCached = this.temperature;
|
|
350
|
-
this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
|
|
351
|
-
this.CurrentRelativeHumidityCached = this.humidity!;
|
|
352
|
-
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidityCached;
|
|
353
|
-
this.BatteryLevelCached = this.battery!;
|
|
354
|
-
this.accessory.context.BatteryLevel = this.BatteryLevelCached;
|
|
355
|
-
this.parseStatus();
|
|
356
|
-
this.updateHomeKitCharacteristics();
|
|
357
|
-
} else {
|
|
358
|
-
this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
359
371
|
if (this.platform.config.credentials?.openToken) {
|
|
360
372
|
this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
361
373
|
this.openAPIRefreshStatus();
|
|
362
374
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
this.openAPIRefreshStatus();
|
|
377
|
-
}
|
|
378
|
-
this.apiError(e);
|
|
379
|
-
});
|
|
375
|
+
this.apiError(e);
|
|
376
|
+
});
|
|
377
|
+
} else {
|
|
378
|
+
await this.BLEconnection();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
private async BLEconnection() {
|
|
383
|
+
this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
384
|
+
if (this.platform.config.credentials?.openToken) {
|
|
385
|
+
this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
386
|
+
await this.openAPIRefreshStatus();
|
|
387
|
+
}
|
|
380
388
|
}
|
|
381
389
|
|
|
382
390
|
private async openAPIRefreshStatus() {
|
package/src/devices/motion.ts
CHANGED
|
@@ -130,12 +130,12 @@ export class Motion {
|
|
|
130
130
|
if (this.device.scanDuration) {
|
|
131
131
|
this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
|
|
132
132
|
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
133
|
-
this.warnLog(`
|
|
133
|
+
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
134
134
|
}
|
|
135
135
|
} else {
|
|
136
136
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
137
137
|
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
138
|
-
this.warnLog(`
|
|
138
|
+
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -229,7 +229,7 @@ export class Motion {
|
|
|
229
229
|
private connectBLE() {
|
|
230
230
|
// Convert to BLE Address
|
|
231
231
|
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
232
|
-
this.debugLog(`
|
|
232
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
233
233
|
const switchbot = this.platform.connectBLE();
|
|
234
234
|
return switchbot;
|
|
235
235
|
}
|
|
@@ -239,59 +239,67 @@ export class Motion {
|
|
|
239
239
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
240
240
|
const switchbot = this.connectBLE();
|
|
241
241
|
// Start to monitor advertisement packets
|
|
242
|
-
switchbot
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
this.
|
|
258
|
-
|
|
242
|
+
if (switchbot !== false) {
|
|
243
|
+
switchbot.startScan({
|
|
244
|
+
model: 's',
|
|
245
|
+
id: this.device.bleMac,
|
|
246
|
+
}).then(() => {
|
|
247
|
+
// Set an event hander
|
|
248
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
249
|
+
this.serviceData = ad.serviceData;
|
|
250
|
+
this.movement = ad.serviceData.movement;
|
|
251
|
+
this.battery = ad.serviceData.battery;
|
|
252
|
+
this.lightLevel = ad.serviceData.lightLevel;
|
|
253
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
254
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: `
|
|
255
|
+
+ `${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
|
|
256
|
+
|
|
257
|
+
if (this.serviceData) {
|
|
258
|
+
this.connected = true;
|
|
259
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
260
|
+
} else {
|
|
261
|
+
this.connected = false;
|
|
262
|
+
this.debugLog(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
// Wait 10 seconds
|
|
266
|
+
return switchbot.wait(this.scanDuration * 1000);
|
|
267
|
+
}).then(async () => {
|
|
268
|
+
// Stop to monitor
|
|
269
|
+
switchbot.stopScan();
|
|
270
|
+
if (this.connected) {
|
|
271
|
+
this.parseStatus();
|
|
272
|
+
this.updateHomeKitCharacteristics();
|
|
259
273
|
} else {
|
|
260
|
-
this.
|
|
261
|
-
|
|
274
|
+
await this.BLEconnection();
|
|
275
|
+
}
|
|
276
|
+
}).catch(async (e: any) => {
|
|
277
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
278
|
+
if (this.deviceLogging === 'debug') {
|
|
279
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
280
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
281
|
+
}
|
|
282
|
+
if (this.platform.debugMode) {
|
|
283
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
284
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
262
285
|
}
|
|
263
|
-
};
|
|
264
|
-
// Wait 10 seconds
|
|
265
|
-
return switchbot.wait(this.scanDuration * 1000);
|
|
266
|
-
}).then(async () => {
|
|
267
|
-
// Stop to monitor
|
|
268
|
-
switchbot.stopScan();
|
|
269
|
-
if (this.connected) {
|
|
270
|
-
this.parseStatus();
|
|
271
|
-
this.updateHomeKitCharacteristics();
|
|
272
|
-
} else {
|
|
273
|
-
this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
274
286
|
if (this.platform.config.credentials?.openToken) {
|
|
275
287
|
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
276
288
|
await this.openAPIRefreshStatus();
|
|
277
289
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
await this.openAPIRefreshStatus();
|
|
292
|
-
}
|
|
293
|
-
this.apiError(e);
|
|
294
|
-
});
|
|
290
|
+
this.apiError(e);
|
|
291
|
+
});
|
|
292
|
+
} else {
|
|
293
|
+
await this.BLEconnection();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private async BLEconnection() {
|
|
298
|
+
this.errorLog(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
299
|
+
if (this.platform.config.credentials?.openToken) {
|
|
300
|
+
this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
301
|
+
await this.openAPIRefreshStatus();
|
|
302
|
+
}
|
|
295
303
|
}
|
|
296
304
|
|
|
297
305
|
private async openAPIRefreshStatus() {
|
package/src/devices/plugs.ts
CHANGED
|
@@ -134,12 +134,12 @@ export class Plug {
|
|
|
134
134
|
if (this.device.scanDuration) {
|
|
135
135
|
this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration;
|
|
136
136
|
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
137
|
-
this.warnLog(`
|
|
137
|
+
this.warnLog(`Plug: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
138
138
|
}
|
|
139
139
|
} else {
|
|
140
140
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
141
141
|
if (this.platform.debugMode || (this.deviceLogging === 'debug')) {
|
|
142
|
-
this.warnLog(`
|
|
142
|
+
this.warnLog(`Plug: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
}
|