|
1 | 1 | /* ------------------------------------------------------------------ |
2 | 2 | * node-linking - switchbot-device.js |
3 | 3 | * |
4 | | -* Copyright (c) 2019, Futomi Hatano, All rights reserved. |
| 4 | +* Copyright (c) 2019-2020, Futomi Hatano, All rights reserved. |
5 | 5 | * Released under the MIT license |
6 | | -* Date: 2019-11-20 |
| 6 | +* Date: 2020-02-10 |
7 | 7 | * ---------------------------------------------------------------- */ |
8 | 8 | 'use strict'; |
9 | 9 | const parameterChecker = require('./parameter-checker.js'); |
@@ -188,11 +188,12 @@ class SwitchbotDevice { |
188 | 188 | } else if (c.uuid === this._CHAR_UUID_NOTIFY) { |
189 | 189 | char_notify = c; |
190 | 190 | } else if (c.uuid === this._CHAR_UUID_DEVICE) { |
| 191 | + // Some models of Bot don't seem to support this characteristic UUID |
191 | 192 | char_device = c; |
192 | 193 | } |
193 | 194 | }); |
194 | | - if (!(char_write && char_notify && char_device)) { |
195 | | - reject(new Error('No characteristic was found')); |
| 195 | + if (!(char_write && char_notify)) { |
| 196 | + reject(new Error('No characteristic was found.')); |
196 | 197 | return; |
197 | 198 | } |
198 | 199 |
|
@@ -298,6 +299,10 @@ class SwitchbotDevice { |
298 | 299 | return new Promise((resolve, reject) => { |
299 | 300 | let name = ''; |
300 | 301 | this._connect().then(() => { |
| 302 | + if (!this._chars.device) { |
| 303 | + // Some models of Bot don't seem to support this characteristic UUID |
| 304 | + throw new Error('The device does not support the characteristic UUID 0x' + this._CHAR_UUID_DEVICE + '.'); |
| 305 | + } |
301 | 306 | return this._read(this._chars.device); |
302 | 307 | }).then((buf) => { |
303 | 308 | name = buf.toString('utf8'); |
@@ -336,6 +341,10 @@ class SwitchbotDevice { |
336 | 341 |
|
337 | 342 | let buf = Buffer.from(name, 'utf8'); |
338 | 343 | this._connect().then(() => { |
| 344 | + if (!this._chars.device) { |
| 345 | + // Some models of Bot don't seem to support this characteristic UUID |
| 346 | + throw new Error('The device does not support the characteristic UUID 0x' + this._CHAR_UUID_DEVICE + '.'); |
| 347 | + } |
339 | 348 | return this._write(this._chars.device, buf); |
340 | 349 | }).then(() => { |
341 | 350 | return this._disconnect(); |
|
0 commit comments