From 0854d71f398a86f5f0f971a9ca5efc254817ca11 Mon Sep 17 00:00:00 2001 From: Andreas Holstenson Date: Sun, 16 Apr 2017 20:38:30 +0200 Subject: [PATCH] _setup is now named init --- README.md | 8 ++++++++ lib/device.js | 2 +- lib/devices/gateway.js | 4 ++-- lib/index.js | 5 +---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 10009b9..b13a9ff 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,14 @@ const device = miio.createDevice({ }); ``` +You will need to call `device.init()` manually to initialize the device: + +```javascript +device.init() + .then(() => /* device is ready for commands */) + .catch(console.error); +``` + ## Advanced: Device management Get information and update the wireless settings of devices via the management diff --git a/lib/device.js b/lib/device.js index d3ac80c..93f9cbe 100644 --- a/lib/device.js +++ b/lib/device.js @@ -53,7 +53,7 @@ class Device extends EventEmitter { this.debug = require('debug')('miio.device.' + (options.id || '[' + options.address + ']')); } - _setup() { + init() { // Default setup involves activating monitoring return this.monitor(); } diff --git a/lib/devices/gateway.js b/lib/devices/gateway.js index 3fb1191..7381db8 100644 --- a/lib/devices/gateway.js +++ b/lib/devices/gateway.js @@ -104,8 +104,8 @@ class Gateway extends Device { // TODO: Device removal } - _setup() { - return super._setup() + init() { + return super.init() .then(() => this.findDeveloperKey()); } diff --git a/lib/index.js b/lib/index.js index 2acce5e..da4bbd1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -49,7 +49,7 @@ module.exports.device = function(options) { }); }) .then(device => { - return device._setup() + return device.init() .then(() => device); }); }; @@ -75,9 +75,6 @@ const createDevice = module.exports.createDevice = function(options) { device = new d(options); } - // Run setup, but do not block until it is done - device._setup(); - return device; };