Skip to content

Commit

Permalink
Merge pull request #518 from michikrug/invert-color-percent
Browse files Browse the repository at this point in the history
  • Loading branch information
michikrug authored Oct 10, 2023
2 parents 7113457 + 474d86e commit 8754c93
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Color { ga="Light" [ colorTemperatureRange="2000,9000" ] }
| **Device Type** | [Light](https://developers.home.google.com/cloud-to-cloud/guides/light) |
| **Supported Traits** | [OnOff](https://developers.home.google.com/cloud-to-cloud/traits/onoff), [ColorSetting](https://developers.home.google.com/cloud-to-cloud/traits/colorsetting), [Brightness](https://developers.home.google.com/cloud-to-cloud/traits/brightness) |
| **Supported Items** | Group as `SpecialColorLight` with the following members:<br>(optional) Number or Dimmer as `lightBrightness`<br>(optional) Number or Dimmer as `lightColorTemperature`<br>(optional) Color as `lightColor`<br>(optional) Switch as `lightPower` |
| **Configuration** | (optional) `colorUnit=percent/kelvin/mired`<br>(optional) `checkState=true/false`<br>(optional) `colorTemperatureRange="minK,maxK"`<br>_Hint: if you want to use `lightColorTemperature` you either need to set `colorUnit` to `kelvin` or `mired` or define a `colorTemperatureRange` as `colorUnit` defaults to `percent`_ |
| **Configuration** | (optional) `colorUnit=percent/kelvin/mired`<br>(optional) `checkState=true/false`<br>(optional) `colorTemperatureRange="minK,maxK"`<br>_Hint: if you want to use `lightColorTemperature`, you must either set `colorUnit` to `kelvin` or `mired` or define a `colorTemperatureRange`, because `colorUnit` defaults to `percent`_ |
```shell
Group lightGroup { ga="SpecialColorLight" [ colorUnit="kelvin", colorTemperatureRange="2000,9000" ] }
Expand Down
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 8754c93

Please sign in to comment.