Skip to content

Commit

Permalink
feat(trigger-state): conditions and custom outputs editable
Browse files Browse the repository at this point in the history
* conditions and custom outputs can now be editted after creation.
* Add data type to comparator-value for custom outputs

Closes #221
  • Loading branch information
zachowj committed Sep 26, 2020
1 parent 7d34d68 commit 358c909
Show file tree
Hide file tree
Showing 5 changed files with 510 additions and 582 deletions.
8 changes: 4 additions & 4 deletions docs/node/trigger-state.md
Expand Up @@ -9,10 +9,10 @@ An advanced version of `server:state-changed` node

## Configuration

### Constraints
### Conditions

This node has two default outputs "allowed" and "blocked". If all the
constraints are true the default message will be sent to the "allowed" output
conditions are true the default message will be sent to the "allowed" output
otherwise it will be sent to the "blocked" output.

**See Also:**
Expand All @@ -21,8 +21,8 @@ otherwise it will be sent to the "blocked" output.

### Custom Outputs

All the above constraints need to be true for any custom outputs to be sent,
having zero constraints is a valid option. Each custom output can send the
All the above conditions need to be true for any custom outputs to be sent,
having zero conditions is a valid option. Each custom output can send the
default message or a custom message. Also, each one can have its constraint
on whether or not to be sent.

Expand Down
16 changes: 16 additions & 0 deletions lib/ui/common.scss
Expand Up @@ -52,6 +52,22 @@
}
}

.editable-list-row {
margin-bottom: 4px;
}

#constraint-list {
min-width: 446px;

input {
width: 65%;
}
}

#output-list input {
width: 62%;
}

.ha-node-label-legacy {
fill: #fdfd96;
stroke-width: 0;
Expand Down
8 changes: 4 additions & 4 deletions nodes/trigger-state/trigger-state.js
Expand Up @@ -260,7 +260,7 @@ module.exports = function (RED) {
if (comparatorResult === false) {
this.debugToClient(
`constraint comparator: failed entity "${constraintTarget.entityid}" property "${propertyValue}" with value ${actualValue} failed "${comparatorType}" check against (${comparatorValueDatatype}) ${comparatorValue}`
); // eslint-disable-line
);
}

comparatorResults.push({
Expand Down Expand Up @@ -322,7 +322,7 @@ module.exports = function (RED) {
output.comparatorType,
output.comparatorValue,
result.actualValue,
output.comparatorValueDatatype,
output.comparatorValueDataType,
{
entity: eventMessage.event.new_state,
prevEntity: eventMessage.event.old_state,
Expand Down Expand Up @@ -384,8 +384,8 @@ module.exports = function (RED) {
// If comparator did not match
if (!comparatorMatched) {
this.debugToClient(
`output comparator failed: property "${output.comparatorPropertyValue}" with value ${actualValue} failed "${output.comparatorType}" check against ${output.comparatorValue}`
); // eslint-disable-line
`output comparator failed: property "${output.comparatorPropertyValue}" with value ${actualValue} failed "${output.comparatorType}" check against (${output.comparatorValueDataType}) ${output.comparatorValue}`
);
return null;
}

Expand Down
257 changes: 102 additions & 155 deletions nodes/trigger-state/ui-trigger-state.html
Expand Up @@ -2,6 +2,7 @@
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" />
<input type="hidden" id="node-input-outputs" />
</div>

<!-- Server -->
Expand All @@ -22,173 +23,21 @@
</div>

<div class="form-row">
<label for="node-input-state_type"
><i class="fa fa-tint"></i> State Type</label
>
<label for="node-input-state_type">
<i class="fa fa-tint"></i> State Type
</label>
<select type="text" id="node-input-state_type" style="width: auto">
<option value="str">String</option>
<option value="num">Number</option>
<option value="habool">Boolean</option>
</select>
</div>

<!-- -------------------------------------------------------------- -->
<!-- Add Custom Constraints -->
<!-- -------------------------------------------------------------- -->
<div class="form-row" id="add-constraint-container">
<h3>Add Constraints</h3>
<div>
<!-- Target Selection -->
<div class="form-row">
<!-- Type -->
<select
type="text"
id="constraint-target-type"
style="width: 140px"
>
<option value="this_entity">This Entity</option>
<option value="entity_id">Entity ID</option>
</select>

<!-- Value -->
<input
type="text"
id="constraint-target-value"
style="width: 62%"
disabled
/>
</div>

<!-- Property Selection -->
<div class="form-row">
<!-- Type -->
<select
type="text"
id="constraint-property-type"
style="width: 140px"
>
<option value="current_state">Current State</option>
<option value="previous_state">Previous State</option>
<option value="property">Property</option>
</select>

<!-- Value -->
<input
type="text"
id="constraint-property-value"
style="width: 62%"
disabled
/>
</div>

<!-- Comparator Selection -->
<div class="form-row">
<!-- Type -->
<select
type="text"
id="constraint-comparator-type"
style="width: 140px"
>
<option value="is">Is</option>
<option value="is_not">Is Not</option>

<option value=">">&gt;</option>
<option value=">=">&gt;=</option>
<option value="<">&lt;</option>
<option value="<=">&lt;=</option>

<option value="includes">Includes</option>
<option value="does_not_include">Does Not Include</option>
</select>

<!-- Value -->
<input type="text" id="constraint-comparator-value" />
</div>

<!-- Add Constraint Button -->
<button id="constraint-add-btn" style="width: 100%">
Add Constraint
</button>
</div>
</div>

<!-- Constraints List -->
<div class="form-row">
<ol id="constraint-list"></ol>
</div>

<!-- -------------------------------------------------------------- -->
<!-- Add Custom Outputs -->
<!-- -------------------------------------------------------------- -->
<div class="form-row" id="add-output-container">
<h3>Add Outputs</h3>
<div>
<div class="form-row">
<!-- Type -->
<select type="text" id="output-message-type" style="width: 140px">
<option value="default">Default Msg</option>
<option value="custom">Custom Msg</option>
<option value="payload">Custom Payload</option>
</select>

<input type="text" id="output-message-value" style="width: 62%" />
<input type="hidden" id="output-message-value-type" />
</div>

<!-- Output Comparator Selection -->
<div class="form-row">
<select
type="text"
id="output-comparator-property-type"
style="width: 140px"
>
<option value="always">Send Always</option>
<option value="current_state">If State</option>
<option value="previous_state">If Prev State</option>
<option value="property">If Property</option>
</select>

<input
type="text"
id="output-comparator-property-value"
style="width: 62%"
disabled
/>
</div>

<div class="form-row">
<!-- Type -->
<select
type="text"
id="output-comparator-type"
style="width: 140px"
disabled
>
<option value="is">Is</option>
<option value="is_not">Is Not</option>

<option value=">">&gt;</option>
<option value=">=">&gt;=</option>
<option value="<">&lt;</option>
<option value="<=">&lt;=</option>

<option value="includes">Includes</option>
<option value="does_not_include">Does Not Include</option>
</select>

<input
type="text"
id="output-comparator-value"
style="width: 62%"
disabled
/>
</div>

<!-- Add Output Button -->
<button id="output-add-btn" style="width: 100%">Add Output</button>
</div>
</div>

<!-- Output List -->
<div class="form-row">
<ol id="output-list"></ol>
Expand All @@ -203,3 +52,101 @@ <h3>Add Outputs</h3>
<input type="checkbox" id="node-input-debugenabled" />
<label for="node-input-debugenabled">Show Debug Information</label>
</div>

<div id="constraint-template" style="display: none">
<!-- Target Selection -->
<div class="editable-list-row">
<!-- Type -->
<select type="text" class="target-type" style="width: 140px">
<option value="this_entity">This Entity</option>
<option value="entity_id">Entity ID</option>
</select>

<!-- Value -->
<input type="text" class="target-value" disabled />
</div>
<!-- Property Selection -->
<div class="editable-list-row">
<!-- Type -->
<select type="text" class="property-type" style="width: 140px">
<option value="current_state">Current State</option>
<option value="previous_state">Previous State</option>
<option value="property">Property</option>
</select>

<!-- Value -->
<input type="text" class="property-value" disabled />
</div>

<!-- Comparator Selection -->
<div class="editable-list-row">
<!-- Type -->
<select type="text" class="comparator-type" style="width: 140px">
<option value="is">is</option>
<option value="is_not">is not</option>

<option value=">">&gt;</option>
<option value=">=">&gt;=</option>
<option value="<">&lt;</option>
<option value="<=">&lt;=</option>

<option value="includes">in</option>
<option value="does_not_include">not in</option>
</select>

<!-- Value -->
<input type="text" class="comparator-value" style="width: 65%" />
</div>
</div>

<div id="output-template" style="display: none">
<div class="editable-list-row">
<!-- Type -->
<select type="text" class="message-type" style="width: 140px">
<option value="default">Default Msg</option>
<option value="custom">Custom Msg</option>
<option value="payload">Custom Payload</option>
</select>

<input type="text" class="message-value" style="width: 62%" />
</div>

<!-- Output Comparator Selection -->
<div class="editable-list-row">
<select
type="text"
class="comparator-property-type"
style="width: 140px"
>
<option value="always">Send Always</option>
<option value="current_state">If State</option>
<option value="previous_state">If Prev State</option>
<option value="property">If Property</option>
</select>

<input type="text" class="comparator-property-value" disabled />
</div>

<div class="editable-list-row">
<!-- Type -->
<select
type="text"
class="comparator-type"
style="width: 140px"
disabled
>
<option value="is">is</option>
<option value="is_not">is not</option>

<option value=">">&gt;</option>
<option value=">=">&gt;=</option>
<option value="<">&lt;</option>
<option value="<=">&lt;=</option>

<option value="includes">in</option>
<option value="does_not_include">not in</option>
</select>

<input type="text" class="comparator-value" style="width: 62%" />
</div>
</div>

0 comments on commit 358c909

Please sign in to comment.