Skip to content

Commit

Permalink
Invert color temperature percentage range
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Krug <[email protected]>
  • Loading branch information
michikrug committed Oct 10, 2023
1 parent 229f057 commit d152447
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
5 changes: 1 addition & 4 deletions functions/commands/colorabsolutetemperature.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ class ColorAbsoluteTemperature extends DefaultCommand {
return convertMired(params.color.temperature).toString();
}
const { temperatureMinK, temperatureMaxK } = SpecialColorLight.getAttributes(item).colorTemperatureRange;
return (
100 -
((params.color.temperature - temperatureMinK) / (temperatureMaxK - temperatureMinK)) * 100
).toString();
return (((params.color.temperature - temperatureMinK) / (temperatureMaxK - temperatureMinK)) * 100).toString();
} catch (error) {
return '0';
}
Expand Down
2 changes: 1 addition & 1 deletion functions/devices/specialcolorlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SpecialColorLight extends DefaultDevice {
state.color = {
temperatureK:
temperatureMinK +
Math.round(((temperatureMaxK - temperatureMinK) / 100) * (100 - Number(members[member].state)) || 0)
Math.round(((temperatureMaxK - temperatureMinK) / 100) * Number(members[member].state) || 0)
};
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/colorabsolutetemperature.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('ColorAbsoluteTemperature Command', () => {
}
};
const device = { customData: { deviceType: 'SpecialColorLight' } };
expect(Command.convertParamsToValue(params, item, device)).toBe('75');
expect(Command.convertParamsToValue(params, item, device)).toBe('25');
expect(Command.convertParamsToValue(params, { state: '100,100,50' }, device)).toBe('0');
});

Expand Down
8 changes: 4 additions & 4 deletions tests/devices/specialcolorlight.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe('SpecialColorLight Device', () => {
}
},
{
state: '23',
state: '77',
metadata: {
ga: {
value: 'lightColorTemperature'
Expand Down Expand Up @@ -422,7 +422,7 @@ describe('SpecialColorLight Device', () => {
}
},
{
state: '20',
state: '80',
metadata: {
ga: {
value: 'lightColorTemperature'
Expand Down Expand Up @@ -469,7 +469,7 @@ describe('SpecialColorLight Device', () => {
}
},
{
state: '20',
state: '80',
metadata: {
ga: {
value: 'lightColorTemperature'
Expand Down Expand Up @@ -567,7 +567,7 @@ describe('SpecialColorLight Device', () => {
}
},
{
state: '20',
state: '80',
metadata: {
ga: {
value: 'lightColorTemperature'
Expand Down

0 comments on commit d152447

Please sign in to comment.