forked from aholstenson/miio
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding
miio.devices
to discover and connect to devices and sub-devices
- Loading branch information
1 parent
db2625e
commit d7789b5
Showing
6 changed files
with
245 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const createDevice = require('./createDevice'); | ||
|
||
module.exports = function(options) { | ||
let device = createDevice(options); | ||
return device.call('miIO.info') | ||
.then(data => { | ||
if(options.model) { | ||
// If the model was specified we reuse the device instance | ||
} else { | ||
// If the model was automatically discovered recreate the device | ||
device.destroy(); | ||
device = createDevice(Object.assign({}, options, { | ||
model: data.model, | ||
token: data.token | ||
})); | ||
} | ||
}) | ||
.then(() => { | ||
return device.init() | ||
.then(() => device); | ||
}) | ||
.catch(err => { | ||
device.destroy(); | ||
throw err; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const Device = require('./device'); | ||
const models = require('./models'); | ||
|
||
module.exports = function(options) { | ||
if(! options.address) throw new Error('Address to device is required'); | ||
|
||
const d = models[options.model]; | ||
let device; | ||
if(! d) { | ||
device = new Device(options); | ||
} else { | ||
device = new d(options); | ||
} | ||
|
||
return device; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters