Skip to content

Commit

Permalink
Repeats, custom switches, up/down arrow double click fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rnilssoncx committed Jan 18, 2022
1 parent d484f37 commit 1c56cd1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ The number after `DEVICE` is the ID of the Pico remote you just pressed.
"name": "Home Theater Pico",
"pico": [11,31],
"type": "custom",
"buttons": [2,4]
"buttons": [2,4,5],
"repeat": [2,4]
}
]
}
Expand All @@ -75,6 +76,7 @@ The number after `DEVICE` is the ID of the Pico remote you just pressed.

* `name`: Name of the remote as it will appear in HomeKit
* `pico`: One or more Pico Remotes that will trigger the Homekit button
* `repeat`: (optional) Buttons to enable for repeating long press
* `type`:
* `PJ2-2B`: Two buton Pico (previously `simple` - on/off
* `PJ2-2BRL`: Four button Pico (previously `dimmer`) - on/brighten/dim/off
Expand All @@ -100,7 +102,13 @@ The number after `DEVICE` is the ID of the Pico remote you just pressed.
* `monitor`: Show Lutron commands sent and received on bus
* `full`: Show all bus and keep alive activity

* `clicktime`: The timeout for detecting a doubleclick in milliseconds. (default: 500)
* `clicktime`: The timeout for detecting a doubleclick in milliseconds. (default: `500`)

* `slowbuttons`: The up and down buttons on remotes can repeat when directly paired with a Lutron switch. I believe they already have a built in delay because of this capability. This makes these two buttons not capable of a double click with the default clicktime. This setting allows you to list out buttons you want extra time alloted to correct for this. (default: `[5,6]`)

* `slowextra`: This sets the additional time added to the buttons listed in `slowbuttons`. (default: `250`)

* `repeattime`: The delay for repeating long presses in milliseconds. (default: `500`)

* `longname`: If you'd like the name of the switch added to the function (`Dining Room Single Press` instead of `Single Press`) set this to `true`. For normal installations this should not be needed. (default: `false`)

Expand Down
8 changes: 8 additions & 0 deletions accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ class PicoRemote {
this.name = sw.name;
this.type = sw.type;
this.custom_buttons = sw.buttons || [];
this.repeat = sw.repeat || [];
if (!Array.isArray(this.repeat)) {
this.repeat = [this.repeat]
}
this.version = version;
this.longname = longname;
this.buttons = {};
}

repeatTime(button) {
return this.repeat.includes(parseInt(button))
}

getServices() {
let services = [];
let index = 1;
Expand Down
32 changes: 25 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Pico {
this.log(`${platformPrettyName} Plugin Loaded - Version ${version}`);
this.api = api;
this.clickTime = config.clicktime || 500;
this.slowButtons = config.slowbuttons || [5,6];
this.slowExtra = config.slowextra || 250;
this.repeatTime = config.repeattime || 500;
if (config.quiet) {
this.log('"quiet" config setting is deprecated, switch to "buslog"');
}
Expand Down Expand Up @@ -69,7 +72,12 @@ class Pico {
if (this.servers[event.host][event.device]) {
let eventKey = `${event.host} ${event.device} ${event.button}`
if (!this.clickProcessor[eventKey]) {
this.clickProcessor[eventKey] = new Click(event, this.clickTime, this.log, this.clickHandler.bind(this));
let clickTime = this.clickTime
if (this.slowButtons.includes(parseInt(event.button))) {
clickTime += this.slowExtra
}
this.clickProcessor[eventKey] = new Click(event, clickTime, this.repeatTime, this.log,
this.servers[event.host][event.device].repeatTime(event.button), this.clickHandler.bind(this));
} else {
this.clickProcessor[eventKey].click(event);
}
Expand All @@ -82,15 +90,17 @@ class Pico {
}

class Click {
constructor(event, doubleClickTime, log, callback) {
constructor(event, doubleClickTime, repeatTime, log, repeat, callback) {
this.host = event.host
this.device = event.device
this.button = event.button
this.doubleClickTime = doubleClickTime
this.repeatTime = repeatTime
this.log = log
this.repeat = repeat
this.callback = callback
this.log(`[${this.host}] Device ${this.device} Button ${this.button} - Created tracker`)

this.repeating = false
this.log(`[${this.host}] Device ${this.device} Button ${this.button} Repeat ${this.repeat} Click ${doubleClickTime} - Created tracker`)
this.click(event)
}

Expand All @@ -111,8 +121,8 @@ class Click {
}
}

_setTimer() {
this.timer = setTimeout(this._finished.bind(this), this.doubleClickTime)
_setTimer(milliseconds = this.doubleClickTime) {
this.timer = setTimeout(this._finished.bind(this), milliseconds)
this.ups = 0
}

Expand All @@ -130,9 +140,17 @@ class Click {
event.click = 1
} else if (this.ups == 0) {
event.click = 2
if (this.repeat) {
this.repeating = true
this._setTimer(this.repeatTime)
}
} else {
event.click = 0
}
this.callback(event)
if (!this.repeating || (this.repeating && event.click == 2)) {
this.callback(event)
} else {
this.repeating = false
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-pico",
"version": "1.1.1-beta.0",
"version": "1.2",
"description": "A HomeBridge plugin to expose Lutron Pico Remotes",
"funding": {
"type": "paypal",
Expand Down

0 comments on commit 1c56cd1

Please sign in to comment.