Skip to content

Commit

Permalink
infoFromHostname now returns type of device
Browse files Browse the repository at this point in the history
  • Loading branch information
aholstenson committed Apr 7, 2017
1 parent 05c7bf6 commit 08c5f2d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion devices/air-purifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion devices/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
4 changes: 3 additions & 1 deletion devices/vacuum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
};
};
Expand Down

0 comments on commit 08c5f2d

Please sign in to comment.