Skip to content

Commit

Permalink
Hue dimmer repeat, see #368
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ebaauw committed Aug 19, 2018
1 parent 223d301 commit 709718e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/HuePlatform.js
Expand Up @@ -168,6 +168,9 @@ function HuePlatform (log, configJson, api) {
)
}
break
case 'huedimmerrepeat':
this.config.hueDimmerRepeat = !!value
break
case 'huemotiontemperaturehistory':
this.config.hueMotionTemperatureHistory = !!value
break
Expand Down
17 changes: 13 additions & 4 deletions lib/HueSensor.js
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 709718e

Please sign in to comment.