Skip to content

Commit

Permalink
Updating linting
Browse files Browse the repository at this point in the history
  • Loading branch information
aholstenson committed Jan 4, 2018
1 parent 30e20d8 commit 3dfd6a7
Show file tree
Hide file tree
Showing 24 changed files with 1,275 additions and 1,160 deletions.
11 changes: 9 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"plugins": [ "node" ],
"extends": [ "eslint:recommended", "plugin:node/recommended" ],
"env": {},
"ecmaFeatures": {},
"globals": {},
"rules": {
"strict": [ "error", "global" ],
"node/no-unsupported-features": [
"error",
{
Expand All @@ -15,6 +15,13 @@
"quotes": [
2,
"single"
]
],
"no-unused-vars": [
"error",
{ "vars": "all", "args": "none", "ignoreRestSiblings": false }
],
"eqeqeq": [ "error" ],
"no-throw-literal": [ "error" ],
"semi": [ "error", "always" ]
}
}
16 changes: 9 additions & 7 deletions lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const DeviceManagement = require('./management');
const IDENTITY_MAPPER = v => v;

const ERRORS = {
'-5001': (method, args, err) => err.message == 'invalid_arg' ? 'Invalid argument' : err.message,
'-5005': (method, args, err) => err.message == 'params error' ? 'Invalid argument' : err.message,
'-5001': (method, args, err) => err.message === 'invalid_arg' ? 'Invalid argument' : err.message,
'-5005': (method, args, err) => err.message === 'params error' ? 'Invalid argument' : err.message,
'-10000': (method) => 'Method `' + method + '` is not supported'
};

Expand Down Expand Up @@ -105,7 +105,7 @@ module.exports = Thing.type(BaseAppliance => class MiioAppliance extends BaseApp
}

// Handle null-terminated strings
if(data[data.length - 1] == 0) {
if(data[data.length - 1] === 0) {
data = data.slice(0, data.length - 1);
}

Expand Down Expand Up @@ -188,7 +188,7 @@ module.exports = Thing.type(BaseAppliance => class MiioAppliance extends BaseApp
args = [];
}

const id = this._id = this._id == 10000 ? 1 : this._id + 1;
const id = this._id = this._id === 10000 ? 1 : this._id + 1;
const request = {
id: id,
method: method,
Expand All @@ -214,9 +214,11 @@ module.exports = Thing.type(BaseAppliance => class MiioAppliance extends BaseApp
// - delay a bit to make sure the device has time to respond
setTimeout(() => {
const properties = Array.isArray(options.refresh) ? options.refresh : this._propertiesToMonitor;

this._loadProperties(properties)
.then(() => resolve(res))
.catch(() => resolve(res))
.catch(() => resolve(res));

}, (options && options.refreshDelay) || 50);
} else {
resolve(res);
Expand Down Expand Up @@ -303,7 +305,7 @@ module.exports = Thing.type(BaseAppliance => class MiioAppliance extends BaseApp
} else if(typeof def === 'undefined') {
def = {
mapper: IDENTITY_MAPPER
}
};
}

if(! def.mapper) {
Expand Down Expand Up @@ -455,7 +457,7 @@ module.exports = Thing.type(BaseAppliance => class MiioAppliance extends BaseApp
* Check that the current result is equal to the string `ok`.
*/
static checkOk(result) {
if(result != 'ok') throw new Error('Could not perform operation');
if(! result || result.toLowerCase() !== 'ok') throw new Error('Could not perform operation');

return null;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/devices/air-purifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = class extends AirPurifier

// LED state
this.defineProperty('led', {
mapper: v => v == 'on'
mapper: v => v === 'on'
});
this.defineProperty('led_b', {
name: 'ledBrightness',
Expand All @@ -86,7 +86,7 @@ module.exports = class extends AirPurifier

// Buzzer and beeping
this.defineProperty('buzzer', {
mapper: v => v == 'on'
mapper: v => v === 'on'
});
}

Expand All @@ -108,7 +108,7 @@ module.exports = class extends AirPurifier
})
.then(MiioApi.checkOk)
.catch(err => {
throw err.code == -5001 ? new Error('Mode `' + mode + '` not supported') : err
throw err.code === -5001 ? new Error('Mode `' + mode + '` not supported') : err;
});
}

Expand Down Expand Up @@ -186,4 +186,4 @@ module.exports = class extends AirPurifier
return this.call('set_buzzer', [ active ? 'on' : 'off' ], { refresh: true })
.then(() => null);
}
}
};
4 changes: 2 additions & 2 deletions lib/devices/chuangmi.plug.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MiioPower = require('./capabilities/power');

module.exports = class extends Thing.with(PowerPlug, PowerOutlet, MiioApi, MiioPower, EasyNameable) {
static get type() {
return 'miio:power-plug'
return 'miio:power-plug';
}

constructor(options) {
Expand Down Expand Up @@ -39,7 +39,7 @@ module.exports = class extends Thing.with(PowerPlug, PowerOutlet, MiioApi, MiioP
break;
}
}
}
};

class USBOutlet extends PowerOutlet.with(SwitchablePower) {

Expand Down
6 changes: 3 additions & 3 deletions lib/devices/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const types = require('./gateway/subdevices');
function generateKey() {
let result = '';
for(let i=0; i<16; i++) {
let idx = Math.floor(Math.random() * CHARS.length)
let idx = Math.floor(Math.random() * CHARS.length);
result += CHARS[idx];
}
return result;
Expand All @@ -40,10 +40,10 @@ function generateKey() {
*/
const Gateway = Thing.type(Parent => class Gateway extends Parent.with(MiioApi, Children, EasyNameable) {
static get type() {
return 'miio:gateway'
return 'miio:gateway';
}

static get SubDevice() { return SubDevice }
static get SubDevice() { return SubDevice; }

static registerSubDevice(id, deviceClass) {
types[id] = deviceClass;
Expand Down
4 changes: 2 additions & 2 deletions lib/devices/gateway/ctrl_ln1.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ module.exports = class CtrlLN1 extends WallSwitch.with(SubDevice, Children) {

this.defineProperty('channel_0', {
name: 'powerChannel0',
mapper: v => v == 'on'
mapper: v => v === 'on'
});

this.addChild(new LightChannel(this, 0));
}

changePowerChannel(channel, power) {
return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ])
return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ]);
}

propertyUpdated(key, value) {
Expand Down
6 changes: 3 additions & 3 deletions lib/devices/gateway/ctrl_ln2.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ module.exports = class CtrlLN2 extends WallSwitch.with(SubDevice, Children) {

this.defineProperty('channel_0', {
name: 'powerChannel0',
mapper: v => v == 'on'
mapper: v => v === 'on'
});
this.defineProperty('channel_1', {
name: 'powerChannel1',
mapper: v => v == 'on'
mapper: v => v === 'on'
});

this.addChild(new LightChannel(this, 0));
this.addChild(new LightChannel(this, 1));
}

changePowerChannel(channel, power) {
return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ])
return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ]);
}

propertyUpdated(key, value) {
Expand Down
4 changes: 2 additions & 2 deletions lib/devices/gateway/ctrl_neutral1.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ module.exports = class CtrlNeutral1 extends WallSwitch.with(SubDevice, Children)

this.defineProperty('channel_0', {
name: 'powerChannel0',
mapper: v => v == 'on'
mapper: v => v === 'on'
});

this.addChild(new LightChannel(this, 0));
}

changePowerChannel(channel, power) {
return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ])
return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ]);
}

propertyUpdated(key, value) {
Expand Down
6 changes: 3 additions & 3 deletions lib/devices/gateway/ctrl_neutral2.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ module.exports = class CtrlNeutral2 extends WallSwitch.with(SubDevice, Children)

this.defineProperty('channel_0', {
name: 'powerChannel0',
mapper: v => v == 'on'
mapper: v => v === 'on'
});
this.defineProperty('channel_1', {
name: 'powerChannel1',
mapper: v => v == 'on'
mapper: v => v === 'on'
});

this.addChild(new LightChannel(this, 0));
this.addChild(new LightChannel(this, 1));
}

changePowerChannel(channel, power) {
return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ])
return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ]);
}

propertyUpdated(key, value) {
Expand Down
4 changes: 2 additions & 2 deletions lib/devices/gateway/developer-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = class DeveloperApi extends EventEmitter {
this.address = address;

// Bind a custom function instead of using directly to skip resolving debug before id is set
this.debug = function() { parent.debug.apply(parent, arguments) };
this.debug = function() { parent.debug.apply(parent, arguments); };

this.socket = dgram.createSocket({
type: 'udp4',
Expand Down Expand Up @@ -73,4 +73,4 @@ module.exports = class DeveloperApi extends EventEmitter {
}
}
}
}
};
4 changes: 2 additions & 2 deletions lib/devices/gateway/plug.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = class Plug extends SubDevice

this.defineProperty('status', {
name: 'power',
mapper: v => v == 'on'
mapper: v => v === 'on'
});

this.defineProperty('load_voltage', {
Expand All @@ -40,7 +40,7 @@ module.exports = class Plug extends SubDevice
}

changePower(power) {
return this.call('toggle_plug', [ 'neutral_0', power ? 'on' : 'off' ])
return this.call('toggle_plug', [ 'neutral_0', power ? 'on' : 'off' ]);
}

};
2 changes: 1 addition & 1 deletion lib/devices/gateway/subdevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports = Thing.type(Parent => class SubDevice extends Parent {
} else if(typeof def === 'undefined') {
def = {
mapper: IDENTITY_MAPPER
}
};
}

if(! def.mapper) {
Expand Down
2 changes: 1 addition & 1 deletion lib/devices/gateway/subdevices.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ module.exports = {
21: require('./ctrl_ln2'),

//51: require('./switch2')
}
};
4 changes: 2 additions & 2 deletions lib/devices/humidifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = class extends Humidifier

// Buzzer and beeping
this.defineProperty('buzzer', {
mapper: v => v == 'on'
mapper: v => v === 'on'
});

this.defineProperty('led_b', {
Expand Down Expand Up @@ -80,7 +80,7 @@ module.exports = class extends Humidifier
})
.then(MiioApi.checkOk)
.catch(err => {
throw err.code == -5001 ? new Error('Mode `' + mode + '` not supported') : err
throw err.code === -5001 ? new Error('Mode `' + mode + '` not supported') : err;
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/devices/philips-light-bulb.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = class BallLamp extends LightBulb
.with(MiioApi, Power, Dimmable, EasyNameable, Colorable, ColorTemperature)
{
static get type() {
return 'miio:philiphs-ball-lamp'
return 'miio:philiphs-ball-lamp';
}

constructor(options) {
Expand Down
4 changes: 2 additions & 2 deletions lib/devices/power-plug.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = class extends Thing
.with(PowerPlug, PowerOutlet, MiioApi, Power, EasyNameable)
{
static get type() {
return 'miio:power-plug'
return 'miio:power-plug';
}

constructor(options) {
Expand All @@ -23,4 +23,4 @@ module.exports = class extends Thing
changePower(power) {
return this.call('set_power', [ power ? 'on' : 'off' ], { refresh: true });
}
}
};
6 changes: 3 additions & 3 deletions lib/devices/power-strip.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const { PowerStrip } = require('abstract-things/electrical');

const MiioApi = require('../device');
const Power = require('./capabilities/power');
const Mode = require('./capabilities/mode')
const Mode = require('./capabilities/mode');

module.exports = class extends PowerStrip
.with(MiioApi, Power, Mode, EasyNameable)
{
static get type() {
return 'miio:power-strip'
return 'miio:power-strip';
}

constructor(options) {
Expand All @@ -36,4 +36,4 @@ module.exports = class extends PowerStrip
changeMode(mode) {
return this.call('set_power_mode', [ mode ]);
}
}
};
6 changes: 3 additions & 3 deletions lib/devices/vacuum.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = class extends Vacuum
.with(MiioApi, EasyNameable)
{
static get type() {
return 'miio:vacuum'
return 'miio:vacuum';
}

constructor(options) {
Expand Down Expand Up @@ -136,7 +136,7 @@ module.exports = class extends Vacuum
* Get if the device is charging.
*/
get charging() {
return this.state == 'charging';
return this.state === 'charging';
}

/**
Expand Down Expand Up @@ -199,7 +199,7 @@ module.exports = class extends Vacuum
return {
count: result[2],
days: result[3].map(ts => new Date(ts * 1000))
}
};
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Browser = module.exports.Browser = class Browser extends TimedDiscovery {
token: storedToken || this._manualToken(id),
autoToken: false
});
})
});
} else {
// Token could be discovered or no token storage
this[tryAdd]({
Expand Down Expand Up @@ -123,7 +123,7 @@ const Browser = module.exports.Browser = class Browser extends TimedDiscovery {
[util.inspect.custom]() {
return 'MiioBrowser{}';
}
}
};

class Devices extends BasicDiscovery {
static get type() {
Expand Down
Loading

0 comments on commit 3dfd6a7

Please sign in to comment.