Skip to content

Commit

Permalink
Updated window-covering to use “stop” instead of “off”
Browse files Browse the repository at this point in the history
  • Loading branch information
lprhodes committed Apr 20, 2017
1 parent 7304dd2 commit 6345337
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ key | description
--- | -----------
open | A hex code string to be sent when the window-covering is requested to open.
close | A hex code string to be sent when the window-covering is requested to close.
off | A hex code string to be sent when the window-covering is turned off automatically. i.e. When disableAutomaticOff is set to false.
stop | A hex code string to be sent when the window-covering is stopped automatically.


### air-conditioner
Expand Down
34 changes: 17 additions & 17 deletions accessories/windowCovering.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {

const { config, data, log, name } = this;
const { initialDelay } = config;
const { off } = data;
const { stop } = data;

if (off && this.operationID ) {
if (stop && this.operationID ) {
log(`${name} setTargetPosition: cancel last operation`);
this.stop();
}
Expand All @@ -25,9 +25,9 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {

async performSetTargetPosition (hexData, previousValue) {
const { config, data, log, name } = this;
const { open, close, off } = data;
const { open, close, stop } = data;

if (off && this.operationID ) {
if (stop && this.operationID ) {
log(`${name} setTargetPosition: cancel last operation`);
this.stop();
}
Expand Down Expand Up @@ -73,13 +73,13 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {

async openOrClose ({ hexData, increments, previousValue, currentOperationID }) {
let { config, data, host, name, log } = this;
let { hold, percentageChangePerSend, interval, disableAutomaticOff, onDuration, onDurationOpen, onDurationClose, totalDurationOpen, totalDurationClose } = config;
const { off } = data;
let { hold, percentageChangePerSend, interval, disableAutomaticStop, onDuration, onDurationOpen, onDurationClose, totalDurationOpen, totalDurationClose } = config;
const { stop } = data;

if (interval === undefined) interval = 0.5;
if (hold === undefined) hold = true;
if (!percentageChangePerSend) percentageChangePerSend = 10;
if (disableAutomaticOff === undefined) disableAutomaticOff = true;
if (disableAutomaticStop === undefined) disableAutomaticStop = true;
if (!onDuration) onDuration = this.opening ? onDurationOpen : onDurationClose;
if (!onDuration) onDuration = 2;

Expand All @@ -102,13 +102,13 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {
const durationPerPercentage = fullOpenCloseTime / 100;
totalTime = durationPerPercentage * difference;

log(`${name} setTargetPosition: ${totalTime}s (${fullOpenCloseTime} / 100 * ${difference}) until auto-off ${currentOperationID}`);
log(`${name} setTargetPosition: ${totalTime}s (${fullOpenCloseTime} / 100 * ${difference}) until auto-stop ${currentOperationID}`);

} else {
const durationPerPercentage = onDuration / percentageChangePerSend;
totalTime = durationPerPercentage * difference;

log(`${name} setTargetPosition: ${totalTime}s (${onDuration} / ${percentageChangePerSend} * ${difference}) until auto-off ${currentOperationID}`);
log(`${name} setTargetPosition: ${totalTime}s (${onDuration} / ${percentageChangePerSend} * ${difference}) until auto-stop ${currentOperationID}`);
}


Expand All @@ -133,16 +133,16 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {
sendData({ host, hexData, log });
this.windowCoveringService.setCharacteristic(Characteristic.CurrentPosition, currentValue);

if (!disableAutomaticOff) {
log(`${name} setTargetPosition: waiting ${onDuration}s until auto-off ${currentOperationID}`);
if (!disableAutomaticStop) {
log(`${name} setTargetPosition: waiting ${onDuration}s until auto-stop ${currentOperationID}`);
await delayForDuration(onDuration);
if (currentOperationID !== this.operationID) return;

if (!off) throw new Error('An "off" hex code must be set if "disableAutomaticOff" is set to false.')
if (!stop) throw new Error('An "stop" hex code must be set if "disableAutomaticStop" is set to false.')
this.windowCoveringService.setCharacteristic(Characteristic.PositionState, Characteristic.PositionState.STOPPED);

log(`${name} setTargetPosition: auto-off`);
sendData({ host, hexData: off, log });
log(`${name} setTargetPosition: auto-stop`);
sendData({ host, hexData: stop, log });
}

log(`${name} setTargetPosition: waiting ${interval}s for next send ${currentOperationID}`);
Expand All @@ -155,7 +155,7 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {

stop () {
const { data, host, log, name } = this;
const { off } = data;
const { stop } = data;

if (this.autoStopTimeout) clearTimeout(this.autoStopTimeout)
if (this.updateCurrentPositionTimeout) clearTimeout(this.updateCurrentPositionTimeout)
Expand All @@ -165,8 +165,8 @@ class WindowCoveringAccessory extends BroadlinkRMAccessory {

this.windowCoveringService.setCharacteristic(Characteristic.PositionState, Characteristic.PositionState.STOPPED);

log(`${name} setTargetPosition: off`);
if (off) sendData({ host, hexData: off, log });
log(`${name} setTargetPosition: stop`);
if (stop) sendData({ host, hexData: stop, log });
}

updateCurrentPositionAtIntervals (currentOperationID) {
Expand Down
2 changes: 1 addition & 1 deletion config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"data":{
"open":"2600500000012...",
"close":"2600500000012...",
"off":"2600500000012..."
"stop":"2600500000012..."
}
}
]
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": "1.3.9",
"version": "1.4.0",
"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 6345337

Please sign in to comment.