Method for manually attaching devices as a workaround for connection issues
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Nathan Kellenicki 2020-06-03 09:05:41 -07:00
parent 1b2c988409
commit e6c6a3c18f
3 changed files with 17 additions and 2 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "node-poweredup", "name": "node-poweredup",
"version": "6.5.0", "version": "6.5.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "node-poweredup", "name": "node-poweredup",
"version": "6.5.0", "version": "6.5.1",
"description": "A Javascript module to interface with LEGO Powered Up components.", "description": "A Javascript module to interface with LEGO Powered Up components.",
"homepage": "https://github.com/nathankellenicki/node-poweredup/", "homepage": "https://github.com/nathankellenicki/node-poweredup/",
"main": "dist/node/index-node.js", "main": "dist/node/index-node.js",

View File

@ -331,8 +331,23 @@ export class BaseHub extends EventEmitter {
} }
public manuallyAttachDevice(deviceType: number, portId: number) {
if (!this._attachedDevices[portId]) {
const device = this._createDevice(deviceType, portId);
this._attachDevice(device);
return device;
} else {
return false;
}
}
protected _attachDevice (device: Device) { protected _attachDevice (device: Device) {
if (this._attachedDevices[device.portId] && this._attachedDevices[device.portId].type === device.type) {
return;
}
this._attachedDevices[device.portId] = device; this._attachedDevices[device.portId] = device;
/** /**
* Emits when a device is attached to the Hub. * Emits when a device is attached to the Hub.
* @event Hub#attach * @event Hub#attach