Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ Monitoring the advertising packets, you can find your devices and know the lates

```JavaScript
// Load the node-switchbot and get a `Switchbot` constructor object
let Switchbot = require('node-switchbot');
const Switchbot = require('node-switchbot');
// Create an `Switchbot` object
let switchbot = new Switchbot();
const switchbot = new Switchbot();

(async () => {
// Start to monitor advertisement packets
Expand All @@ -137,9 +137,9 @@ The [`startScan()`](#startscan-method) and [`wait()`](#Switchbot-wait-method) me

```javascript
// Load the node-switchbot and get a `Switchbot` constructor object
let Switchbot = require("node-switchbot");
const Switchbot = require("node-switchbot");
// Create an `Switchbot` object
let switchbot = new Switchbot();
const switchbot = new Switchbot();

// Start to monitor advertisement packets
switchbot
Expand Down Expand Up @@ -213,18 +213,18 @@ This sample discovers a Bot (WoHand), then put the Bot's arm down, finally put i

```javascript
// Load the node-switchbot and get a `Switchbot` constructor object
let Switchbot = require("node-switchbot");
const Switchbot = require("node-switchbot");
// Create an `Switchbot` object
let switchbot = new Switchbot();
const switchbot = new Switchbot();

(async () => {
// Find a Bot (WoHand)
let bot_list = await switchbot.discover({ model: "H", quick: true });
const bot_list = await switchbot.discover({ model: "H", quick: true });
if (bot_list.length === 0) {
throw new Error("No device was found.");
}
// The `SwitchbotDeviceWoHand` object representing the found Bot.
let device = bot_list[0];
const device = bot_list[0];
// Put the Bot's arm down (stretch the arm)
await device.down();
// Wait for 5 seconds
Expand All @@ -246,13 +246,13 @@ In this code, you can get a [`SwitchbotDeviceWoHand`](#SwitchbotDeviceWoHand-obj
In order to use the node-switchbot, you have to load the node-switchbot module as follows:

```JavaScript
let Switchbot = require('node-switchbot');
const Switchbot = require('node-switchbot');
```

You can get an `Switchbot` constructor from the code above. Then you have to create an `Switchbot` object from the `Switchbot` constructor as follows:

```javascript
let switchbot = new Switchbot();
const switchbot = new Switchbot();
```

The `Switchbot` constructor takes an argument optionally. It must be a hash object containing the properties as follows:
Expand All @@ -263,15 +263,15 @@ The `Switchbot` constructor takes an argument optionally. It must be a hash obje

The node-switchbot module uses the [`@abandonware/noble`](https://github.com/abandonware/noble) module in order to interact with BLE devices. If you want to interact other BLE devices using the `@abandonware/noble` module, you can create an `Noble` object by yourself, then pass it to this module. If you don't specify a `Noble` object to the `noble` property, this module automatically create a `Noble` object internally.

The sample code below shows how to pass a `Nobel` object to the `Switchbot` constructor.
The sample code below shows how to pass a `Noble` object to the `Switchbot` constructor.

```JavaScript
// Create a Noble object
let noble = require('@abandonware/noble');
const noble = require('@abandonware/noble');

// Create a Switchbot object
let Switchbot = require('node-switchbot');
let switchbot = new Switchbot({'noble': noble});
const Switchbot = require('node-switchbot');
const switchbot = new Switchbot({'noble': noble});
```

In the code snippet above, the variable `switchbot` is an `Switchbot` object. The `Switchbot` object has a lot of methods as described in sections below.
Expand Down Expand Up @@ -565,7 +565,7 @@ The code below calls the [`press()`](#SwitchbotDeviceWoHand-press-method) method
switchbot
.discover({ model: "H", quick: true })
.then((device_list) => {
let device = device_list[0];
const device = device_list[0];
if (!device) {
console.log("No device was found.");
process.exit();
Expand Down
14 changes: 7 additions & 7 deletions lib/parameter-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ParameterChecker {
* an `Error` object will be set to `this._error`.
*
* [Usage]
* let valid = parameterChecker.check(params, {
* const valid = parameterChecker.check(params, {
* level: {
* required: false,
* type: 'integer',
Expand All @@ -50,7 +50,7 @@ class ParameterChecker {
* }
* });
* if(!valid) {
* let e = parameterChecker.error.message;
* const e = parameterChecker.error.message;
* throw new Error(message);
* }
* ---------------------------------------------------------------- */
Expand Down Expand Up @@ -79,11 +79,11 @@ class ParameterChecker {
}

let result = true;
let name_list = Object.keys(rules);
const name_list = Object.keys(rules);

for (let i = 0; i < name_list.length; i++) {
let name = name_list[i];
let v = obj[name];
const name = name_list[i];
const v = obj[name];
let rule = rules[name];

if (!rule) {
Expand Down Expand Up @@ -458,7 +458,7 @@ class ParameterChecker {
}
}
if (typeof rule.minBytes === "number") {
let blen = Buffer.from(value, "utf8").length;
const blen = Buffer.from(value, "utf8").length;
if (blen < rule.minBytes) {
this._error = {
code: "LENGTH_UNDERFLOW",
Expand All @@ -475,7 +475,7 @@ class ParameterChecker {
}
}
if (typeof rule.maxBytes === "number") {
let blen = Buffer.from(value, "utf8").length;
const blen = Buffer.from(value, "utf8").length;
if (blen > rule.maxBytes) {
this._error = {
code: "LENGTH_OVERFLOW",
Expand Down
Loading