Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #292 from home-assistant/get-fan-speed-on-event
Browse files Browse the repository at this point in the history
Get fan rotation speed on event change
  • Loading branch information
schmittx authored Feb 14, 2018
2 parents 1cd2beb + 7f61917 commit 3449ec3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions accessories/fan.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ HomeAssistantFan.prototype = {
if (newState.state) {
this.fanService.getCharacteristic(Characteristic.On)
.setValue(newState.state === 'on', null, 'internal');

if (newState.state === 'on') {
let speed;
if (newState.attributes.speed_list) {
var speedList = newState.attributes.speed_list;
if (speedList.length > 2) {
speed = speedList.indexOf(newState.attributes.speed);
}
} else {
switch (newState.attributes.speed) {
case 'low':
speed = 25;
break;
case 'medium':
speed = 50;
break;
case 'high':
speed = 100;
break;
default:
speed = 0;
}
}
this.fanService.getCharacteristic(Characteristic.RotationSpeed)
.setValue(speed, null, 'internal');
}
}
},
getPowerState(callback) {
Expand Down

0 comments on commit 3449ec3

Please sign in to comment.