Skip to content

Commit

Permalink
fix: correct minimum brightness for Litra Beam devices
Browse files Browse the repository at this point in the history
This library validates that brightness values (provided in Lumens) are within the device's supported range.

When adding support for the Litra Beam, I assumed that it would have the same minimum brightness as the Litra Glow (30 Lumens), but it turns out that the minimum is 30. This fixes the validations.
  • Loading branch information
timrogers committed Jan 24, 2023
1 parent 9b68dc0 commit 377b5f0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/commonjs/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const PRODUCT_IDS = [
const USAGE_PAGE = 0xff43;
const MINIMUM_BRIGHTNESS_IN_LUMEN_BY_DEVICE_TYPE = {
[DeviceType.LitraGlow]: 20,
[DeviceType.LitraBeam]: 20,
[DeviceType.LitraBeam]: 30,
};
const MAXIMUM_BRIGHTNESS_IN_LUMEN_BY_DEVICE_TYPE = {
[DeviceType.LitraGlow]: 250,
Expand Down
2 changes: 1 addition & 1 deletion dist/esm/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const PRODUCT_IDS = [
const USAGE_PAGE = 0xff43;
const MINIMUM_BRIGHTNESS_IN_LUMEN_BY_DEVICE_TYPE = {
[DeviceType.LitraGlow]: 20,
[DeviceType.LitraBeam]: 20,
[DeviceType.LitraBeam]: 30,
};
const MAXIMUM_BRIGHTNESS_IN_LUMEN_BY_DEVICE_TYPE = {
[DeviceType.LitraGlow]: 250,
Expand Down
2 changes: 1 addition & 1 deletion src/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const USAGE_PAGE = 0xff43;

const MINIMUM_BRIGHTNESS_IN_LUMEN_BY_DEVICE_TYPE = {
[DeviceType.LitraGlow]: 20,
[DeviceType.LitraBeam]: 20,
[DeviceType.LitraBeam]: 30,
};

const MAXIMUM_BRIGHTNESS_IN_LUMEN_BY_DEVICE_TYPE = {
Expand Down
8 changes: 4 additions & 4 deletions tests/driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('setBrightnessInLumen', () => {
const fakeLitraBeam = { type: DeviceType.LitraBeam, hid: { write: jest.fn() } };

expect(() => setBrightnessInLumen(fakeLitraBeam, 19)).toThrowError(
'Provided brightness must be between 20 and 400',
'Provided brightness must be between 30 and 400',
);
});

Expand All @@ -173,7 +173,7 @@ describe('setBrightnessInLumen', () => {
const fakeLitraBeam = { type: DeviceType.LitraBeam, hid: { write: jest.fn() } };

expect(() => setBrightnessInLumen(fakeLitraBeam, 401)).toThrowError(
'Provided brightness must be between 20 and 400',
'Provided brightness must be between 30 and 400',
);
});

Expand Down Expand Up @@ -219,7 +219,7 @@ describe('setBrightnessPercentage', () => {
setBrightnessPercentage(fakeLitraBeam, 0);

expect(fakeLitraBeam.hid.write).toBeCalledWith([
17, 255, 4, 76, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17, 255, 4, 76, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);
});

Expand Down Expand Up @@ -248,7 +248,7 @@ describe('getMinimumBrightnessInLumenForDevice', () => {

it('returns the correct minimum brightness for a Litra Beam', () => {
const fakeDevice = { type: DeviceType.LitraBeam, hid: { write: jest.fn() } };
expect(getMinimumBrightnessInLumenForDevice(fakeDevice)).toEqual(20);
expect(getMinimumBrightnessInLumenForDevice(fakeDevice)).toEqual(30);
});
});

Expand Down

0 comments on commit 377b5f0

Please sign in to comment.