Skip to content

Commit

Permalink
Support for multiple and repeat hex codes in the “window-covering” ac…
Browse files Browse the repository at this point in the history
…cessory.
  • Loading branch information
lprhodes committed Mar 14, 2018
1 parent 0796158 commit e7b50e5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
59 changes: 54 additions & 5 deletions accessories/windowCovering.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {
this.autoStopPromise.cancel();
this.autoStopPromise = null;
}

// Clear Multi-hex timeouts
if (this.intervalTimeoutPromise) {
this.intervalTimeoutPromise.cancel();
this.intervalTimeoutPromise = null;
}

if (this.pauseTimeoutPromise) {
this.pauseTimeoutPromise.cancel();
this.pauseTimeoutPromise = null;
}
}

// User requested a specific position or asked the window-covering to be open or closed
Expand Down Expand Up @@ -86,10 +97,6 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {
}

async openOrClose ({ hexData, previousValue }) {
await this.openOrCloseActual({ hexData, previousValue })
}

async openOrCloseActual ({ hexData, previousValue }) {
let { config, data, host, name, log, state, debug, serviceManager } = this;
let { totalDurationOpen, totalDurationClose } = config;
const { stop } = data;
Expand All @@ -98,7 +105,8 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {
serviceManager.setCharacteristic(Characteristic.PositionState, newPositionState);

log(`${name} setTargetPosition: currently ${state.currentPosition}%, moving to ${state.targetPosition}%`);
sendData({ host, hexData, log, name, debug });

this.performSend(hexData);

let difference = state.targetPosition - state.currentPosition
if (!state.opening) difference = -1 * difference;
Expand Down Expand Up @@ -200,6 +208,47 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {
});
}

async performSend (hexData) {
const { debug, config, host, log, name } = this;

if (typeof hexData === 'string') {
sendData({ host, hexData, log, name, debug });

return;
}

await catchDelayCancelError(async () => {
// Itterate through each hex config in the array
for (let index = 0; index < hexData.length; index++) {
const { pause } = hexData[index]

await this.performRepeatSend(hexData[index]);

if (pause) {
this.pauseTimeoutPromise = delayForDuration(pause);
await this.pauseTimeoutPromise;
}
}
});
}

async performRepeatSend (hexConfig) {
const { host, log, name, debug } = this;
let { data, interval, sendCount } = hexConfig;

interval = interval || 1;

// Itterate through each hex config in the array
for (let index = 0; index < sendCount; index++) {
sendData({ host, hexData: data, log, name, debug });

if (index < sendCount - 1) {
this.intervalTimeoutPromise = delayForDuration(interval);
await this.intervalTimeoutPromise;
}
}
}

setupServiceManager () {
const { data, log, name, serviceManagerType } = this;

Expand Down
21 changes: 21 additions & 0 deletions config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@
"close":"2600500000012...",
"stop":"2600500000012..."
}
},
{
"name":"Blind Multi",
"type":"window-covering",
"totalDurationOpen": 5,
"totalDurationClose": 2,
"data":{
"open":"OPEN_HEX...",
"close":[
{
"data": "CLOSE_HEX_1...",
"sendCount": 2,
"interval": 0.3,
"pause": 0.3
},
{
"data": "CLOSE_HEX_2..."
}
],
"stop":"STOP_HEX..."
}
}
]
}
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.3",
"version": "3.0.4",
"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 e7b50e5

Please sign in to comment.