From 0796158ddf7201e05656705cf1028261faa3e8d4 Mon Sep 17 00:00:00 2001 From: Luke Rhodes Date: Wed, 14 Mar 2018 12:20:14 +1100 Subject: [PATCH] Prevent repeat sends of fan speed codes --- accessories/fan.js | 11 ++++++++++- package.json | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/accessories/fan.js b/accessories/fan.js index eccf587e..6d656cad 100644 --- a/accessories/fan.js +++ b/accessories/fan.js @@ -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}`]; diff --git a/package.json b/package.json index 3929ccbc..433bfb42 100644 --- a/package.json +++ b/package.json @@ -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": [