Skip to content

Commit

Permalink
feat(current-state): Added ability to block input overrides to config
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed May 31, 2019
1 parent d3751d6 commit 9d46441
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 13 additions & 4 deletions nodes/current-state/current-state.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
state_location: { value: "payload" },
override_payload: { value: "msg" }, // state location type
entity_location: { value: "data" },
override_data: { value: "msg" } // entity location types
override_data: { value: "msg" }, // entity location types
blockInputOverrides: { value: false }
},
oneditprepare: function() {
nodeVersion.check(this);
Expand Down Expand Up @@ -166,9 +167,14 @@
<input type="text" id="node-input-entity_location" />
</div>

<div class="form-row">
<input type="checkbox" id="node-input-override_topic" checked style="margin-left:105px;display:inline-block; width:auto; vertical-align:baseline;">&nbsp;
<label for="node-input-override_topic" style="width: auto;margin-right: 20px;">Override Topic</label>
<div class="form-row checkboxOption">
<input type="checkbox" id="node-input-override_topic">&nbsp;
<label for="node-input-override_topic">Override Topic</label>
</div>

<div class="form-row checkboxOption">
<input type="checkbox" id="node-input-blockInputOverrides">&nbsp;
<label for="node-input-blockInputOverrides">Block Input Overrides</label>
</div>
</script>

Expand Down Expand Up @@ -200,6 +206,9 @@ <h3>Configuration</h3>

<dt>Override Topic<span class="property-type">boolean</span></dt>
<dd>Write entity id to <code>msg.topic</code></dd>

<dt>Block Input Overrides<span class="property-type">boolean</span></dt>
<dd>Stop <code>msg.payload</code> values from overriding local config</dd>
</dl>

<h3>Outputs</h3>
Expand Down
8 changes: 6 additions & 2 deletions nodes/current-state/current-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = function(RED) {
entity_location: nodeDef => nodeDef.entity_location || 'data',
// entity location type
override_data: nodeDef =>
nodeDef.override_data !== false ? 'msg' : 'none'
nodeDef.override_data !== false ? 'msg' : 'none',
blockInputOverrides: {}
},
input: {
entity_id: {
Expand All @@ -39,7 +40,10 @@ module.exports = function(RED) {
/* eslint-disable camelcase */
async onInput({ parsedMessage, message }) {
const config = this.nodeConfig;
const entityId = parsedMessage.entity_id.value;
const entityId =
config.blockInputOverrides === true
? config.entity_id
: parsedMessage.entity_id.value;

if (config.server === null) {
this.node.error('No valid server selected.', message);
Expand Down

0 comments on commit 9d46441

Please sign in to comment.