@switchbot/homebridge-switchbot 1.12.6 → 1.12.7-beta.2
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/config.schema.json +9 -0
- package/dist/device/bot.d.ts +2 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +9 -4
- package/dist/device/bot.js.map +1 -1
- package/dist/device/contact.d.ts +2 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +12 -9
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +8 -6
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +2 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +7 -0
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/meter.d.ts +2 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +7 -0
- package/dist/device/meter.js.map +1 -1
- package/dist/device/motion.d.ts +2 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +25 -4
- package/dist/device/motion.js.map +1 -1
- package/dist/settings.d.ts +4 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +76 -76
- package/src/device/bot.ts +10 -4
- package/src/device/contact.ts +15 -11
- package/src/device/curtain.ts +10 -7
- package/src/device/humidifier.ts +8 -0
- package/src/device/meter.ts +8 -0
- package/src/device/motion.ts +28 -6
- package/src/settings.ts +4 -0
package/src/device/motion.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { interval, Subject } from 'rxjs';
|
|
|
2
2
|
import { skipWhile } from 'rxjs/operators';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
4
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
5
|
-
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus } from '../settings';
|
|
5
|
+
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus, ad } from '../settings';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Platform Accessory
|
|
@@ -31,6 +31,7 @@ export class Motion {
|
|
|
31
31
|
switchbot!: switchbot;
|
|
32
32
|
SwitchToOpenAPI?: boolean;
|
|
33
33
|
serviceData!: serviceData;
|
|
34
|
+
address!: ad['address'];
|
|
34
35
|
battery!: serviceData['battery'];
|
|
35
36
|
movement!: serviceData['movement'];
|
|
36
37
|
lightLevel!: serviceData['lightLevel'];
|
|
@@ -213,21 +214,42 @@ export class Motion {
|
|
|
213
214
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE RefreshStatus`);
|
|
214
215
|
const switchbot = await this.platform.connectBLE();
|
|
215
216
|
// Convert to BLE Address
|
|
216
|
-
this.device.bleMac = this.device
|
|
217
|
+
this.device.bleMac = this.device.customBLEaddress || this.device
|
|
217
218
|
.deviceId!.match(/.{1,2}/g)!
|
|
218
219
|
.join(':')
|
|
219
220
|
.toLowerCase();
|
|
220
221
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
222
|
+
(async () => {
|
|
223
|
+
// Start to monitor advertisement packets
|
|
224
|
+
await switchbot.startScan({
|
|
225
|
+
model: 's',
|
|
226
|
+
//id: this.device.bleMac,
|
|
227
|
+
});
|
|
228
|
+
// Set an event handler
|
|
229
|
+
switchbot.onadvertisement = (ad: any) => {
|
|
230
|
+
this.warnLog(JSON.stringify(ad, null, ' '));
|
|
231
|
+
};
|
|
232
|
+
await switchbot.wait(10000);
|
|
233
|
+
// Stop to monitor
|
|
234
|
+
switchbot.stopScan();
|
|
235
|
+
})();
|
|
221
236
|
// Start to monitor advertisement packets
|
|
222
237
|
if (switchbot !== false) {
|
|
223
|
-
switchbot
|
|
238
|
+
await switchbot
|
|
224
239
|
.startScan({
|
|
225
240
|
model: 's',
|
|
226
241
|
id: this.device.bleMac,
|
|
227
242
|
})
|
|
228
|
-
.then(() => {
|
|
243
|
+
.then(async () => {
|
|
229
244
|
// Set an event hander
|
|
230
245
|
switchbot.onadvertisement = (ad: any) => {
|
|
246
|
+
this.address = ad.address;
|
|
247
|
+
if (this.deviceLogging.includes('debug')) {
|
|
248
|
+
this.infoLog(this.address);
|
|
249
|
+
this.infoLog(this.device.bleMac);
|
|
250
|
+
this.infoLog(`Motion Sensor: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
251
|
+
this.infoLog(`Motion Sensor: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
252
|
+
}
|
|
231
253
|
this.serviceData = ad.serviceData;
|
|
232
254
|
this.movement = ad.serviceData.movement;
|
|
233
255
|
this.battery = ad.serviceData.battery;
|
|
@@ -235,7 +257,7 @@ export class Motion {
|
|
|
235
257
|
this.debugLog(`Motion Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
236
258
|
this.debugLog(
|
|
237
259
|
`Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: ` +
|
|
238
|
-
|
|
260
|
+
`${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`,
|
|
239
261
|
);
|
|
240
262
|
|
|
241
263
|
if (this.serviceData) {
|
|
@@ -247,7 +269,7 @@ export class Motion {
|
|
|
247
269
|
}
|
|
248
270
|
};
|
|
249
271
|
// Wait 10 seconds
|
|
250
|
-
return switchbot.wait(this.scanDuration * 1000);
|
|
272
|
+
return await switchbot.wait(this.scanDuration * 1000);
|
|
251
273
|
})
|
|
252
274
|
.then(async () => {
|
|
253
275
|
// Stop to monitor
|
package/src/settings.ts
CHANGED
|
@@ -53,6 +53,7 @@ export interface devicesConfig extends device {
|
|
|
53
53
|
plug?: Record<any, any>;
|
|
54
54
|
lock?: lock;
|
|
55
55
|
ble?: boolean;
|
|
56
|
+
customBLEaddress?: string;
|
|
56
57
|
scanDuration?: number;
|
|
57
58
|
hide_device?: boolean;
|
|
58
59
|
offline?: boolean;
|
|
@@ -299,6 +300,9 @@ export type deviceStatus = {
|
|
|
299
300
|
};
|
|
300
301
|
|
|
301
302
|
export type ad = {
|
|
303
|
+
id: string;
|
|
304
|
+
address: string;
|
|
305
|
+
rssi: number;
|
|
302
306
|
serviceData: serviceData;
|
|
303
307
|
};
|
|
304
308
|
|