From 03ff690fbb92ea8b47cb479201f90174d3b5bee3 Mon Sep 17 00:00:00 2001 From: mrbungle64 Date: Sat, 8 Jan 2022 20:06:59 +0100 Subject: [PATCH 1/2] Correct some typos --- lib/switchbot-advertising.js | 6 +++--- lib/switchbot-device-wocurtain.js | 8 +++---- lib/switchbot-device-wohand.js | 10 ++++----- lib/switchbot-device-wohumi.js | 10 ++++----- lib/switchbot-device.js | 10 ++++----- lib/switchbot.js | 36 +++++++++++++++---------------- 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/switchbot-advertising.js b/lib/switchbot-advertising.js index 18230423..f8055c85 100644 --- a/lib/switchbot-advertising.js +++ b/lib/switchbot-advertising.js @@ -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', @@ -56,7 +56,7 @@ class SwitchbotAdvertising { * lightLevel: 1 * } * } - * + * * If the specified `Peripheral` does not represent any switchbot * device, this method will return `null`. * ---------------------------------------------------------------- */ diff --git a/lib/switchbot-device-wocurtain.js b/lib/switchbot-device-wocurtain.js index 2af017dd..24cc7348 100644 --- a/lib/switchbot-device-wocurtain.js +++ b/lib/switchbot-device-wocurtain.js @@ -10,7 +10,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -25,7 +25,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -40,7 +40,7 @@ class SwitchbotDeviceWoCurtain extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -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()`. * ---------------------------------------------------------------- */ diff --git a/lib/switchbot-device-wohand.js b/lib/switchbot-device-wohand.js index d2f86082..e0c6a09e 100644 --- a/lib/switchbot-device-wohand.js +++ b/lib/switchbot-device-wohand.js @@ -10,7 +10,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -25,7 +25,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -40,7 +40,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -55,7 +55,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -70,7 +70,7 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ diff --git a/lib/switchbot-device-wohumi.js b/lib/switchbot-device-wohumi.js index 5ac1e97d..fa4bf0ba 100644 --- a/lib/switchbot-device-wohumi.js +++ b/lib/switchbot-device-wohumi.js @@ -10,7 +10,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -25,7 +25,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -40,7 +40,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -55,7 +55,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -70,7 +70,7 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ diff --git a/lib/switchbot-device.js b/lib/switchbot-device.js index 88b6190c..66922e85 100644 --- a/lib/switchbot-device.js +++ b/lib/switchbot-device.js @@ -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 @@ -83,7 +83,7 @@ class SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -285,7 +285,7 @@ class SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -329,7 +329,7 @@ class SwitchbotDevice { * [Arguments] * - none * - * [Returen value] + * [Return value] * - Promise object * The device name will be passed to the `resolve()`. * ---------------------------------------------------------------- */ @@ -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()`. * ---------------------------------------------------------------- */ diff --git a/lib/switchbot.js b/lib/switchbot.js index a5540497..1215bfe2 100644 --- a/lib/switchbot.js +++ b/lib/switchbot.js @@ -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. @@ -30,7 +30,7 @@ class Switchbot { noble = require('@abandonware/noble'); } - // Plublic properties + // Public properties this.noble = noble; this.ondiscover = null; this.onadvertisement = null; @@ -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 @@ -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. @@ -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) { @@ -136,7 +136,7 @@ class Switchbot { } }); - // Start scaning + // Start scanning this.noble.startScanning(this._PRIMARY_SERVICE_UUID_LIST, false, (error) => { if (error) { reject(error); @@ -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()`. * ---------------------------------------------------------------- */ @@ -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)) { @@ -301,7 +301,7 @@ class Switchbot { } }); - // Start scaning + // Start scanning this.noble.startScanning(this._PRIMARY_SERVICE_UUID_LIST, true, (error) => { if (error) { reject(error); @@ -323,7 +323,7 @@ class Switchbot { * [Arguments] * - none * - * [Returen value] + * [Return value] * - none * ---------------------------------------------------------------- */ stopScan() { @@ -338,7 +338,7 @@ class Switchbot { * [Arguments] * - msec | Integer | Required | Msec. * - * [Returen value] + * [Return value] * - Promise object * Nothing will be passed to the `resolve()`. * ---------------------------------------------------------------- */ From 3b247a89063a841899edb75d61f8a7f2eda106bd Mon Sep 17 00:00:00 2001 From: mrbungle64 Date: Mon, 21 Feb 2022 21:13:48 +0100 Subject: [PATCH 2/2] Fix for SwitchBot "Contact" (Contact Sensor) and "Motion" (Motion Sensor) --- lib/switchbot-advertising.js | 6 ++---- lib/switchbot.js | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/switchbot-advertising.js b/lib/switchbot-advertising.js index f8055c85..95569d3c 100644 --- a/lib/switchbot-advertising.js +++ b/lib/switchbot-advertising.js @@ -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; } diff --git a/lib/switchbot.js b/lib/switchbot.js index 1215bfe2..2dc7fb18 100644 --- a/lib/switchbot.js +++ b/lib/switchbot.js @@ -38,7 +38,7 @@ class Switchbot { // Private properties this._scanning = false; this._DEFAULT_DISCOVERY_DURATION = 5000 - this._PRIMARY_SERVICE_UUID_LIST = ['cba20d00224d11e69fb80002a5d5c51b']; + this._PRIMARY_SERVICE_UUID_LIST = []; }; /* ------------------------------------------------------------------ @@ -360,4 +360,4 @@ class Switchbot { } -module.exports = Switchbot; \ No newline at end of file +module.exports = Switchbot;