Skip to content

Commit

Permalink
Cleaning up lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aholstenson committed Jan 23, 2018
1 parent a5002d6 commit bd8c8d9
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 67 deletions.
7 changes: 3 additions & 4 deletions cli/commands/configure.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const chalk = require('chalk');
const log = require('../log');
const deviceFinder = require('../device-finder');

Expand Down Expand Up @@ -51,16 +50,16 @@ exports.handler = function(argv) {
})
.then(() => {
pending--;
process.exit(0);
process.exit(0); // eslint-disable-line
});
});

const doneHandler = () => {
if(pending == 0) {
if(pending === 0) {
if(! foundDevice) {
log.warn('Could not find device');
}
process.exit(0);
process.exit(0); // eslint-disable-line
}
};
setTimeout(doneHandler, 5000);
Expand Down
10 changes: 4 additions & 6 deletions cli/commands/control.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const chalk = require('chalk');
const log = require('../log');
const deviceFinder = require('../device-finder');

Expand All @@ -21,8 +20,7 @@ exports.handler = function(argv) {
browser.on('available', device => {
if(! device[argv.method]) {
log.error('The method ' + argv.method + ' is not available');
process.exit(0);
return;
process.exit(0); // eslint-disable-line
}

pending++;
Expand All @@ -39,16 +37,16 @@ exports.handler = function(argv) {
})
.then(() => {
pending--;
process.exit(0);
process.exit(0); // eslint-disable-line
});
});

const doneHandler = () => {
if(pending == 0) {
if(pending === 0) {
if(! foundDevice) {
log.warn('Could not find device');
}
process.exit(0);
process.exit(0); // eslint-disable-line
}
};
setTimeout(doneHandler, 5000);
Expand Down
6 changes: 3 additions & 3 deletions cli/commands/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ exports.builder = {
};

exports.handler = function(argv) {
log.info('Discovering devices. Press Ctrl+C to stop.')
log.info('Discovering devices. Press Ctrl+C to stop.');
log.plain();

const browser = deviceFinder();
browser.on('available', device => {
try {
log.device(device);
} catch(ex) {
console.log(ex);
log.error(ex);
}

const mgmt = device.management;
if(argv.sync && mgmt.token && mgmt.autoToken) {
tokens.update(device.id, mgmt.token)
.catch(err => {
error('Could not update token for', device.id, ':', err);
log.error('Could not update token for', device.id, ':', err);
});
}
});
Expand Down
9 changes: 4 additions & 5 deletions cli/commands/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const chalk = require('chalk');
const log = require('../log');
const deviceFinder = require('../device-finder');
const Tokens = require('../../lib/tokens');

exports.command = 'inspect <idOrIp>';
exports.description = 'Inspect a device';
Expand Down Expand Up @@ -80,24 +79,24 @@ exports.handler = function(argv) {
log.plain(chalk.bold('Parent:'));
log.group(() => {
log.device(mgmt.parent);
})
});
}
})
.catch(err => {
log.error('Could inspect device. Error was:', err.message);
})
.then(() => {
pending--;
process.exit(0);
process.exit(0); // eslint-disable-line
});
});

const doneHandler = () => {
if(pending == 0) {
if(pending === 0) {
if(! foundDevice) {
log.warn('Could not find device');
}
process.exit(0);
process.exit(0); // eslint-disable-line
}
};
setTimeout(doneHandler, 5000);
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const path = require('path');

exports.command = 'protocol <command>'
exports.command = 'protocol <command>';
exports.description = 'Inspect and test raw miIO-commands';
exports.builder = yargs => yargs.commandDir(path.join(__dirname, 'protocol'));
exports.handler = () => {};
10 changes: 4 additions & 6 deletions cli/commands/protocol/call.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

const chalk = require('chalk');
const log = require('../../log');
const deviceFinder = require('../../device-finder');
const tokens = require('../../../lib/tokens');

exports.command = 'call <idOrIp> <method> [params]';
exports.description = 'Call a raw method on a device';
Expand All @@ -29,7 +27,7 @@ exports.handler = function(argv) {
const parsedArgs = argv.params ? JSON.parse(argv.params) : [];
device.miioCall(argv.method, parsedArgs)
.then(result => {
log.info('Got result:')
log.info('Got result:');
log.plain(JSON.stringify(result, null, ' '));
})
.catch(err => {
Expand All @@ -40,16 +38,16 @@ exports.handler = function(argv) {
})
.then(() => {
pending--;
process.exit(0);
process.exit(0); // eslint-disable-line
});
});

const doneHandler = () => {
if(pending == 0) {
if(pending === 0) {
if(! foundDevice) {
log.warn('Could not find device');
}
process.exit(0);
process.exit(0); // eslint-disable-line
}
};
setTimeout(doneHandler, 5000);
Expand Down
4 changes: 2 additions & 2 deletions cli/commands/protocol/json-dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ exports.handler = function(argv) {
if(! udp) return;

let out;
if(udp['udp.dstport'] == '54321') {
if(udp['udp.dstport'] === '54321') {
// Packet that is being sent to the device
out = true;
} else if(udp['udp.srcport'] == '54321') {
} else if(udp['udp.srcport'] === '54321') {
// Packet coming from the device
out = false;
} else {
Expand Down
2 changes: 0 additions & 2 deletions cli/commands/protocol/packet.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const fs = require('fs');
const chalk = require('chalk');
const log = require('../../log');
const Packet = require('../../../lib/packet');

Expand Down
2 changes: 1 addition & 1 deletion cli/commands/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const path = require('path');

exports.command = 'tokens <command>'
exports.command = 'tokens <command>';
exports.description = 'Manage tokens of devices';
exports.builder = yargs => yargs.commandDir(path.join(__dirname, 'tokens'));
exports.handler = () => {};
8 changes: 3 additions & 5 deletions cli/commands/tokens/update.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

const chalk = require('chalk');
const log = require('../../log');
const deviceFinder = require('../../device-finder');
const tokens = require('../../../lib/tokens');

exports.command = 'update <idOrIp>';
exports.description = 'Update the token to use for the given device';
Expand Down Expand Up @@ -43,16 +41,16 @@ exports.handler = function(argv) {
})
.then(() => {
pending--;
process.exit(0);
process.exit(0); // eslint-disable-line
});
});

const doneHandler = () => {
if(pending == 0) {
if(pending === 0) {
if(! foundDevice) {
log.warn('Could not find device');
}
process.exit(0);
process.exit(0); // eslint-disable-line
}
};
setTimeout(doneHandler, 5000);
Expand Down
2 changes: 1 addition & 1 deletion cli/device-finder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { EventEmitter } = require('events');
const { Browser, Devices } = require('../lib/discovery');
const { Devices } = require('../lib/discovery');
const connectToDevice = require('../lib/connectToDevice');

const IP = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
Expand Down
3 changes: 2 additions & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env node
'use strict';

const path = require('path');
const argv = require('yargs')
require('yargs')
.commandDir(path.join(__dirname, 'commands'))
.recommendCommands()
.demandCommand()
Expand Down
10 changes: 5 additions & 5 deletions cli/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ module.exports = {
indent: '',

info(...args) {
console.log(this.indent + chalk.bgWhite.black(' INFO '), args.join(' '));
console.log(this.indent + chalk.bgWhite.black(' INFO '), args.join(' ')); // eslint-disable-line
},

error(...args) {
console.log(this.indent + chalk.bgRed.white(' ERROR '), args.join(' '));
console.log(this.indent + chalk.bgRed.white(' ERROR '), args.join(' ')); // eslint-disable-line
},

warn(...args) {
console.log(this.indent + chalk.bgYellow.black(' WARNING '), args.join(' '));
console.log(this.indent + chalk.bgYellow.black(' WARNING '), args.join(' ')); // eslint-disable-line
},

plain(...args) {
console.log(this.indent + args.join(' '));
console.log(this.indent + args.join(' ')); // eslint-disable-line
},

group(g) {
Expand Down Expand Up @@ -50,7 +50,7 @@ module.exports = {
if(mgmt.token) {
this.plain(chalk.bold('Token:'), mgmt.token, mgmt.autoToken ? chalk.green('via auto-token') : chalk.yellow('via stored token'));
} else if(! mgmt.parent) {
this.plain(chalk.bold('Token:'), '???')
this.plain(chalk.bold('Token:'), '???');
} else {
this.plain(chalk.bold('Token:'), chalk.green('Automatic via parent device'));
}
Expand Down
9 changes: 0 additions & 9 deletions lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,10 @@
const isDeepEqual = require('deep-equal');
const { Thing, Polling } = require('abstract-things');

const dgram = require('dgram');
const Packet = require('./packet');

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,
'-10000': (method) => 'Method `' + method + '` is not supported'
};

module.exports = Thing.type(Parent => class extends Parent.with(Polling) {
static get type() {
return 'miio';
Expand Down
2 changes: 1 addition & 1 deletion lib/devices/air-purifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module.exports = class extends AirPurifier
return Promise.resolve(this.property('favoriteLevel'));
}

return setFavoriteLevel(level);
return this.setFavoriteLevel(level);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/devices/vacuum.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { EasyNameable, ChargingState, AutonomousCharging } = require('abstract-things');
const {
Vacuum, CleaningState, AdjustableFanSpeed, AutonomousCleaning, SpotCleaning
Vacuum, AdjustableFanSpeed, AutonomousCleaning, SpotCleaning
} = require('abstract-things/climate');

const MiioApi = require('../device');
Expand All @@ -20,7 +20,7 @@ function checkResult(r) {
*/
module.exports = class extends Vacuum.with(
MiioApi, EasyNameable, BatteryLevel, AutonomousCharging, AutonomousCleaning,
SpotCleaning, AdjustableFanSpeed
SpotCleaning, AdjustableFanSpeed, ChargingState
) {
static get type() {
return 'miio:vacuum';
Expand Down
7 changes: 1 addition & 6 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

const { TimedDiscovery, BasicDiscovery, search, addService, removeService } = require('tinkerhub-discovery');
const { Children } = require('abstract-things');
const { ThingDiscovery } = require('abstract-things/discovery');

const util = require('util');
const dgram = require('dgram');
const dns = require('dns');

const network = require('./network');
const infoFromHostname = require('./infoFromHostname');
const Packet = require('./packet');

const connectToDevice = require('./connectToDevice');

const PORT = 54321;

const tryAdd = Symbol('tryAdd');

const Browser = module.exports.Browser = class Browser extends TimedDiscovery {
Expand Down Expand Up @@ -118,7 +113,7 @@ class Devices extends BasicDiscovery {
.then(device => {
reg.device = device;
return reg;
})
});
});

this._browser.on('available', s => {
Expand Down
1 change: 0 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const discovery = require('./discovery');
const Device = require('./device');

/**
* Get information about the models supported. Can be used to extend the models
Expand Down
3 changes: 0 additions & 3 deletions lib/infoFromHostname.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict';


const models = require('./models');

module.exports = function(hostname) {
// Extract info via hostname structure
const m = /(.+)_miio(\d+)/g.exec(hostname);
Expand Down
2 changes: 1 addition & 1 deletion lib/management.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DeviceManagement {
updateToken(token) {
if(token instanceof Buffer) {
token = token.toString('hex');
} else if(! token instanceof String) {
} else if(! (token instanceof String)) {
return Promise.resolve(new Error('Token must be a hex-string or a Buffer'));
}

Expand Down
Loading

0 comments on commit bd8c8d9

Please sign in to comment.