diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..76b1657 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "preLaunchTask": "build and install", + "program": "/Users/brandonwatson/.npm-global/bin/homebridge", + "sourceMaps": true, + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..ad92e87 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,17 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "build", + "problemMatcher": [] + }, + { + "type": "shell", + "label": "build and install", + "command": "npm run build&&sudo npm install -g --unsafe-perm ." + } + ] +} \ No newline at end of file diff --git a/src/DataProviders/HubDataProvider.ts b/src/DataProviders/HubDataProvider.ts index 35bf308..47c6fa4 100644 --- a/src/DataProviders/HubDataProvider.ts +++ b/src/DataProviders/HubDataProvider.ts @@ -96,7 +96,9 @@ class HubDataProvider { await Promise.all( //Turn off devices devicesToTurnOff.map(async (device: IDevice) => { - await device.powerOff(); + if (device) { + await device.powerOff(); + } }) ); @@ -124,7 +126,7 @@ class HubDataProvider { //Turn on devices await Promise.all(devicesToTurnOn.map(async (device: IDevice) => { - if (device && device.name && this.devices[device.name]) { + if (device && device.name) { if (!device.on) { this.log(`Turning on device ${device.name}`) await device.powerOn(); @@ -479,10 +481,10 @@ class HubDataProvider { let powerOnCommand: string = "Power On"; let powerToggleCommand: string = "Power Toggle"; if (this.supportsCommand(powerOnCommand)) { - await this.sendCommand(this.getCommand(powerOnCommand)); + await this.sendCommand(powerOnCommand); this.on = true; } else if (this.supportsCommand(powerToggleCommand)) { - await this.sendCommand(this.getCommand(powerToggleCommand)); + await this.sendCommand(powerToggleCommand); this.on = true; } }, @@ -490,18 +492,16 @@ class HubDataProvider { let powerOffCommand: string = "Power Off"; let powerToggleCommand: string = "Power Toggle"; if (this.supportsCommand(powerOffCommand)) { - await this.sendCommand(this.getCommand(powerOffCommand)); + await this.sendCommand(powerOffCommand); this.on = false; } else if (this.supportsCommand(powerToggleCommand)) { - await this.sendCommand(this.getCommand(powerToggleCommand)); + await this.sendCommand(powerToggleCommand); this.on = false; } } } } } - - this.log(`Device list: ${JSON.stringify(this.devices)}`); } } diff --git a/tsconfig.json b/tsconfig.json index dbe99c3..9bcfa13 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "declaration": true, "outDir": "./bin", "strict": true, + "sourceMap": true, }, "include": [ "src"