node-switchbot 2.5.0-beta.1 → 2.5.0-beta.10
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/advertising.d.ts +32 -15
- package/dist/advertising.d.ts.map +1 -1
- package/dist/advertising.js +72 -72
- package/dist/advertising.js.map +1 -1
- package/dist/device/woblindtilt.d.ts +19 -50
- package/dist/device/woblindtilt.d.ts.map +1 -1
- package/dist/device/woblindtilt.js +39 -98
- package/dist/device/woblindtilt.js.map +1 -1
- package/dist/device/wobulb.d.ts +41 -15
- package/dist/device/wobulb.d.ts.map +1 -1
- package/dist/device/wobulb.js +71 -127
- package/dist/device/wobulb.js.map +1 -1
- package/dist/device/woceilinglight.d.ts +47 -21
- package/dist/device/woceilinglight.d.ts.map +1 -1
- package/dist/device/woceilinglight.js +94 -169
- package/dist/device/woceilinglight.js.map +1 -1
- package/dist/device/wocontact.d.ts +11 -1
- package/dist/device/wocontact.d.ts.map +1 -1
- package/dist/device/wocontact.js +22 -21
- package/dist/device/wocontact.js.map +1 -1
- package/dist/device/wocurtain.d.ts +39 -1
- package/dist/device/wocurtain.d.ts.map +1 -1
- package/dist/device/wocurtain.js +68 -102
- package/dist/device/wocurtain.js.map +1 -1
- package/dist/device/wohand.d.ts +37 -2
- package/dist/device/wohand.d.ts.map +1 -1
- package/dist/device/wohand.js +54 -88
- package/dist/device/wohand.js.map +1 -1
- package/dist/device/wohub2.d.ts +11 -1
- package/dist/device/wohub2.d.ts.map +1 -1
- package/dist/device/wohub2.js +22 -22
- package/dist/device/wohub2.js.map +1 -1
- package/dist/device/wohumi.d.ts +37 -2
- package/dist/device/wohumi.d.ts.map +1 -1
- package/dist/device/wohumi.js +51 -82
- package/dist/device/wohumi.js.map +1 -1
- package/dist/device/woiosensorth.d.ts +12 -1
- package/dist/device/woiosensorth.d.ts.map +1 -1
- package/dist/device/woiosensorth.js +26 -22
- package/dist/device/woiosensorth.js.map +1 -1
- package/dist/device/woplugmini.d.ts +45 -12
- package/dist/device/woplugmini.d.ts.map +1 -1
- package/dist/device/woplugmini.js +69 -75
- package/dist/device/woplugmini.js.map +1 -1
- package/dist/device/wopresence.d.ts +11 -1
- package/dist/device/wopresence.d.ts.map +1 -1
- package/dist/device/wopresence.js +20 -26
- package/dist/device/wopresence.js.map +1 -1
- package/dist/device/wosensorth.d.ts +18 -2
- package/dist/device/wosensorth.d.ts.map +1 -1
- package/dist/device/wosensorth.js +34 -40
- package/dist/device/wosensorth.js.map +1 -1
- package/dist/device/wosmartlock.d.ts +56 -13
- package/dist/device/wosmartlock.d.ts.map +1 -1
- package/dist/device/wosmartlock.js +106 -194
- package/dist/device/wosmartlock.js.map +1 -1
- package/dist/device/wosmartlockpro.d.ts +61 -18
- package/dist/device/wosmartlockpro.d.ts.map +1 -1
- package/dist/device/wosmartlockpro.js +114 -203
- package/dist/device/wosmartlockpro.js.map +1 -1
- package/dist/device/wostrip.d.ts +37 -18
- package/dist/device/wostrip.d.ts.map +1 -1
- package/dist/device/wostrip.js +78 -124
- package/dist/device/wostrip.js.map +1 -1
- package/dist/device.d.ts +86 -223
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +123 -407
- package/dist/device.js.map +1 -1
- package/dist/parameter-checker.d.ts +78 -18
- package/dist/parameter-checker.d.ts.map +1 -1
- package/dist/parameter-checker.js +139 -334
- package/dist/parameter-checker.js.map +1 -1
- package/dist/settings.d.ts +23 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +23 -2
- package/dist/settings.js.map +1 -1
- package/dist/switchbot.d.ts +67 -35
- package/dist/switchbot.d.ts.map +1 -1
- package/dist/switchbot.js +182 -380
- package/dist/switchbot.js.map +1 -1
- package/dist/test/woblindtilt.test.d.ts.map +1 -0
- package/dist/test/woblindtilt.test.js +93 -0
- package/dist/test/woblindtilt.test.js.map +1 -0
- package/dist/{device → test}/wobulb.test.d.ts.map +1 -1
- package/dist/test/wobulb.test.js +100 -0
- package/dist/test/wobulb.test.js.map +1 -0
- package/dist/test/woceilinglight.test.d.ts.map +1 -0
- package/dist/test/woceilinglight.test.js +91 -0
- package/dist/test/woceilinglight.test.js.map +1 -0
- package/dist/test/wocontact.test.d.ts.map +1 -0
- package/dist/test/wocontact.test.js +34 -0
- package/dist/test/wocontact.test.js.map +1 -0
- package/dist/test/wocurtain.test.d.ts.map +1 -0
- package/dist/test/wocurtain.test.js +72 -0
- package/dist/test/wocurtain.test.js.map +1 -0
- package/dist/{device → test}/wohand.test.d.ts.map +1 -1
- package/dist/test/wohand.test.js +72 -0
- package/dist/test/wohand.test.js.map +1 -0
- package/dist/test/wohub2.test.d.ts +2 -0
- package/dist/test/wohub2.test.d.ts.map +1 -0
- package/dist/{device/wohand2.test.js → test/wohub2.test.js} +6 -4
- package/dist/test/wohub2.test.js.map +1 -0
- package/dist/{device → test}/wohumi.test.d.ts.map +1 -1
- package/dist/{device → test}/wohumi.test.js +1 -2
- package/dist/test/wohumi.test.js.map +1 -0
- package/dist/test/woiosensorth.test.d.ts.map +1 -0
- package/dist/{device → test}/woiosensorth.test.js +7 -5
- package/dist/test/woiosensorth.test.js.map +1 -0
- package/dist/test/woplugmini.test.d.ts.map +1 -0
- package/dist/{device → test}/woplugmini.test.js +6 -5
- package/dist/test/woplugmini.test.js.map +1 -0
- package/dist/test/wopresence.test.d.ts.map +1 -0
- package/dist/{device → test}/wopresence.test.js +1 -1
- package/dist/test/wopresence.test.js.map +1 -0
- package/dist/test/wosensorth.test.d.ts.map +1 -0
- package/dist/{device → test}/wosensorth.test.js +3 -4
- package/dist/test/wosensorth.test.js.map +1 -0
- package/dist/test/wosmartlock.test.d.ts.map +1 -0
- package/dist/test/wosmartlock.test.js +143 -0
- package/dist/test/wosmartlock.test.js.map +1 -0
- package/dist/test/wosmartlockpro.test.d.ts.map +1 -0
- package/dist/{device → test}/wosmartlockpro.test.js +26 -26
- package/dist/test/wosmartlockpro.test.js.map +1 -0
- package/dist/{device → test}/wostrip.test.d.ts.map +1 -1
- package/dist/{device → test}/wostrip.test.js +18 -19
- package/dist/test/wostrip.test.js.map +1 -0
- package/dist/types/types.d.ts +52 -120
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/device/woblindtilt.test.d.ts.map +0 -1
- package/dist/device/woblindtilt.test.js +0 -26
- package/dist/device/woblindtilt.test.js.map +0 -1
- package/dist/device/wobulb.test.js +0 -52
- package/dist/device/wobulb.test.js.map +0 -1
- package/dist/device/woceilinglight.test.d.ts.map +0 -1
- package/dist/device/woceilinglight.test.js +0 -63
- package/dist/device/woceilinglight.test.js.map +0 -1
- package/dist/device/wocontact.test.d.ts.map +0 -1
- package/dist/device/wocontact.test.js +0 -34
- package/dist/device/wocontact.test.js.map +0 -1
- package/dist/device/wocurtain.test.d.ts.map +0 -1
- package/dist/device/wocurtain.test.js +0 -33
- package/dist/device/wocurtain.test.js.map +0 -1
- package/dist/device/wohand.test.js +0 -62
- package/dist/device/wohand.test.js.map +0 -1
- package/dist/device/wohand2.test.d.ts +0 -2
- package/dist/device/wohand2.test.d.ts.map +0 -1
- package/dist/device/wohand2.test.js.map +0 -1
- package/dist/device/wohumi.test.js.map +0 -1
- package/dist/device/woiosensorth.test.d.ts.map +0 -1
- package/dist/device/woiosensorth.test.js.map +0 -1
- package/dist/device/woplugmini.test.d.ts.map +0 -1
- package/dist/device/woplugmini.test.js.map +0 -1
- package/dist/device/wopresence.test.d.ts.map +0 -1
- package/dist/device/wopresence.test.js.map +0 -1
- package/dist/device/wosensorth.test.d.ts.map +0 -1
- package/dist/device/wosensorth.test.js.map +0 -1
- package/dist/device/wosmartlock.test.d.ts.map +0 -1
- package/dist/device/wosmartlock.test.js +0 -84
- package/dist/device/wosmartlock.test.js.map +0 -1
- package/dist/device/wosmartlockpro.test.d.ts.map +0 -1
- package/dist/device/wosmartlockpro.test.js.map +0 -1
- package/dist/device/wostrip.test.js.map +0 -1
- /package/dist/{device → test}/woblindtilt.test.d.ts +0 -0
- /package/dist/{device → test}/wobulb.test.d.ts +0 -0
- /package/dist/{device → test}/woceilinglight.test.d.ts +0 -0
- /package/dist/{device → test}/wocontact.test.d.ts +0 -0
- /package/dist/{device → test}/wocurtain.test.d.ts +0 -0
- /package/dist/{device → test}/wohand.test.d.ts +0 -0
- /package/dist/{device → test}/wohumi.test.d.ts +0 -0
- /package/dist/{device → test}/woiosensorth.test.d.ts +0 -0
- /package/dist/{device → test}/woplugmini.test.d.ts +0 -0
- /package/dist/{device → test}/wopresence.test.d.ts +0 -0
- /package/dist/{device → test}/wosensorth.test.d.ts +0 -0
- /package/dist/{device → test}/wosmartlock.test.d.ts +0 -0
- /package/dist/{device → test}/wosmartlockpro.test.d.ts +0 -0
- /package/dist/{device → test}/wostrip.test.d.ts +0 -0
package/dist/advertising.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import type * as Noble from '@stoprocent/noble';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
rssi: number;
|
|
7
|
-
serviceData: Record<string, unknown>;
|
|
8
|
-
} | null;
|
|
9
|
-
export interface AdvertisementData {
|
|
10
|
-
serviceData: Buffer | null;
|
|
11
|
-
manufacturerData: Buffer | null;
|
|
12
|
-
}
|
|
2
|
+
import type { Ad } from './types/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents the advertising data parser for SwitchBot devices.
|
|
5
|
+
*/
|
|
13
6
|
export declare class Advertising {
|
|
14
7
|
constructor();
|
|
15
8
|
/**
|
|
@@ -18,10 +11,34 @@ export declare class Advertising {
|
|
|
18
11
|
* This function processes advertising packets received from SwitchBot devices
|
|
19
12
|
* and extracts relevant information based on the device type.
|
|
20
13
|
*
|
|
21
|
-
* @param peripheral - The peripheral device object from noble.
|
|
22
|
-
* @param onlog - A logging function for debugging purposes.
|
|
23
|
-
* @returns An object containing parsed data specific to the SwitchBot device type, or `null` if the device is not recognized.
|
|
14
|
+
* @param {Noble.Peripheral} peripheral - The peripheral device object from noble.
|
|
15
|
+
* @param {(message: string) => void} [onlog] - A logging function for debugging purposes.
|
|
16
|
+
* @returns {Promise<Ad | null>} - An object containing parsed data specific to the SwitchBot device type, or `null` if the device is not recognized.
|
|
17
|
+
*/
|
|
18
|
+
static parse(peripheral: Noble.Peripheral, onlog?: (message: string) => void): Promise<Ad | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Validates if the buffer is a valid Buffer object with a minimum length.
|
|
21
|
+
*
|
|
22
|
+
* @param {any} buffer - The buffer to validate.
|
|
23
|
+
* @returns {boolean} - True if the buffer is valid, false otherwise.
|
|
24
|
+
*/
|
|
25
|
+
private static validateBuffer;
|
|
26
|
+
/**
|
|
27
|
+
* Parses the service data based on the device model.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} model - The device model.
|
|
30
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
31
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
32
|
+
* @param {(message: string) => void} [onlog] - A logging function for debugging purposes.
|
|
33
|
+
* @returns {Promise<any>} - The parsed service data.
|
|
34
|
+
*/
|
|
35
|
+
private static parseServiceData;
|
|
36
|
+
/**
|
|
37
|
+
* Formats the address of the peripheral.
|
|
38
|
+
*
|
|
39
|
+
* @param {Noble.Peripheral} peripheral - The peripheral device object from noble.
|
|
40
|
+
* @returns {string} - The formatted address.
|
|
24
41
|
*/
|
|
25
|
-
static
|
|
42
|
+
private static formatAddress;
|
|
26
43
|
}
|
|
27
44
|
//# sourceMappingURL=advertising.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advertising.d.ts","sourceRoot":"","sources":["../src/advertising.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAE/C,OAAO,
|
|
1
|
+
{"version":3,"file":"advertising.d.ts","sourceRoot":"","sources":["../src/advertising.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,EAAE,EAAE,EAAe,MAAM,kBAAkB,CAAA;AAqBvD;;GAEG;AACH,qBAAa,WAAW;;IAGtB;;;;;;;;;OASG;WACU,KAAK,CAChB,UAAU,EAAE,KAAK,CAAC,UAAU,EAC5B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAChC,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC;IAgCrB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAI7B;;;;;;;;OAQG;mBACkB,gBAAgB;IAkDrC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;CAY7B"}
|
package/dist/advertising.js
CHANGED
|
@@ -15,6 +15,9 @@ import { WoSmartLock } from './device/wosmartlock.js';
|
|
|
15
15
|
import { WoSmartLockPro } from './device/wosmartlockpro.js';
|
|
16
16
|
import { WoStrip } from './device/wostrip.js';
|
|
17
17
|
import { SwitchBotBLEModel } from './types/types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Represents the advertising data parser for SwitchBot devices.
|
|
20
|
+
*/
|
|
18
21
|
export class Advertising {
|
|
19
22
|
constructor() { }
|
|
20
23
|
/**
|
|
@@ -23,119 +26,116 @@ export class Advertising {
|
|
|
23
26
|
* This function processes advertising packets received from SwitchBot devices
|
|
24
27
|
* and extracts relevant information based on the device type.
|
|
25
28
|
*
|
|
26
|
-
* @param peripheral - The peripheral device object from noble.
|
|
27
|
-
* @param onlog - A logging function for debugging purposes.
|
|
28
|
-
* @returns An object containing parsed data specific to the SwitchBot device type, or `null` if the device is not recognized.
|
|
29
|
+
* @param {Noble.Peripheral} peripheral - The peripheral device object from noble.
|
|
30
|
+
* @param {(message: string) => void} [onlog] - A logging function for debugging purposes.
|
|
31
|
+
* @returns {Promise<Ad | null>} - An object containing parsed data specific to the SwitchBot device type, or `null` if the device is not recognized.
|
|
29
32
|
*/
|
|
30
33
|
static async parse(peripheral, onlog) {
|
|
31
34
|
const ad = peripheral.advertisement;
|
|
32
35
|
if (!ad || !ad.serviceData) {
|
|
33
36
|
return null;
|
|
34
37
|
}
|
|
35
|
-
const
|
|
38
|
+
const serviceData = ad.serviceData[0]?.data;
|
|
36
39
|
const manufacturerData = ad.manufacturerData;
|
|
37
|
-
|
|
38
|
-
function validateBuffer(buffer) {
|
|
39
|
-
return buffer && Buffer.isBuffer(buffer) && buffer.length >= 3;
|
|
40
|
-
}
|
|
41
|
-
if (!validateBuffer(serviceData) || !validateBuffer(manufacturerData)) {
|
|
40
|
+
if (!Advertising.validateBuffer(serviceData) || !Advertising.validateBuffer(manufacturerData)) {
|
|
42
41
|
return null;
|
|
43
42
|
}
|
|
44
43
|
const model = serviceData.subarray(0, 1).toString('utf8');
|
|
45
|
-
|
|
44
|
+
const sd = await Advertising.parseServiceData(model, serviceData, manufacturerData, onlog);
|
|
45
|
+
if (!sd) {
|
|
46
|
+
onlog?.(`[parseAdvertising.${peripheral.id}.${model}] return null, parsed serviceData empty!`);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const address = Advertising.formatAddress(peripheral);
|
|
50
|
+
const data = {
|
|
51
|
+
id: peripheral.id,
|
|
52
|
+
address,
|
|
53
|
+
rssi: peripheral.rssi,
|
|
54
|
+
serviceData: { model, ...sd },
|
|
55
|
+
};
|
|
56
|
+
onlog?.(`[parseAdvertising.${peripheral.id}.${model}] return ${JSON.stringify(data)}`);
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Validates if the buffer is a valid Buffer object with a minimum length.
|
|
61
|
+
*
|
|
62
|
+
* @param {any} buffer - The buffer to validate.
|
|
63
|
+
* @returns {boolean} - True if the buffer is valid, false otherwise.
|
|
64
|
+
*/
|
|
65
|
+
static validateBuffer(buffer) {
|
|
66
|
+
return buffer && Buffer.isBuffer(buffer) && buffer.length >= 3;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parses the service data based on the device model.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} model - The device model.
|
|
72
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
73
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
74
|
+
* @param {(message: string) => void} [onlog] - A logging function for debugging purposes.
|
|
75
|
+
* @returns {Promise<any>} - The parsed service data.
|
|
76
|
+
*/
|
|
77
|
+
static async parseServiceData(model, serviceData, manufacturerData, onlog) {
|
|
46
78
|
switch (model) {
|
|
47
79
|
case SwitchBotBLEModel.Bot:
|
|
48
|
-
|
|
49
|
-
break;
|
|
80
|
+
return WoHand.parseServiceData(serviceData, onlog);
|
|
50
81
|
case SwitchBotBLEModel.Curtain:
|
|
51
82
|
case SwitchBotBLEModel.Curtain3:
|
|
52
|
-
|
|
53
|
-
break;
|
|
83
|
+
return WoCurtain.parseServiceData(serviceData, manufacturerData, onlog);
|
|
54
84
|
case SwitchBotBLEModel.Humidifier:
|
|
55
|
-
|
|
56
|
-
break;
|
|
85
|
+
return WoHumi.parseServiceData(serviceData, onlog);
|
|
57
86
|
case SwitchBotBLEModel.Meter:
|
|
58
|
-
|
|
59
|
-
break;
|
|
87
|
+
return WoSensorTH.parseServiceData(serviceData, onlog);
|
|
60
88
|
case SwitchBotBLEModel.MeterPlus:
|
|
61
|
-
|
|
62
|
-
break;
|
|
89
|
+
return WoSensorTH.parseServiceData_Plus(serviceData, onlog);
|
|
63
90
|
case SwitchBotBLEModel.Hub2:
|
|
64
|
-
|
|
65
|
-
break;
|
|
91
|
+
return WoHub2.parseServiceData(manufacturerData, onlog);
|
|
66
92
|
case SwitchBotBLEModel.OutdoorMeter:
|
|
67
|
-
|
|
68
|
-
break;
|
|
93
|
+
return WoIOSensorTH.parseServiceData(serviceData, manufacturerData, onlog);
|
|
69
94
|
case SwitchBotBLEModel.MotionSensor:
|
|
70
|
-
|
|
71
|
-
break;
|
|
95
|
+
return WoPresence.parseServiceData(serviceData, onlog);
|
|
72
96
|
case SwitchBotBLEModel.ContactSensor:
|
|
73
|
-
|
|
74
|
-
break;
|
|
97
|
+
return WoContact.parseServiceData(serviceData, onlog);
|
|
75
98
|
case SwitchBotBLEModel.ColorBulb:
|
|
76
|
-
|
|
77
|
-
break;
|
|
99
|
+
return WoBulb.parseServiceData(serviceData, manufacturerData, onlog);
|
|
78
100
|
case SwitchBotBLEModel.CeilingLight:
|
|
79
|
-
|
|
80
|
-
break;
|
|
101
|
+
return WoCeilingLight.parseServiceData(manufacturerData, onlog);
|
|
81
102
|
case SwitchBotBLEModel.CeilingLightPro:
|
|
82
|
-
|
|
83
|
-
break;
|
|
103
|
+
return WoCeilingLight.parseServiceData_Pro(manufacturerData, onlog);
|
|
84
104
|
case SwitchBotBLEModel.StripLight:
|
|
85
|
-
|
|
86
|
-
break;
|
|
105
|
+
return WoStrip.parseServiceData(serviceData, onlog);
|
|
87
106
|
case SwitchBotBLEModel.PlugMiniUS:
|
|
88
|
-
|
|
89
|
-
break;
|
|
107
|
+
return WoPlugMini.parseServiceData_US(manufacturerData, onlog);
|
|
90
108
|
case SwitchBotBLEModel.PlugMiniJP:
|
|
91
|
-
|
|
92
|
-
break;
|
|
109
|
+
return WoPlugMini.parseServiceData_JP(manufacturerData, onlog);
|
|
93
110
|
case SwitchBotBLEModel.Lock:
|
|
94
|
-
|
|
95
|
-
break;
|
|
111
|
+
return WoSmartLock.parseServiceData(serviceData, manufacturerData, onlog);
|
|
96
112
|
case SwitchBotBLEModel.LockPro:
|
|
97
|
-
|
|
98
|
-
break;
|
|
113
|
+
return WoSmartLockPro.parseServiceData(serviceData, manufacturerData, onlog);
|
|
99
114
|
case SwitchBotBLEModel.BlindTilt:
|
|
100
|
-
|
|
101
|
-
break;
|
|
115
|
+
return WoBlindTilt.parseServiceData(serviceData, manufacturerData, onlog);
|
|
102
116
|
default:
|
|
103
|
-
|
|
104
|
-
onlog(`[parseAdvertising.${peripheral.id}] return null, model "${model}" not available!`);
|
|
105
|
-
}
|
|
117
|
+
onlog?.(`[parseAdvertising.${model}] return null, model "${model}" not available!`);
|
|
106
118
|
return null;
|
|
107
119
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Formats the address of the peripheral.
|
|
123
|
+
*
|
|
124
|
+
* @param {Noble.Peripheral} peripheral - The peripheral device object from noble.
|
|
125
|
+
* @returns {string} - The formatted address.
|
|
126
|
+
*/
|
|
127
|
+
static formatAddress(peripheral) {
|
|
114
128
|
let address = peripheral.address || '';
|
|
115
129
|
if (address === '') {
|
|
116
|
-
const str = peripheral.advertisement.manufacturerData
|
|
117
|
-
.toString('hex')
|
|
118
|
-
.slice(4, 16);
|
|
130
|
+
const str = peripheral.advertisement.manufacturerData?.toString('hex').slice(4, 16) || '';
|
|
119
131
|
if (str !== '') {
|
|
120
|
-
address = str.
|
|
121
|
-
for (let i = 2; i < str.length; i += 2) {
|
|
122
|
-
address = `${address}:${str.substring(i, i + 2)}`;
|
|
123
|
-
}
|
|
132
|
+
address = str.match(/.{1,2}/g)?.join(':') || '';
|
|
124
133
|
}
|
|
125
134
|
}
|
|
126
135
|
else {
|
|
127
136
|
address = address.replace(/-/g, ':');
|
|
128
137
|
}
|
|
129
|
-
|
|
130
|
-
id: peripheral.id,
|
|
131
|
-
address,
|
|
132
|
-
rssi: peripheral.rssi,
|
|
133
|
-
serviceData: sd,
|
|
134
|
-
};
|
|
135
|
-
if (onlog && typeof onlog === 'function') {
|
|
136
|
-
onlog(`[parseAdvertising.${peripheral.id}.${model}] return ${JSON.stringify(data)}`);
|
|
137
|
-
}
|
|
138
|
-
return data;
|
|
138
|
+
return address;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
//# sourceMappingURL=advertising.js.map
|
package/dist/advertising.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advertising.js","sourceRoot":"","sources":["../src/advertising.ts"],"names":[],"mappings":"
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AAgB,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,CAAA;YACzF,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;gBACf,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;YACjD,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QACtC,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF"}
|
|
@@ -1,106 +1,75 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { SwitchbotDevice } from '../device.js';
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a WoBlindTilt device.
|
|
5
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain.md
|
|
6
|
+
*/
|
|
3
7
|
export declare class WoBlindTilt extends SwitchbotDevice {
|
|
4
8
|
private _reverse;
|
|
5
9
|
/**
|
|
6
10
|
* Parses the service data and manufacturer data for the WoBlindTilt device.
|
|
7
|
-
*
|
|
8
11
|
* @param {Buffer} serviceData - The service data buffer.
|
|
9
12
|
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
10
13
|
* @param {(message: string) => void} [onlog] - Optional logging function.
|
|
11
14
|
* @param {boolean} [reverse] - Whether to reverse the tilt percentage.
|
|
12
|
-
* @returns {object | null} The parsed data object or null if the data is invalid.
|
|
15
|
+
* @returns {Promise<object | null>} - The parsed data object or null if the data is invalid.
|
|
13
16
|
*/
|
|
14
|
-
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, onlog
|
|
17
|
+
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, onlog?: (message: string) => void, reverse?: boolean): Promise<object | null>;
|
|
15
18
|
/**
|
|
16
|
-
* open
|
|
17
|
-
*
|
|
18
19
|
* Opens the blind tilt to the fully open position.
|
|
19
|
-
*
|
|
20
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
20
|
+
* @returns {Promise<void>}
|
|
21
21
|
*/
|
|
22
22
|
open(): Promise<void>;
|
|
23
23
|
/**
|
|
24
|
-
* closeUp
|
|
25
|
-
*
|
|
26
24
|
* Closes the blind tilt up to the nearest endpoint.
|
|
27
|
-
*
|
|
28
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
25
|
+
* @returns {Promise<void>}
|
|
29
26
|
*/
|
|
30
27
|
closeUp(): Promise<void>;
|
|
31
28
|
/**
|
|
32
|
-
* closeDown
|
|
33
|
-
*
|
|
34
29
|
* Closes the blind tilt down to the nearest endpoint.
|
|
35
|
-
*
|
|
36
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
30
|
+
* @returns {Promise<void>}
|
|
37
31
|
*/
|
|
38
32
|
closeDown(): Promise<void>;
|
|
39
33
|
/**
|
|
40
|
-
* close
|
|
41
|
-
*
|
|
42
34
|
* Closes the blind tilt to the nearest endpoint.
|
|
43
|
-
*
|
|
44
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
35
|
+
* @returns {Promise<void>}
|
|
45
36
|
*/
|
|
46
37
|
close(): Promise<void>;
|
|
47
38
|
/**
|
|
48
|
-
* getPosition
|
|
49
|
-
*
|
|
50
39
|
* Retrieves the current position of the blind tilt.
|
|
51
|
-
*
|
|
52
|
-
* @returns {number} - The current position of the blind tilt (0-100).
|
|
40
|
+
* @returns {Promise<number>} - The current position of the blind tilt (0-100).
|
|
53
41
|
*/
|
|
54
42
|
getPosition(): Promise<number>;
|
|
55
43
|
/**
|
|
56
|
-
* _getAdvValue
|
|
57
|
-
*
|
|
58
44
|
* Retrieves the advertised value for a given key.
|
|
59
|
-
*
|
|
60
45
|
* @param {string} key - The key for the advertised value.
|
|
61
46
|
* @returns {Promise<number>} - The advertised value.
|
|
47
|
+
* @private
|
|
62
48
|
*/
|
|
63
49
|
private _getAdvValue;
|
|
64
50
|
/**
|
|
65
|
-
* getBasicInfo
|
|
66
|
-
*
|
|
67
51
|
* Retrieves the basic information of the blind tilt.
|
|
68
|
-
*
|
|
69
|
-
* @returns {Promise<object>} - A promise that resolves to an object containing the basic information of the blind tilt.
|
|
52
|
+
* @returns {Promise<object | null>} - A promise that resolves to an object containing the basic information of the blind tilt.
|
|
70
53
|
*/
|
|
71
54
|
getBasicInfo(): Promise<object | null>;
|
|
72
55
|
/**
|
|
73
56
|
* Pauses the blind tilt operation.
|
|
74
|
-
*
|
|
75
|
-
* This method sends a command to pause the current operation of the blind tilt.
|
|
76
|
-
*
|
|
77
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
78
|
-
* No value is passed to the `resolve()` function.
|
|
57
|
+
* @returns {Promise<void>}
|
|
79
58
|
*/
|
|
80
59
|
pause(): Promise<void>;
|
|
81
60
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* This method sends a command to run the blind tilt to the specified position.
|
|
85
|
-
*
|
|
61
|
+
* Runs the blind tilt to the specified position.
|
|
86
62
|
* @param {number} percent - The target position percentage (0-100).
|
|
87
63
|
* @param {number} mode - The running mode (0 or 1).
|
|
88
|
-
* @returns {Promise<void>}
|
|
64
|
+
* @returns {Promise<void>}
|
|
89
65
|
*/
|
|
90
66
|
runToPos(percent: number, mode: number): Promise<void>;
|
|
91
67
|
/**
|
|
92
68
|
* Sends a command to operate the blind tilt and handles the response.
|
|
93
|
-
*
|
|
94
|
-
* This method constructs a buffer from the provided byte array and sends it as a command to the device.
|
|
95
|
-
* It returns a promise that resolves if the device responds with a success code (0x01) and rejects if the device
|
|
96
|
-
* returns an error or if the command fails.
|
|
97
|
-
*
|
|
98
69
|
* @param {number[]} bytes - The byte array representing the command to be sent to the device.
|
|
99
|
-
* @returns {Promise<void>}
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* @throws {Error} Throws an error if the device returns an error code or if the command fails.
|
|
70
|
+
* @returns {Promise<void>}
|
|
71
|
+
* @private
|
|
103
72
|
*/
|
|
104
|
-
operateBlindTilt
|
|
73
|
+
private operateBlindTilt;
|
|
105
74
|
}
|
|
106
75
|
//# sourceMappingURL=woblindtilt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"woblindtilt.d.ts","sourceRoot":"","sources":["../../src/device/woblindtilt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"woblindtilt.d.ts","sourceRoot":"","sources":["../../src/device/woblindtilt.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;;GAGG;AACH,qBAAa,WAAY,SAAQ,eAAe;IAC9C,OAAO,CAAC,QAAQ,CAAiB;IAEjC;;;;;;;OAOG;WACU,gBAAgB,CAC3B,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,EACjC,OAAO,GAAE,OAAe,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA6BzB;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAKpC;;;;;OAKG;YACW,YAAY;IAO1B;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA2C5C;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5D;;;;;OAKG;YACW,gBAAgB;CAO/B"}
|