Skip to content

Commit

Permalink
Update SDK and improve error handling (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
DallasHoff committed Dec 9, 2021
1 parent aacf5d3 commit 4aa67fe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 49 deletions.
49 changes: 6 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"color-convert": "^2.0.1",
"openrgb-sdk": "^0.4.3"
"openrgb-sdk": "^0.5.0-beta.4"
},
"devDependencies": {
"@types/node": "^14.14.31",
Expand Down
18 changes: 14 additions & 4 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,27 @@ export class OpenRgbPlatform implements DynamicPlatformPlugin {
try {
await Promise.race([client.connect(), timeout()]);
} catch (err) {
this.log.warn(`Unable to connect to OpenRGB SDK server at ${serverHost}:${serverPort}.`);
this.log.warn(`Unable to connect to OpenRGB SDK server at ${serverHost}:${serverPort}`);
return 1;
}

// Build array of device information
const devices: rgbDevice[] = [];
const controllerCount = await client.getControllerCount();
let controllerCount = 0;

try {
controllerCount = await client.getControllerCount();
} catch (err) {
this.log.warn(`Unable to enumerate RGB devices on OpenRGB SDK server at ${serverHost}:${serverPort}`);
}

for (let deviceId = 0; deviceId < controllerCount; deviceId++) {
const device: rgbDevice = await client.getControllerData(deviceId);
devices.push(device);
try {
const device: rgbDevice = await client.getControllerData(deviceId);
devices.push(device);
} catch (err) {
this.log.warn(`Unable to get status of RGB device ${deviceId} on OpenRGB SDK server at ${serverHost}:${serverPort}`);
}
}

// Perform supplied action then disconnect
Expand Down
8 changes: 7 additions & 1 deletion src/platformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,19 @@ export class OpenRgbPlatformAccessory {
if (!device) {
return;
}

const ledColor: openRgbColor = {
red: newColorRgb[0],
green: newColorRgb[1],
blue: newColorRgb[2],
};
const ledColors: openRgbColor[] = Array(device.colors.length).fill(ledColor);
await client.updateLeds(device.deviceId, ledColors);

try {
await client.updateLeds(device.deviceId, ledColors);
} catch (err) {
this.platform.log.warn(`Failed to set light color on device: ${device.name}`);
}
});
}

Expand Down

0 comments on commit 4aa67fe

Please sign in to comment.