From 7f6191783393229721dc013b74a6ba316892b9a8 Mon Sep 17 00:00:00 2001 From: Matt Schmitt Date: Tue, 13 Feb 2018 22:24:46 -0500 Subject: [PATCH] Get fan rotation speed on event change --- accessories/fan.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/accessories/fan.js b/accessories/fan.js index 09c41ec..8b17edf 100644 --- a/accessories/fan.js +++ b/accessories/fan.js @@ -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) {