node-red-contrib-simple-gate
Advanced tools
Comparing version 0.1.7 to 0.2.0
30
gate.js
@@ -21,2 +21,3 @@ /** | ||
const closedStatus = {fill:'red',shape:'ring',text:'closed'}; | ||
var status; | ||
// Copy configuration items | ||
@@ -29,16 +30,18 @@ this.controlTopic = config.controlTopic.toLowerCase(); | ||
this.defaultState = config.defaultState.toLowerCase(); | ||
this.persist = config.persist; | ||
// Save "this" object | ||
var node = this | ||
// Display gate status | ||
var state = node.defaultState; | ||
if (state === 'open') { | ||
node.status (openStatus); | ||
} else { | ||
node.status (closedStatus); | ||
var context = node.context(); | ||
var persist = node.persist; | ||
var state = context.get('state'); //debug | ||
if (!persist || typeof state === 'undefined') { | ||
state = node.defaultState; | ||
} | ||
context.set('state',state); | ||
// Show status | ||
status = (state === 'open') ? openStatus:closedStatus; | ||
node.status(status); | ||
// Process inputs | ||
node.on('input', function(msg) { | ||
var context = node.context(); | ||
// Copy configuration items (moved) | ||
var state = context.get('state') || node.defaultState; | ||
state = context.get('state'); | ||
// Change state | ||
@@ -69,8 +72,5 @@ if (msg.topic !== undefined && msg.topic.toLowerCase() === node.controlTopic) { | ||
context.set('state',state); | ||
// Show status | ||
if (state === 'open') { | ||
node.status (openStatus); | ||
} else { | ||
node.status (closedStatus); | ||
} | ||
// Show status | ||
status = (state === 'open') ? openStatus:closedStatus; | ||
node.status(status); | ||
node.send(null); | ||
@@ -77,0 +77,0 @@ } |
{ | ||
"name" : "node-red-contrib-simple-gate", | ||
"version" : "0.1.7", | ||
"version" : "0.2.0", | ||
"description" : "A gate node for node-RED", | ||
@@ -5,0 +5,0 @@ "license" : "Apache-2.0", |
@@ -18,3 +18,3 @@ # node-red-contrib-simple-gate | ||
When first deployed or after a `default` command, the gate is in the user-selected state defined by `Default State`. | ||
When first deployed or after a `default` command, the gate is in the user-selected state defined by `Default State` (see below regarding persistence). | ||
@@ -25,2 +25,5 @@ | ||
## State persistence | ||
By default, the node enters the `Default State` on startup, either when first deployed in the editor, re-deployed as part of a modified flow or entire workspace, or when Node-RED is restarted by the user or by a system service. The user can, however, select the `Restore from saved state` option (checkbox) in the edit dialog. Then, if a persistent form of context storage has been enabled in the Node-RED `settings.js` file, the node will attempt to enter the state last saved in the node context and will use the `Default State` only if no saved state is available. | ||
## Examples | ||
@@ -27,0 +30,0 @@ This flow demonstrates the basic operation of the `gate` node and the commands that can be used to change its state. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
245173
41