node-switchbot 1.2.1-beta.9 → 1.4.1

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/lib/switchbot.js CHANGED
@@ -1,33 +1,34 @@
1
- 'use strict';
2
- const parameterChecker = require('./parameter-checker.js');
3
- const switchbotAdvertising = require('./switchbot-advertising.js');
1
+ "use strict";
2
+ const parameterChecker = require("./parameter-checker.js");
3
+ const switchbotAdvertising = require("./switchbot-advertising.js");
4
4
 
5
- const SwitchbotDevice = require('./switchbot-device.js');
6
- const SwitchbotDeviceWoHand = require('./switchbot-device-wohand.js');
7
- const SwitchbotDeviceWoCurtain = require('./switchbot-device-wocurtain.js');
8
- const SwitchbotDeviceWoPresence = require('./switchbot-device-wopresence.js');
9
- const SwitchbotDeviceWoContact = require('./switchbot-device-wocontact.js');
10
- const SwitchbotDeviceWoSensorTH = require('./switchbot-device-wosensorth.js');
11
- const SwitchbotDeviceWoHumi = require('./switchbot-device-wohumi.js');
5
+ const SwitchbotDevice = require("./switchbot-device.js");
6
+ const SwitchbotDeviceWoHand = require("./switchbot-device-wohand.js");
7
+ const SwitchbotDeviceWoCurtain = require("./switchbot-device-wocurtain.js");
8
+ const SwitchbotDeviceWoPresence = require("./switchbot-device-wopresence.js");
9
+ const SwitchbotDeviceWoContact = require("./switchbot-device-wocontact.js");
10
+ const SwitchbotDeviceWoSensorTH = require("./switchbot-device-wosensorth.js");
11
+ const SwitchbotDeviceWoHumi = require("./switchbot-device-wohumi.js");
12
+ const SwitchbotDeviceWoPlugMini = require("./switchbot-device-woplugmini.js");
12
13
 
13
14
  class Switchbot {
14
15
  /* ------------------------------------------------------------------
15
- * Constructor
16
- *
17
- * [Arguments]
18
- * - params | Object | Optional |
19
- * - noble | Noble | Optional | The Nobel object created by the noble module.
20
- * | | | This parameter is optional.
21
- * | | | If you don't specify this parameter, this
22
- * | | | module automatically creates it.
23
- * ---------------------------------------------------------------- */
16
+ * Constructor
17
+ *
18
+ * [Arguments]
19
+ * - params | Object | Optional |
20
+ * - noble | Noble | Optional | The Nobel object created by the noble module.
21
+ * | | | This parameter is optional.
22
+ * | | | If you don't specify this parameter, this
23
+ * | | | module automatically creates it.
24
+ * ---------------------------------------------------------------- */
24
25
  constructor(params) {
25
26
  // Check parameters
26
27
  let noble = null;
27
28
  if (params && params.noble) {
28
29
  noble = params.noble;
29
30
  } else {
30
- noble = require('@abandonware/noble');
31
+ noble = require("@abandonware/noble");
31
32
  }
32
33
 
33
34
  // Public properties
@@ -38,56 +39,64 @@ class Switchbot {
38
39
 
39
40
  // Private properties
40
41
  this._scanning = false;
41
- this._DEFAULT_DISCOVERY_DURATION = 5000
42
+ this._DEFAULT_DISCOVERY_DURATION = 5000;
42
43
  this._PRIMARY_SERVICE_UUID_LIST = [];
43
- };
44
+ }
44
45
 
45
46
  /* ------------------------------------------------------------------
46
- * discover([params])
47
- * - Discover switchbot devices
48
- *
49
- * [Arguments]
50
- * - params | Object | Optional |
51
- * - duration | Integer | Optional | Duration for discovery process (msec).
52
- * | | | The value must be in the range of 1 to 60000.
53
- * | | | The default value is 5000 (msec).
54
- * - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
55
- * | | | If "H" is specified, this method will discover only Bots.
56
- * | | | If "T" is specified, this method will discover only Meters.
57
- * | | | If "e" is specified, this method will discover only Humidifiers.
58
- * | | | If "s" is specified, this method will discover only Motion Sensors.
59
- * | | | If "d" is specified, this method will discover only Contact Sensors.
60
- * | | | If "c" is specified, this method will discover only Curtains.
61
- * | | | If "u" is specified, this method will discover only Color Bulbs.
62
- * | | | If "g" is specified, this method will discover only Plugs.
63
- * | | | If "o" is specified, this method will discover only Locks.
64
- * | | | If "i" is specified, this method will discover only Meter Pluses.
65
- * | | | If "r" is specified, this method will discover only Locks.
66
- * - id | String | Optional | If this value is set, this method will discover
67
- * | | | only a device whose ID is as same as this value.
68
- * | | | The ID is identical to the MAC address.
69
- * | | | This parameter is case-insensitive, and
70
- * | | | colons are ignored.
71
- * - quick | Boolean | Optional | If this value is true, this method finishes
72
- * | | | the discovery process when the first device
73
- * | | | is found, then calls the resolve() function
74
- * | | | without waiting the specified duration.
75
- * | | | The default value is false.
76
- *
77
- * [Return value]
78
- * - Promise object
79
- * An array will be passed to the `resolve()`, which includes
80
- * `SwitchbotDevice` objects representing the found devices.
81
- * ---------------------------------------------------------------- */
47
+ * discover([params])
48
+ * - Discover switchbot devices
49
+ *
50
+ * [Arguments]
51
+ * - params | Object | Optional |
52
+ * - duration | Integer | Optional | Duration for discovery process (msec).
53
+ * | | | The value must be in the range of 1 to 60000.
54
+ * | | | The default value is 5000 (msec).
55
+ * - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
56
+ * | | | If "H" is specified, this method will discover only Bots.
57
+ * | | | If "T" is specified, this method will discover only Meters.
58
+ * | | | If "e" is specified, this method will discover only Humidifiers.
59
+ * | | | If "s" is specified, this method will discover only Motion Sensors.
60
+ * | | | If "d" is specified, this method will discover only Contact Sensors.
61
+ * | | | If "c" is specified, this method will discover only Curtains.
62
+ * | | | If "u" is specified, this method will discover only Color Bulbs.
63
+ * | | | If "g" is specified, this method will discover only Plugs.
64
+ * | | | If "o" is specified, this method will discover only Locks.
65
+ * | | | If "i" is specified, this method will discover only Meter Pluses.
66
+ * | | | If "r" is specified, this method will discover only Locks.
67
+ * - id | String | Optional | If this value is set, this method will discover
68
+ * | | | only a device whose ID is as same as this value.
69
+ * | | | The ID is identical to the MAC address.
70
+ * | | | This parameter is case-insensitive, and
71
+ * | | | colons are ignored.
72
+ * - quick | Boolean | Optional | If this value is true, this method finishes
73
+ * | | | the discovery process when the first device
74
+ * | | | is found, then calls the resolve() function
75
+ * | | | without waiting the specified duration.
76
+ * | | | The default value is false.
77
+ *
78
+ * [Return value]
79
+ * - Promise object
80
+ * An array will be passed to the `resolve()`, which includes
81
+ * `SwitchbotDevice` objects representing the found devices.
82
+ * ---------------------------------------------------------------- */
82
83
  discover(params = {}) {
83
84
  let promise = new Promise((resolve, reject) => {
84
85
  // Check the parameters
85
- let valid = parameterChecker.check(params, {
86
- duration: { required: false, type: 'integer', min: 1, max: 60000 },
87
- model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c', 'u', 'g', 'o', 'i', 'r'] },
88
- id: { required: false, type: 'string', min: 12, max: 17 },
89
- quick: { required: false, type: 'boolean' }
90
- }, false);
86
+ let valid = parameterChecker.check(
87
+ params,
88
+ {
89
+ duration: { required: false, type: "integer", min: 1, max: 60000 },
90
+ model: {
91
+ required: false,
92
+ type: "string",
93
+ enum: ["H", "T", "e", "s", "d", "c", "u", "g", "j", "o", "i", "r"],
94
+ },
95
+ id: { required: false, type: "string", min: 12, max: 17 },
96
+ quick: { required: false, type: "boolean" },
97
+ },
98
+ false
99
+ );
91
100
 
92
101
  if (!valid) {
93
102
  reject(new Error(parameterChecker.error.message));
@@ -101,60 +110,66 @@ class Switchbot {
101
110
  // Determine the values of the parameters
102
111
  let p = {
103
112
  duration: params.duration || this._DEFAULT_DISCOVERY_DURATION,
104
- model: params.model || '',
105
- id: params.id || '',
106
- quick: params.quick ? true : false
113
+ model: params.model || "",
114
+ id: params.id || "",
115
+ quick: params.quick ? true : false,
107
116
  };
108
117
 
109
118
  // Initialize the noble object
110
- this._init().then(() => {
111
- let peripherals = {};
112
- let timer = null;
113
- let finishDiscovery = () => {
114
- if (timer) {
115
- clearTimeout(timer);
116
- }
117
- this.noble.removeAllListeners('discover');
118
- this.noble.stopScanning();
119
- let device_list = [];
120
- for (let addr in peripherals) {
121
- device_list.push(peripherals[addr]);
122
- }
123
- resolve(device_list);
124
- };
119
+ this._init()
120
+ .then(() => {
121
+ let peripherals = {};
122
+ let timer = null;
123
+ let finishDiscovery = () => {
124
+ if (timer) {
125
+ clearTimeout(timer);
126
+ }
127
+ this.noble.removeAllListeners("discover");
128
+ this.noble.stopScanning();
129
+ let device_list = [];
130
+ for (let addr in peripherals) {
131
+ device_list.push(peripherals[addr]);
132
+ }
133
+ resolve(device_list);
134
+ };
125
135
 
126
- // Set a handler for the 'discover' event
127
- this.noble.on('discover', (peripheral) => {
128
- let device = this._getDeviceObject(peripheral, p.id, p.model);
129
- if (!device) {
130
- return;
131
- }
132
- let id = device.id;
133
- peripherals[id] = device;
136
+ // Set a handler for the 'discover' event
137
+ this.noble.on("discover", (peripheral) => {
138
+ let device = this._getDeviceObject(peripheral, p.id, p.model);
139
+ if (!device) {
140
+ return;
141
+ }
142
+ let id = device.id;
143
+ peripherals[id] = device;
134
144
 
135
- if (this.ondiscover && typeof (this.ondiscover) === 'function') {
136
- this.ondiscover(device);
137
- }
145
+ if (this.ondiscover && typeof this.ondiscover === "function") {
146
+ this.ondiscover(device);
147
+ }
138
148
 
139
- if (p.quick) {
140
- finishDiscovery();
141
- return;
142
- }
143
- });
149
+ if (p.quick) {
150
+ finishDiscovery();
151
+ return;
152
+ }
153
+ });
144
154
 
145
- // Start scanning
146
- this.noble.startScanning(this._PRIMARY_SERVICE_UUID_LIST, false, (error) => {
147
- if (error) {
148
- reject(error);
149
- return;
150
- }
151
- timer = setTimeout(() => {
152
- finishDiscovery();
153
- }, p.duration);
155
+ // Start scanning
156
+ this.noble.startScanning(
157
+ this._PRIMARY_SERVICE_UUID_LIST,
158
+ false,
159
+ (error) => {
160
+ if (error) {
161
+ reject(error);
162
+ return;
163
+ }
164
+ timer = setTimeout(() => {
165
+ finishDiscovery();
166
+ }, p.duration);
167
+ }
168
+ );
169
+ })
170
+ .catch((error) => {
171
+ reject(error);
154
172
  });
155
- }).catch((error) => {
156
- reject(error);
157
- });
158
173
  });
159
174
  return promise;
160
175
  }
@@ -162,19 +177,23 @@ class Switchbot {
162
177
  _init() {
163
178
  let promise = new Promise((resolve, reject) => {
164
179
  switch (this.noble.state) {
165
- case 'poweredOn':
180
+ case "poweredOn":
166
181
  resolve();
167
182
  return;
168
- case 'unsupported', 'unauthorized', 'poweredOff':
169
- let err = new Error('Failed to initialize the Noble object: ' + this.noble.state);
183
+ case ("unsupported", "unauthorized", "poweredOff"):
184
+ let err = new Error(
185
+ "Failed to initialize the Noble object: " + this.noble.state
186
+ );
170
187
  reject(err);
171
188
  return;
172
189
  default: // 'resetting', 'unknown'
173
- this.noble.once('stateChange', (state) => {
174
- if (state === 'poweredOn') {
190
+ this.noble.once("stateChange", (state) => {
191
+ if (state === "poweredOn") {
175
192
  resolve();
176
193
  } else {
177
- let err = new Error('Failed to initialize the Noble object: ' + state);
194
+ let err = new Error(
195
+ "Failed to initialize the Noble object: " + state
196
+ );
178
197
  reject(err);
179
198
  }
180
199
  });
@@ -188,37 +207,38 @@ class Switchbot {
188
207
  if (this._filterAdvertising(ad, id, model)) {
189
208
  let device = null;
190
209
  switch (ad.serviceData.model) {
191
- case 'H':
210
+ case "H":
192
211
  device = new SwitchbotDeviceWoHand(peripheral, this.noble);
193
212
  break;
194
- case 'T':
213
+ case "T":
195
214
  device = new SwitchbotDeviceWoSensorTH(peripheral, this.noble);
196
215
  break;
197
- case 'e':
216
+ case "e":
198
217
  device = new SwitchbotDeviceWoHumi(peripheral, this.noble);
199
218
  break;
200
- case 's':
219
+ case "s":
201
220
  device = new SwitchbotDeviceWoPresence(peripheral, this.noble);
202
221
  break;
203
- case 'd':
222
+ case "d":
204
223
  device = new SwitchbotDeviceWoContact(peripheral, this.noble);
205
224
  break;
206
- case 'c':
225
+ case "c":
207
226
  device = new SwitchbotDeviceWoCurtain(peripheral, this.noble);
208
227
  break;
209
- case 'u':
228
+ case "u":
210
229
  device = new SwitchbotDeviceWoColorBulb(peripheral, this.noble);
211
230
  break;
212
- case 'g':
231
+ case "g":
232
+ case "j":
213
233
  device = new SwitchbotDeviceWoPlugMini(peripheral, this.noble);
214
234
  break;
215
- case 'o':
235
+ case "o":
216
236
  device = new SwitchbotDeviceWoSmartLock(peripheral, this.noble);
217
237
  break;
218
- case 'i':
238
+ case "i":
219
239
  device = new SwitchbotDeviceWoSensorTHPlus(peripheral, this.noble);
220
240
  break;
221
- case 'r':
241
+ case "r":
222
242
  device = new SwitchbotDeviceWoLEDStripLight(peripheral, this.noble);
223
243
  break;
224
244
  default: // 'resetting', 'unknown'
@@ -235,8 +255,8 @@ class Switchbot {
235
255
  return false;
236
256
  }
237
257
  if (id) {
238
- id = id.toLowerCase().replace(/\:/g, '');
239
- let ad_id = ad.address.toLowerCase().replace(/[^a-z0-9]/g, '');
258
+ id = id.toLowerCase().replace(/\:/g, "");
259
+ let ad_id = ad.address.toLowerCase().replace(/[^a-z0-9]/g, "");
240
260
  if (ad_id !== id) {
241
261
  return false;
242
262
  }
@@ -250,64 +270,72 @@ class Switchbot {
250
270
  }
251
271
 
252
272
  /* ------------------------------------------------------------------
253
- * startScan([params])
254
- * - Start to monitor advertising packets coming from switchbot devices
255
- *
256
- * [Arguments]
257
- * - params | Object | Optional |
258
- * - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
259
- * | | | If "H" is specified, the `onadvertisement`
260
- * | | | event handler will be called only when advertising
261
- * | | | packets comes from Bots.
262
- * | | | If "T" is specified, the `onadvertisement`
263
- * | | | event handler will be called only when advertising
264
- * | | | packets comes from Meters.
265
- * | | | If "e" is specified, the `onadvertisement`
266
- * | | | event handler will be called only when advertising
267
- * | | | packets comes from Humidifiers.
268
- * | | | If "s" is specified, the `onadvertisement`
269
- * | | | event handler will be called only when advertising
270
- * | | | packets comes from Motion Sensor.
271
- * | | | If "d" is specified, the `onadvertisement`
272
- * | | | event handler will be called only when advertising
273
- * | | | packets comes from Contact Sensor.
274
- * | | | If "c" is specified, the `onadvertisement`
275
- * | | | event handler will be called only when advertising
276
- * | | | packets comes from Curtains.
277
- * | | | If "u" is specified, the `onadvertisement`
278
- * | | | event handler will be called only when advertising
279
- * | | | packets comes from Color Bulb.
280
- * | | | If "g" is specified, the `onadvertisement`
281
- * | | | event handler will be called only when advertising
282
- * | | | packets comes from Plug Mini.
283
- * | | | If "o" is specified, the `onadvertisement`
284
- * | | | event handler will be called only when advertising
285
- * | | | packets comes from Smart Lock.
286
- * | | | If "i" is specified, the `onadvertisement`
287
- * | | | event handler will be called only when advertising
288
- * | | | packets comes from Meter Plus.
289
- * | | | If "r" is specified, the `onadvertisement`
290
- * | | | event handler will be called only when advertising
291
- * | | | packets comes from LED Strip Light.
292
- * - id | String | Optional | If this value is set, the `onadvertisement`
293
- * | | | event handler will be called only when advertising
294
- * | | | packets comes from devices whose ID is as same as
295
- * | | | this value.
296
- * | | | The ID is identical to the MAC address.
297
- * | | | This parameter is case-insensitive, and
298
- * | | | colons are ignored.
299
- *
300
- * [Return value]
301
- * - Promise object
302
- * Nothing will be passed to the `resolve()`.
303
- * ---------------------------------------------------------------- */
273
+ * startScan([params])
274
+ * - Start to monitor advertising packets coming from switchbot devices
275
+ *
276
+ * [Arguments]
277
+ * - params | Object | Optional |
278
+ * - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
279
+ * | | | If "H" is specified, the `onadvertisement`
280
+ * | | | event handler will be called only when advertising
281
+ * | | | packets comes from Bots.
282
+ * | | | If "T" is specified, the `onadvertisement`
283
+ * | | | event handler will be called only when advertising
284
+ * | | | packets comes from Meters.
285
+ * | | | If "e" is specified, the `onadvertisement`
286
+ * | | | event handler will be called only when advertising
287
+ * | | | packets comes from Humidifiers.
288
+ * | | | If "s" is specified, the `onadvertisement`
289
+ * | | | event handler will be called only when advertising
290
+ * | | | packets comes from Motion Sensor.
291
+ * | | | If "d" is specified, the `onadvertisement`
292
+ * | | | event handler will be called only when advertising
293
+ * | | | packets comes from Contact Sensor.
294
+ * | | | If "c" is specified, the `onadvertisement`
295
+ * | | | event handler will be called only when advertising
296
+ * | | | packets comes from Curtains.
297
+ * | | | If "u" is specified, the `onadvertisement`
298
+ * | | | event handler will be called only when advertising
299
+ * | | | packets comes from Color Bulb.
300
+ * | | | If "g" is specified, the `onadvertisement`
301
+ * | | | event handler will be called only when advertising
302
+ * | | | packets comes from Plug Mini.
303
+ * | | | If "o" is specified, the `onadvertisement`
304
+ * | | | event handler will be called only when advertising
305
+ * | | | packets comes from Smart Lock.
306
+ * | | | If "i" is specified, the `onadvertisement`
307
+ * | | | event handler will be called only when advertising
308
+ * | | | packets comes from Meter Plus.
309
+ * | | | If "r" is specified, the `onadvertisement`
310
+ * | | | event handler will be called only when advertising
311
+ * | | | packets comes from LED Strip Light.
312
+ * - id | String | Optional | If this value is set, the `onadvertisement`
313
+ * | | | event handler will be called only when advertising
314
+ * | | | packets comes from devices whose ID is as same as
315
+ * | | | this value.
316
+ * | | | The ID is identical to the MAC address.
317
+ * | | | This parameter is case-insensitive, and
318
+ * | | | colons are ignored.
319
+ *
320
+ * [Return value]
321
+ * - Promise object
322
+ * Nothing will be passed to the `resolve()`.
323
+ * ---------------------------------------------------------------- */
304
324
  startScan(params) {
305
325
  let promise = new Promise((resolve, reject) => {
306
326
  // Check the parameters
307
- let valid = parameterChecker.check(params, {
308
- model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c', 'u', 'g', 'o', 'i', 'r'] },
309
- id: { required: false, type: 'string', min: 12, max: 17 },
310
- }, false);
327
+ let valid = parameterChecker.check(
328
+ params,
329
+ {
330
+ model: {
331
+ required: false,
332
+ type: "string",
333
+ enum: ["H", "T", "e", "s", "d", "c", "u", "g", "j", "o", "i", "r"],
334
+ },
335
+ id: { required: false, type: "string", min: 12, max: 17 },
336
+ },
337
+ false
338
+ );
311
339
 
312
340
  if (!valid) {
313
341
  reject(new Error(parameterChecker.error.message));
@@ -319,71 +347,82 @@ class Switchbot {
319
347
  }
320
348
 
321
349
  // Initialize the noble object
322
- this._init().then(() => {
350
+ this._init()
351
+ .then(() => {
352
+ // Determine the values of the parameters
353
+ let p = {
354
+ model: params.model || "",
355
+ id: params.id || "",
356
+ };
323
357
 
324
- // Determine the values of the parameters
325
- let p = {
326
- model: params.model || '',
327
- id: params.id || ''
328
- };
329
-
330
- // Set a handler for the 'discover' event
331
- this.noble.on('discover', (peripheral) => {
332
- let ad = switchbotAdvertising.parse(peripheral, this.onlog);
333
- if (this._filterAdvertising(ad, p.id, p.model)) {
334
- if (this.onadvertisement && typeof (this.onadvertisement) === 'function') {
335
- this.onadvertisement(ad);
358
+ // Set a handler for the 'discover' event
359
+ this.noble.on("discover", (peripheral) => {
360
+ let ad = switchbotAdvertising.parse(peripheral, this.onlog);
361
+ if (this._filterAdvertising(ad, p.id, p.model)) {
362
+ if (
363
+ this.onadvertisement &&
364
+ typeof this.onadvertisement === "function"
365
+ ) {
366
+ this.onadvertisement(ad);
367
+ }
336
368
  }
337
- }
338
- });
369
+ });
339
370
 
340
- // Start scanning
341
- this.noble.startScanning(this._PRIMARY_SERVICE_UUID_LIST, true, (error) => {
342
- if (error) {
343
- reject(error);
344
- } else {
345
- resolve();
346
- }
371
+ // Start scanning
372
+ this.noble.startScanning(
373
+ this._PRIMARY_SERVICE_UUID_LIST,
374
+ true,
375
+ (error) => {
376
+ if (error) {
377
+ reject(error);
378
+ } else {
379
+ resolve();
380
+ }
381
+ }
382
+ );
383
+ })
384
+ .catch((error) => {
385
+ reject(error);
347
386
  });
348
- }).catch((error) => {
349
- reject(error);
350
- });
351
387
  });
352
388
  return promise;
353
389
  }
354
390
 
355
391
  /* ------------------------------------------------------------------
356
- * stopScan()
357
- * - Stop to monitor advertising packets coming from switchbot devices
358
- *
359
- * [Arguments]
360
- * - none
361
- *
362
- * [Return value]
363
- * - none
364
- * ---------------------------------------------------------------- */
392
+ * stopScan()
393
+ * - Stop to monitor advertising packets coming from switchbot devices
394
+ *
395
+ * [Arguments]
396
+ * - none
397
+ *
398
+ * [Return value]
399
+ * - none
400
+ * ---------------------------------------------------------------- */
365
401
  stopScan() {
366
- this.noble.removeAllListeners('discover');
402
+ this.noble.removeAllListeners("discover");
367
403
  this.noble.stopScanning();
368
404
  }
369
405
 
370
406
  /* ------------------------------------------------------------------
371
- * wait(msec) {
372
- * - Wait for the specified time (msec)
373
- *
374
- * [Arguments]
375
- * - msec | Integer | Required | Msec.
376
- *
377
- * [Return value]
378
- * - Promise object
379
- * Nothing will be passed to the `resolve()`.
380
- * ---------------------------------------------------------------- */
407
+ * wait(msec) {
408
+ * - Wait for the specified time (msec)
409
+ *
410
+ * [Arguments]
411
+ * - msec | Integer | Required | Msec.
412
+ *
413
+ * [Return value]
414
+ * - Promise object
415
+ * Nothing will be passed to the `resolve()`.
416
+ * ---------------------------------------------------------------- */
381
417
  wait(msec) {
382
418
  return new Promise((resolve, reject) => {
383
419
  // Check the parameters
384
- let valid = parameterChecker.check({ msec: msec }, {
385
- msec: { required: true, type: 'integer', min: 0 }
386
- });
420
+ let valid = parameterChecker.check(
421
+ { msec: msec },
422
+ {
423
+ msec: { required: true, type: "integer", min: 0 },
424
+ }
425
+ );
387
426
 
388
427
  if (!valid) {
389
428
  reject(new Error(parameterChecker.error.message));
@@ -393,7 +432,6 @@ class Switchbot {
393
432
  setTimeout(resolve, msec);
394
433
  });
395
434
  }
396
-
397
435
  }
398
436
 
399
437
  module.exports = Switchbot;