Skip to content

Commit

Permalink
Support for resetting to a default fan speed each time a fan is turne…
Browse files Browse the repository at this point in the history
…d on (#503)

          "alwaysResetToDefaults": true,
          "defaultFanSpeed": 30,
  • Loading branch information
Luke Rhodes committed Jan 1, 2020
1 parent 451dec9 commit 024d341
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion accessories/fan.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,33 @@ const SwitchAccessory = require('./switch');
class FanAccessory extends SwitchAccessory {

async setSwitchState (hexData, previousValue) {
const { config, state, serviceManager } = this;

if (!this.state.switchState) {
this.lastFanSpeed = undefined;
}

// Reset the fan speed back to the default speed when turned off
if (this.state.switchState === false && config && config.alwaysResetToDefaults) {
this.setDefaults();
serviceManager.setCharacteristic(Characteristic.RotationSpeed, state.fanSpeed);
}

super.setSwitchState(hexData, previousValue);
}

setDefaults () {
super.setDefaults();

let { config, state } = this;

// Reset the fan speed back to the default speed when turned off
// This will also be called whenever homebridge is restarted
if (config && config.alwaysResetToDefaults) {
state.fanSpeed = (config.defaultFanSpeed !== undefined) ? config.defaultFanSpeed : 100;
}
}

async setFanSpeed (hexData) {
const { data, host, log, state, name, debug} = this;

Expand All @@ -30,7 +50,6 @@ class FanAccessory extends SwitchAccessory {
})

if (foundSpeeds.length === 0) {

return log(`${name} setFanSpeed: No fan speed hex codes provided.`)
}

Expand Down

0 comments on commit 024d341

Please sign in to comment.