Skip to content

Commit

Permalink
fix: remove the setTemperaturePercentage function, because you can't
Browse files Browse the repository at this point in the history
actually set
a Litra's temperature to an arbitrary percentage

BREAKING CHANGE: The `setTemperaturePercentage` function has been
removed because it claims to allow users to set their Litra device's
temperature toan arbitrary percentage value, but the device only
allows a limited set of temperatures (multiples of 100 between the
minimum and maximum) - see #92. The `setTemperatureInKelvin`
function for setting the temperature to a value in Kelvin is still
available.
  • Loading branch information
timrogers committed Feb 23, 2023
1 parent 17439b7 commit deaa0d9
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 137 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,6 @@ if (device) {
}
```

You can also set temperature level to a percentage with `setTemperaturePercentage` if you don't want to think in Kelvin:

```js
import { findDevice, setTemperaturePercentage } from 'litra';

const device = findDevice();

if (device) {
setTemperaturePercentage(device, 75);
}
```

## Using with Oversight

Litra integrates with [Oversight](https://objective-see.org/products/oversight.html) to allow you to automatically turn your Litra device on or off when your webcam turns on and off. This allows you to be illuminated every time you join a video call!
Expand Down
8 changes: 0 additions & 8 deletions dist/commonjs/driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ export declare const turnOff: (device: Device) => void;
* functions to get the minimum and maximum temperature for your device.
*/
export declare const setTemperatureInKelvin: (device: Device, temperatureInKelvin: number) => void;
/**
* Set the temperature of your Logitech Litra device to a percentage
* of the device's maximum temperature
*
* @param {Device} device The device to set the temperature of
* @param {number} temperaturePercentage The percentage to set the temperature to
*/
export declare const setTemperaturePercentage: (device: Device, temperaturePercentage: number) => void;
/**
* Sets the brightness of your Logitech Litra device, measured in Lumen
*
Expand Down
20 changes: 1 addition & 19 deletions dist/commonjs/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNameForDevice = exports.getMaximumTemperatureInKelvinForDevice = exports.getMinimumTemperatureInKelvinForDevice = exports.getMaximumBrightnessInLumenForDevice = exports.getMinimumBrightnessInLumenForDevice = exports.setBrightnessPercentage = exports.setBrightnessInLumen = exports.setTemperaturePercentage = exports.setTemperatureInKelvin = exports.turnOff = exports.turnOn = exports.findDevices = exports.findDevice = exports.DeviceType = void 0;
exports.getNameForDevice = exports.getMaximumTemperatureInKelvinForDevice = exports.getMinimumTemperatureInKelvinForDevice = exports.getMaximumBrightnessInLumenForDevice = exports.getMinimumBrightnessInLumenForDevice = exports.setBrightnessPercentage = exports.setBrightnessInLumen = exports.setTemperatureInKelvin = exports.turnOff = exports.turnOn = exports.findDevices = exports.findDevice = exports.DeviceType = void 0;
const node_hid_1 = __importDefault(require("node-hid"));
const utils_1 = require("./utils");
var DeviceType;
Expand Down Expand Up @@ -120,24 +120,6 @@ const setTemperatureInKelvin = (device, temperatureInKelvin) => {
device.hid.write((0, utils_1.padRight)([0x11, 0xff, 0x04, 0x9c, ...(0, utils_1.integerToBytes)(temperatureInKelvin)], 20, 0x00));
};
exports.setTemperatureInKelvin = setTemperatureInKelvin;
/**
* Set the temperature of your Logitech Litra device to a percentage
* of the device's maximum temperature
*
* @param {Device} device The device to set the temperature of
* @param {number} temperaturePercentage The percentage to set the temperature to
*/
const setTemperaturePercentage = (device, temperaturePercentage) => {
if (temperaturePercentage < 0 || temperaturePercentage > 100) {
throw 'Percentage must be between 0 and 100';
}
const minimumTemperature = (0, exports.getMinimumTemperatureInKelvinForDevice)(device);
const maximumTemperature = (0, exports.getMaximumTemperatureInKelvinForDevice)(device);
return (0, exports.setTemperatureInKelvin)(device, temperaturePercentage === 0
? minimumTemperature
: (0, utils_1.percentageWithinRange)(temperaturePercentage, minimumTemperature, maximumTemperature));
};
exports.setTemperaturePercentage = setTemperaturePercentage;
/**
* Sets the brightness of your Logitech Litra device, measured in Lumen
*
Expand Down
8 changes: 0 additions & 8 deletions dist/esm/driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ export declare const turnOff: (device: Device) => void;
* functions to get the minimum and maximum temperature for your device.
*/
export declare const setTemperatureInKelvin: (device: Device, temperatureInKelvin: number) => void;
/**
* Set the temperature of your Logitech Litra device to a percentage
* of the device's maximum temperature
*
* @param {Device} device The device to set the temperature of
* @param {number} temperaturePercentage The percentage to set the temperature to
*/
export declare const setTemperaturePercentage: (device: Device, temperaturePercentage: number) => void;
/**
* Sets the brightness of your Logitech Litra device, measured in Lumen
*
Expand Down
17 changes: 0 additions & 17 deletions dist/esm/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,6 @@ export const setTemperatureInKelvin = (device, temperatureInKelvin) => {
}
device.hid.write(padRight([0x11, 0xff, 0x04, 0x9c, ...integerToBytes(temperatureInKelvin)], 20, 0x00));
};
/**
* Set the temperature of your Logitech Litra device to a percentage
* of the device's maximum temperature
*
* @param {Device} device The device to set the temperature of
* @param {number} temperaturePercentage The percentage to set the temperature to
*/
export const setTemperaturePercentage = (device, temperaturePercentage) => {
if (temperaturePercentage < 0 || temperaturePercentage > 100) {
throw 'Percentage must be between 0 and 100';
}
const minimumTemperature = getMinimumTemperatureInKelvinForDevice(device);
const maximumTemperature = getMaximumTemperatureInKelvinForDevice(device);
return setTemperatureInKelvin(device, temperaturePercentage === 0
? minimumTemperature
: percentageWithinRange(temperaturePercentage, minimumTemperature, maximumTemperature));
};
/**
* Sets the brightness of your Logitech Litra device, measured in Lumen
*
Expand Down
30 changes: 0 additions & 30 deletions src/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,36 +145,6 @@ export const setTemperatureInKelvin = (
);
};

/**
* Set the temperature of your Logitech Litra device to a percentage
* of the device's maximum temperature
*
* @param {Device} device The device to set the temperature of
* @param {number} temperaturePercentage The percentage to set the temperature to
*/
export const setTemperaturePercentage = (
device: Device,
temperaturePercentage: number,
): void => {
if (temperaturePercentage < 0 || temperaturePercentage > 100) {
throw 'Percentage must be between 0 and 100';
}

const minimumTemperature = getMinimumTemperatureInKelvinForDevice(device);
const maximumTemperature = getMaximumTemperatureInKelvinForDevice(device);

return setTemperatureInKelvin(
device,
temperaturePercentage === 0
? minimumTemperature
: percentageWithinRange(
temperaturePercentage,
minimumTemperature,
maximumTemperature,
),
);
};

/**
* Sets the brightness of your Logitech Litra device, measured in Lumen
*
Expand Down
43 changes: 0 additions & 43 deletions tests/driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
setBrightnessInLumen,
setBrightnessPercentage,
setTemperatureInKelvin,
setTemperaturePercentage,
turnOff,
turnOn,
Device,
Expand Down Expand Up @@ -96,48 +95,6 @@ describe('setTemperatureInKelvin', () => {
});
});

describe('setTemperaturePercentage', () => {
it('sends the instruction to set the device temperature based on a percentage, ', () => {
setTemperaturePercentage(fakeLitraGlow, 100);

expect(fakeLitraGlow.hid.write).toBeCalledWith([
17, 255, 4, 156, 25, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);

setTemperaturePercentage(fakeLitraBeam, 100);

expect(fakeLitraBeam.hid.write).toBeCalledWith([
17, 255, 4, 156, 25, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);
});

it('sends the instruction to set the device temperature to the minimum temperature when set to 0%', () => {
setTemperaturePercentage(fakeLitraGlow, 0);

expect(fakeLitraGlow.hid.write).toBeCalledWith([
17, 255, 4, 156, 10, 140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);

setTemperaturePercentage(fakeLitraBeam, 0);

expect(fakeLitraBeam.hid.write).toBeCalledWith([
17, 255, 4, 156, 10, 140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);
});

it('throws an error if the provided percentage is less than 0', () => {
expect(() => setTemperaturePercentage(fakeDevice, -1)).toThrowError(
'Percentage must be between 0 and 100',
);
});

it('throws an error if the provided percentage is more than 100', () => {
expect(() => setTemperaturePercentage(fakeDevice, 101)).toThrowError(
'Percentage must be between 0 and 100',
);
});
});

describe('setBrightnessInLumen', () => {
it('sends the instruction to set the device temperature', () => {
setBrightnessInLumen(fakeDevice, 20);
Expand Down

0 comments on commit deaa0d9

Please sign in to comment.