Skip to content

Commit

Permalink
linting, testing and async fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bitcloud committed Sep 21, 2020
1 parent 422f4e7 commit 64b9744
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
8 changes: 5 additions & 3 deletions lib/hci-socket/hci.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ const Hci = function (options) {

this._handleBuffers = {};

this._deviceId = options.deviceId != null ? parseInt(options.deviceId, 10) :
process.env.NOBLE_HCI_DEVICE_ID ? parseInt(process.env.NOBLE_HCI_DEVICE_ID, 10) :
undefined;
this._deviceId = options.deviceId != null
? parseInt(options.deviceId, 10)
: process.env.NOBLE_HCI_DEVICE_ID
? parseInt(process.env.NOBLE_HCI_DEVICE_ID, 10)
: undefined;

this._userChannel = (typeof options.userChannel === 'undefined' && options.userChannel) || process.env.HCI_CHANNEL_USER;

Expand Down
4 changes: 2 additions & 2 deletions lib/noble.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ Noble.prototype.setScanParameters = function (interval, window, callback) {
this.once('scanParametersSet', callback);
}
this._bindings.setScanParameters(interval, window);
}
};

Noble.prototype.onScanParametersSet = function () {
debug('scanParametersSet');
this.emit('scanParametersSet');
};

Noble.prototype.startScanning = function (serviceUuids, allowDuplicates, callback) {
const startScanning = function (serviceUuids, allowDuplicates, callback) {
if (typeof serviceUuids === 'function') {
this.emit('warning', 'calling startScanning(callback) is deprecated');
}
Expand Down
16 changes: 12 additions & 4 deletions lib/peripheral.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Peripheral.prototype.toString = function () {
});
};

Peripheral.prototype.connect = function (options, callback) {
const connect = function (options, callback) {
if (typeof options === 'function') {
callback = options;
options = undefined;
Expand All @@ -46,11 +46,17 @@ Peripheral.prototype.connect = function (options, callback) {
this.emit('connect', new Error('Peripheral already connected'));
} else {
this.state = 'connecting';
console.log('connecting');
this._noble.connect(this.id, options);
}
};

Peripheral.prototype.cancelConnect = function (options, callback) {
Peripheral.prototype.connect = connect;
Peripheral.prototype.connectAsync = function (options) {
return util.promisify((callback) => this.connect(options, callback))();
};

const cancelConnect = function (options, callback) {
if (typeof options === 'function') {
callback = options;
options = undefined;
Expand All @@ -70,8 +76,10 @@ Peripheral.prototype.cancelConnect = function (options, callback) {
}
};

Peripheral.prototype.connect = connect;
Peripheral.prototype.connectAsync = util.promisify(connect);
Peripheral.prototype.cancelConnect = cancelConnect;
Peripheral.prototype.cancelConnectAsync = function (options) {
return util.promisify((callback) => this.cancleConnect(options, callback))();
};

const disconnect = function (callback) {
if (callback) {
Expand Down
4 changes: 2 additions & 2 deletions test/test-peripheral.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Peripheral', function () {
it('should delegate to noble', function () {
peripheral.connect();

mockNoble.connect.calledWithExactly(mockId).should.equal(true);
mockNoble.connect.calledWithExactly(mockId, undefined).should.equal(true);
});

it('should callback', function () {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('Peripheral', function () {
peripheral.emit('connect');
await promise;

mockNoble.connect.calledWithExactly(mockId).should.equal(true);
mockNoble.connect.calledWithExactly(mockId, undefined).should.equal(true);
});
});

Expand Down

0 comments on commit 64b9744

Please sign in to comment.