Просмотр исходного кода

Update to help style guide.

add input temperature payload as string.
add input topic as undefined.
Luigi Cisana лет назад: 6
Родитель
Сommit
e2d64cb3f5
3 измененных файлов с 137 добавлено и 90 удалено
  1. 1 1
      package.json
  2. 60 13
      ramp-thermostat/ramp-thermostat.html
  3. 76 76
      ramp-thermostat/ramp-thermostat.js

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
     "name"         : "node-red-contrib-ramp-thermostat",
-    "version"      : "0.3.4",
+    "version"      : "1.0.0",
     "description"  : "A Node-RED node that emulates a thermostat",
     "dependencies": {
     },

+ 60 - 13
ramp-thermostat/ramp-thermostat.html

@@ -22,22 +22,68 @@
 <script type="text/x-red" data-help-name="ramp-thermostat">
     <p>A node that emulates a thermostat.</p>
     <p>The ramp-thermostat controls an actuator depending on the current input temperature and the target temperature.</p>
-    <p>The target temperature is defined by a profile that
+        
+    <h3>Inputs</h3>
+      <dl class="message-properties">
+        <dt>payload
+            <span class="property-type">number</span>
+        </dt>
+        <dd> current temperature</dd>
+        <dt class="optional">topic <span class="property-type">string</span></dt>
+        <dd> setCurrent (or undefined)</dd>
+      </dl>
+      <dl class="message-properties">
+        <dt>payload
+            <span class="property-type">number</span>
+        </dt>
+        <dd> target temperature</dd>
+        <dt class="optional">topic <span class="property-type">string</span></dt>
+        <dd> setTarget</dd>
+      </dl>
+      <dl class="message-properties">
+        <dt>payload
+            <span class="property-type">string</span>
+        </dt>
+        <dd> profile name</dd>
+        <dt class="optional">topic <span class="property-type">string</span></dt>
+        <dd> setProfile</dd>
+      </dl>
+       <dl class="message-properties">
+        <dt>payload
+            <span class="property-type">object</span>
+        </dt>
+        <dd> JSON e.g. {"name":"myGreatProfile","points":{"00:00":16.0,"08:00":20.0,
+        "20:00":20.0,"24:00":16.0}}</dd>
+        <dt class="optional">topic <span class="property-type">string</span></dt>
+        <dd> setProfile</dd>
+      </dl>     
+    <h3>Outputs</h3>
+      <ol class="node-ports">
+         <li>State
+             <dl class="message-properties">
+                 <dt>payload <span class="property-type">boolean</span></dt>
+                 <dd>the state of the thermostat.</dd>
+             </dl>
+         </li>
+         <li>Current Temperature
+             <dl class="message-properties">
+                 <dt>payload <span class="property-type">number</span></dt>
+                 <dd>the current temperature.</dd>
+             </dl>
+         </li>
+         <li>Target Temperature
+             <dl class="message-properties">
+                 <dt>payload <span class="property-type">number</span></dt>
+                 <dd>the actual target temperature.</dd>
+             </dl>
+         </li>
+      </ol>
+     
+    <h3>Details</h3>
+    <p>The target temperature is defined by a profile that 
     provides the value depending on the current time <code>00:00-24:00</code>.
     The profile consists of several points whose connections build a sequence of lines.
     The switching moment can be optimized by defining a gradient line like a <code>ramp</code>.</p>
-    <p>Input settings at runtime:</p>
-      <ul>
-        <li>msg.topic: setTarget, msg.payload: number</li>
-        <li>msg.topic: setProfile, msg.payload: profile-name</li>
-      </ul>
-
-    <p>The node provides 3 outputs:</p>
-      <ul>
-        <li><code>state (boolean)</code></li>
-        <li><code>current temperature</code></li>
-        <li><code>target temperature</code></li>
-      </ul>
 </script>
 
 <script type="text/javascript">
@@ -52,6 +98,7 @@
         },
         inputs:1,
         outputs:3,
+        outputLabels: ["state","current temperature","target temperature"],
         icon: "trigger.png",
         label: function() {
             return this.name||"ramp-thermostat";

+ 76 - 76
ramp-thermostat/ramp-thermostat.js

@@ -61,90 +61,90 @@ module.exports = function(RED) {
       if (typeof msg.payload === "undefined") {
         this.warn("msg.payload undefined"); 
       } else { 
-        if(typeof msg.topic === "undefined") {
-          this.warn("msg.topic undefined");
-        } else {
-          switch (msg.topic) {
-            case "setCurrent":
-            case "":
-              if (typeof msg.payload !== "number") {
-                this.warn("Non numeric input");            
+        switch (msg.topic) {
+          case "setCurrent":
+          case "":
+          case undefined:
+            if (typeof msg.payload === "string") {
+              msg.payload = parseFloat(msg.payload);
+            }
+            if (isNaN(msg.payload)) {
+              this.warn("Non numeric input");            
+            } else {
+              result = this.getState(msg.payload, this.profile);
+              if (result.state !== null) {
+                msg1.payload = result.state;
               } else {
-                result = this.getState(msg.payload, this.profile);
-                if (result.state !== null) {
-                  msg1.payload = result.state;
-                } else {
-                  msg1 = null;
-                }
-                msg2.payload = msg.payload;
-                msg3.payload = result.target;
-                this.send([msg1, msg2, msg3]);
-                this.current_status = result.status;
-                this.status(this.current_status);
-              }
-              break;
-              
-            case "setTarget":
-              result = setTarget(msg.payload);
-              
-              if (result.isValid) {
-                this.profile = result.profile;
-                globalContext.set(node_name, this.profile);
-                this.current_status = result.status;
-                this.status(this.current_status); 
+                msg1 = null;
               }
-              break;
+              msg2.payload = msg.payload;
+              msg3.payload = result.target;
+              this.send([msg1, msg2, msg3]);
+              this.current_status = result.status;
+              this.status(this.current_status);
+            }
+            break;
+            
+          case "setTarget":
+            result = setTarget(msg.payload);
+            
+            if (result.isValid) {
+              this.profile = result.profile;
+              globalContext.set(node_name, this.profile);
+              this.current_status = result.status;
+              this.status(this.current_status); 
+            }
+            break;
+          
+          case "setProfile":
+            //this.warn(JSON.stringify(msg.payload));
+            result = setProfile(msg.payload);
             
-            case "setProfile":
-              //this.warn(JSON.stringify(msg.payload));
-              result = setProfile(msg.payload);
-              
-              if (result.found) {
-                this.profile = result.profile;
-                if (this.profile.name === "default") {
-                  this.profile = RED.nodes.getNode(config.profile);
-                  this.points_result = getPoints(this.profile.n);
-                  if (this.points_result.isValid) {
-                    this.profile.points = this.points_result.points;
-                  } else {
-                    this.warn("Profile temperature not numeric.");
-                  }         
-                  //this.warn("default "+this.profile.name);
-                  this.current_status = {fill:"green",shape:"dot",text:"profile set to default ("+this.profile.name+")"};
+            if (result.found) {
+              this.profile = result.profile;
+              if (this.profile.name === "default") {
+                this.profile = RED.nodes.getNode(config.profile);
+                this.points_result = getPoints(this.profile.n);
+                if (this.points_result.isValid) {
+                  this.profile.points = this.points_result.points;
                 } else {
-                  this.current_status = result.status;
-                }
-                globalContext.set(node_name, this.profile);
+                  this.warn("Profile temperature not numeric.");
+                }         
+                //this.warn("default "+this.profile.name);
+                this.current_status = {fill:"green",shape:"dot",text:"profile set to default ("+this.profile.name+")"};
               } else {
                 this.current_status = result.status;
-                this.warn(msg.payload+" not found");
               }
-              this.status(this.current_status);
-              break;
-              
-            case "checkUpdate":
-              var version = readNodeVersion();
-              var pck_name = "node-red-contrib-ramp-thermostat";
-              
-              read_npmVersion(pck_name, function(npm_version) {
-                if (npm_version > version) {
-                  this.warn("A new "+pck_name+" version "+npm_version+" is avaiable.");
-                } else {
-                  this.warn(pck_name+" "+version+" is up to date.");
-                }
-              }.bind(this));
+              globalContext.set(node_name, this.profile);
+            } else {
+              this.current_status = result.status;
+              this.warn(msg.payload+" not found");
+            }
+            this.status(this.current_status);
+            break;
+            
+          case "checkUpdate":
+            var version = readNodeVersion();
+            var pck_name = "node-red-contrib-ramp-thermostat";
+            
+            read_npmVersion(pck_name, function(npm_version) {
+              if (npm_version > version) {
+                this.warn("A new "+pck_name+" version "+npm_version+" is avaiable.");
+              } else {
+                this.warn(pck_name+" "+version+" is up to date.");
+              }
+            }.bind(this));
 
-              this.warn("ramp-thermostat version: "+version);
-              this.status({fill:"green",shape:"dot",text:"version: "+version});
-              var set_timeout = setTimeout(function() {
-                this.status(this.current_status);
-              }.bind(this), 4000);
-              break;
-              
-            default:
-              this.warn("invalid topic >"+msg.topic+"<");
-          }
-        }       
+            this.warn("ramp-thermostat version: "+version);
+            this.status({fill:"green",shape:"dot",text:"version: "+version});
+            var set_timeout = setTimeout(function() {
+              this.status(this.current_status);
+            }.bind(this), 4000);
+            break;
+            
+          default:
+            this.warn("invalid topic >"+msg.topic+"<");
+        }
       }
     });
   }