diff --git a/package-lock.json b/package-lock.json index 6367e69..d19fb20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-poweredup", - "version": "6.5.1", + "version": "6.5.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 812cf34..bdf7657 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-poweredup", - "version": "6.5.1", + "version": "6.5.2", "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 343a22a..17ce350 100644 --- a/src/hubs/basehub.ts +++ b/src/hubs/basehub.ts @@ -333,11 +333,17 @@ export class BaseHub extends EventEmitter { public manuallyAttachDevice(deviceType: number, portId: number) { if (!this._attachedDevices[portId]) { + debug(`No device attached to portId ${portId}, creating and attaching device type ${deviceType}`); const device = this._createDevice(deviceType, portId); this._attachDevice(device); return device; } else { - return false; + if (this._attachedDevices[portId].type === deviceType) { + debug(`Device of ${deviceType} already attached to portId ${portId}, returning existing device`); + return this._attachedDevices[portId]; + } else { + throw new Error(`Already a different type of device attached to portId ${portId}. Only use this method when you are certain what's attached.`); + } } }