node-switchbot 1.10.0 → 2.0.0-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/.gitattributes +2 -0
- package/.github/dependabot.yml +17 -0
- package/.github/labeler.yml +38 -0
- package/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/beta-release.yml +31 -0
- package/.github/workflows/build.yml +18 -0
- package/.github/workflows/changerelease.yml +13 -0
- package/.github/workflows/dependabot.yml +17 -0
- package/.github/workflows/labeler.yml +16 -0
- package/.github/workflows/release-drafter.yml +14 -0
- package/.github/workflows/release.yml +24 -0
- package/.github/workflows/stale.yml +12 -0
- package/CHANGELOG.md +308 -0
- package/dist/advertising.d.ts +172 -0
- package/dist/advertising.d.ts.map +1 -0
- package/dist/advertising.js +620 -0
- package/dist/advertising.js.map +1 -0
- package/dist/device/woblindtilt.d.ts +9 -0
- package/dist/device/woblindtilt.d.ts.map +1 -0
- package/dist/device/woblindtilt.js +108 -0
- package/dist/device/woblindtilt.js.map +1 -0
- package/dist/device/wobulb.d.ts +39 -0
- package/dist/device/wobulb.d.ts.map +1 -0
- package/dist/device/wobulb.js +156 -0
- package/dist/device/wobulb.js.map +1 -0
- package/dist/device/wocontact.d.ts +4 -0
- package/dist/device/wocontact.d.ts.map +1 -0
- package/dist/device/wocontact.js +8 -0
- package/dist/device/wocontact.js.map +1 -0
- package/dist/device/wocurtain.d.ts +9 -0
- package/dist/device/wocurtain.d.ts.map +1 -0
- package/dist/device/wocurtain.js +104 -0
- package/dist/device/wocurtain.js.map +1 -0
- package/dist/device/wohand.d.ts +10 -0
- package/dist/device/wohand.d.ts.map +1 -0
- package/dist/device/wohand.js +93 -0
- package/dist/device/wohand.js.map +1 -0
- package/dist/device/wohumi.d.ts +10 -0
- package/dist/device/wohumi.d.ts.map +1 -0
- package/dist/device/wohumi.js +93 -0
- package/dist/device/wohumi.js.map +1 -0
- package/dist/device/woiosensorth.d.ts +4 -0
- package/dist/device/woiosensorth.d.ts.map +1 -0
- package/dist/device/woiosensorth.js +4 -0
- package/dist/device/woiosensorth.js.map +1 -0
- package/dist/device/woplugmini.d.ts +31 -0
- package/dist/device/woplugmini.d.ts.map +1 -0
- package/dist/device/woplugmini.js +68 -0
- package/dist/device/woplugmini.js.map +1 -0
- package/dist/device/wopresence.d.ts +4 -0
- package/dist/device/wopresence.d.ts.map +1 -0
- package/dist/device/wopresence.js +4 -0
- package/dist/device/wopresence.js.map +1 -0
- package/dist/device/wosensorth.d.ts +4 -0
- package/dist/device/wosensorth.d.ts.map +1 -0
- package/dist/device/wosensorth.js +4 -0
- package/dist/device/wosensorth.js.map +1 -0
- package/dist/device/wostrip.d.ts +39 -0
- package/dist/device/wostrip.d.ts.map +1 -0
- package/dist/device/wostrip.js +145 -0
- package/dist/device/wostrip.js.map +1 -0
- package/dist/device.d.ts +46 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +498 -0
- package/dist/device.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/parameter-checker.d.ts +25 -0
- package/dist/parameter-checker.d.ts.map +1 -0
- package/dist/parameter-checker.js +488 -0
- package/dist/parameter-checker.js.map +1 -0
- package/dist/switchbot.d.ts +29 -0
- package/dist/switchbot.d.ts.map +1 -0
- package/dist/switchbot.js +461 -0
- package/dist/switchbot.js.map +1 -0
- package/errros.log +13 -0
- package/package.json +19 -12
- package/lib/parameter-checker.js +0 -524
- package/lib/switchbot-advertising.js +0 -713
- package/lib/switchbot-device-woblindtilt.js +0 -120
- package/lib/switchbot-device-wobulb.js +0 -188
- package/lib/switchbot-device-wocontact.js +0 -6
- package/lib/switchbot-device-wocurtain.js +0 -117
- package/lib/switchbot-device-wohand.js +0 -106
- package/lib/switchbot-device-wohumi.js +0 -106
- package/lib/switchbot-device-woiosensorth.js +0 -6
- package/lib/switchbot-device-woplugmini.js +0 -84
- package/lib/switchbot-device-wopresence.js +0 -6
- package/lib/switchbot-device-wosensorth.js +0 -6
- package/lib/switchbot-device-wostrip.js +0 -182
- package/lib/switchbot-device.js +0 -536
- package/lib/switchbot.js +0 -496
package/dist/device.js
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { ParameterChecker } from './parameter-checker.js';
|
|
3
|
+
import { Advertising } from './advertising.js';
|
|
4
|
+
export class SwitchbotDevice {
|
|
5
|
+
_peripheral;
|
|
6
|
+
_noble;
|
|
7
|
+
_chars;
|
|
8
|
+
_SERV_UUID_PRIMARY;
|
|
9
|
+
_CHAR_UUID_WRITE;
|
|
10
|
+
_CHAR_UUID_NOTIFY;
|
|
11
|
+
_CHAR_UUID_DEVICE;
|
|
12
|
+
_READ_TIMEOUT_MSEC;
|
|
13
|
+
_WRITE_TIMEOUT_MSEC;
|
|
14
|
+
_COMMAND_TIMEOUT_MSEC;
|
|
15
|
+
_id;
|
|
16
|
+
_address;
|
|
17
|
+
_model;
|
|
18
|
+
_modelName;
|
|
19
|
+
_was_connected_explicitly;
|
|
20
|
+
_connected;
|
|
21
|
+
_onconnect;
|
|
22
|
+
_ondisconnect;
|
|
23
|
+
_ondisconnect_internal;
|
|
24
|
+
_onnotify_internal;
|
|
25
|
+
/* ------------------------------------------------------------------
|
|
26
|
+
* Constructor
|
|
27
|
+
*
|
|
28
|
+
* [Arguments]
|
|
29
|
+
* - peripheral | Object | Required | The `peripheral` object of noble,
|
|
30
|
+
* | | | which represents this device
|
|
31
|
+
* - noble | Noble | Required | The Noble object created by the noble module.
|
|
32
|
+
* ---------------------------------------------------------------- */
|
|
33
|
+
constructor(peripheral, noble) {
|
|
34
|
+
this._peripheral = peripheral;
|
|
35
|
+
this._noble = noble;
|
|
36
|
+
this._chars = null;
|
|
37
|
+
this._SERV_UUID_PRIMARY = 'cba20d00224d11e69fb80002a5d5c51b';
|
|
38
|
+
this._CHAR_UUID_WRITE = 'cba20002224d11e69fb80002a5d5c51b';
|
|
39
|
+
// Save the device information
|
|
40
|
+
const ad = Advertising.parse(peripheral);
|
|
41
|
+
this._id = ad?.id;
|
|
42
|
+
this._address = ad?.address;
|
|
43
|
+
this._model = ad?.serviceData.model;
|
|
44
|
+
this._modelName = ad?.serviceData.modelName;
|
|
45
|
+
this._was_connected_explicitly = false;
|
|
46
|
+
this._connected = false;
|
|
47
|
+
this._onconnect = () => { };
|
|
48
|
+
this._ondisconnect = () => { };
|
|
49
|
+
this._ondisconnect_internal = () => { };
|
|
50
|
+
this._onnotify_internal = () => { };
|
|
51
|
+
}
|
|
52
|
+
// Getters
|
|
53
|
+
get id() {
|
|
54
|
+
return this._id;
|
|
55
|
+
}
|
|
56
|
+
get address() {
|
|
57
|
+
return this._address;
|
|
58
|
+
}
|
|
59
|
+
get model() {
|
|
60
|
+
return this._model;
|
|
61
|
+
}
|
|
62
|
+
get modelName() {
|
|
63
|
+
return this._modelName;
|
|
64
|
+
}
|
|
65
|
+
get connectionState() {
|
|
66
|
+
if (!this._connected && this._peripheral.state === 'disconnecting') {
|
|
67
|
+
return 'disconnected';
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return this._peripheral.state;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Setters
|
|
74
|
+
set onconnect(func) {
|
|
75
|
+
if (!func || typeof func !== 'function') {
|
|
76
|
+
throw new Error('The `onconnect` must be a function.');
|
|
77
|
+
}
|
|
78
|
+
this._onconnect = func;
|
|
79
|
+
}
|
|
80
|
+
set ondisconnect(func) {
|
|
81
|
+
if (!func || typeof func !== 'function') {
|
|
82
|
+
throw new Error('The `ondisconnect` must be a function.');
|
|
83
|
+
}
|
|
84
|
+
this._ondisconnect = func;
|
|
85
|
+
}
|
|
86
|
+
/* ------------------------------------------------------------------
|
|
87
|
+
* connect()
|
|
88
|
+
* - Connect the device
|
|
89
|
+
*
|
|
90
|
+
* [Arguments]
|
|
91
|
+
* - none
|
|
92
|
+
*
|
|
93
|
+
* [Return value]
|
|
94
|
+
* - Promise object
|
|
95
|
+
* Nothing will be passed to the `resolve()`.
|
|
96
|
+
* ---------------------------------------------------------------- */
|
|
97
|
+
connect() {
|
|
98
|
+
this._was_connected_explicitly = true;
|
|
99
|
+
return this._connect();
|
|
100
|
+
}
|
|
101
|
+
_connect() {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
// Check the bluetooth state
|
|
104
|
+
if (this._noble.state !== 'poweredOn') {
|
|
105
|
+
reject(new Error('The Bluetooth status is ' + this._noble.state + ', not poweredOn.'));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// Check the connection state
|
|
109
|
+
const state = this.connectionState;
|
|
110
|
+
if (state === 'connected') {
|
|
111
|
+
resolve();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
else if (state === 'connecting' || state === 'disconnecting') {
|
|
115
|
+
reject(new Error('Now ' + state + '. Wait for a few seconds then try again.'));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// Set event handlers for events fired on the `Peripheral` object
|
|
119
|
+
this._peripheral.once('connect', () => {
|
|
120
|
+
this._connected = true;
|
|
121
|
+
this._onconnect();
|
|
122
|
+
});
|
|
123
|
+
this._peripheral.once('disconnect', () => {
|
|
124
|
+
this._connected = false;
|
|
125
|
+
this._chars = null;
|
|
126
|
+
this._peripheral.removeAllListeners();
|
|
127
|
+
this._ondisconnect_internal();
|
|
128
|
+
this._ondisconnect();
|
|
129
|
+
});
|
|
130
|
+
// Connect
|
|
131
|
+
this._peripheral.connect((error) => {
|
|
132
|
+
if (error) {
|
|
133
|
+
reject(error);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this._getCharacteristics()
|
|
137
|
+
.then((chars) => {
|
|
138
|
+
this._chars = chars;
|
|
139
|
+
return this._subscribe();
|
|
140
|
+
})
|
|
141
|
+
.then(() => {
|
|
142
|
+
resolve();
|
|
143
|
+
})
|
|
144
|
+
.catch((error) => {
|
|
145
|
+
this._peripheral.disconnect();
|
|
146
|
+
reject(error);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
_getCharacteristics() {
|
|
152
|
+
return new Promise((resolve, reject) => {
|
|
153
|
+
// Set timeout timer
|
|
154
|
+
let timer = setTimeout(() => {
|
|
155
|
+
this._ondisconnect_internal = () => { };
|
|
156
|
+
timer = null;
|
|
157
|
+
reject(new Error('Failed to discover services and characteristics: TIMEOUT'));
|
|
158
|
+
}, 5000);
|
|
159
|
+
// Watch the connection state
|
|
160
|
+
this._ondisconnect_internal = () => {
|
|
161
|
+
if (timer) {
|
|
162
|
+
clearTimeout(timer);
|
|
163
|
+
timer = null;
|
|
164
|
+
this._ondisconnect_internal = () => { };
|
|
165
|
+
}
|
|
166
|
+
reject(new Error('Failed to discover services and characteristics: DISCONNECTED'));
|
|
167
|
+
};
|
|
168
|
+
// Discover services and characteristics
|
|
169
|
+
(async () => {
|
|
170
|
+
const service_list = await this._discoverServices();
|
|
171
|
+
if (!timer) {
|
|
172
|
+
throw new Error('');
|
|
173
|
+
}
|
|
174
|
+
const chars = {
|
|
175
|
+
write: null,
|
|
176
|
+
notify: null,
|
|
177
|
+
device: null,
|
|
178
|
+
};
|
|
179
|
+
for (const service of service_list) {
|
|
180
|
+
const char_list = await this._discoverCharacteristics(service);
|
|
181
|
+
for (const char of char_list) {
|
|
182
|
+
if (char.uuid === this._CHAR_UUID_WRITE) {
|
|
183
|
+
chars.write = char;
|
|
184
|
+
}
|
|
185
|
+
else if (char.uuid === this._CHAR_UUID_NOTIFY) {
|
|
186
|
+
chars.notify = char;
|
|
187
|
+
}
|
|
188
|
+
else if (char.uuid === this._CHAR_UUID_DEVICE) {
|
|
189
|
+
// Some models of Bot don't seem to support this characteristic UUID
|
|
190
|
+
chars.device = char;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (chars.write && chars.notify) {
|
|
195
|
+
resolve(chars);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
reject(new Error('No characteristic was found.'));
|
|
199
|
+
}
|
|
200
|
+
})().catch((error) => {
|
|
201
|
+
if (timer) {
|
|
202
|
+
clearTimeout(timer);
|
|
203
|
+
timer = null;
|
|
204
|
+
this._ondisconnect_internal = () => { };
|
|
205
|
+
reject(error);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
// Do nothing
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
_discoverServices() {
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
this._peripheral.discoverServices([], (error, service_list) => {
|
|
216
|
+
if (error) {
|
|
217
|
+
reject(error);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
let service = null;
|
|
221
|
+
for (const s of service_list) {
|
|
222
|
+
if (s.uuid === this._SERV_UUID_PRIMARY) {
|
|
223
|
+
service = s;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (service) {
|
|
228
|
+
resolve(service_list);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
reject(new Error('No service was found.'));
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
_discoverCharacteristics(service) {
|
|
237
|
+
return new Promise((resolve, reject) => {
|
|
238
|
+
service.discoverCharacteristics([], (error, char_list) => {
|
|
239
|
+
if (error) {
|
|
240
|
+
reject(error);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
resolve(char_list);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
_subscribe() {
|
|
249
|
+
return new Promise((resolve, reject) => {
|
|
250
|
+
const char = this._chars.notify;
|
|
251
|
+
if (!char) {
|
|
252
|
+
reject(new Error('No notify characteristic was found.'));
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
char.subscribe((error) => {
|
|
256
|
+
if (error) {
|
|
257
|
+
reject(error);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
char.on('data', () => {
|
|
261
|
+
this._onnotify_internal();
|
|
262
|
+
});
|
|
263
|
+
resolve();
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
_unsubscribe() {
|
|
268
|
+
return new Promise((resolve) => {
|
|
269
|
+
const char = this._chars.notify;
|
|
270
|
+
if (!char) {
|
|
271
|
+
resolve();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
char.removeAllListeners();
|
|
275
|
+
char.unsubscribe(() => {
|
|
276
|
+
resolve();
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/* ------------------------------------------------------------------
|
|
281
|
+
* disconnect()
|
|
282
|
+
* - Disconnect the device
|
|
283
|
+
*
|
|
284
|
+
* [Arguments]
|
|
285
|
+
* - none
|
|
286
|
+
*
|
|
287
|
+
* [Return value]
|
|
288
|
+
* - Promise object
|
|
289
|
+
* Nothing will be passed to the `resolve()`.
|
|
290
|
+
* ---------------------------------------------------------------- */
|
|
291
|
+
disconnect() {
|
|
292
|
+
return new Promise((resolve, reject) => {
|
|
293
|
+
this._was_connected_explicitly = false;
|
|
294
|
+
// Check the connection state
|
|
295
|
+
const state = this._peripheral.state;
|
|
296
|
+
if (state === 'disconnected') {
|
|
297
|
+
resolve();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
else if (state === 'connecting' || state === 'disconnecting') {
|
|
301
|
+
reject(new Error('Now ' + state + '. Wait for a few seconds then try again.'));
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
// Unsubscribe
|
|
305
|
+
this._unsubscribe().then(() => {
|
|
306
|
+
// Disconnect
|
|
307
|
+
this._peripheral.disconnect(() => {
|
|
308
|
+
resolve();
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
_disconnect() {
|
|
314
|
+
if (this._was_connected_explicitly) {
|
|
315
|
+
return new Promise((resolve) => {
|
|
316
|
+
resolve();
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
return this.disconnect();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/* ------------------------------------------------------------------
|
|
324
|
+
* getDeviceName()
|
|
325
|
+
* - Retrieve the device name
|
|
326
|
+
*
|
|
327
|
+
* [Arguments]
|
|
328
|
+
* - none
|
|
329
|
+
*
|
|
330
|
+
* [Return value]
|
|
331
|
+
* - Promise object
|
|
332
|
+
* The device name will be passed to the `resolve()`.
|
|
333
|
+
* ---------------------------------------------------------------- */
|
|
334
|
+
getDeviceName() {
|
|
335
|
+
return new Promise((resolve, reject) => {
|
|
336
|
+
let name = '';
|
|
337
|
+
this._connect()
|
|
338
|
+
.then(() => {
|
|
339
|
+
if (!this._chars.device) {
|
|
340
|
+
// Some models of Bot don't seem to support this characteristic UUID
|
|
341
|
+
throw new Error('The device does not support the characteristic UUID 0x' +
|
|
342
|
+
this._CHAR_UUID_DEVICE +
|
|
343
|
+
'.');
|
|
344
|
+
}
|
|
345
|
+
return this._read(this._chars.device);
|
|
346
|
+
})
|
|
347
|
+
.then((buf) => {
|
|
348
|
+
name = buf.toString('utf8');
|
|
349
|
+
return this._disconnect();
|
|
350
|
+
})
|
|
351
|
+
.then(() => {
|
|
352
|
+
resolve(name);
|
|
353
|
+
})
|
|
354
|
+
.catch((error) => {
|
|
355
|
+
reject(error);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
/* ------------------------------------------------------------------
|
|
360
|
+
* setDeviceName(name)
|
|
361
|
+
* - Set the device name
|
|
362
|
+
*
|
|
363
|
+
* [Arguments]
|
|
364
|
+
* - name | String | Required | Device name. The bytes length of the name
|
|
365
|
+
* | | | must be in the range of 1 to 20 bytes.
|
|
366
|
+
*
|
|
367
|
+
* [Return value]
|
|
368
|
+
* - Promise object
|
|
369
|
+
* Nothing will be passed to the `resolve()`.
|
|
370
|
+
* ---------------------------------------------------------------- */
|
|
371
|
+
setDeviceName(name) {
|
|
372
|
+
return new Promise((resolve, reject) => {
|
|
373
|
+
// Check the parameters
|
|
374
|
+
const valid = ParameterChecker.check({ name: name }, {
|
|
375
|
+
name: { required: true, type: 'string', minBytes: 1, maxBytes: 100 },
|
|
376
|
+
}, true);
|
|
377
|
+
if (!valid) {
|
|
378
|
+
reject(new Error(ParameterChecker.error.message));
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const buf = Buffer.from(name, 'utf8');
|
|
382
|
+
this._connect()
|
|
383
|
+
.then(() => {
|
|
384
|
+
if (!this._chars.device) {
|
|
385
|
+
// Some models of Bot don't seem to support this characteristic UUID
|
|
386
|
+
throw new Error('The device does not support the characteristic UUID 0x' +
|
|
387
|
+
this._CHAR_UUID_DEVICE +
|
|
388
|
+
'.');
|
|
389
|
+
}
|
|
390
|
+
return this._write(this._chars.device, buf);
|
|
391
|
+
})
|
|
392
|
+
.then(() => {
|
|
393
|
+
return this._disconnect();
|
|
394
|
+
})
|
|
395
|
+
.then(() => {
|
|
396
|
+
resolve();
|
|
397
|
+
})
|
|
398
|
+
.catch((error) => {
|
|
399
|
+
reject(error);
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
// Write the specified Buffer data to the write characteristic
|
|
404
|
+
// and receive the response from the notify characteristic
|
|
405
|
+
// with connection handling
|
|
406
|
+
_command(req_buf) {
|
|
407
|
+
return new Promise((resolve, reject) => {
|
|
408
|
+
if (!Buffer.isBuffer(req_buf)) {
|
|
409
|
+
reject(new Error('The specified data is not acceptable for writing.'));
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
let res_buf;
|
|
413
|
+
this._connect()
|
|
414
|
+
.then(() => {
|
|
415
|
+
if (!this._chars) {
|
|
416
|
+
return reject(new Error('No characteristics available.'));
|
|
417
|
+
}
|
|
418
|
+
return this._write(this._chars.write, req_buf);
|
|
419
|
+
})
|
|
420
|
+
.then(() => {
|
|
421
|
+
return this._waitCommandResponse();
|
|
422
|
+
})
|
|
423
|
+
.then((buf) => {
|
|
424
|
+
res_buf = buf;
|
|
425
|
+
return this._disconnect();
|
|
426
|
+
})
|
|
427
|
+
.then(() => {
|
|
428
|
+
resolve(res_buf);
|
|
429
|
+
})
|
|
430
|
+
.catch((error) => {
|
|
431
|
+
reject(error);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
_waitCommandResponse() {
|
|
436
|
+
return new Promise((resolve, reject) => {
|
|
437
|
+
const buf = null;
|
|
438
|
+
let timer = setTimeout(() => {
|
|
439
|
+
timer = undefined;
|
|
440
|
+
this._onnotify_internal = () => { };
|
|
441
|
+
reject(new Error('COMMAND_TIMEOUT'));
|
|
442
|
+
}, this._COMMAND_TIMEOUT_MSEC);
|
|
443
|
+
this._onnotify_internal = () => {
|
|
444
|
+
if (timer) {
|
|
445
|
+
clearTimeout(timer);
|
|
446
|
+
timer = undefined;
|
|
447
|
+
}
|
|
448
|
+
this._onnotify_internal = () => { };
|
|
449
|
+
resolve(buf);
|
|
450
|
+
};
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
// Read data from the specified characteristic
|
|
454
|
+
_read(char) {
|
|
455
|
+
return new Promise((resolve, reject) => {
|
|
456
|
+
// Set a timeout timer
|
|
457
|
+
let timer = setTimeout(() => {
|
|
458
|
+
reject('READ_TIMEOUT');
|
|
459
|
+
}, this._READ_TIMEOUT_MSEC);
|
|
460
|
+
// Read charcteristic data
|
|
461
|
+
char.read((error, buf) => {
|
|
462
|
+
if (timer) {
|
|
463
|
+
clearTimeout(timer);
|
|
464
|
+
timer = undefined;
|
|
465
|
+
}
|
|
466
|
+
if (error) {
|
|
467
|
+
reject(error);
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
resolve(buf);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
// Write the specified Buffer data to the specified characteristic
|
|
476
|
+
_write(char, buf) {
|
|
477
|
+
return new Promise((resolve, reject) => {
|
|
478
|
+
// Set a timeout timer
|
|
479
|
+
let timer = setTimeout(() => {
|
|
480
|
+
reject('WRITE_TIMEOUT');
|
|
481
|
+
}, this._WRITE_TIMEOUT_MSEC);
|
|
482
|
+
// write charcteristic data
|
|
483
|
+
char.write(buf, false, (error) => {
|
|
484
|
+
if (timer) {
|
|
485
|
+
clearTimeout(timer);
|
|
486
|
+
timer = undefined;
|
|
487
|
+
}
|
|
488
|
+
if (error) {
|
|
489
|
+
reject(error);
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
resolve();
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
//# sourceMappingURL=device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAS/C,MAAM,OAAO,eAAe;IAC1B,WAAW,CAAC;IACZ,MAAM,CAAC;IACP,MAAM,CAAC;IACP,kBAAkB,CAAC;IACnB,gBAAgB,CAAC;IACjB,iBAAiB,CAAC;IAClB,iBAAiB,CAAC;IAClB,kBAAkB,CAAC;IACnB,mBAAmB,CAAC;IACpB,qBAAqB,CAAC;IACtB,GAAG,CAAC;IACJ,QAAQ,CAAC;IACT,MAAM,CAAC;IACP,UAAU,CAAC;IACX,yBAAyB,CAAC;IAC1B,UAAU,CAAC;IACX,UAAU,CAAa;IACvB,aAAa,CAAa;IAC1B,sBAAsB,CAAa;IACnC,kBAAkB,CAAa;IAC/B;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AAO,EAAE,MAAM,EAAE,EAAE;YAC3C,sBAAsB;YACtB,IAAI,KAAK,GAA+B,UAAU,CAAC,GAAG,EAAE;gBACtD,MAAM,CAAC,eAAe,CAAC,CAAC;YAC1B,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;YAE7B,2BAA2B;YAC3B,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC/B,IAAI,KAAK,EAAE,CAAC;oBACV,YAAY,CAAC,KAAK,CAAC,CAAC;oBACpB,KAAK,GAAG,SAAS,CAAC;gBACpB,CAAC;gBACD,IAAI,KAAK,EAAE,CAAC;oBACV,MAAM,CAAC,KAAK,CAAC,CAAC;gBAChB,CAAC;qBAAM,CAAC;oBACN,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type Rule = {
|
|
2
|
+
required?: boolean;
|
|
3
|
+
min?: number;
|
|
4
|
+
max?: number;
|
|
5
|
+
minBytes?: number;
|
|
6
|
+
maxBytes?: number;
|
|
7
|
+
pattern?: RegExp;
|
|
8
|
+
enum?: any[];
|
|
9
|
+
};
|
|
10
|
+
export declare class ParameterChecker {
|
|
11
|
+
_error: any;
|
|
12
|
+
static error: any;
|
|
13
|
+
constructor();
|
|
14
|
+
get error(): any;
|
|
15
|
+
static isSpecified(value: any): boolean;
|
|
16
|
+
static check(obj: any, rules: any, required: any): boolean;
|
|
17
|
+
static isFloat(value: any, rule: Rule, name?: string): boolean;
|
|
18
|
+
static isInteger(value: any, rule: Rule, name?: string): boolean;
|
|
19
|
+
static isBoolean(value: any, rule: Rule, name?: string): boolean;
|
|
20
|
+
static isObject(value: any, rule: Rule, name?: string): boolean;
|
|
21
|
+
static isArray(value: any, rule: Rule, name?: string): boolean;
|
|
22
|
+
static isString(value: any, rule: Rule, name?: string): boolean;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=parameter-checker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter-checker.d.ts","sourceRoot":"","sources":["../src/parameter-checker.ts"],"names":[],"mappings":"AAEA,KAAK,IAAI,GAAG;IACV,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;CACd,CAAC;AAEF,qBAAa,gBAAgB;IAE3B,MAAM,MAAC;IACP,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC;;IAKlB,IAAI,KAAK,QAUR;IAED,MAAM,CAAC,WAAW,CAAC,KAAK,KAAA;IAqCxB,MAAM,CAAC,KAAK,CAAC,GAAG,KAAA,EAAE,KAAK,KAAA,EAAE,QAAQ,KAAA;IAsGjC,MAAM,CAAC,OAAO,CAAC,KAAK,KAAA,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,SAAU;IAkFhD,MAAM,CAAC,SAAS,CAAC,KAAK,KAAA,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,SAAU;IAqClD,MAAM,CAAC,SAAS,CAAC,KAAK,KAAA,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,SAAU;IAgClD,MAAM,CAAC,QAAQ,CAAC,KAAK,KAAA,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,SAAU;IAoCjD,MAAM,CAAC,OAAO,CAAC,KAAK,KAAA,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,SAAU;IAuEhD,MAAM,CAAC,QAAQ,CAAC,KAAK,KAAA,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,SAAU;CAuGlD"}
|