diff --git a/package-lock.json b/package-lock.json index 231cf74..6367e69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-poweredup", - "version": "6.5.0", + "version": "6.5.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e4dfa84..812cf34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-poweredup", - "version": "6.5.0", + "version": "6.5.1", "description": "A Javascript module to interface with LEGO Powered Up components.", "homepage": "https://github.com/nathankellenicki/node-poweredup/", "main": "dist/node/index-node.js", diff --git a/src/hubs/basehub.ts b/src/hubs/basehub.ts index 025b6dc..343a22a 100644 --- a/src/hubs/basehub.ts +++ b/src/hubs/basehub.ts @@ -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) { + if (this._attachedDevices[device.portId] && this._attachedDevices[device.portId].type === device.type) { + return; + } this._attachedDevices[device.portId] = device; + /** * Emits when a device is attached to the Hub. * @event Hub#attach