node-red-contrib-freya-nodes 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,8 +23,7 @@
23
23
  name: {value:""},
24
24
  interval: {value: 60, required: true, validate: RED.validators.number()},
25
25
  duration: {value: 30, required: true, validate: RED.validators.number()},
26
- tickInterval: {value: 60, required: true, validate: function(v) { return RED.validators.number()(v) && parseInt(v) >= 1; }},
27
- nightDisable: {value: false}
26
+ tickInterval: {value: 60, required: true, validate: function(v) { return RED.validators.number()(v) && parseInt(v) >= 1; }}
28
27
  },
29
28
  inputs:1,
30
29
  outputs:2,
@@ -56,11 +55,6 @@
56
55
  <label for="node-input-tickInterval"><i class="fa fa-clock-o"></i> Tick Interval (seconds)</label>
57
56
  <input type="number" id="node-input-tickInterval" placeholder="60" step="1" min="1">
58
57
  </div>
59
- <hr/>
60
- <div class="form-row">
61
- <input type="checkbox" id="node-input-nightDisable" style="display:inline-block; width:auto; vertical-align:top;">
62
- <label for="node-input-nightDisable" style="width:auto;"><i class="fa fa-moon-o"></i> Disable precipitation at night</label>
63
- </div>
64
58
  </script>
65
59
 
66
60
  <script type="text/html" data-help-name="precipitation controller">
@@ -70,14 +64,19 @@
70
64
  <h3>Input</h3>
71
65
  <dl class="message-properties">
72
66
  <dt>msg.topic = "interval" <span class="property-type">number</span></dt>
73
- <dd><code>msg.payload</code> sets the precipitation interval in milliseconds, overriding the configured default</dd>
67
+ <dd><code>msg.payload</code> sets the precipitation interval in minutes, overriding the configured default</dd>
74
68
 
75
69
  <dt>msg.topic = "duration" <span class="property-type">number</span></dt>
76
- <dd><code>msg.payload</code> sets the pump duration in milliseconds, overriding the configured default</dd>
70
+ <dd><code>msg.payload</code> sets the pump duration in seconds, overriding the configured default</dd>
71
+
72
+ <dt>msg.topic = "nightDisable" <span class="property-type">boolean</span></dt>
73
+ <dd><code>msg.payload</code> enables (<code>true</code>) or disables (<code>false</code>) the
74
+ nighttime pause feature at runtime. Defaults to <code>false</code> on deploy.
75
+ Switching from <code>true</code> to <code>false</code> while paused resumes normal operation immediately.</dd>
77
76
 
78
77
  <dt>msg.topic = "night" <span class="property-type">boolean</span></dt>
79
78
  <dd><code>msg.payload</code> signals nighttime (<code>true</code>) or daytime (<code>false</code>).
80
- Only effective when the nighttime disable toggle is enabled in the editor.
79
+ Only effective when nighttime disable has been enabled via the <code>nightDisable</code> topic.
81
80
  During nighttime no new precipitation events are started. If the pump is already active
82
81
  when night begins, the current cycle finishes normally.</dd>
83
82
  </dl>
@@ -110,11 +109,12 @@
110
109
  to prevent it from getting stuck on.</p>
111
110
 
112
111
  <h3>Nighttime Disable</h3>
113
- <p>When the nighttime disable toggle is enabled, the node tracks a night/day state
114
- updated via <code>msg.topic = "night"</code>. During nighttime no new precipitation events
115
- are started. If the pump is already active when night begins, the current cycle is
116
- allowed to finish normally. When the toggle is off, night messages are ignored and
117
- precipitation runs 24/7.</p>
112
+ <p>The nighttime disable feature is controlled at runtime via <code>msg.topic = "nightDisable"</code>.
113
+ On deploy it defaults to off (precipitation runs 24/7). When enabled, the node tracks a
114
+ night/day state updated via <code>msg.topic = "night"</code>. During nighttime no new
115
+ precipitation events are started. If the pump is already active when night begins, the
116
+ current cycle is allowed to finish normally. Switching nighttime disable off while paused
117
+ causes the node to resume normal tick evaluation immediately.</p>
118
118
 
119
119
  <h3>Status Messages</h3>
120
120
  <p>Status messages are emitted on output 2 only when the state changes:</p>
@@ -130,7 +130,6 @@
130
130
  <li><strong>Interval:</strong> Time between precipitation events in minutes (default: 60)</li>
131
131
  <li><strong>Duration:</strong> How long the pump runs per event in seconds (default: 30)</li>
132
132
  <li><strong>Tick Interval:</strong> How often to evaluate whether precipitation is due in seconds (default: 60)</li>
133
- <li><strong>Disable precipitation at night:</strong> When enabled, precipitation is paused during nighttime</li>
134
133
  </ul>
135
134
 
136
135
  <h3>Node Status</h3>
@@ -17,12 +17,12 @@ const precipitationController = (RED) => {
17
17
  this.interval = parseFloat(config.interval) || 60;
18
18
  this.duration = parseFloat(config.duration) || 30;
19
19
  this.tickInterval = parseInt(config.tickInterval) || 60;
20
- this.nightDisable = config.nightDisable || false;
21
20
  const state = {
22
21
  lastPrecipitation: null,
23
22
  pumpActive: false,
24
23
  intervalMs: (node.interval || 60) * 60000,
25
24
  durationMs: (node.duration || 30) * 1000,
25
+ nightDisable: false,
26
26
  night: false,
27
27
  previousState: null
28
28
  };
@@ -44,7 +44,7 @@ const precipitationController = (RED) => {
44
44
  if (state.pumpActive) {
45
45
  return;
46
46
  }
47
- if (node.nightDisable && state.night) {
47
+ if (state.nightDisable && state.night) {
48
48
  node.status({ fill: 'grey', shape: 'ring', text: 'paused (night)' });
49
49
  emitStatus('paused');
50
50
  return;
@@ -91,19 +91,25 @@ const precipitationController = (RED) => {
91
91
  };
92
92
  node.on('input', (msg, send, done) => {
93
93
  if (msg.topic === 'interval' && typeof msg.payload === 'number' && isFinite(msg.payload)) {
94
- state.intervalMs = msg.payload;
95
- node.log(`Interval updated: ${msg.payload}ms`);
94
+ state.intervalMs = msg.payload * 60000;
95
+ node.log(`Interval updated: ${msg.payload} minutes`);
96
96
  }
97
97
  else if (msg.topic === 'duration' && typeof msg.payload === 'number' && isFinite(msg.payload)) {
98
- state.durationMs = msg.payload;
99
- node.log(`Duration updated: ${msg.payload}ms`);
98
+ state.durationMs = msg.payload * 1000;
99
+ node.log(`Duration updated: ${msg.payload} seconds`);
100
100
  }
101
- else if (msg.topic === 'night' && typeof msg.payload === 'boolean') {
102
- if (node.nightDisable) {
103
- state.night = msg.payload;
104
- node.log(`Night state updated: ${msg.payload}`);
101
+ else if (msg.topic === 'nightDisable' && typeof msg.payload === 'boolean') {
102
+ const wasEnabled = state.nightDisable;
103
+ state.nightDisable = msg.payload;
104
+ node.log(`Nighttime disable updated: ${msg.payload}`);
105
+ if (wasEnabled && !msg.payload && state.night && !state.pumpActive) {
106
+ evaluatePrecipitation();
105
107
  }
106
108
  }
109
+ else if (msg.topic === 'night' && typeof msg.payload === 'boolean') {
110
+ state.night = msg.payload;
111
+ node.log(`Night state updated: ${msg.payload}`);
112
+ }
107
113
  done === null || done === void 0 ? void 0 : done();
108
114
  });
109
115
  node.on('close', (done) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-freya-nodes",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Custom nodes for Freya Vivarium Control System",
5
5
  "author": "Sanne 'SpuQ' Santens",
6
6
  "license": "GPL-3.0",