From 709718ea939cc1714349966a544755af46cae752 Mon Sep 17 00:00:00 2001 From: ebaauw Date: Sun, 19 Aug 2018 13:19:30 +0200 Subject: [PATCH] Hue dimmer repeat, see #368 Experimental support for repeat setting on the Hue dimmer switch. When setting `"hueDimmerRepeat": true` in config.json, the Hue dimmer switch _Dim Up_ and _Dim Down_ buttons continuously fire HomeKit _Short Press_ events while held. --- lib/HuePlatform.js | 3 +++ lib/HueSensor.js | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/HuePlatform.js b/lib/HuePlatform.js index 7616617a..c7af329b 100644 --- a/lib/HuePlatform.js +++ b/lib/HuePlatform.js @@ -168,6 +168,9 @@ function HuePlatform (log, configJson, api) { ) } break + case 'huedimmerrepeat': + this.config.hueDimmerRepeat = !!value + break case 'huemotiontemperaturehistory': this.config.hueMotionTemperatureHistory = !!value break diff --git a/lib/HueSensor.js b/lib/HueSensor.js index b04c16eb..d3394abe 100644 --- a/lib/HueSensor.js +++ b/lib/HueSensor.js @@ -129,7 +129,7 @@ const DROP = 8 // As homebridge-hue polls the Hue bridge, not all dimmer switch buttonevents // are received reliably. Consequently, we only issue one HomeKit change per // Press/Hold/Release event series. -function hkZLLSwitchAction (value, oldValue) { +function hkZLLSwitchAction (value, oldValue, repeat = false) { const button = Math.floor(value / 1000) const oldButton = Math.floor(oldValue / 1000) const event = value % 1000 @@ -142,6 +142,9 @@ function hkZLLSwitchAction (value, oldValue) { return Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS case HOLD: case LONG_RELEASE: + if (repeat && (button === 2 || button === 3)) { + return Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS + } if (button === oldButton && oldEvent === HOLD) { // Already issued action on previous Hold. return null @@ -238,8 +241,14 @@ function HueSensor (accessory, id, obj) { // 1.2 - Hue wireless dimmer switch this.createLabel(Characteristic.ServiceLabelNamespace.ARABIC_NUMERALS) this.createButton(1, 'On', SINGLE_LONG) - this.createButton(2, 'Dim Up', SINGLE_LONG) - this.createButton(3, 'Dim Down', SINGLE_LONG) + if (this.bridge.platform.config.hueDimmerRepeat) { + this.repeat = true + this.createButton(2, 'Dim Up', SINGLE) + this.createButton(3, 'Dim Down', SINGLE) + } else { + this.createButton(2, 'Dim Up', SINGLE_LONG) + this.createButton(3, 'Dim Down', SINGLE_LONG) + } this.createButton(4, 'Off', SINGLE_LONG) this.type = { key: 'buttonevent', @@ -1308,7 +1317,7 @@ HueSensor.prototype.checkButtonevent = function ( ) const buttonIndex = this.type.homekitValue(buttonevent) const action = this.type.homekitAction( - buttonevent, this.obj.state.buttonevent + buttonevent, this.obj.state.buttonevent, this.repeat ) this.obj.state.buttonevent = buttonevent if (