Skip to content

Commit

Permalink
feat(wait-until): Added ability to check against current state
Browse files Browse the repository at this point in the history
Ability to check against current state and not wait for the state to
change
  • Loading branch information
zachowj committed Feb 12, 2019
1 parent 8bd6e42 commit c6343a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 12 additions & 1 deletion nodes/wait-until/wait-until.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
timeout: { value: 0 },
timeoutUnits: { value: "seconds" },
entityLocation: { value: "data" },
entityLocationType: { value: "none" }
entityLocationType: { value: "none" },
checkCurrentState: { value: true }
},
oneditprepare: function() {
const $entityIdField = $("#node-input-entityId");
Expand Down Expand Up @@ -91,6 +92,11 @@
minLength: 0
});
}

if (node.checkCurrentState === undefined) {
$("#node-input-checkCurrentState").prop("checked", false);
}

const defaultTypes = ["str", "num", "bool", "re"];
$("#node-input-value")
.typedInput({
Expand Down Expand Up @@ -192,6 +198,11 @@
<input type="hidden" id="node-input-entityLocationType" />
<input type="text" id="node-input-entityLocation" />
</div>

<div class="form-row">
<input type="checkbox" id="node-input-checkCurrentState" checked style="margin-left:105px;display:inline-block; width:auto; vertical-align:baseline;">&nbsp;
<label for="node-input-checkCurrentState" style="width: auto;margin-right: 20px;">Check against current state</label>
</div>
</script>

<script type="text/x-red" data-help-name="ha-wait-until">
Expand Down
13 changes: 11 additions & 2 deletions nodes/wait-until/wait-until.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = function(RED) {
timeout: {},
timeoutUnits: {},
entityLocation: {},
entityLocationType: {}
entityLocationType: {},
checkCurrentState: {}
}
};

Expand Down Expand Up @@ -90,7 +91,7 @@ module.exports = function(RED) {
}
}

onInput({ parsedMessage, message }) {
async onInput({ parsedMessage, message }) {
const node = this;
const config = node.nodeConfig;

Expand Down Expand Up @@ -167,6 +168,14 @@ module.exports = function(RED) {
}, node.timeout);
}
node.status({ fill: 'blue', text: statusText });

if (config.checkCurrentState === true) {
const currentState = await this.nodeConfig.server.homeAssistant.getStates(
config.entityId
);

node.onEntityChange({ event: { new_state: currentState } });
}
}

timeoutStatus(milliseconds = 0) {
Expand Down

0 comments on commit c6343a9

Please sign in to comment.