Skip to content

Commit

Permalink
Model names now use dots to match info from devices
Browse files Browse the repository at this point in the history
  • Loading branch information
aholstenson committed Apr 7, 2017
1 parent 08c5f2d commit 3aa6a9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Create a handle to the device:
// Create a device - with a model to get a more specific device instance
const device = miio.createDevice({
token: 'token-as-hex', // Token of device
model: 'zhimi-airpurifier-m1',
model: 'zhimi.airpurifier.m1',
address: '192.168.100.8'
});

Expand Down
16 changes: 9 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const Switch = require('./devices/switch');
const Vacuum = require('./devices/vacuum');

const devices = {
'zhimi-airpurifier-m1': AirPurifier,
'zhimi.airpurifier.m1': AirPurifier,

'chuangmi-plug-m1': Switch,
'chuangmi-plug-v1': Switch,
'chuangmi-plug-v2': Switch,
'chuangmi.plug.m1': Switch,
'chuangmi.plug.v1': Switch,
'chuangmi.plug.v2': Switch,

'rockrobo-vacuum-v1': Vacuum
'rockrobo.vacuum.v1': Vacuum
};

module.exports.Device = Device;
Expand Down Expand Up @@ -47,9 +47,11 @@ module.exports.infoFromHostname = function(hostname) {
const m = /(.+)_miio(\d+)/g.exec(hostname);
if(! m) return null;

const device = devices[m[1]];
const model = m[1].replace(/-/g, '.');

const device = devices[model];
return {
model: m[1],
model: model,
type: (device && device.TYPE) || 'generic',
id: m[2]
};
Expand Down

0 comments on commit 3aa6a9e

Please sign in to comment.