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
12 changes: 5 additions & 7 deletions lib/switchbot-advertising.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class SwitchbotAdvertising {
* [Arguments]
* - peripheral | Object | Required | A `Peripheral` object of noble
*
* [Returen value]
* [Return value]
* - An object as follows:
*
* WoHand
* WoHand
* {
* id: 'c12e453e2008',
* address: 'c1:2e:45:3e:20:08',
Expand Down Expand Up @@ -56,7 +56,7 @@ class SwitchbotAdvertising {
* lightLevel: 1
* }
* }
*
*
* If the specified `Peripheral` does not represent any switchbot
* device, this method will return `null`.
* ---------------------------------------------------------------- */
Expand All @@ -65,10 +65,8 @@ class SwitchbotAdvertising {
if (!ad || !ad.serviceData) {
return null;
}
if (ad.serviceData[0].uuid !== '0d00') {
return null;
}
let buf = ad.serviceData[0].data;
let serviceData = ad.serviceData[0] || ad.serviceData;
let buf = serviceData.data;
if (!buf || !Buffer.isBuffer(buf) || buf.length < 3) {
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/switchbot-device-wocurtain.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -25,7 +25,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -40,7 +40,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -55,7 +55,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
* [Arguments]
* - percent | number | Required | the percentage of target position
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand Down
10 changes: 5 additions & 5 deletions lib/switchbot-device-wohand.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -25,7 +25,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -40,7 +40,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -55,7 +55,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -70,7 +70,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand Down
10 changes: 5 additions & 5 deletions lib/switchbot-device-wohumi.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -25,7 +25,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -40,7 +40,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -55,7 +55,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -70,7 +70,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand Down
10 changes: 5 additions & 5 deletions lib/switchbot-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const switchbotAdvertising = require('./switchbot-advertising.js');
class SwitchbotDevice {
/* ------------------------------------------------------------------
* Constructor
*
*
* [Arguments]
* - peripheral | Object | Required | The `peripheral` object of noble,
* | | | which represents this device
Expand Down Expand Up @@ -83,7 +83,7 @@ class SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand Down Expand Up @@ -285,7 +285,7 @@ class SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand Down Expand Up @@ -329,7 +329,7 @@ class SwitchbotDevice {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - Promise object
* The device name will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand Down Expand Up @@ -361,7 +361,7 @@ class SwitchbotDevice {
* - name | String | Required | Device name. The bytes length of the name
* | | | must be in the range of 1 to 20 bytes.
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand Down
40 changes: 20 additions & 20 deletions lib/switchbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const SwitchbotDeviceWoHumi = require('./switchbot-device-wohumi.js');
class Switchbot {
/* ------------------------------------------------------------------
* Constructor
*
*
* [Arguments]
* - params | Object | Optional |
* - noble | Noble | Optional | The Nobel object created by the noble module.
Expand All @@ -30,15 +30,15 @@ class Switchbot {
noble = require('@abandonware/noble');
}

// Plublic properties
// Public properties
this.noble = noble;
this.ondiscover = null;
this.onadvertisement = null;

// Private properties
this._scanning = false;
this._DEFAULT_DISCOVERY_DURATION = 5000
this._PRIMARY_SERVICE_UUID_LIST = ['cba20d00224d11e69fb80002a5d5c51b'];
this._PRIMARY_SERVICE_UUID_LIST = [];
};

/* ------------------------------------------------------------------
Expand All @@ -57,7 +57,7 @@ class Switchbot {
* | | | If "s" is specified, this method will discover only Motion Sensors.
* | | | If "d" is specified, this method will discover only Contact Sensors.
* | | | If "c" is specified, this method will discover only Curtains.
* - id | String | Optional | If this value is set, this method willl discover
* - id | String | Optional | If this value is set, this method will discover
* | | | only a device whose ID is as same as this value.
* | | | The ID is identical to the MAC address.
* | | | This parameter is case-insensitive, and
Expand All @@ -68,7 +68,7 @@ class Switchbot {
* | | | without waiting the specified duration.
* | | | The default value is false.
*
* [Returen value]
* [Return value]
* - Promise object
* An array will be passed to the `resolve()`, which includes
* `SwitchbotDevice` objects representing the found devices.
Expand Down Expand Up @@ -117,7 +117,7 @@ class Switchbot {
resolve(device_list);
};

// Set an handler for the 'discover' event
// Set a handler for the 'discover' event
this.noble.on('discover', (peripheral) => {
let device = this._getDeviceObject(peripheral, p.id, p.model);
if (!device) {
Expand All @@ -136,7 +136,7 @@ class Switchbot {
}
});

// Start scaning
// Start scanning
this.noble.startScanning(this._PRIMARY_SERVICE_UUID_LIST, false, (error) => {
if (error) {
reject(error);
Expand Down Expand Up @@ -236,32 +236,32 @@ class Switchbot {
* - params | Object | Optional |
* - model | String | Optional | "H", "T", "e", "s", "d", or "c".
* | | | If "H" is specified, the `onadvertisement`
* | | | event hander will be called only when advertising
* | | | event handler will be called only when advertising
* | | | packets comes from Bots.
* | | | If "T" is specified, the `onadvertisement`
* | | | event hander will be called only when advertising
* | | | event handler will be called only when advertising
* | | | packets comes from Meters.
* | | | If "e" is specified, the `onadvertisement`
* | | | event hander will be called only when advertising
* | | | event handler will be called only when advertising
* | | | packets comes from Humidifiers.
* | | | If "s" is specified, the `onadvertisement`
* | | | event hander will be called only when advertising
* | | | event handler will be called only when advertising
* | | | packets comes from Motion Sensor.
* | | | If "d" is specified, the `onadvertisement`
* | | | event hander will be called only when advertising
* | | | event handler will be called only when advertising
* | | | packets comes from Contact Sensor.
* | | | If "c" is specified, the `onadvertisement`
* | | | event hander will be called only when advertising
* | | | event handler will be called only when advertising
* | | | packets comes from Curtains.
* - id | String | Optional | If this value is set, the `onadvertisement`
* | | | event hander will be called only when advertising
* | | | event handler will be called only when advertising
* | | | packets comes from devices whose ID is as same as
* | | | this value.
* | | | The ID is identical to the MAC address.
* | | | This parameter is case-insensitive, and
* | | | colons are ignored.
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand Down Expand Up @@ -291,7 +291,7 @@ class Switchbot {
id: params.id || ''
};

// Set an handler for the 'discover' event
// Set a handler for the 'discover' event
this.noble.on('discover', (peripheral) => {
let ad = switchbotAdvertising.parse(peripheral);
if (this._filterAdvertising(ad, p.id, p.model)) {
Expand All @@ -301,7 +301,7 @@ class Switchbot {
}
});

// Start scaning
// Start scanning
this.noble.startScanning(this._PRIMARY_SERVICE_UUID_LIST, true, (error) => {
if (error) {
reject(error);
Expand All @@ -323,7 +323,7 @@ class Switchbot {
* [Arguments]
* - none
*
* [Returen value]
* [Return value]
* - none
* ---------------------------------------------------------------- */
stopScan() {
Expand All @@ -338,7 +338,7 @@ class Switchbot {
* [Arguments]
* - msec | Integer | Required | Msec.
*
* [Returen value]
* [Return value]
* - Promise object
* Nothing will be passed to the `resolve()`.
* ---------------------------------------------------------------- */
Expand All @@ -360,4 +360,4 @@ class Switchbot {

}

module.exports = Switchbot;
module.exports = Switchbot;