Skip to content

Commit

Permalink
Prevent repeat sends of fan speed codes
Browse files Browse the repository at this point in the history
  • Loading branch information
lprhodes committed Mar 14, 2018
1 parent 4e9c82e commit 0796158
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion accessories/fan.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ class FanAccessory extends SwitchAccessory {
foundSpeeds.push(parts[1])
})

if (foundSpeeds.length === 0) return log(`${name} setFanSpeed: No fan speed hex codes provided.`)
if (foundSpeeds.length === 0) {

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

// Find speed closest to the one requested
const closest = foundSpeeds.reduce((prev, curr) => Math.abs(curr - state.fanSpeed) < Math.abs(prev - state.fanSpeed) ? curr : prev);
log(`${name} setFanSpeed: (closest: ${closest})`);

if (this.lastFanSpeed === closest) {
return;
}

this.lastFanSpeed = closest;

// Get the closest speed's hex data
hexData = data[`fanSpeed${closest}`];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-broadlink-rm",
"version": "3.0.2",
"version": "3.0.3",
"description": "Broadlink RM plugin (including the mini and pro) for homebridge: https://github.com/nfarina/homebridge",
"license": "ISC",
"keywords": [
Expand Down

0 comments on commit 0796158

Please sign in to comment.