Skip to content

Commit

Permalink
Adjust Fan to use supportsFanSpeedPercent option
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Krug <[email protected]>
  • Loading branch information
michikrug committed Sep 11, 2023
1 parent 355692f commit 6178cde
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Player transportItem (tvGroup) { ga="tvTransport" }
| **Device Type** | [Fan](https://developers.home.google.com/cloud-to-cloud/guides/fan), [Hood](https://developers.home.google.com/cloud-to-cloud/guides/hood), [AirPurifier](https://developers.home.google.com/cloud-to-cloud/guides/airpurifier) |
| **Supported Traits** | [OnOff](https://developers.home.google.com/cloud-to-cloud/traits/OnOff), [FanSpeed](https://developers.home.google.com/cloud-to-cloud/traits/fanspeed) (depending on used item type) |
| **Supported Items** | Switch (no speed control), Dimmer |
| **Configuration** | (optional) `checkState=true/false`<br>(optional) `speeds="0=away:zero,50=default:standard:one,100=high:two"`<br>(optional) `lang="en"`<br>(optional) `ordered=true/false`<br>_Hint: if you are using a Dimmer then `speeds` is required_ |
| **Configuration** | (optional) `checkState=true/false`<br>(optional) `speeds="0=away:zero,50=default:standard:one,100=high:two"`<br>(optional) `lang="en"`<br>(optional) `ordered=true/false` |
Fans (and similar device types, like AirPurifier or Hood) support the `FanSpeed` trait.
If you do not specify the `speeds` option, Google will use and expect percentage values for the fan speed.
Expand Down
4 changes: 3 additions & 1 deletion functions/devices/fan.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Fan extends DefaultDevice {
static getAttributes(item) {
const config = this.getConfig(item);
if (!config || !config.speeds) {
return {};
return {
supportsFanSpeedPercent: true
};
}
const attributes = {
availableFanSpeeds: {
Expand Down
4 changes: 3 additions & 1 deletion tests/devices/fan.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ describe('Fan Device', () => {
}
}
};
expect(Device.getAttributes(item)).toStrictEqual({});
expect(Device.getAttributes(item)).toStrictEqual({
supportsFanSpeedPercent: true
});
});

test('getAttributes speeds', () => {
Expand Down

0 comments on commit 6178cde

Please sign in to comment.