Fixed Typescript defs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Nathan Kellenicki 2020-12-22 15:17:59 -08:00
parent 224415801f
commit d1fe3a49e4
11 changed files with 20 additions and 20 deletions

View File

@ -50,7 +50,7 @@ export class AbsoluteMotor extends TachoMotor {
throw new Error("Absolute positioning is not available on the WeDo 2.0 Smart Hub"); throw new Error("Absolute positioning is not available on the WeDo 2.0 Smart Hub");
} }
this.cancelEventTimer(); this.cancelEventTimer();
return new Promise((resolve) => { return new Promise<void>((resolve) => {
this._busy = true; this._busy = true;
if (speed === undefined || speed === null) { if (speed === undefined || speed === null) {
speed = 100; speed = 100;
@ -81,7 +81,7 @@ export class AbsoluteMotor extends TachoMotor {
* @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished). * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
*/ */
public gotoRealZero (speed: number = 100) { public gotoRealZero (speed: number = 100) {
return new Promise((resolve) => { return new Promise<void>((resolve) => {
const oldMode = this.mode; const oldMode = this.mode;
let calibrated = false; let calibrated = false;
this.on("absolute", async ({ angle }) => { this.on("absolute", async ({ angle }) => {
@ -110,7 +110,7 @@ export class AbsoluteMotor extends TachoMotor {
* @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished). * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
*/ */
public resetZero () { public resetZero () {
return new Promise((resolve) => { return new Promise<void>((resolve) => {
const data = Buffer.from([0x81, this.portId, 0x11, 0x51, 0x02, 0x00, 0x00, 0x00, 0x00]); const data = Buffer.from([0x81, this.portId, 0x11, 0x51, 0x02, 0x00, 0x00, 0x00, 0x00]);
this.send(data); this.send(data);
return resolve(); return resolve();

View File

@ -178,7 +178,7 @@ export class ColorDistanceSensor extends Device {
* @returns {Promise} Resolved upon successful issuance of the command. * @returns {Promise} Resolved upon successful issuance of the command.
*/ */
public setColor (color: number | boolean) { public setColor (color: number | boolean) {
return new Promise((resolve, reject) => { return new Promise<void>((resolve) => {
if (color === false) { if (color === false) {
color = 0; color = 0;
} }
@ -186,7 +186,7 @@ export class ColorDistanceSensor extends Device {
throw new Error("Setting LED color is not available on the WeDo 2.0 Smart Hub"); throw new Error("Setting LED color is not available on the WeDo 2.0 Smart Hub");
} else { } else {
this.subscribe(Mode.LED); this.subscribe(Mode.LED);
this.writeDirect(0x05, Buffer.from([color])); this.writeDirect(0x05, Buffer.from([color as number]));
} }
return resolve(); return resolve();
}); });

View File

@ -21,7 +21,7 @@ export class DuploTrainBaseSpeaker extends Device {
* @returns {Promise} Resolved upon successful issuance of the command. * @returns {Promise} Resolved upon successful issuance of the command.
*/ */
public playSound (sound: Consts.DuploTrainBaseSound) { public playSound (sound: Consts.DuploTrainBaseSound) {
return new Promise((resolve, reject) => { return new Promise<void>((resolve) => {
this.subscribe(Mode.SOUND); this.subscribe(Mode.SOUND);
this.writeDirect(0x01, Buffer.from([sound])); this.writeDirect(0x01, Buffer.from([sound]));
return resolve(); return resolve();

View File

@ -23,7 +23,7 @@ export class HubLED extends Device {
* @returns {Promise} Resolved upon successful issuance of the command. * @returns {Promise} Resolved upon successful issuance of the command.
*/ */
public setColor (color: number | boolean) { public setColor (color: number | boolean) {
return new Promise((resolve, reject) => { return new Promise<void>((resolve) => {
if (typeof color === "boolean") { if (typeof color === "boolean") {
color = 0; color = 0;
} }
@ -48,7 +48,7 @@ export class HubLED extends Device {
* @returns {Promise} Resolved upon successful issuance of the command. * @returns {Promise} Resolved upon successful issuance of the command.
*/ */
public setRGB (red: number, green: number, blue: number) { public setRGB (red: number, green: number, blue: number) {
return new Promise((resolve, reject) => { return new Promise<void>((resolve) => {
if (this.isWeDo2SmartHub) { if (this.isWeDo2SmartHub) {
this.send(Buffer.from([0x06, 0x17, 0x01, 0x02]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE); this.send(Buffer.from([0x06, 0x17, 0x01, 0x02]), Consts.BLECharacteristic.WEDO2_PORT_TYPE_WRITE);
this.send(Buffer.from([0x06, 0x04, 0x03, red, green, blue]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE); this.send(Buffer.from([0x06, 0x04, 0x03, red, green, blue]), Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);

View File

@ -27,7 +27,7 @@ export class Light extends Device {
if (interrupt) { if (interrupt) {
this.cancelEventTimer(); this.cancelEventTimer();
} }
return new Promise((resolve) => { return new Promise<void>((resolve) => {
this.writeDirect(0x00, Buffer.from([brightness])); this.writeDirect(0x00, Buffer.from([brightness]));
return resolve(); return resolve();
}); });

View File

@ -103,7 +103,7 @@ export class TachoMotor extends BasicMotor {
throw new Error("Motor speed is not available on the WeDo 2.0 Smart Hub"); throw new Error("Motor speed is not available on the WeDo 2.0 Smart Hub");
} }
this.cancelEventTimer(); this.cancelEventTimer();
return new Promise((resolve) => { return new Promise<void>((resolve) => {
this._busy = true; this._busy = true;
if (speed === undefined || speed === null) { if (speed === undefined || speed === null) {
speed = 100; speed = 100;
@ -145,7 +145,7 @@ export class TachoMotor extends BasicMotor {
throw new Error("Rotation is not available on the WeDo 2.0 Smart Hub"); throw new Error("Rotation is not available on the WeDo 2.0 Smart Hub");
} }
this.cancelEventTimer(); this.cancelEventTimer();
return new Promise((resolve) => { return new Promise<void>((resolve) => {
this._busy = true; this._busy = true;
if (speed === undefined || speed === null) { if (speed === undefined || speed === null) {
speed = 100; speed = 100;

View File

@ -174,7 +174,7 @@ export class LPF2Hub extends BaseHub {
private _requestHubPropertyValue (property: number) { private _requestHubPropertyValue (property: number) {
return new Promise((resolve) => { return new Promise<void>((resolve) => {
this._propertyRequestCallbacks[property] = (message) => { this._propertyRequestCallbacks[property] = (message) => {
this._parseHubPropertyResponse(message); this._parseHubPropertyResponse(message);
return resolve(); return resolve();

View File

@ -41,7 +41,7 @@ export class WeDo2SmartHub extends BaseHub {
public connect () { public connect () {
return new Promise<void>(async (resolve, reject) => { return new Promise<void>(async (resolve) => {
debug("Connecting to WeDo 2.0 Smart Hub"); debug("Connecting to WeDo 2.0 Smart Hub");
await super.connect(); await super.connect();
await this._bleDevice.discoverCharacteristicsForService(Consts.BLEService.WEDO2_SMART_HUB); await this._bleDevice.discoverCharacteristicsForService(Consts.BLEService.WEDO2_SMART_HUB);
@ -113,7 +113,7 @@ export class WeDo2SmartHub extends BaseHub {
if (name.length > 14) { if (name.length > 14) {
throw new Error("Name must be 14 characters or less"); throw new Error("Name must be 14 characters or less");
} }
return new Promise((resolve, reject) => { return new Promise<void>((resolve) => {
const data = Buffer.from(name, "ascii"); const data = Buffer.from(name, "ascii");
// Send this twice, as sometimes the first time doesn't take // Send this twice, as sometimes the first time doesn't take
this.send(data, Consts.BLECharacteristic.WEDO2_NAME_ID); this.send(data, Consts.BLECharacteristic.WEDO2_NAME_ID);

View File

@ -92,9 +92,9 @@ export class NobleDevice extends EventEmitter implements IBLEAbstraction {
return discoverReject(err); return discoverReject(err);
} }
debug("Service/characteristic discovery started"); debug("Service/characteristic discovery started");
const servicePromises: Promise<null>[] = []; const servicePromises: Promise<void>[] = [];
services.forEach((service) => { services.forEach((service) => {
servicePromises.push(new Promise((resolve, reject) => { servicePromises.push(new Promise((resolve) => {
service.discoverCharacteristics([], (err, characteristics) => { service.discoverCharacteristics([], (err, characteristics) => {
characteristics.forEach((characteristic) => { characteristics.forEach((characteristic) => {
this._characteristics[characteristic.uuid] = characteristic; this._characteristics[characteristic.uuid] = characteristic;

View File

@ -128,7 +128,7 @@ export class PoweredUP extends EventEmitter {
private _determineLPF2HubType (device: IBLEAbstraction): Promise<Consts.HubType> { private _determineLPF2HubType (device: IBLEAbstraction): Promise<Consts.HubType> {
return new Promise((resolve, reject) => { return new Promise((resolve) => {
let buf: Buffer = Buffer.alloc(0); let buf: Buffer = Buffer.alloc(0);
device.subscribeToCharacteristic(Consts.BLECharacteristic.LPF2_ALL, (data: Buffer) => { device.subscribeToCharacteristic(Consts.BLECharacteristic.LPF2_ALL, (data: Buffer) => {
buf = Buffer.concat([buf, data]); buf = Buffer.concat([buf, data]);

View File

@ -14,7 +14,7 @@ export class WebBLEDevice extends EventEmitter implements IBLEAbstraction {
private _listeners: {[uuid: string]: any} = {}; private _listeners: {[uuid: string]: any} = {};
private _characteristics: {[uuid: string]: any} = {}; private _characteristics: {[uuid: string]: any} = {};
private _queue: Promise<any> = Promise.resolve(); private _queue: Promise<void> = Promise.resolve();
private _mailbox: Buffer[] = []; private _mailbox: Buffer[] = [];
private _connected: boolean = false; private _connected: boolean = false;
@ -58,7 +58,7 @@ export class WebBLEDevice extends EventEmitter implements IBLEAbstraction {
public connect () { public connect () {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve) => {
this._connected = true; this._connected = true;
return resolve(); return resolve();
}); });
@ -66,7 +66,7 @@ export class WebBLEDevice extends EventEmitter implements IBLEAbstraction {
public disconnect () { public disconnect () {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve) => {
this._webBLEServer.device.gatt.disconnect(); this._webBLEServer.device.gatt.disconnect();
return resolve(); return resolve();
}); });