From 3aa6a9ebbac354f474399074ebabff0baacb2b32 Mon Sep 17 00:00:00 2001 From: Andreas Holstenson Date: Fri, 7 Apr 2017 13:16:39 +0200 Subject: [PATCH] Model names now use dots to match info from devices --- README.md | 2 +- index.js | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b24a904..40fbba1 100644 --- a/README.md +++ b/README.md @@ -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' }); diff --git a/index.js b/index.js index 9b03fc4..9ac744f 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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] };