diff --git a/devices/air-purifier.js b/devices/air-purifier.js index 13db270..6a823a9 100644 --- a/devices/air-purifier.js +++ b/devices/air-purifier.js @@ -3,10 +3,12 @@ const Device = require('../device'); class AirPurifier extends Device { + static get TYPE() { return 'air-purifier' }; + constructor(options) { super(options); - this.type = 'air-purifier'; + this.type = AirPurifier.TYPE; this.defineProperty('power', v => v === 'on'); this.defineProperty('mode'); diff --git a/devices/switch.js b/devices/switch.js index fc76207..90eb2db 100644 --- a/devices/switch.js +++ b/devices/switch.js @@ -3,10 +3,12 @@ const Device = require('../device'); class Switch extends Device { + static get TYPE() { return 'switch' }; + constructor(options) { super(options); - this.type = 'switch'; + this.type = Switch.TYPE; this.defineProperty('power', v => v === 'on'); diff --git a/devices/vacuum.js b/devices/vacuum.js index f7881dd..768fb80 100644 --- a/devices/vacuum.js +++ b/devices/vacuum.js @@ -13,10 +13,12 @@ function checkResult(r) { * doesn't use properties via get_prop but instead has a get_status. */ class Vacuum extends Device { + static get TYPE() { return 'vacuum' }; + constructor(options) { super(options); - this.type = 'vacuum'; + this.type = Vacuum.TYPE; this.defineProperty('state', s => { switch(s) { diff --git a/index.js b/index.js index ccd71cf..9b03fc4 100644 --- a/index.js +++ b/index.js @@ -47,8 +47,10 @@ module.exports.infoFromHostname = function(hostname) { const m = /(.+)_miio(\d+)/g.exec(hostname); if(! m) return null; + const device = devices[m[1]]; return { model: m[1], + type: (device && device.TYPE) || 'generic', id: m[2] }; };