More error handling around manuallyAttachDevice
This commit is contained in:
parent
e6c6a3c18f
commit
dee732c8ca
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-poweredup",
|
||||
"version": "6.5.1",
|
||||
"version": "6.5.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -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",
|
||||
|
@ -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.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user