diff --git a/src/hubs/basehub.ts b/src/hubs/basehub.ts index 90a8aba..75e313e 100644 --- a/src/hubs/basehub.ts +++ b/src/hubs/basehub.ts @@ -360,7 +360,8 @@ export class BaseHub extends EventEmitter { const device = this._createDevice(deviceType, portId); this._attachDevice(device); return device; - } else { + } + else if (deviceType) { if (this._attachedDevices[portId].type === deviceType) { debug(`Device of ${deviceType} already attached to portId ${portId}, returning existing device`); return this._attachedDevices[portId]; @@ -368,6 +369,9 @@ export class BaseHub extends EventEmitter { throw new Error(`Already a different type of device attached to portId ${portId}. Only use this method when you are certain what's attached.`); } } + else { + this._detachDevice(this._attachedDevices[portId]); + } }