node-switchbot 2.5.0-beta.11 → 2.5.0-beta.13
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/switchbot.d.ts +17 -52
- package/dist/switchbot.d.ts.map +1 -1
- package/dist/switchbot.js +107 -172
- package/dist/switchbot.js.map +1 -1
- package/package.json +1 -1
package/dist/switchbot.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type * as Noble from '@stoprocent/noble';
|
|
1
2
|
import type { Ad, Params } from './types/types.js';
|
|
2
|
-
import * as Noble from '@stoprocent/noble';
|
|
3
3
|
import { SwitchbotDevice } from './device.js';
|
|
4
4
|
/**
|
|
5
|
-
* SwitchBot class to interact with SwitchBot devices.
|
|
5
|
+
* SwitchBot class to interact with SwitchBot devices via BLE.
|
|
6
6
|
*/
|
|
7
7
|
export declare class SwitchBot {
|
|
8
8
|
private ready;
|
|
@@ -12,72 +12,37 @@ export declare class SwitchBot {
|
|
|
12
12
|
onlog?: (message: string) => void;
|
|
13
13
|
DEFAULT_DISCOVERY_DURATION: number;
|
|
14
14
|
PRIMARY_SERVICE_UUID_LIST: string[];
|
|
15
|
-
/**
|
|
16
|
-
* Constructor
|
|
17
|
-
*
|
|
18
|
-
* @param {Params} [params] - Optional parameters
|
|
19
|
-
* @param {typeof Noble} [params.noble] - Optional noble instance
|
|
20
|
-
*/
|
|
21
15
|
constructor(params?: Params);
|
|
22
16
|
/**
|
|
23
17
|
* Initializes the noble object.
|
|
24
|
-
*
|
|
25
|
-
* @param {Params} [params] - Optional parameters
|
|
26
|
-
* @param {typeof Noble} [params.noble] - Optional noble instance
|
|
27
|
-
* @returns {Promise<void>} - Resolves when initialization is complete
|
|
28
|
-
*/
|
|
29
|
-
init(params?: Params): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Discover SwitchBot devices based on the provided parameters.
|
|
32
|
-
*
|
|
33
|
-
* @param {Params} params - The parameters for discovery.
|
|
34
|
-
* @returns {Promise<SwitchbotDevice[]>} - A promise that resolves with a list of discovered devices.
|
|
18
|
+
* @param params Optional parameters.
|
|
35
19
|
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Initializes the noble object and waits for it to be powered on.
|
|
39
|
-
*
|
|
40
|
-
* @returns {Promise<void>} - Resolves when the noble object is powered on.
|
|
41
|
-
*/
|
|
42
|
-
_init(): Promise<void>;
|
|
20
|
+
private init;
|
|
43
21
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @param {Noble.Peripheral} peripheral - The peripheral object.
|
|
47
|
-
* @param {string} id - The device id.
|
|
48
|
-
* @param {string} model - The device model.
|
|
49
|
-
* @returns {Promise<SwitchbotDevice | null>} - The device object or null.
|
|
22
|
+
* Ensures the noble object is powered on.
|
|
50
23
|
*/
|
|
51
|
-
|
|
24
|
+
private ensureNobleReady;
|
|
52
25
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @param {Ad} ad - The advertising data.
|
|
56
|
-
* @param {string} id - The device id.
|
|
57
|
-
* @param {string} model - The device model.
|
|
58
|
-
* @returns {boolean} - True if the advertising data matches the id and model, false otherwise.
|
|
26
|
+
* Discover SwitchBot devices.
|
|
27
|
+
* @param params Optional parameters for discovery.
|
|
59
28
|
*/
|
|
60
|
-
|
|
29
|
+
discover(params?: Params): Promise<SwitchbotDevice[]>;
|
|
61
30
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @param {Params} [params] - Optional parameters.
|
|
65
|
-
* @returns {Promise<void>} - Resolves when scanning starts successfully.
|
|
31
|
+
* Start monitoring advertising packets from SwitchBot devices.
|
|
32
|
+
* @param params Optional parameters for scanning.
|
|
66
33
|
*/
|
|
67
34
|
startScan(params?: Params): Promise<void>;
|
|
68
35
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @returns {Promise<void>} - Resolves when scanning stops successfully.
|
|
36
|
+
* Stop monitoring advertising packets from SwitchBot devices.
|
|
72
37
|
*/
|
|
73
|
-
stopScan():
|
|
38
|
+
stopScan(): void;
|
|
74
39
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @param {number} msec - The time to wait in milliseconds.
|
|
78
|
-
* @returns {Promise<void>} - Resolves after the specified time.
|
|
40
|
+
* Wait for the specified time.
|
|
41
|
+
* @param msec Time in milliseconds.
|
|
79
42
|
*/
|
|
80
43
|
wait(msec: number): Promise<void>;
|
|
44
|
+
private getDeviceObject;
|
|
45
|
+
private filterAdvertising;
|
|
81
46
|
}
|
|
82
47
|
export { SwitchbotDevice };
|
|
83
48
|
//# sourceMappingURL=switchbot.d.ts.map
|
package/dist/switchbot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switchbot.d.ts","sourceRoot":"","sources":["../src/switchbot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"switchbot.d.ts","sourceRoot":"","sources":["../src/switchbot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAM/C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAGlD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAmB7C;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAe;IAC5B,KAAK,EAAG,OAAO,KAAK,CAAA;IACpB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAA;IAC9C,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,IAAI,CAAA;IAClC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,0BAA0B,SAAO;IACjC,yBAAyB,EAAE,MAAM,EAAE,CAAK;gBAE5B,MAAM,CAAC,EAAE,MAAM;IAI3B;;;OAGG;YACW,IAAI;IAIlB;;OAEG;YACW,gBAAgB;IAiB9B;;;OAGG;IACG,QAAQ,CAAC,MAAM,GAAE,MAAW,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IA4C/D;;;OAGG;IACG,SAAS,CAAC,MAAM,GAAE,MAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCnD;;OAEG;IACH,QAAQ,IAAI,IAAI;IAOhB;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAQnB,eAAe;IA6B7B,OAAO,CAAC,iBAAiB;CAY1B;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
package/dist/switchbot.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as Noble from '@stoprocent/noble';
|
|
2
1
|
import { Advertising } from './advertising.js';
|
|
3
2
|
import { SwitchbotDevice } from './device.js';
|
|
4
3
|
import { WoBlindTilt } from './device/woblindtilt.js';
|
|
@@ -19,7 +18,7 @@ import { WoStrip } from './device/wostrip.js';
|
|
|
19
18
|
import { parameterChecker } from './parameter-checker.js';
|
|
20
19
|
import { SwitchBotBLEModel } from './types/types.js';
|
|
21
20
|
/**
|
|
22
|
-
* SwitchBot class to interact with SwitchBot devices.
|
|
21
|
+
* SwitchBot class to interact with SwitchBot devices via BLE.
|
|
23
22
|
*/
|
|
24
23
|
export class SwitchBot {
|
|
25
24
|
ready;
|
|
@@ -29,30 +28,38 @@ export class SwitchBot {
|
|
|
29
28
|
onlog;
|
|
30
29
|
DEFAULT_DISCOVERY_DURATION = 5000;
|
|
31
30
|
PRIMARY_SERVICE_UUID_LIST = [];
|
|
32
|
-
/**
|
|
33
|
-
* Constructor
|
|
34
|
-
*
|
|
35
|
-
* @param {Params} [params] - Optional parameters
|
|
36
|
-
* @param {typeof Noble} [params.noble] - Optional noble instance
|
|
37
|
-
*/
|
|
38
31
|
constructor(params) {
|
|
39
32
|
this.ready = this.init(params);
|
|
40
33
|
}
|
|
41
34
|
/**
|
|
42
35
|
* Initializes the noble object.
|
|
43
|
-
*
|
|
44
|
-
* @param {Params} [params] - Optional parameters
|
|
45
|
-
* @param {typeof Noble} [params.noble] - Optional noble instance
|
|
46
|
-
* @returns {Promise<void>} - Resolves when initialization is complete
|
|
36
|
+
* @param params Optional parameters.
|
|
47
37
|
*/
|
|
48
38
|
async init(params) {
|
|
49
|
-
this.noble = params?.noble ??
|
|
39
|
+
this.noble = params?.noble ?? await import('@stoprocent/noble');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Ensures the noble object is powered on.
|
|
43
|
+
*/
|
|
44
|
+
async ensureNobleReady() {
|
|
45
|
+
await this.ready;
|
|
46
|
+
if (this.noble._state === 'poweredOn') {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
this.noble.once('stateChange', (state) => {
|
|
51
|
+
if (state === 'poweredOn') {
|
|
52
|
+
resolve();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
reject(new Error(`Noble state: ${state}`));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
50
59
|
}
|
|
51
60
|
/**
|
|
52
|
-
* Discover SwitchBot devices
|
|
53
|
-
*
|
|
54
|
-
* @param {Params} params - The parameters for discovery.
|
|
55
|
-
* @returns {Promise<SwitchbotDevice[]>} - A promise that resolves with a list of discovered devices.
|
|
61
|
+
* Discover SwitchBot devices.
|
|
62
|
+
* @param params Optional parameters for discovery.
|
|
56
63
|
*/
|
|
57
64
|
async discover(params = {}) {
|
|
58
65
|
const valid = parameterChecker.check(params, {
|
|
@@ -65,195 +72,123 @@ export class SwitchBot {
|
|
|
65
72
|
throw new Error(parameterChecker.error.message);
|
|
66
73
|
}
|
|
67
74
|
const { duration = this.DEFAULT_DISCOVERY_DURATION, model = '', id = '', quick = false } = params;
|
|
68
|
-
await this.
|
|
69
|
-
if (!this.noble) {
|
|
70
|
-
throw new Error('noble failed to initialize');
|
|
71
|
-
}
|
|
75
|
+
await this.ensureNobleReady();
|
|
72
76
|
const peripherals = {};
|
|
73
|
-
let timer;
|
|
74
|
-
const finishDiscovery = () => {
|
|
75
|
-
clearTimeout(timer);
|
|
76
|
-
this.noble.removeAllListeners('discover');
|
|
77
|
-
this.noble.stopScanning();
|
|
78
|
-
return Object.values(peripherals);
|
|
79
|
-
};
|
|
80
77
|
return new Promise((resolve, reject) => {
|
|
81
|
-
|
|
82
|
-
this.noble.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
const finishDiscovery = () => {
|
|
79
|
+
this.noble.removeAllListeners('discover');
|
|
80
|
+
this.noble.stopScanning();
|
|
81
|
+
resolve(Object.values(peripherals));
|
|
82
|
+
};
|
|
83
|
+
this.noble.on('discover', async (peripheral) => {
|
|
84
|
+
const device = await this.getDeviceObject(peripheral, id, model);
|
|
85
|
+
if (device) {
|
|
86
|
+
peripherals[device.id] = device;
|
|
87
|
+
this.ondiscover?.(device);
|
|
88
|
+
if (quick) {
|
|
89
|
+
finishDiscovery();
|
|
92
90
|
}
|
|
93
|
-
});
|
|
94
|
-
this.noble.startScanningAsync(this.PRIMARY_SERVICE_UUID_LIST, false)
|
|
95
|
-
.then(() => {
|
|
96
|
-
timer = setTimeout(() => {
|
|
97
|
-
resolve(finishDiscovery());
|
|
98
|
-
}, duration);
|
|
99
|
-
})
|
|
100
|
-
.catch((error) => {
|
|
101
|
-
reject(new Error(error.message));
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
reject(new Error(String(error)));
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Initializes the noble object and waits for it to be powered on.
|
|
111
|
-
*
|
|
112
|
-
* @returns {Promise<void>} - Resolves when the noble object is powered on.
|
|
113
|
-
*/
|
|
114
|
-
async _init() {
|
|
115
|
-
await this.ready;
|
|
116
|
-
if (this.noble._state === 'poweredOn') {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
return new Promise((resolve, reject) => {
|
|
120
|
-
this.noble.once('stateChange', (state) => {
|
|
121
|
-
if (state === 'poweredOn') {
|
|
122
|
-
resolve();
|
|
123
|
-
}
|
|
124
|
-
else if (['unsupported', 'unauthorized', 'poweredOff'].includes(state)) {
|
|
125
|
-
reject(new Error(`Failed to initialize the Noble object: ${state}`));
|
|
126
91
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
reject(new Error(`Unknown state: ${state}`));
|
|
92
|
+
});
|
|
93
|
+
this.noble.startScanning(this.PRIMARY_SERVICE_UUID_LIST, false, (error) => {
|
|
94
|
+
if (error) {
|
|
95
|
+
return reject(error);
|
|
132
96
|
}
|
|
97
|
+
setTimeout(finishDiscovery, duration);
|
|
133
98
|
});
|
|
134
99
|
});
|
|
135
100
|
}
|
|
136
101
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* @param {Noble.Peripheral} peripheral - The peripheral object.
|
|
140
|
-
* @param {string} id - The device id.
|
|
141
|
-
* @param {string} model - The device model.
|
|
142
|
-
* @returns {Promise<SwitchbotDevice | null>} - The device object or null.
|
|
143
|
-
*/
|
|
144
|
-
async getDeviceObject(peripheral, id, model) {
|
|
145
|
-
const ad = await Advertising.parse(peripheral, this.onlog);
|
|
146
|
-
if (!ad || !this.filterAdvertising(ad, id, model)) {
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
const modelMapping = {
|
|
150
|
-
[SwitchBotBLEModel.Bot]: WoHand,
|
|
151
|
-
[SwitchBotBLEModel.Curtain]: WoCurtain,
|
|
152
|
-
[SwitchBotBLEModel.Curtain3]: WoCurtain,
|
|
153
|
-
[SwitchBotBLEModel.Humidifier]: WoHumi,
|
|
154
|
-
[SwitchBotBLEModel.Meter]: WoSensorTH,
|
|
155
|
-
[SwitchBotBLEModel.MeterPlus]: WoSensorTH,
|
|
156
|
-
[SwitchBotBLEModel.Hub2]: WoHub2,
|
|
157
|
-
[SwitchBotBLEModel.OutdoorMeter]: WoIOSensorTH,
|
|
158
|
-
[SwitchBotBLEModel.MotionSensor]: WoPresence,
|
|
159
|
-
[SwitchBotBLEModel.ContactSensor]: WoContact,
|
|
160
|
-
[SwitchBotBLEModel.ColorBulb]: WoBulb,
|
|
161
|
-
[SwitchBotBLEModel.CeilingLight]: WoCeilingLight,
|
|
162
|
-
[SwitchBotBLEModel.CeilingLightPro]: WoCeilingLight,
|
|
163
|
-
[SwitchBotBLEModel.StripLight]: WoStrip,
|
|
164
|
-
[SwitchBotBLEModel.PlugMiniUS]: WoPlugMini,
|
|
165
|
-
[SwitchBotBLEModel.PlugMiniJP]: WoPlugMini,
|
|
166
|
-
[SwitchBotBLEModel.Lock]: WoSmartLock,
|
|
167
|
-
[SwitchBotBLEModel.LockPro]: WoSmartLockPro,
|
|
168
|
-
[SwitchBotBLEModel.BlindTilt]: WoBlindTilt,
|
|
169
|
-
};
|
|
170
|
-
const DeviceClass = ad?.serviceData?.model ? modelMapping[ad.serviceData.model] : SwitchbotDevice;
|
|
171
|
-
return new DeviceClass(peripheral, this.noble);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Filters advertising data based on id and model.
|
|
175
|
-
*
|
|
176
|
-
* @param {Ad} ad - The advertising data.
|
|
177
|
-
* @param {string} id - The device id.
|
|
178
|
-
* @param {string} model - The device model.
|
|
179
|
-
* @returns {boolean} - True if the advertising data matches the id and model, false otherwise.
|
|
180
|
-
*/
|
|
181
|
-
filterAdvertising(ad, id, model) {
|
|
182
|
-
if (!ad) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
if (id) {
|
|
186
|
-
const normalizedId = id.toLowerCase().replace(/:/g, '');
|
|
187
|
-
const adId = ad.address.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
188
|
-
if (adId !== normalizedId) {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (model && ad.serviceData.model !== model) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Starts scanning for SwitchBot devices.
|
|
199
|
-
*
|
|
200
|
-
* @param {Params} [params] - Optional parameters.
|
|
201
|
-
* @returns {Promise<void>} - Resolves when scanning starts successfully.
|
|
102
|
+
* Start monitoring advertising packets from SwitchBot devices.
|
|
103
|
+
* @param params Optional parameters for scanning.
|
|
202
104
|
*/
|
|
203
105
|
async startScan(params = {}) {
|
|
204
106
|
const valid = parameterChecker.check(params, {
|
|
205
|
-
model: {
|
|
206
|
-
required: false,
|
|
207
|
-
type: 'string',
|
|
208
|
-
enum: Object.values(SwitchBotBLEModel),
|
|
209
|
-
},
|
|
107
|
+
model: { required: false, type: 'string', enum: Object.values(SwitchBotBLEModel) },
|
|
210
108
|
id: { required: false, type: 'string', min: 12, max: 17 },
|
|
211
109
|
}, false);
|
|
212
110
|
if (!valid) {
|
|
213
111
|
throw new Error(parameterChecker.error.message);
|
|
214
112
|
}
|
|
215
|
-
await this._init();
|
|
216
|
-
if (!this.noble) {
|
|
217
|
-
throw new Error('noble object failed to initialize');
|
|
218
|
-
}
|
|
219
113
|
const { model = '', id = '' } = params;
|
|
114
|
+
await this.ensureNobleReady();
|
|
220
115
|
this.noble.on('discover', async (peripheral) => {
|
|
221
116
|
const ad = await Advertising.parse(peripheral, this.onlog);
|
|
222
117
|
if (ad && this.filterAdvertising(ad, id, model)) {
|
|
223
|
-
|
|
224
|
-
this.onadvertisement(ad);
|
|
225
|
-
}
|
|
118
|
+
this.onadvertisement?.(ad);
|
|
226
119
|
}
|
|
227
120
|
});
|
|
228
|
-
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
this.noble.startScanning(this.PRIMARY_SERVICE_UUID_LIST, true, (error) => {
|
|
123
|
+
if (error) {
|
|
124
|
+
reject(error);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
resolve();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
229
131
|
}
|
|
230
132
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* @returns {Promise<void>} - Resolves when scanning stops successfully.
|
|
133
|
+
* Stop monitoring advertising packets from SwitchBot devices.
|
|
234
134
|
*/
|
|
235
|
-
|
|
236
|
-
if (
|
|
237
|
-
|
|
135
|
+
stopScan() {
|
|
136
|
+
if (this.noble) {
|
|
137
|
+
this.noble.removeAllListeners('discover');
|
|
138
|
+
this.noble.stopScanning();
|
|
238
139
|
}
|
|
239
|
-
this.noble.removeAllListeners('discover');
|
|
240
|
-
await this.noble.stopScanningAsync();
|
|
241
140
|
}
|
|
242
141
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* @param {number} msec - The time to wait in milliseconds.
|
|
246
|
-
* @returns {Promise<void>} - Resolves after the specified time.
|
|
142
|
+
* Wait for the specified time.
|
|
143
|
+
* @param msec Time in milliseconds.
|
|
247
144
|
*/
|
|
248
|
-
|
|
249
|
-
const valid = parameterChecker.check({ msec }, {
|
|
250
|
-
msec: { required: true, type: 'integer', min: 0 },
|
|
251
|
-
}, true);
|
|
145
|
+
wait(msec) {
|
|
146
|
+
const valid = parameterChecker.check({ msec }, { msec: { required: true, type: 'integer', min: 0 } }, true);
|
|
252
147
|
if (!valid) {
|
|
253
|
-
|
|
148
|
+
return Promise.reject(new Error(parameterChecker.error.message));
|
|
254
149
|
}
|
|
255
150
|
return new Promise(resolve => setTimeout(resolve, msec));
|
|
256
151
|
}
|
|
152
|
+
async getDeviceObject(peripheral, id, model) {
|
|
153
|
+
const ad = await Advertising.parse(peripheral, this.onlog);
|
|
154
|
+
if (ad && this.filterAdvertising(ad, id, model)) {
|
|
155
|
+
switch (ad.serviceData.model) {
|
|
156
|
+
case SwitchBotBLEModel.Bot: return new WoHand(peripheral, this.noble);
|
|
157
|
+
case SwitchBotBLEModel.Curtain:
|
|
158
|
+
case SwitchBotBLEModel.Curtain3: return new WoCurtain(peripheral, this.noble);
|
|
159
|
+
case SwitchBotBLEModel.Humidifier: return new WoHumi(peripheral, this.noble);
|
|
160
|
+
case SwitchBotBLEModel.Meter:
|
|
161
|
+
case SwitchBotBLEModel.MeterPlus: return new WoSensorTH(peripheral, this.noble);
|
|
162
|
+
case SwitchBotBLEModel.Hub2: return new WoHub2(peripheral, this.noble);
|
|
163
|
+
case SwitchBotBLEModel.OutdoorMeter: return new WoIOSensorTH(peripheral, this.noble);
|
|
164
|
+
case SwitchBotBLEModel.MotionSensor: return new WoPresence(peripheral, this.noble);
|
|
165
|
+
case SwitchBotBLEModel.ContactSensor: return new WoContact(peripheral, this.noble);
|
|
166
|
+
case SwitchBotBLEModel.ColorBulb: return new WoBulb(peripheral, this.noble);
|
|
167
|
+
case SwitchBotBLEModel.CeilingLight:
|
|
168
|
+
case SwitchBotBLEModel.CeilingLightPro: return new WoCeilingLight(peripheral, this.noble);
|
|
169
|
+
case SwitchBotBLEModel.StripLight: return new WoStrip(peripheral, this.noble);
|
|
170
|
+
case SwitchBotBLEModel.PlugMiniUS:
|
|
171
|
+
case SwitchBotBLEModel.PlugMiniJP: return new WoPlugMini(peripheral, this.noble);
|
|
172
|
+
case SwitchBotBLEModel.Lock: return new WoSmartLock(peripheral, this.noble);
|
|
173
|
+
case SwitchBotBLEModel.LockPro: return new WoSmartLockPro(peripheral, this.noble);
|
|
174
|
+
case SwitchBotBLEModel.BlindTilt: return new WoBlindTilt(peripheral, this.noble);
|
|
175
|
+
default: return new SwitchbotDevice(peripheral, this.noble);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
filterAdvertising(ad, id, model) {
|
|
181
|
+
if (!ad) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (id && ad.address.toLowerCase().replace(/[^a-z0-9]/g, '') !== id.toLowerCase().replace(/:/g, '')) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (model && ad.serviceData.model !== model) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
257
192
|
}
|
|
258
193
|
export { SwitchbotDevice };
|
|
259
194
|
//# sourceMappingURL=switchbot.js.map
|
package/dist/switchbot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switchbot.js","sourceRoot":"","sources":["../src/switchbot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"switchbot.js","sourceRoot":"","sources":["../src/switchbot.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,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IAAI,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;gBAChF,OAAO,CAAC,CAAC,OAAO,IAAI,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;YAC7D,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,iBAAiB,CAAC,EAAM,EAAE,EAAU,EAAE,KAAa;QACzD,IAAI,CAAC,EAAE,EAAE,CAAC;YACR,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;YACpG,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,KAAK,IAAI,EAAE,CAAC,WAAW,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;YAC5C,OAAO,KAAK,CAAA;QACd,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-switchbot",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.5.0-beta.
|
|
4
|
+
"version": "2.5.0-beta.13",
|
|
5
5
|
"description": "The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).",
|
|
6
6
|
"author": "OpenWonderLabs (https://github.com/OpenWonderLabs)",
|
|
7
7
|
"license": "MIT",
|